kodi
LanguageHook.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "AddonClass.h"
12 #include "CallbackHandler.h"
13 #include "threads/Event.h"
14 
20 class IPlayerCallback;
21 
22 namespace XBMCAddon
23 {
24  namespace xbmc
25  {
26  class Monitor;
27  }
28 
29  class LanguageHook : public AddonClass
30  {
31  protected:
32  inline LanguageHook() = default;
33 
34  public:
35  ~LanguageHook() override;
36 
47  virtual void DelayedCallOpen() { }
48 
61  virtual void DelayedCallClose() { }
62 
63  virtual void MakePendingCalls() {}
64 
69  virtual CallbackHandler* GetCallbackHandler() { return NULL; }
70 
78  virtual void Constructing(AddonClass* beingConstructed) { }
79 
87  virtual void Destructing(AddonClass* beingDestructed) { }
88 
99  virtual String GetAddonId() { return emptyString; }
100  virtual String GetAddonVersion() { return emptyString; }
101  virtual long GetInvokerId() { return -1; }
102 
103  virtual void RegisterPlayerCallback(IPlayerCallback* player) = 0;
104  virtual void UnregisterPlayerCallback(IPlayerCallback* player) = 0;
105  virtual void RegisterMonitorCallback(XBMCAddon::xbmc::Monitor* player) = 0;
106  virtual void UnregisterMonitorCallback(XBMCAddon::xbmc::Monitor* player) = 0;
107  virtual bool WaitForEvent(CEvent& hEvent, unsigned int milliseconds) = 0;
108 
109  static void SetLanguageHook(LanguageHook* languageHook);
110  static LanguageHook* GetLanguageHook();
111  static void ClearLanguageHook();
112  };
113 
123  {
124  LanguageHook* languageHook;
125  bool clearOnExit = false;
126 
127  public:
128  inline explicit DelayedCallGuard(LanguageHook* languageHook_) : languageHook(languageHook_)
129  { if (languageHook) languageHook->DelayedCallOpen(); }
130 
131  inline DelayedCallGuard() : languageHook(LanguageHook::GetLanguageHook())
132  { if (languageHook) languageHook->DelayedCallOpen(); }
133 
134  inline ~DelayedCallGuard()
135  {
136  if (clearOnExit) LanguageHook::ClearLanguageHook();
137  if (languageHook) languageHook->DelayedCallClose();
138  }
139 
140  inline LanguageHook* getLanguageHook() { return languageHook; }
141  };
142 
144  {
145  public:
146  inline explicit SetLanguageHookGuard(LanguageHook* languageHook) { LanguageHook::SetLanguageHook(languageHook); }
147  inline ~SetLanguageHookGuard() { LanguageHook::ClearLanguageHook(); }
148  };
149 
150 }
151 
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
virtual void Constructing(AddonClass *beingConstructed)
This is a callback method that can be overridden to receive a callback when an AddonClass that has th...
Definition: LanguageHook.h:78
virtual String GetAddonId()
This method should be done a different way but since the only other way I can think to do it requires...
Definition: LanguageHook.h:99
This is the abstraction representing different ways to handle the execution of callbacks.
Definition: CallbackHandler.h:21
virtual void DelayedCallClose()
If the scripting language needs special handling for calls that block or are delayed in any other mea...
Definition: LanguageHook.h:61
virtual void DelayedCallOpen()
If the scripting language needs special handling for calls that block or are delayed in any other mea...
Definition: LanguageHook.h:47
Definition: Monitor.h:29
Defining LOG_LIFECYCLE_EVENTS will log all instantiations, deletions and also reference countings (in...
Definition: Addon.cpp:25
Definition: IPlayerCallback.h:18
Definition: LanguageHook.h:143
Definition: LanguageHook.h:29
virtual CallbackHandler * GetCallbackHandler()
For scripting languages that need a global callback handler, this method should be overloaded to supp...
Definition: LanguageHook.h:69
This class can be used to access the language hook's DelayedCallOpen and DelayedCallClose.
Definition: LanguageHook.h:122
virtual void Destructing(AddonClass *beingDestructed)
This is a callback method that can be overridden to receive a callback when an AddonClass that has th...
Definition: LanguageHook.h:87
This class is the superclass for all reference counted classes in the api.
Definition: AddonClass.h:57