You.i Engine
YiTizenNaClMessaging.h
Go to the documentation of this file.
1 // © You i Labs Inc. 2000-2017. All rights reserved.
2 #if defined(YI_TIZEN_NACL)
3 #ifndef _YI_TIZEN_NACL_MESSAGING_
4 #define _YI_TIZEN_NACL_MESSAGING_
5 
7 
8 #pragma GCC diagnostic push
9 #pragma GCC diagnostic ignored "-Wfloat-equal"
10 #include <ppapi/cpp/instance.h>
11 #include <ppapi/cpp/var_dictionary.h>
12 #pragma GCC diagnostic pop
13 
83 class CYITizenNaClMessaging
84 {
85 public:
86 
87  struct SynchronousResponseData
88  {
89  SynchronousResponseData() : latch(1) {};
90  pp::Var result;
91  CYICountDownLatch latch;
92  };
93 
98  static CYITizenNaClMessaging *GetInstance();
99 
103  void PostMessageNoResponse(const pp::Var &message);
104 
109  pp::Var PostMessageSyncResponse(const pp::Var &message, const CYIString &key, uint32_t uTimeoutMs);
110 
118  void PostMessageAsyncResponse(const pp::Var &message, const CYIString &key, CYISignal<pp::Var> *pResponseSignal);
119 
128  bool RegisterListener(const CYIString &key, CYISignal<pp::VarDictionary> *pOnEventSignal);
129 
135  bool UnregisterListener(const CYIString &key, CYISignal<pp::VarDictionary> *pOnEventSignal);
136 
137  /*
138  \details Provides a message event to be handled. This is called when the application receives a
139  PSE_INSTANCE_HANDLEMESSAGE event containing a pp::VarDictionary so that the event can be dispatched
140  to the correct listener. Returns true if the message was passed to a listener.
141  */
142  bool HandleMessageEvent(const pp::VarDictionary &dictionaryEvent);
143 
144  /*
145  \details Creates a simple "command" dictionary. The \a key (if provided) must match the key sent to PPInstance::PostMessage.
146  */
147  static pp::VarDictionary CreateCommandDictionary(const CYIString &className, const CYIString &methodName, const CYIString &key = CYIString::EMPTY_STRING);
148 
149  /*
150  \details Creates a simple "command" dictionary. The \a key (if provided) must match the key sent to PPInstance::PostMessage.
151  The \a method dictionary should be complete with a "name" entry and any other parameters needed by the target method.
152  */
153  static pp::VarDictionary CreateCommandDictionary(const CYIString &className, const pp::VarDictionary &method, const CYIString &key = CYIString::EMPTY_STRING);
154 private:
155  struct TizenEvent
156  {
157  CYIString key;
158  CYISignal<pp::VarDictionary> *pOnEventSignal;
159 
160  TizenEvent(const CYIString &key, CYISignal<pp::VarDictionary> *pOnEventSignal)
161  : key(key)
162  , pOnEventSignal(pOnEventSignal)
163  {
164  };
165  };
166 
167  CYITizenNaClMessaging();
168 
169  CYIMutex m_listenersMutex;
170  std::vector<TizenEvent> m_registeredListeners;
171  pp::Instance m_PPInstance;
172 };
173 
174 
177 #endif // _YI_TIZEN_NACL_MESSAGING_
178 #endif // YI_TIZEN_NACL
Definition: YiMutex.h:110
Container class for Unicode strings. Conceptually, a CYIString object is a sequence of Unicode charac...
Definition: YiString.h:35
Definition: YiCountDownLatch.h:32
Signals and slots are a thread-safe and flexible communication framework that will allow various obje...
Definition: YiSignal.h:164
static const CYIString EMPTY_STRING
Definition: YiString.h:37