4 * Copyright (C) 2005-2013 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/WindowIDs.h"
26 #include "threads/Thread.h"
27 #include "threads/Event.h"
28 #include <boost/shared_ptr.hpp>
31 #include "utils/GlobalsHandling.h"
47 #define TMSG_DIALOG_DOMODAL 100
48 #define TMSG_EXECUTE_SCRIPT 102
49 #define TMSG_EXECUTE_BUILT_IN 103
50 #define TMSG_EXECUTE_OS 104
52 #define TMSG_MEDIA_PLAY 200
53 #define TMSG_MEDIA_STOP 201
54 // the PAUSE is indeed a PLAYPAUSE
55 #define TMSG_MEDIA_PAUSE 202
56 #define TMSG_MEDIA_RESTART 203
57 #define TMSG_MEDIA_UNPAUSE 204
58 #define TMSG_MEDIA_PAUSE_IF_PLAYING 205
60 #define TMSG_PLAYLISTPLAYER_PLAY 210
61 #define TMSG_PLAYLISTPLAYER_NEXT 211
62 #define TMSG_PLAYLISTPLAYER_PREV 212
63 #define TMSG_PLAYLISTPLAYER_ADD 213
64 #define TMSG_PLAYLISTPLAYER_CLEAR 214
65 #define TMSG_PLAYLISTPLAYER_SHUFFLE 215
66 #define TMSG_PLAYLISTPLAYER_GET_ITEMS 216
67 #define TMSG_PLAYLISTPLAYER_PLAY_SONG_ID 217
68 #define TMSG_PLAYLISTPLAYER_INSERT 218
69 #define TMSG_PLAYLISTPLAYER_REMOVE 219
70 #define TMSG_PLAYLISTPLAYER_SWAP 223
71 #define TMSG_PLAYLISTPLAYER_REPEAT 224
72 #define TMSG_UPDATE_CURRENT_ITEM 225
74 #define TMSG_PICTURE_SHOW 220
75 #define TMSG_PICTURE_SLIDESHOW 221
77 #define TMSG_SHUTDOWN 300
78 #define TMSG_POWERDOWN 301
80 #define TMSG_HIBERNATE 303
81 #define TMSG_SUSPEND 304
82 #define TMSG_RESTART 305
83 #define TMSG_RESET 306
84 #define TMSG_RESTARTAPP 307
85 #define TMSG_SWITCHTOFULLSCREEN 308
86 #define TMSG_MINIMIZE 309
87 #define TMSG_TOGGLEFULLSCREEN 310
88 #define TMSG_SETLANGUAGE 311
89 #define TMSG_RENDERER_FLUSH 312
90 #define TMSG_INHIBITIDLESHUTDOWN 313
91 #define TMSG_LOADPROFILE 314
92 #define TMSG_ACTIVATESCREENSAVER 315
94 #define TMSG_NETWORKMESSAGE 500
96 #define TMSG_GUI_DO_MODAL 600
97 #define TMSG_GUI_SHOW 601
98 #define TMSG_GUI_ACTIVATE_WINDOW 604
99 #define TMSG_GUI_PYTHON_DIALOG 605
100 #define TMSG_GUI_WINDOW_CLOSE 606
101 #define TMSG_GUI_ACTION 607
102 #define TMSG_GUI_INFOLABEL 608
103 #define TMSG_GUI_INFOBOOL 609
104 #define TMSG_GUI_ADDON_DIALOG 610
105 #define TMSG_GUI_MESSAGE 611
106 #define TMSG_START_ANDROID_ACTIVITY 612
108 #define TMSG_CALLBACK 800
110 #define TMSG_VOLUME_SHOW 900
111 #define TMSG_SPLASH_MESSAGE 901
113 #define TMSG_DISPLAY_SETUP 1000
114 #define TMSG_DISPLAY_DESTROY 1001
118 unsigned int dwMessage;
119 unsigned int dwParam1;
120 unsigned int dwParam2;
122 std::vector<CStdString> params;
123 boost::shared_ptr<CEvent> waitEvent;
128 class CDelayedMessage : public CThread
131 CDelayedMessage(ThreadMessage& msg, unsigned int delay);
132 virtual void Process();
135 unsigned int m_delay;
139 struct ThreadMessageCallback
141 void (*callback)(void *userptr);
145 class CApplicationMessenger;
148 template<class T> class GlobalsSingleton;
151 class CApplicationMessenger
155 \brief The only way through which the global instance of the CApplicationMessenger should be accessed.
156 \return the global instance.
158 static CApplicationMessenger& Get();
161 // if a message has to be send to the gui, use MSG_TYPE_WINDOW instead
162 void SendMessage(ThreadMessage& msg, bool wait = false);
163 void ProcessMessages(); // only call from main thread.
164 void ProcessWindowMessages();
167 void MediaPlay(std::string filename);
168 void MediaPlay(const CFileItem &item);
169 void MediaPlay(const CFileItemList &item, int song = 0);
170 void MediaPlay(int playlistid, int song = -1);
171 void MediaStop(bool bWait = true, int playlistid = -1);
174 void MediaPauseIfPlaying();
175 void MediaRestart(bool bWait);
177 void PlayListPlayerPlay();
178 void PlayListPlayerPlay(int iSong);
179 bool PlayListPlayerPlaySongId(int songId);
180 void PlayListPlayerNext();
181 void PlayListPlayerPrevious();
182 void PlayListPlayerAdd(int playlist, const CFileItem &item);
183 void PlayListPlayerAdd(int playlist, const CFileItemList &list);
184 void PlayListPlayerClear(int playlist);
185 void PlayListPlayerShuffle(int playlist, bool shuffle);
186 void PlayListPlayerGetItems(int playlist, CFileItemList &list);
187 void PlayListPlayerInsert(int playlist, const CFileItem &item, int position);
188 void PlayListPlayerInsert(int playlist, const CFileItemList &list, int position);
189 void PlayListPlayerRemove(int playlist, int position);
190 void PlayListPlayerSwap(int playlist, int indexItem1, int indexItem2);
191 void PlayListPlayerRepeat(int playlist, int repeatState);
193 void PlayFile(const CFileItem &item, bool bRestart = false); // thread safe version of g_application.PlayFile()
194 void PictureShow(std::string filename);
195 void PictureSlideShow(std::string pathname, bool addTBN = false);
196 void SetGUILanguage(const std::string &strLanguage);
205 void InhibitIdleShutdown(bool inhibit);
206 void ActivateScreensaver();
207 void SwitchToFullscreen(); //
208 void Minimize(bool wait = false);
209 void ExecOS(const CStdString command, bool waitExit = false);
210 void UserEvent(int code);
211 //! \brief Set the tag for the currently playing song
212 void SetCurrentSongTag(const MUSIC_INFO::CMusicInfoTag& tag);
213 //! \brief Set the tag for the currently playing video
214 void SetCurrentVideoTag(const CVideoInfoTag& tag);
215 //! \brief Set the currently currently item
216 void SetCurrentItem(const CFileItem& item);
218 void LoadProfile(unsigned int idx);
220 CStdString GetResponse();
221 int SetResponse(CStdString response);
222 void ExecBuiltIn(const CStdString &command, bool wait = false);
224 void NetworkMessage(unsigned int dwMessage, unsigned int dwParam = 0);
226 void DoModal(CGUIDialog *pDialog, int iWindowID, const CStdString ¶m = "");
227 void Show(CGUIDialog *pDialog);
228 void Close(CGUIWindow *window, bool forceClose, bool waitResult = true, int nextWindowID = 0, bool enableSound = true);
229 void ActivateWindow(int windowID, const std::vector<CStdString> ¶ms, bool swappingWindows);
230 void SendAction(const CAction &action, int windowID = WINDOW_INVALID, bool waitResult=true);
232 /*! \brief Send a GUIMessage, optionally waiting before it's processed to return.
233 Should be used to send messages to the GUI from other threads.
234 \param msg the GUIMessage to send.
235 \param windowID optional window to send the message to (defaults to no specified window).
236 \param waitResult whether to wait for the result (defaults to false).
238 void SendGUIMessage(const CGUIMessage &msg, int windowID = WINDOW_INVALID, bool waitResult=false);
240 std::vector<CStdString> GetInfoLabels(const std::vector<CStdString> &properties);
241 std::vector<bool> GetInfoBooleans(const std::vector<CStdString> &properties);
243 void ShowVolumeBar(bool up);
245 void SetSplashMessage(const CStdString& message);
246 void SetSplashMessage(int stringID);
249 bool DestroyDisplay();
250 void StartAndroidActivity(const std::vector<CStdString> ¶ms);
252 virtual ~CApplicationMessenger();
254 // private construction, and no assignements; use the provided singleton methods
255 friend class xbmcutil::GlobalsSingleton<CApplicationMessenger>;
256 CApplicationMessenger();
257 CApplicationMessenger(const CApplicationMessenger&);
258 CApplicationMessenger const& operator=(CApplicationMessenger const&);
259 void ProcessMessage(ThreadMessage *pMsg);
261 std::queue<ThreadMessage*> m_vecMessages;
262 std::queue<ThreadMessage*> m_vecWindowMessages;
263 CCriticalSection m_critSection;
264 CCriticalSection m_critBuffer;
265 CStdString bufferResponse;
268 XBMC_GLOBAL_REF(CApplicationMessenger,s_messenger);
269 #define s_messenger XBMC_GLOBAL_USE(CApplicationMessenger)