mod_MobileDial.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #ifndef _MOD_MOBILE_DIAL_H
  2. #define _MOD_MOBILE_DIAL_H
  3. #pragma once
  4. #include "MobileDialFSM.h"
  5. using namespace MobileDial;
  6. #if HAS_NEW_ALL_IN_ONE
  7. #include "../mod_WirelessDevAgent/WirelessDevAgent_client_g.h"
  8. #include "../mod_WirelessDevAgent/WirelessDevAgent_msg_g.h"
  9. #endif
  10. class CMobileDialEntity;
  11. class CMobileDialServerSession: public MobileDialService_ServerSessionBase
  12. {
  13. public:
  14. CMobileDialServerSession(CMobileDialEntity *pEntity):m_pEntity(pEntity){}
  15. virtual ~CMobileDialServerSession(){}
  16. virtual void Handle_Query(SpReqAnsContext<MobileDialService_Query_Req, MobileDialService_Query_Ans>::Pointer ctx);
  17. virtual void Handle_GetDevInfo(SpReqAnsContext<MobileDialService_GetDevInfo_Req, MobileDialService_GetDevInfo_Ans>::Pointer ctx);
  18. virtual void Handle_ShowDialog(SpOnewayCallContext<MobileDialService_ShowDialog_Info>::Pointer ctx);
  19. private:
  20. CMobileDialEntity *m_pEntity;
  21. };
  22. class CMobileDialEntity : public CEntityBase
  23. #if HAS_NEW_ALL_IN_ONE
  24. , public IBroadcastListener
  25. #endif
  26. {
  27. public:
  28. CMobileDialEntity(): m_bDialogCreateBusy(false),m_hDialogWnd(NULL),m_hGUIReadyEvent(NULL), m_hGUIClosedEvent(NULL){}
  29. virtual ~CMobileDialEntity(){
  30. if (m_hGUIReadyEvent != 0)
  31. {
  32. CloseHandle(m_hGUIReadyEvent);
  33. m_hGUIReadyEvent = 0;
  34. }
  35. if (m_hGUIClosedEvent != 0)
  36. {
  37. CloseHandle(m_hGUIClosedEvent);
  38. m_hGUIClosedEvent = 0;
  39. }
  40. }
  41. virtual const char *GetEntityName() const { return "MobileDial"; }
  42. virtual CServerSessionBase* OnNewSession(const char* , const char * )
  43. {
  44. LOG_FUNCTION();
  45. return new CMobileDialServerSession(this);
  46. }
  47. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  48. {
  49. ErrorCodeEnum rt = Error_Succeed;
  50. #if HAS_NEW_ALL_IN_ONE
  51. CSystemStaticInfo staticInfo;
  52. CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
  53. spEntityFunction->GetSystemStaticInfo(staticInfo);
  54. if(staticInfo.strSite.Compare("CMB.FLB", true) == 0) {
  55. rt = spEntityFunction->SubscribeBroadcast("WirelessDevAgent", NULL, this, m_uiWirelessListener);
  56. if(rt != 0) {
  57. LOG_TRACE("Subscribe WirelessDevAgent failed: %u", rt);
  58. } else {
  59. Dbg("Subscribe WirelessDevAgent successfully!");
  60. }
  61. }
  62. #endif
  63. rt = m_fsm.Init(this);
  64. pTransactionContext->SendAnswer(rt);
  65. }
  66. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  67. {
  68. CSimpleStringA str = EncryptString("cmb#$%^&*() !@123");
  69. Dbg("Encrpyted:(%s)", (LPCTSTR)str);
  70. CSimpleStringA str1 = DecryptString(str);
  71. Dbg("Decrpyted:(%s)", (LPCTSTR)str1);
  72. pTransactionContext->SendAnswer(Error_Succeed);
  73. }
  74. virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
  75. {
  76. //m_fsm._InsertLocal2MacFilter();
  77. //ULONG data;
  78. //m_fsm.GetPersistentRequestId(data);
  79. //Dbg("Request Id: %d", data);
  80. pTransactionContext->SendAnswer(Error_Succeed);
  81. }
  82. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  83. {
  84. m_fsm.OnExit();
  85. pTransactionContext->SendAnswer(Error_Succeed);
  86. }
  87. void Query(SpReqAnsContext<MobileDialService_Query_Req, MobileDialService_Query_Ans>::Pointer ctx)
  88. {
  89. LOG_FUNCTION();
  90. ctx->Ans.netstatus = m_fsm.GetSignalStatus();
  91. ctx->Ans.battery = m_fsm.GetBatteryRemains();
  92. Dbg("query result:%d,%d",ctx->Ans.netstatus,ctx->Ans.battery);
  93. // [Josephus in 16:20:30 2016/3/28]
  94. if(ctx->Ans.netstatus == 0) {
  95. ctx->Ans.reserved3 = m_fsm.GetFurtherDetail(TRUE);
  96. }
  97. ctx->Answer(Error_Succeed);
  98. }
  99. ErrorCodeEnum CreateMobileDialog(SpOnewayCallContext<MobileDialService_ShowDialog_Info>::Pointer ctx)
  100. {
  101. LOG_FUNCTION();
  102. if(IsDialogExisted()) {
  103. Dbg("Aleady creating the dialog, you should try again later");
  104. if(m_hDialogWnd) {
  105. if (IsIconic(m_hDialogWnd))
  106. ShowWindow(m_hDialogWnd, SW_RESTORE);
  107. else
  108. BringWindowToTop(m_hDialogWnd);
  109. }
  110. return Error_Block;
  111. }
  112. m_bDialogCreateBusy = true;
  113. if(m_hDialogWnd != NULL) {
  114. Dbg("Mobile dialog occurs duplicate!");
  115. m_bDialogCreateBusy = false;
  116. return Error_Duplication;
  117. }
  118. if (m_hGUIReadyEvent == 0) {
  119. m_hGUIReadyEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
  120. }
  121. if (m_hGUIClosedEvent == 0) {
  122. m_hGUIClosedEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
  123. }
  124. HANDLE hGUIThread = (HANDLE)_beginthreadex(0, 0, &WndThreadEntry, this, 0, 0);
  125. if (hGUIThread == 0) {
  126. Dbg("Create dialog entry thread failed : GLE=%d", GetLastError());
  127. m_bDialogCreateBusy = false;
  128. return Error_Resource;
  129. }
  130. CloseHandle(hGUIThread);
  131. m_fsm.PostEventLIFO(new FSMEvent(USER_EVT_DIALOG_INTO));
  132. if(WaitForSingleObject(m_hGUIReadyEvent, 10000) == WAIT_OBJECT_0) {
  133. Dbg("Receive the create-succeed signal !");
  134. m_bDialogCreateBusy = false;
  135. return Error_Succeed;
  136. }
  137. m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_DIALOG_OUT));
  138. m_bDialogCreateBusy = false;
  139. return Error_TimeOut;
  140. }
  141. void GetDevInfo(SpReqAnsContext<MobileDialService_GetDevInfo_Req, MobileDialService_GetDevInfo_Ans>::Pointer ctx)
  142. {
  143. }
  144. void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  145. {
  146. m_fsm.SelfTest(eTestType,pTransactionContext);
  147. }
  148. virtual bool IsService()const{return true;}
  149. virtual bool IsMultiThread()const{return true;}
  150. ErrorCodeEnum CloseDialog() {
  151. if (m_hDialogWnd == NULL)
  152. return Error_NotInit;
  153. ResetEvent(m_hGUIClosedEvent);
  154. PostMessage(m_hDialogWnd, WM_CLOSE, 0, 0);
  155. WaitForSingleObject(m_hGUIClosedEvent, INFINITE);
  156. return Error_Succeed;
  157. }
  158. bool IsDialogExisted() const {return (m_bDialogCreateBusy || m_hDialogWnd != NULL);}
  159. LPCTSTR GetLastErrMsg() const {
  160. return m_fsm.m_csErrMsg;
  161. }
  162. int UpdateDongleInfo() {
  163. LOG_FUNCTION();
  164. int res = m_fsm.RetrieveDongleInfo();
  165. return res < 0 ? res : g_DongleInfos.GetCount();
  166. }
  167. BOOL UpdateProfileInfo(LPCTSTR lpszInterfaceId);
  168. BOOL UpdateProfileInfo(int nCurSel);
  169. BOOL UpdateSubInfo(int nCurSel);
  170. ErrorCodeEnum Connect(int nWayToConnect, LPCTSTR lpszInterfaceID, LPCTSTR lpszProfileName);
  171. ErrorCodeEnum Disconnect(int nWayToConnect, LPCTSTR lpszInterfaceID);
  172. ErrorCodeEnum AddNewProfile(const CSimpleStringA csInterfaceID, const AccessKeyInfo newInfo, bool fApplyNow);
  173. ErrorCodeEnum UpdateProfile(const CSimpleStringA csInterfaceID, LPCTSTR lpszProfileName, const AccessKeyInfo newInfo, bool fApplyNow);
  174. ErrorCodeEnum DeleteProfile(int nDongleIdx, int nProfileIdx);
  175. ErrorCodeEnum SwitchDefaultSlot(int slotIdx);
  176. ErrorCodeEnum ConnectWIFIWithDefault();
  177. BOOL IsManageByUser() const {
  178. return m_fsm.m_bManageByUser;
  179. }
  180. int GetCurAdvancedConfig(bool fRead5RunCfg = false) {
  181. return m_fsm.GetAdvancedGen(fRead5RunCfg);
  182. }
  183. BOOL IsAndroidControl() {
  184. return m_fsm.isUsingNewVerAllInOne();
  185. }
  186. void GetMBBRunConfig(MBBParams& params, BOOL fSetDefaultIfEmpty) {
  187. m_fsm.GetMBBConfig(&params, fSetDefaultIfEmpty);
  188. }
  189. void SEtMBBRunConfig(const MBBParams& params) {
  190. m_fsm.SaveMBBConfig(&params, FALSE);
  191. }
  192. void RequireManageByUser(bool fEnable) {
  193. m_fsm.SetAutoManage(!fEnable);
  194. }
  195. void SetAdvancedConfig(int value) {
  196. m_fsm.SetAdvancedGen(value);
  197. }
  198. #if HAS_NEW_ALL_IN_ONE
  199. SP_BEGIN_MSG_DISPATCH_MAP(CMobileDialEntity)
  200. SP_BEGIN_ENTITY_MSG("WirelessDevAgent")
  201. SP_MSG_HANDLE_NS(WirelessDevAgent, NetStatusEvt, onWirelessNetStatusChanged)
  202. SP_END_ENTITY_MSG()
  203. SP_END_MSG_DISPATCH_MAP()
  204. #endif
  205. private:
  206. int WndEntry();
  207. static unsigned int WINAPI WndThreadEntry(PVOID param);
  208. #if HAS_NEW_ALL_IN_ONE
  209. void onWirelessNetStatusChanged(const char *pszEntityName, DWORD dwMessageId,
  210. DWORD dwMessageSignature, WirelessDevAgent::NetStatusEvt &evt) {
  211. Dbg("onWirelessNetStatusChanged: %d", evt.simStatus);
  212. m_fsm.SetSignalVal(evt.simStatus);
  213. m_fsm.SendNetStatusMsg();
  214. }
  215. #endif
  216. private:
  217. CMobileDialFSM m_fsm;
  218. CUUID m_uiWirelessListener;
  219. bool m_bDialogCreateBusy;
  220. HWND m_hDialogWnd;
  221. HANDLE m_hGUIReadyEvent;
  222. HANDLE m_hGUIClosedEvent;
  223. //CSimpleStringA m_strDialogErrMsg;
  224. friend class CMobileDlg;
  225. };
  226. #endif //_MOD_MOBILE_DIAL_H