2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "AddonCallback.h"
12 #include "AddonString.h"
20 /// \ingroup python_xbmc
21 /// \defgroup python_monitor Monitor
23 /// @brief **Kodi's monitor class.**
25 /// \python_class{ xbmc.Monitor() }
27 /// Creates a new monitor to notify addon about changes.
29 class Monitor
: public AddonCallback
38 inline void OnSettingsChanged() { XBMC_TRACE
; invokeCallback(new CallbackFunction
<Monitor
>(this,&Monitor::onSettingsChanged
)); }
39 inline void OnScreensaverActivated() { XBMC_TRACE
; invokeCallback(new CallbackFunction
<Monitor
>(this,&Monitor::onScreensaverActivated
)); }
40 inline void OnScreensaverDeactivated() { XBMC_TRACE
; invokeCallback(new CallbackFunction
<Monitor
>(this,&Monitor::onScreensaverDeactivated
)); }
41 inline void OnDPMSActivated() { XBMC_TRACE
; invokeCallback(new CallbackFunction
<Monitor
>(this,&Monitor::onDPMSActivated
)); }
42 inline void OnDPMSDeactivated() { XBMC_TRACE
; invokeCallback(new CallbackFunction
<Monitor
>(this,&Monitor::onDPMSDeactivated
)); }
43 inline void OnScanStarted(const String
&library
)
47 new CallbackFunction
<Monitor
, const String
>(this, &Monitor::onScanStarted
, library
));
49 inline void OnScanFinished(const String
&library
)
53 new CallbackFunction
<Monitor
, const String
>(this, &Monitor::onScanFinished
, library
));
55 inline void OnCleanStarted(const String
& library
)
59 new CallbackFunction
<Monitor
, const String
>(this, &Monitor::onCleanStarted
, library
));
61 inline void OnCleanFinished(const String
& library
)
65 new CallbackFunction
<Monitor
, const String
>(this, &Monitor::onCleanFinished
, library
));
67 inline void OnNotification(const String
& sender
, const String
& method
, const String
& data
)
70 invokeCallback(new CallbackFunction
<Monitor
, const String
, const String
, const String
>(
71 this, &Monitor::onNotification
, sender
, method
, data
));
74 inline const String
& GetId() { return Id
; }
75 inline long GetInvokerId() { return invokerId
; }
78 * Called from XBPython to notify registered monitors that a script is aborting/ending.
83 #ifdef DOXYGEN_SHOULD_USE_THIS
85 /// \ingroup python_monitor
86 /// @brief \python_func{ onSettingsChanged() }
87 /// onSettingsChanged method.
89 /// Will be called when addon settings are changed
93 virtual void onSettingsChanged() { XBMC_TRACE
; }
96 #ifdef DOXYGEN_SHOULD_USE_THIS
98 /// \ingroup python_monitor
99 /// @brief \python_func{ onScreensaverActivated() }
100 /// onScreensaverActivated method.
102 /// Will be called when screensaver kicks in
104 onScreensaverActivated();
106 virtual void onScreensaverActivated() { XBMC_TRACE
; }
109 #ifdef DOXYGEN_SHOULD_USE_THIS
111 /// \ingroup python_monitor
112 /// @brief \python_func{ onScreensaverDeactivated() }
113 /// onScreensaverDeactivated method.
115 /// Will be called when screensaver goes off
117 onScreensaverDeactivated();
119 virtual void onScreensaverDeactivated() { XBMC_TRACE
; }
122 #ifdef DOXYGEN_SHOULD_USE_THIS
124 /// \ingroup python_monitor
125 /// @brief \python_func{ onDPMSActivated() }
126 /// onDPMSActivated method.
128 /// Will be called when energysaving/DPMS gets active
132 virtual void onDPMSActivated() { XBMC_TRACE
; }
135 #ifdef DOXYGEN_SHOULD_USE_THIS
137 /// \ingroup python_monitor
138 /// @brief \python_func{ onDPMSDeactivated() }
139 /// onDPMSDeactivated method.
141 /// Will be called when energysaving/DPMS is turned off
145 virtual void onDPMSDeactivated() { XBMC_TRACE
; }
148 #ifdef DOXYGEN_SHOULD_USE_THIS
150 /// \ingroup python_monitor
151 /// @brief \python_func{ onScanStarted(library) }
152 /// onScanStarted method.
154 /// @param library Video / music as string
157 /// @note Will be called when library clean has ended and return video or
158 /// music to indicate which library is being scanned
161 ///-----------------------------------------------------------------------
162 /// @python_v14 New function added.
166 virtual void onScanStarted(const String library
) { XBMC_TRACE
; }
169 #ifdef DOXYGEN_SHOULD_USE_THIS
171 /// \ingroup python_monitor
172 /// @brief \python_func{ onScanFinished(library) }
173 /// onScanFinished method.
175 /// @param library Video / music as string
178 /// @note Will be called when library clean has ended and return video or
179 /// music to indicate which library has been scanned
182 ///-----------------------------------------------------------------------
183 /// @python_v14 New function added.
187 virtual void onScanFinished(const String library
) { XBMC_TRACE
; }
190 #ifdef DOXYGEN_SHOULD_USE_THIS
192 /// \ingroup python_monitor
193 /// @brief \python_func{ onCleanStarted(library) }
194 /// onCleanStarted method.
196 /// @param library Video / music as string
199 /// @note Will be called when library clean has ended and return video or
200 /// music to indicate which library has been cleaned
203 ///-----------------------------------------------------------------------
204 /// @python_v14 New function added.
208 virtual void onCleanStarted(const String library
) { XBMC_TRACE
; }
211 #ifdef DOXYGEN_SHOULD_USE_THIS
213 /// \ingroup python_monitor
214 /// @brief \python_func{ onCleanFinished(library) }
215 /// onCleanFinished method.
217 /// @param library Video / music as string
220 /// @note Will be called when library clean has ended and return video or
221 /// music to indicate which library has been finished
224 ///-----------------------------------------------------------------------
225 /// @python_v14 New function added.
227 onCleanFinished(...);
229 virtual void onCleanFinished(const String library
) { XBMC_TRACE
; }
232 #ifdef DOXYGEN_SHOULD_USE_THIS
234 /// \ingroup python_monitor
235 /// @brief \python_func{ onNotification(sender, method, data) }
236 /// onNotification method.
238 /// @param sender Sender of the notification
239 /// @param method Name of the notification
240 /// @param data JSON-encoded data of the notification
242 /// @note Will be called when Kodi receives or sends a notification
245 ///-----------------------------------------------------------------------
246 /// @python_v13 New function added.
250 virtual void onNotification(const String sender
, const String method
, const String data
)
256 #ifdef DOXYGEN_SHOULD_USE_THIS
257 /// \ingroup python_monitor
258 /// @brief \python_func{ waitForAbort([timeout]) }
260 /// \anchor xbmc_Monitor_waitForAbort
262 /// Block until abort is requested, or until timeout occurs. If an
263 /// abort requested have already been made, return immediately.
265 /// @param timeout [opt] float - timeout in seconds.
266 /// Default: no timeout.
268 /// @return True when abort have been requested,
269 /// False if a timeout is given and the
270 /// operation times out.
273 ///-----------------------------------------------------------------------
274 /// @python_v14 New function added.
277 /// ~~~~~~~~~~~~~{.py}
279 /// monitor = xbmc.Monitor()
281 /// monitor.waitForAbort(10) # sleeps for 10 secs or returns early if kodi aborts
282 /// if monitor.abortRequested():
283 /// # abort was requested to Kodi (e.g. shutdown), do your cleanup logic
289 bool waitForAbort(double timeout
= -1);
292 #ifdef DOXYGEN_SHOULD_USE_THIS
293 /// \ingroup python_monitor
294 /// @brief \python_func{ abortRequested() }
295 /// Returns True if abort has been requested.
297 /// @return True if requested
300 ///-----------------------------------------------------------------------
301 /// @python_v14 New function added.
305 bool abortRequested();