diff --git a/core/ContextBase.cpp b/core/ContextBase.cpp index 756983bf..1bd138ea 100644 --- a/core/ContextBase.cpp +++ b/core/ContextBase.cpp @@ -91,7 +91,8 @@ ContextBase::ContextBase(const MsgTask* msgTask, const char* libName) : mLBSProxy(getLBSProxy(libName)), mMsgTask(msgTask), - mLocApi(createLocApi(exMask)) + mLocApi(createLocApi(exMask)), + mLocApiProxy(mLocApi->getLocApiProxy()) { } diff --git a/core/ContextBase.h b/core/ContextBase.h index 93cb31ff..b41dd780 100644 --- a/core/ContextBase.h +++ b/core/ContextBase.h @@ -46,7 +46,7 @@ protected: const LBSProxyBase* mLBSProxy; const MsgTask* mMsgTask; LocApiBase* mLocApi; - + LocApiProxyBase *mLocApiProxy; public: ContextBase(const MsgTask* msgTask, LOC_API_ADAPTER_EVENT_MASK_T exMask, @@ -55,6 +55,7 @@ public: inline const MsgTask* getMsgTask() { return mMsgTask; } inline LocApiBase* getLocApi() { return mLocApi; } + inline LocApiProxyBase* getLocApiProxy() { return mLocApiProxy; } inline bool hasAgpsExt() { return mLBSProxy->hasAgpsExt(); } inline void requestUlp(LocAdapterBase* adapter, unsigned long capabilities) { diff --git a/core/LocAdapterBase.cpp b/core/LocAdapterBase.cpp index 48d179f5..8bbe873f 100644 --- a/core/LocAdapterBase.cpp +++ b/core/LocAdapterBase.cpp @@ -36,26 +36,6 @@ namespace loc_core { -struct LocOpenMsg : public LocMsg { - LocAdapterBase* mLocAdapter; - LocApiBase* mLocApi; - inline LocOpenMsg(LocAdapterBase* locAdapter, - LocApiBase* locApi) : - LocMsg(), mLocAdapter(locAdapter), mLocApi(locApi) - { - locallog(); - } - inline virtual void proc() const { - mLocApi->addAdapter(mLocAdapter); - } - inline void locallog() { - LOC_LOGV("LocOpen"); - } - inline virtual void log() { - locallog(); - } -}; - // This is the top level class, so the constructor will // always gets called. Here we prepare for the default. // But if getLocApi(targetEnumType target) is overriden, @@ -65,7 +45,7 @@ LocAdapterBase::LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, mEvtMask(mask), mContext(context), mLocApi(context->getLocApi()), mMsgTask(context->getMsgTask()) { - sendMsg(new LocOpenMsg(this, mLocApi)); + mLocApi->addAdapter(this); } void LocAdapterBase:: diff --git a/core/LocAdapterBase.h b/core/LocAdapterBase.h index f279f9fd..be31de6e 100644 --- a/core/LocAdapterBase.h +++ b/core/LocAdapterBase.h @@ -44,12 +44,10 @@ protected: inline LocAdapterBase(const MsgTask* msgTask) : mEvtMask(0), mContext(NULL), mLocApi(NULL), mMsgTask(msgTask) {} - +public: + inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); } LocAdapterBase(const LOC_API_ADAPTER_EVENT_MASK_T mask, ContextBase* context); - inline virtual ~LocAdapterBase() { mLocApi->removeAdapter(this); } - -public: inline LOC_API_ADAPTER_EVENT_MASK_T checkMask(LOC_API_ADAPTER_EVENT_MASK_T mask) const { return mEvtMask & mask; diff --git a/core/LocApiBase.cpp b/core/LocApiBase.cpp index 7a6456c1..2978fb3f 100644 --- a/core/LocApiBase.cpp +++ b/core/LocApiBase.cpp @@ -103,6 +103,27 @@ struct LocSsrMsg : public LocMsg { } }; +struct LocOpenMsg : public LocMsg { + LocApiBase* mLocApi; + LOC_API_ADAPTER_EVENT_MASK_T mMask; + inline LocOpenMsg(LocApiBase* locApi, + LOC_API_ADAPTER_EVENT_MASK_T mask) : + LocMsg(), mLocApi(locApi), mMask(mask) + { + locallog(); + } + inline virtual void proc() const { + mLocApi->open(mMask); + } + inline void locallog() { + LOC_LOGV("%s:%d]: LocOpen Mask: %x\n", + __func__, __LINE__, mMask); + } + inline virtual void log() { + locallog(); + } +}; + LocApiBase::LocApiBase(const MsgTask* msgTask, LOC_API_ADAPTER_EVENT_MASK_T excludedMask) : mExcludedMask(excludedMask), mMsgTask(msgTask), mMask(0) @@ -137,7 +158,8 @@ void LocApiBase::addAdapter(LocAdapterBase* adapter) for (int i = 0; i < MAX_ADAPTERS && mLocAdapters[i] != adapter; i++) { if (mLocAdapters[i] == NULL) { mLocAdapters[i] = adapter; - open(mMask | (adapter->getEvtMask() & ~mExcludedMask)); + mMsgTask->sendMsg(new LocOpenMsg(this, + (adapter->getEvtMask()))); break; } } @@ -173,7 +195,7 @@ void LocApiBase::removeAdapter(LocAdapterBase* adapter) close(); } else { // else we need to remove the bit - open(getEvtMask() & ~mExcludedMask); + mMsgTask->sendMsg(new LocOpenMsg(this, getEvtMask())); } } } @@ -298,7 +320,8 @@ void LocApiBase::requestNiNotify(GpsNiNotification ¬ify, const void* data) void* LocApiBase :: getSibling() DEFAULT_IMPL(NULL) -void* LocApiBase :: getSibling2() + +LocApiProxyBase* LocApiBase :: getLocApiProxy() DEFAULT_IMPL(NULL) enum loc_api_adapter_err LocApiBase:: diff --git a/core/LocApiBase.h b/core/LocApiBase.h index 4ddc57f1..04afa53a 100644 --- a/core/LocApiBase.h +++ b/core/LocApiBase.h @@ -34,6 +34,7 @@ #include #include #include + namespace loc_core { int hexcode(char *hexstring, int string_size, @@ -51,14 +52,23 @@ int decodeAddress(char *addr_string, int string_size, #define TO_1ST_HANDLING_ADAPTER(adapters, call) \ for (int i = 0; i