4 * Copyright (C) 2005-2012 Team XBMC
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with XBMC; see the file COPYING. If not, see
19 * <http://www.gnu.org/licenses/>.
23 #include "threads/CriticalSection.h"
24 #include "utils/StdString.h"
25 #include "guilib/Key.h"
26 #include "threads/Thread.h"
27 #include "threads/Event.h"
28 #include <boost/shared_ptr.hpp>
30 #include "PlatformDefs.h"
33 #include "utils/GlobalsHandling.h"
48 #define TMSG_DIALOG_DOMODAL 100
49 #define TMSG_EXECUTE_SCRIPT 102
50 #define TMSG_EXECUTE_BUILT_IN 103
51 #define TMSG_EXECUTE_OS 104
53 #define TMSG_MEDIA_PLAY 200
54 #define TMSG_MEDIA_STOP 201
55 #define TMSG_MEDIA_PAUSE 202
56 #define TMSG_MEDIA_RESTART 203
57 #define TMSG_MEDIA_UNPAUSE 204
59 #define TMSG_PLAYLISTPLAYER_PLAY 210
60 #define TMSG_PLAYLISTPLAYER_NEXT 211
61 #define TMSG_PLAYLISTPLAYER_PREV 212
62 #define TMSG_PLAYLISTPLAYER_ADD 213
63 #define TMSG_PLAYLISTPLAYER_CLEAR 214
64 #define TMSG_PLAYLISTPLAYER_SHUFFLE 215
65 #define TMSG_PLAYLISTPLAYER_GET_ITEMS 216
66 #define TMSG_PLAYLISTPLAYER_PLAY_SONG_ID 217
67 #define TMSG_PLAYLISTPLAYER_INSERT 218
68 #define TMSG_PLAYLISTPLAYER_REMOVE 219
69 #define TMSG_PLAYLISTPLAYER_SWAP 223
70 #define TMSG_PLAYLISTPLAYER_REPEAT 224
71 #define TMSG_UPDATE_CURRENT_ITEM 225
73 #define TMSG_PICTURE_SHOW 220
74 #define TMSG_PICTURE_SLIDESHOW 221
76 #define TMSG_SHUTDOWN 300
77 #define TMSG_POWERDOWN 301
79 #define TMSG_HIBERNATE 303
80 #define TMSG_SUSPEND 304
81 #define TMSG_RESTART 305
82 #define TMSG_RESET 306
83 #define TMSG_RESTARTAPP 307
84 #define TMSG_SWITCHTOFULLSCREEN 308
85 #define TMSG_MINIMIZE 309
86 #define TMSG_TOGGLEFULLSCREEN 310
87 #define TMSG_SETLANGUAGE 311
88 #define TMSG_RENDERER_FLUSH 312
89 #define TMSG_INHIBITIDLESHUTDOWN 313
90 #define TMSG_LOADPROFILE 314
92 #define TMSG_NETWORKMESSAGE 500
94 #define TMSG_GUI_DO_MODAL 600
95 #define TMSG_GUI_SHOW 601
96 #define TMSG_GUI_ACTIVATE_WINDOW 604
97 #define TMSG_GUI_PYTHON_DIALOG 605
98 #define TMSG_GUI_WINDOW_CLOSE 606
99 #define TMSG_GUI_ACTION 607
100 #define TMSG_GUI_INFOLABEL 608
101 #define TMSG_GUI_INFOBOOL 609
102 #define TMSG_GUI_ADDON_DIALOG 610
103 #define TMSG_GUI_MESSAGE 611
105 #define TMSG_CALLBACK 800
107 #define TMSG_VOLUME_SHOW 900
108 #define TMSG_SPLASH_MESSAGE 901
110 #define TMSG_DISPLAY_SETUP 1000
111 #define TMSG_DISPLAY_DESTROY 1001
119 std::vector<CStdString> params;
120 boost::shared_ptr<CEvent> waitEvent;
125 class CDelayedMessage : public CThread
128 CDelayedMessage(ThreadMessage& msg, unsigned int delay);
129 virtual void Process();
132 unsigned int m_delay;
136 struct ThreadMessageCallback
138 void (*callback)(void *userptr);
142 class CApplicationMessenger;
145 template<class T> class GlobalsSingleton;
148 class CApplicationMessenger
152 \brief The only way through which the global instance of the CApplicationMessenger should be accessed.
153 \return the global instance.
155 static CApplicationMessenger& Get();
158 // if a message has to be send to the gui, use MSG_TYPE_WINDOW instead
159 void SendMessage(ThreadMessage& msg, bool wait = false);
160 void ProcessMessages(); // only call from main thread.
161 void ProcessWindowMessages();
164 void MediaPlay(std::string filename);
165 void MediaPlay(const CFileItem &item);
166 void MediaPlay(const CFileItemList &item, int song = 0);
167 void MediaPlay(int playlistid, int song = -1);
168 void MediaStop(bool bWait = true);
170 void MediaRestart(bool bWait);
172 void PlayListPlayerPlay();
173 void PlayListPlayerPlay(int iSong);
174 bool PlayListPlayerPlaySongId(int songId);
175 void PlayListPlayerNext();
176 void PlayListPlayerPrevious();
177 void PlayListPlayerAdd(int playlist, const CFileItem &item);
178 void PlayListPlayerAdd(int playlist, const CFileItemList &list);
179 void PlayListPlayerClear(int playlist);
180 void PlayListPlayerShuffle(int playlist, bool shuffle);
181 void PlayListPlayerGetItems(int playlist, CFileItemList &list);
182 void PlayListPlayerInsert(int playlist, const CFileItem &item, int position);
183 void PlayListPlayerInsert(int playlist, const CFileItemList &list, int position);
184 void PlayListPlayerRemove(int playlist, int position);
185 void PlayListPlayerSwap(int playlist, int indexItem1, int indexItem2);
186 void PlayListPlayerRepeat(int playlist, int repeatState);
188 void PlayFile(const CFileItem &item, bool bRestart = false); // thread safe version of g_application.PlayFile()
189 void PictureShow(std::string filename);
190 void PictureSlideShow(std::string pathname, bool addTBN = false);
191 void SetGUILanguage(const std::string &strLanguage);
200 void InhibitIdleShutdown(bool inhibit);
201 void SwitchToFullscreen(); //
202 void Minimize(bool wait = false);
203 void ExecOS(const CStdString command, bool waitExit = false);
204 void UserEvent(int code);
205 //! \brief Set the tag for the currently playing song
206 void SetCurrentSongTag(const MUSIC_INFO::CMusicInfoTag& tag);
207 //! \brief Set the tag for the currently playing video
208 void SetCurrentVideoTag(const CVideoInfoTag& tag);
209 //! \brief Set the currently currently item
210 void SetCurrentItem(const CFileItem& item);
212 void LoadProfile(unsigned int idx);
214 CStdString GetResponse();
215 int SetResponse(CStdString response);
216 void ExecBuiltIn(const CStdString &command, bool wait = false);
218 void NetworkMessage(DWORD dwMessage, DWORD dwParam = 0);
220 void DoModal(CGUIDialog *pDialog, int iWindowID, const CStdString ¶m = "");
221 void Show(CGUIDialog *pDialog);
222 void Close(CGUIWindow *window, bool forceClose, bool waitResult = true, int nextWindowID = 0, bool enableSound = true);
223 void ActivateWindow(int windowID, const std::vector<CStdString> ¶ms, bool swappingWindows);
224 void SendAction(const CAction &action, int windowID = WINDOW_INVALID, bool waitResult=true);
226 /*! \brief Send a GUIMessage, optionally waiting before it's processed to return.
227 Should be used to send messages to the GUI from other threads.
228 \param msg the GUIMessage to send.
229 \param windowID optional window to send the message to (defaults to no specified window).
230 \param waitResult whether to wait for the result (defaults to false).
232 void SendGUIMessage(const CGUIMessage &msg, int windowID = WINDOW_INVALID, bool waitResult=false);
234 std::vector<CStdString> GetInfoLabels(const std::vector<CStdString> &properties);
235 std::vector<bool> GetInfoBooleans(const std::vector<CStdString> &properties);
237 void ShowVolumeBar(bool up);
239 void SetSplashMessage(const CStdString& message);
240 void SetSplashMessage(int stringID);
243 bool DestroyDisplay();
245 virtual ~CApplicationMessenger();
247 // private construction, and no assignements; use the provided singleton methods
248 friend class xbmcutil::GlobalsSingleton<CApplicationMessenger>;
249 CApplicationMessenger();
250 CApplicationMessenger(const CApplicationMessenger&);
251 CApplicationMessenger const& operator=(CApplicationMessenger const&);
252 void ProcessMessage(ThreadMessage *pMsg);
254 std::queue<ThreadMessage*> m_vecMessages;
255 std::queue<ThreadMessage*> m_vecWindowMessages;
256 CCriticalSection m_critSection;
257 CCriticalSection m_critBuffer;
258 CStdString bufferResponse;
261 XBMC_GLOBAL_REF(CApplicationMessenger,s_messenger);
262 #define s_messenger XBMC_GLOBAL_USE(CApplicationMessenger)