RemoteMessagePort::SendMessage() returns E_SYSTEM when the socket receiver buffer...
[platform/framework/native/appfw.git] / src / app / FApp_SqlDataControlImpl.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 40f2003..4c95acd
@@ -27,6 +27,7 @@
 #include <FBaseInteger.h>
 #include <FBaseString.h>
 #include <FBaseLongLong.h>
+#include <FBaseColLinkedList.h>
 #include <FBaseColIList.h>
 #include <FBaseColIMap.h>
 #include <FBaseColIMapEnumerator.h>
 #include "FApp_SqlDataControlImpl.h"
 #include "FApp_AppArg.h"
 #include "FApp_DataControlManager.h"
+#include "FAppPkg_PackageManagerImpl.h"
 
 #define DATACONTROL_PROTOCOL_VER_2_1_0_2 // ver_2.1.0.2
+#define DATACONTROL_PROTOCOL_VER_2_1_0_3 // ver_2.1.0.3
 
 using namespace std;
 
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::Base::Runtime;
-using namespace Tizen::App;
 using namespace Tizen::Io;
+using namespace Tizen::App;
+using namespace Tizen::App::Package;
 
 namespace Tizen { namespace App
 {
@@ -62,7 +66,8 @@ static const int MAX_REQUEST_COUNT = 128;
 static const int REQUEST_THRESHOLD = 100;
 static const int _MAX_ARGUMENT_SIZE = 16384; // 16KB
 static const int _MAX_REQUEST_ARGUMENT_SIZE = 1048576; // 1MB
-static const char* _DATACONTROL_REQUEST_DIR = "/tmp/osp/DataControlRequest/\0";
+//static const char* _DATACONTROL_REQUEST_DIR = "/tmp/osp/DataControlRequest/\0";
+static const char* _DATACONTROL_REQUEST_DIR = "/tmp/osp/data-control/request/\0";
 
 class _SqlDataControlEventArg
        : public IEventArg
@@ -100,7 +105,7 @@ class _SqlDataControlEvent
        : public Event
 {
 protected:
-               virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
+       virtual void FireImpl(IEventListener& listener, const IEventArg& arg);
 };
 
 void
@@ -148,6 +153,19 @@ _SqlDataControlImpl::_SqlDataControlImpl(void)
 _SqlDataControlImpl::~_SqlDataControlImpl(void)
 {
        delete __pSqlDataControlEvent;
+
+       _DataControlManager* pDcMgr = _DataControlManager::GetInstance();
+
+       IEnumerator* pEnum = __pRequestList->GetEnumeratorN();
+       while (pEnum->MoveNext() == E_SUCCESS)
+       {
+               Integer* pReqId = dynamic_cast< Integer* >(pEnum->GetCurrent());
+               if (pReqId != null)
+               {
+                       pDcMgr->RemoveRequestInfo(*pReqId);
+               }
+       }
+       delete __pRequestList;
 }
 
 _SqlDataControlImpl*
@@ -213,8 +231,9 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
                                "[E_OUT_OF_MEMORY] The memory is insufficient");
 
                pReqInfo = new (std::nothrow) _DataControlRequestInfo(__pSqlDataControlEvent);
-               SysTryCatch(NID_APP, pReqId != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
+               SysTryCatch(NID_APP, pReqInfo != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY,
                                "[E_OUT_OF_MEMORY] The memory is insufficient");
+               pReqInfo->SetSqlDataControlImpl(this);
 
                r = pDcMgr->AddRequestInfo(pReqId, pReqInfo);
                SysTryCatch(NID_APP, !IsFailed(r), r = E_SYSTEM, E_SYSTEM, "[%s] Failed to add request info", GetErrorMessage(r));
@@ -228,6 +247,8 @@ _SqlDataControlImpl::StartSqlDataControl(int type, const IList* pDataList, int*
                        return r;
                }
 
+               __pRequestList->Add(new (std::nothrow) Integer(req));
+
                if (pReq)
                {
                        *pReq = req;
@@ -318,7 +339,7 @@ _SqlDataControlImpl::Select(const String& dataId, const IList* pColumnList, cons
                pArgList->Add(*(new String(L"NULL")));
        }
        SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
-                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
 
        pArgList->Add(*(new String(Integer::ToString(pageNo)))); // list(5): page number
 
@@ -383,14 +404,17 @@ _SqlDataControlImpl::SqlDataControlCallback(void* data, _AppArg* pArg, _AppArg*
                }
 
                _SqlDataControlEvent* pSqlDataControlEvent = dynamic_cast< _SqlDataControlEvent* >(pReqInfo->GetEvent());
-               SysTryCatch(NID_APP, pSqlDataControlEvent != null, r = E_SYSTEM, E_SYSTEM,
-                               "[E_SYSTEM] invalid request info");
+               SysTryCatch(NID_APP, pSqlDataControlEvent != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
+
+               pDcMgr->RemoveRequestInfo(key);
+
+               _SqlDataControlImpl* pDcImpl = pReqInfo->GetSqlDataControlImpl();
+               SysTryCatch(NID_APP, pDcImpl != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] invalid request info");
+               pDcImpl->__pRequestList->Remove(key);
 
                // Remove the request from the queue
                SysLog(NID_APP, "Remove the request, req: %d", reqId);
 
-               pDcMgr->RemoveRequestInfo(key);
-
                if (pSqlDataControlEvent != null && typeid(pSqlDataControlEvent) == typeid(_SqlDataControlEvent*))
                {
                        // result list
@@ -536,10 +560,11 @@ _SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, Request
 
        int columnCount = 0;
        int id = 0;
-       int i = 0;
        int uniqueId = -1;
        File request;
        IMapEnumerator* pMapEnum = null;
+       _PackageManagerImpl* pPkgMgrImpl = null;
+       unique_ptr< String > pProviderAppId(null);
        result r = E_SUCCESS;
        SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl INSERT");
 
@@ -635,11 +660,19 @@ _SqlDataControlImpl::Insert(const String& dataId, const IMap& insertMap, Request
 #endif
        }
        SysTryCatch(NID_APP, argSize <= _MAX_REQUEST_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
-                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
 
 #ifdef DATACONTROL_PROTOCOL_VER_2_1_0_2
        request.Flush();
 #endif
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_3
+       pPkgMgrImpl = _PackageManagerImpl::GetInstance();
+       pProviderAppId.reset(pPkgMgrImpl->GetAppIdOfDataControlN(this->__providerId.GetPointer()));
+       SysTryCatch(NID_APP, pProviderAppId != null, r = E_SYSTEM, E_SYSTEM,
+                       "[E_SYSTEM] The method cannot proceed due to a severe system error.");
+       r = pDcMgr->AllowAccess(*(pProviderAppId.get()));
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
+#endif
 
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_INSERT, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -665,10 +698,11 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
 
        int columnCount = 0;
        int id = 0;
-       int i = 0;
        int uniqueId = -1;
        File request;
        IMapEnumerator* pMapEnum = null;
+       _PackageManagerImpl* pPkgMgrImpl = null;
+       unique_ptr< String > pProviderAppId(null);
        result r = E_SUCCESS;
        SysLog(NID_APP, "[DC_CALLER_SEND] SqlDataControl UPDATE");
 
@@ -779,7 +813,16 @@ _SqlDataControlImpl::Update(const String& dataId, const IMap& updateMap, const S
                pArgList->Add(new (std::nothrow) String(L"NULL"));
        }
        SysTryCatch(NID_APP, argSize <= _MAX_REQUEST_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
-                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
+
+#ifdef DATACONTROL_PROTOCOL_VER_2_1_0_3
+       pPkgMgrImpl = _PackageManagerImpl::GetInstance();
+       pProviderAppId.reset(pPkgMgrImpl->GetAppIdOfDataControlN(this->__providerId.GetPointer()));
+       SysTryCatch(NID_APP, pProviderAppId != null, r = E_SYSTEM, E_SYSTEM,
+                       "[E_SYSTEM] The method cannot proceed due to a severe system error.");
+       r = pDcMgr->AllowAccess(*(pProviderAppId.get()));
+       SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
+#endif
 
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_UPDATE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -825,7 +868,7 @@ _SqlDataControlImpl::Delete(const String& dataId, const String* pWhere, RequestI
                pArgList->Add(*(new String(L"NULL")));
        }
        SysTryCatch(NID_APP, argSize <= _MAX_ARGUMENT_SIZE, r = E_MAX_EXCEEDED, E_MAX_EXCEEDED,
-                       "[E_MAX_EXCEEDED] The size of sending argument (%d) exceeds the maximum limit.", argSize);
+                       "[E_MAX_EXCEEDED] The size of sending argument (%lld) exceeds the maximum limit.", argSize);
 
        r = StartSqlDataControl(_DATACONTROL_REQUEST_TYPE_SQL_DELETE, pArgList, &id);
        SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating to caller...", GetErrorMessage(r));
@@ -891,6 +934,9 @@ _SqlDataControlImpl::CreateSqlDataControl(const String& appId, const String& pro
        unique_ptr<_SqlDataControlEvent> pSqlDataControlEvent(new (std::nothrow) _SqlDataControlEvent);
        SysTryReturn(NID_IO, pSqlDataControlEvent != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
 
+       pDcImpl->__pRequestList = new (std::nothrow) LinkedList(SingleObjectDeleter);
+       SysTryReturn(NID_IO, pDcImpl->__pRequestList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
+
        pDcImpl->__pSqlDataControlEvent = pSqlDataControlEvent.release();
 
        if (access == L"readonly")