123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- #ifndef _MOD_MOBILE_DIAL_H
- #define _MOD_MOBILE_DIAL_H
- #pragma once
- #include "MobileDialFSM.h"
- using namespace MobileDial;
- #if HAS_NEW_ALL_IN_ONE
- #include "../mod_WirelessDevAgent/WirelessDevAgent_client_g.h"
- #include "../mod_WirelessDevAgent/WirelessDevAgent_msg_g.h"
- #endif
- class CMobileDialEntity;
- class CMobileDialServerSession: public MobileDialService_ServerSessionBase
- {
- public:
- CMobileDialServerSession(CMobileDialEntity *pEntity):m_pEntity(pEntity){}
- virtual ~CMobileDialServerSession(){}
- virtual void Handle_Query(SpReqAnsContext<MobileDialService_Query_Req, MobileDialService_Query_Ans>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<MobileDialService_GetDevInfo_Req, MobileDialService_GetDevInfo_Ans>::Pointer ctx);
- virtual void Handle_ShowDialog(SpOnewayCallContext<MobileDialService_ShowDialog_Info>::Pointer ctx);
- private:
- CMobileDialEntity *m_pEntity;
- };
- class CMobileDialEntity : public CEntityBase
- #if HAS_NEW_ALL_IN_ONE
- , public IBroadcastListener
- #endif
- {
- public:
- CMobileDialEntity(): m_bDialogCreateBusy(false),m_hDialogWnd(NULL),m_hGUIReadyEvent(NULL), m_hGUIClosedEvent(NULL){}
- virtual ~CMobileDialEntity(){
- if (m_hGUIReadyEvent != 0)
- {
- CloseHandle(m_hGUIReadyEvent);
- m_hGUIReadyEvent = 0;
- }
- if (m_hGUIClosedEvent != 0)
- {
- CloseHandle(m_hGUIClosedEvent);
- m_hGUIClosedEvent = 0;
- }
- }
- virtual const char *GetEntityName() const { return "MobileDial"; }
- virtual CServerSessionBase* OnNewSession(const char* , const char * )
- {
- LOG_FUNCTION();
- return new CMobileDialServerSession(this);
- }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum rt = Error_Succeed;
- #if HAS_NEW_ALL_IN_ONE
- CSystemStaticInfo staticInfo;
- CSmartPointer<IEntityFunction> spEntityFunction = GetFunction();
- spEntityFunction->GetSystemStaticInfo(staticInfo);
- if(staticInfo.strSite.Compare("CMB.FLB", true) == 0) {
- rt = spEntityFunction->SubscribeBroadcast("WirelessDevAgent", NULL, this, m_uiWirelessListener);
- if(rt != 0) {
- LOG_TRACE("Subscribe WirelessDevAgent failed: %u", rt);
- } else {
- Dbg("Subscribe WirelessDevAgent successfully!");
- }
- }
- #endif
- rt = m_fsm.Init(this);
- pTransactionContext->SendAnswer(rt);
- }
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- CSimpleStringA str = EncryptString("cmb#$%^&*() !@123");
- Dbg("Encrpyted:(%s)", (LPCTSTR)str);
- CSimpleStringA str1 = DecryptString(str);
- Dbg("Decrpyted:(%s)", (LPCTSTR)str1);
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- //m_fsm._InsertLocal2MacFilter();
- //ULONG data;
- //m_fsm.GetPersistentRequestId(data);
- //Dbg("Request Id: %d", data);
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.OnExit();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- void Query(SpReqAnsContext<MobileDialService_Query_Req, MobileDialService_Query_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- ctx->Ans.netstatus = m_fsm.GetSignalStatus();
- ctx->Ans.battery = m_fsm.GetBatteryRemains();
- Dbg("query result:%d,%d",ctx->Ans.netstatus,ctx->Ans.battery);
- // [Josephus in 16:20:30 2016/3/28]
- if(ctx->Ans.netstatus == 0) {
- ctx->Ans.reserved3 = m_fsm.GetFurtherDetail(TRUE);
- }
- ctx->Answer(Error_Succeed);
- }
-
- ErrorCodeEnum CreateMobileDialog(SpOnewayCallContext<MobileDialService_ShowDialog_Info>::Pointer ctx)
- {
- LOG_FUNCTION();
- if(IsDialogExisted()) {
- Dbg("Aleady creating the dialog, you should try again later");
- if(m_hDialogWnd) {
- if (IsIconic(m_hDialogWnd))
- ShowWindow(m_hDialogWnd, SW_RESTORE);
- else
- BringWindowToTop(m_hDialogWnd);
- }
- return Error_Block;
- }
- m_bDialogCreateBusy = true;
- if(m_hDialogWnd != NULL) {
- Dbg("Mobile dialog occurs duplicate!");
- m_bDialogCreateBusy = false;
- return Error_Duplication;
- }
- if (m_hGUIReadyEvent == 0) {
- m_hGUIReadyEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
- }
- if (m_hGUIClosedEvent == 0) {
- m_hGUIClosedEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
- }
- HANDLE hGUIThread = (HANDLE)_beginthreadex(0, 0, &WndThreadEntry, this, 0, 0);
- if (hGUIThread == 0) {
- Dbg("Create dialog entry thread failed : GLE=%d", GetLastError());
- m_bDialogCreateBusy = false;
- return Error_Resource;
- }
- CloseHandle(hGUIThread);
- m_fsm.PostEventLIFO(new FSMEvent(USER_EVT_DIALOG_INTO));
- if(WaitForSingleObject(m_hGUIReadyEvent, 10000) == WAIT_OBJECT_0) {
- Dbg("Receive the create-succeed signal !");
- m_bDialogCreateBusy = false;
- return Error_Succeed;
- }
- m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_DIALOG_OUT));
- m_bDialogCreateBusy = false;
- return Error_TimeOut;
- }
- void GetDevInfo(SpReqAnsContext<MobileDialService_GetDevInfo_Req, MobileDialService_GetDevInfo_Ans>::Pointer ctx)
- {
- }
- void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.SelfTest(eTestType,pTransactionContext);
- }
- virtual bool IsService()const{return true;}
- virtual bool IsMultiThread()const{return true;}
- ErrorCodeEnum CloseDialog() {
- if (m_hDialogWnd == NULL)
- return Error_NotInit;
- ResetEvent(m_hGUIClosedEvent);
- PostMessage(m_hDialogWnd, WM_CLOSE, 0, 0);
- WaitForSingleObject(m_hGUIClosedEvent, INFINITE);
- return Error_Succeed;
- }
- bool IsDialogExisted() const {return (m_bDialogCreateBusy || m_hDialogWnd != NULL);}
- LPCTSTR GetLastErrMsg() const {
- return m_fsm.m_csErrMsg;
- }
- int UpdateDongleInfo() {
- LOG_FUNCTION();
- int res = m_fsm.RetrieveDongleInfo();
- return res < 0 ? res : g_DongleInfos.GetCount();
- }
- BOOL UpdateProfileInfo(LPCTSTR lpszInterfaceId);
- BOOL UpdateProfileInfo(int nCurSel);
- BOOL UpdateSubInfo(int nCurSel);
- ErrorCodeEnum Connect(int nWayToConnect, LPCTSTR lpszInterfaceID, LPCTSTR lpszProfileName);
- ErrorCodeEnum Disconnect(int nWayToConnect, LPCTSTR lpszInterfaceID);
- ErrorCodeEnum AddNewProfile(const CSimpleStringA csInterfaceID, const AccessKeyInfo newInfo, bool fApplyNow);
- ErrorCodeEnum UpdateProfile(const CSimpleStringA csInterfaceID, LPCTSTR lpszProfileName, const AccessKeyInfo newInfo, bool fApplyNow);
- ErrorCodeEnum DeleteProfile(int nDongleIdx, int nProfileIdx);
- ErrorCodeEnum SwitchDefaultSlot(int slotIdx);
- ErrorCodeEnum ConnectWIFIWithDefault();
- BOOL IsManageByUser() const {
- return m_fsm.m_bManageByUser;
- }
- int GetCurAdvancedConfig(bool fRead5RunCfg = false) {
- return m_fsm.GetAdvancedGen(fRead5RunCfg);
- }
- BOOL IsAndroidControl() {
- return m_fsm.isUsingNewVerAllInOne();
- }
- void GetMBBRunConfig(MBBParams& params, BOOL fSetDefaultIfEmpty) {
- m_fsm.GetMBBConfig(¶ms, fSetDefaultIfEmpty);
- }
- void SEtMBBRunConfig(const MBBParams& params) {
- m_fsm.SaveMBBConfig(¶ms, FALSE);
- }
- void RequireManageByUser(bool fEnable) {
- m_fsm.SetAutoManage(!fEnable);
- }
- void SetAdvancedConfig(int value) {
- m_fsm.SetAdvancedGen(value);
- }
- #if HAS_NEW_ALL_IN_ONE
- SP_BEGIN_MSG_DISPATCH_MAP(CMobileDialEntity)
- SP_BEGIN_ENTITY_MSG("WirelessDevAgent")
- SP_MSG_HANDLE_NS(WirelessDevAgent, NetStatusEvt, onWirelessNetStatusChanged)
- SP_END_ENTITY_MSG()
- SP_END_MSG_DISPATCH_MAP()
- #endif
- private:
- int WndEntry();
- static unsigned int WINAPI WndThreadEntry(PVOID param);
- #if HAS_NEW_ALL_IN_ONE
- void onWirelessNetStatusChanged(const char *pszEntityName, DWORD dwMessageId,
- DWORD dwMessageSignature, WirelessDevAgent::NetStatusEvt &evt) {
- Dbg("onWirelessNetStatusChanged: %d", evt.simStatus);
- m_fsm.SetSignalVal(evt.simStatus);
- m_fsm.SendNetStatusMsg();
- }
- #endif
- private:
- CMobileDialFSM m_fsm;
- CUUID m_uiWirelessListener;
- bool m_bDialogCreateBusy;
- HWND m_hDialogWnd;
- HANDLE m_hGUIReadyEvent;
- HANDLE m_hGUIClosedEvent;
- //CSimpleStringA m_strDialogErrMsg;
- friend class CMobileDlg;
- };
- #endif //_MOD_MOBILE_DIAL_H
|