Applied Provider/Consumer setting APIs 20/86420/2
authorkmook <kmook.choi@samsung.com>
Thu, 1 Sep 2016 06:22:49 +0000 (15:22 +0900)
committerkmook <kmook.choi@samsung.com>
Thu, 1 Sep 2016 08:04:40 +0000 (17:04 +0900)
Change-Id: I285e6997a56d32dfd7ca71b2d1760567f2392b72
Signed-off-by: kmook <kmook.choi@samsung.com>
daemon/ConnectionManager.cpp
daemon/DiscoveryManager.cpp
daemon/ServiceManager.cpp
daemon/Util.cpp
daemon/Util.h
daemon/service_provider/AppCommServiceProvider.cpp
daemon/service_provider/RemoteAppControlServiceProvider.cpp

index 6e2af16..4d41151 100755 (executable)
@@ -16,6 +16,7 @@
 
 #include "ConnectionManager.h"
 #include "access_control/Privilege.h"
+#include "Util.h"
 
 static conv::ConnectionManager *_instance;
 static conv::Request* cur_Req;
@@ -58,6 +59,13 @@ int conv::ConnectionManager::handleRequest(Request* requestObj)
                return CONV_ERROR_PERMISSION_DENIED;
        }
 
+       if ( !conv::util::isApiActivated()) {
+               _E("API is not activated");
+               requestObj->reply(CONV_ERROR_INVALID_OPERATION);
+               delete requestObj;
+               return CONV_ERROR_INVALID_OPERATION;
+       }
+
        switch (requestObj->getType()) {
                case REQ_SUBSCRIBE:
                {
index 6f9800c..ad879e9 100755 (executable)
@@ -135,6 +135,13 @@ int conv::DiscoveryManager::handleRequest(Request* requestObj)
                                return CONV_ERROR_PERMISSION_DENIED;
                        }
 
+                       if ( !conv::util::isApiActivated()) {
+                               _E("API is not activated");
+                               requestObj->reply(CONV_ERROR_INVALID_OPERATION);
+                               delete requestObj;
+                               return CONV_ERROR_INVALID_OPERATION;
+                       }
+
                        discoveredResults.clear();
 
                        for (DiscoveryProviderList::iterator it = __providerList.begin(); it != __providerList.end(); ++it)
index 971aaa1..18755a6 100755 (executable)
@@ -61,19 +61,15 @@ int conv::ServiceManager::init()
        registerProvider(new(std::nothrow) conv::AppCommServiceProvider());
        registerProvider(new(std::nothrow) conv::RemoteAppControlServiceProvider());
 
-       int error = vconf_get_int(VCONFKEY_SETAPPL_D2D_CONVERGENCE, &__activationState);
-
-       if ( error < 0 ) {
-               _E("vconf error (%d)", error);
-       }
-
-       if ( __activationState == 1 ) {
+       if (conv::util::isServiceActivated()) {
+               __activationState = 1;
                registerDiscoveryInfo();
        } else {
+               __activationState = 0;
                unregisterDiscoveryInfo();
        }
 
-       error = vconf_notify_key_changed(VCONFKEY_SETAPPL_D2D_CONVERGENCE, vconf_update_cb, this);
+       int error = vconf_notify_key_changed(VCONFKEY_SETAPPL_D2D_CONVERGENCE_SERVICE, vconf_update_cb, this);
 
        IF_FAIL_RETURN_TAG(error >= 0, CONV_ERROR_INVALID_OPERATION, _E, "vconf error (%d)", error);
 
@@ -129,6 +125,13 @@ int conv::ServiceManager::handleRequest(Request* requestObj)
                                        delete requestObj;
                                        return CONV_ERROR_PERMISSION_DENIED;
                                }
+                               if ( !conv::util::isApiActivated()) {
+                                       _E("API is not activated");
+                                       requestObj->reply(CONV_ERROR_INVALID_OPERATION);
+                                       delete requestObj;
+                                       return CONV_ERROR_INVALID_OPERATION;
+                               }
+
                                error = (*it)->startRequest(requestObj);
                        } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_STOP)) {
                                if ( !conv::privilege_manager::isAllowed(requestObj->getCreds(), CONV_PRIVILEGE_INTERNET) ||
@@ -139,6 +142,13 @@ int conv::ServiceManager::handleRequest(Request* requestObj)
                                        delete requestObj;
                                        return CONV_ERROR_PERMISSION_DENIED;
                                }
+                               if ( !conv::util::isApiActivated()) {
+                                       _E("API is not activated");
+                                       requestObj->reply(CONV_ERROR_INVALID_OPERATION);
+                                       delete requestObj;
+                                       return CONV_ERROR_INVALID_OPERATION;
+                               }
+
                                error = (*it)->stopRequest(requestObj);
                        } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_GET))   {
                                if ( !conv::privilege_manager::isAllowed(requestObj->getCreds(), CONV_PRIVILEGE_INTERNET) ||
@@ -149,6 +159,13 @@ int conv::ServiceManager::handleRequest(Request* requestObj)
                                        delete requestObj;
                                        return CONV_ERROR_PERMISSION_DENIED;
                                }
+                               if ( !conv::util::isApiActivated()) {
+                                       _E("API is not activated");
+                                       requestObj->reply(CONV_ERROR_INVALID_OPERATION);
+                                       delete requestObj;
+                                       return CONV_ERROR_INVALID_OPERATION;
+                               }
+
                                error = (*it)->readRequest(requestObj);
                        } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_SET)) {
                                if ( !conv::privilege_manager::isAllowed(requestObj->getCreds(), CONV_PRIVILEGE_INTERNET) ||
@@ -160,6 +177,13 @@ int conv::ServiceManager::handleRequest(Request* requestObj)
                                        delete requestObj;
                                        return CONV_ERROR_PERMISSION_DENIED;
                                }
+                               if ( !conv::util::isApiActivated()) {
+                                       _E("API is not activated");
+                                       requestObj->reply(CONV_ERROR_INVALID_OPERATION);
+                                       delete requestObj;
+                                       return CONV_ERROR_INVALID_OPERATION;
+                               }
+
                                error = (*it)->publishRequest(requestObj);
                        } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_RECV)) {
                                return (*it)->registerRequest(requestObj);
index 52759b9..23add03 100755 (executable)
@@ -170,7 +170,7 @@ std::string conv::util::getDeviceId()
        return __deviceId;
 }
 
-bool conv::util::isServiceActivated(int serviceValue)
+bool conv::util::isServiceActivated()
 {
        int currentState;
        int error = vconf_get_int(VCONFKEY_SETAPPL_D2D_CONVERGENCE_SERVICE, &currentState);
@@ -180,7 +180,24 @@ bool conv::util::isServiceActivated(int serviceValue)
                return false;
        }
 
-       if ((serviceValue & currentState) > 0) {
+       if (currentState > 0) {
+               return true;
+       } else {
+               return false;
+       }
+}
+
+bool conv::util::isApiActivated()
+{
+       int currentState;
+       int error = vconf_get_int(VCONFKEY_SETAPPL_D2D_CONVERGENCE, &currentState);
+
+       if (error != 0) {
+               _D("vconf_get_int failed %d", error);
+               return false;
+       }
+
+       if (currentState > 0) {
                return true;
        } else {
                return false;
@@ -214,14 +231,14 @@ bool conv::util::getPeerMac(const string &remoteIP, const int remotePort, char *
                        myarp.arp_dev[sizeof(myarp.arp_dev) - 1] = 0;
                        if(ioctl(sockfd, SIOCGARP, &myarp) != -1) {
                                unsigned char *ptr = (unsigned char*)(&myarp.arp_ha.sa_data[0]);
-                               snprintf(buf, 18,"%02X-%02X-%02X-%02X-%02X-%02X", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5));
+                               snprintf(buf, 18, "%02X-%02X-%02X-%02X-%02X-%02X", *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5));
                                _D("%s MAC = %s\n", myarp.arp_dev, buf);
                                if_freenameindex(head);
                                if(sockfd >= 0)
                                        close(sockfd);
                                return true;
                        } else {
-                               _D( "Device:%s error ioctl %d", myarp.arp_dev, errno);
+                               _D("Device:%s error ioctl %d", myarp.arp_dev, errno);
                        }
                        interface++;
                }
index a04997f..b8470e8 100644 (file)
@@ -26,7 +26,8 @@ namespace conv {
                std::string getDeviceName();
                std::string getP2pMacAddress();
                std::string getDeviceId();
-               bool isServiceActivated(int serviceValue);
+               bool isServiceActivated();
+               bool isApiActivated();
 
                typedef void (*timer_function)(void *data);
                int miscStartTimer(timer_function function, unsigned int interval, void *data);
index 345a29d..dc32dcf 100755 (executable)
@@ -34,10 +34,12 @@ conv::AppCommServiceProvider::AppCommServiceProvider()
        __type = CONV_SERVICE_TYPE_SMARTVIEW_APP_COMMUNICATION;
        __resourceType = CONV_RESOURCE_TYPE_SMARTVIEW_APP_COMMUNICATION;
        __uri = CONV_URI_SMARTVIEW_APP_COMMUNICATION;
-       if (conv::util::isServiceActivated(CONV_INTERNAL_SERVICE_APP_TO_APP_COMMUNICATION))
+
+       if (conv::util::isServiceActivated()) {
                __activationState = 1;
-       else
+       } else {
                __activationState = 0;
+       }
 
        vconf_notify_key_changed(VCONFKEY_SETAPPL_D2D_CONVERGENCE_SERVICE, vconf_update_cb, this);
 }
@@ -46,7 +48,7 @@ int conv::AppCommServiceProvider::handleVconfUpdate(keynode_t *node)
 {
        int current_state = vconf_keynode_get_int(node);
 
-       if ((CONV_INTERNAL_SERVICE_APP_TO_APP_COMMUNICATION & current_state) > 0) {
+       if (current_state > 0) {
                __activationState = 1;
                init();
        } else {
@@ -75,8 +77,6 @@ int conv::AppCommServiceProvider::release()
 
 int conv::AppCommServiceProvider::loadServiceInfo(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        string client;
        conv::ClientInfo* clientObj = NULL;
        int isLocal = 0;
@@ -156,8 +156,6 @@ int conv::AppCommServiceProvider::loadServiceInfo(Request* requestObj)
 
 int conv::AppCommServiceProvider::startRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        _D("communcation/start requested");
        AppCommServiceInfo *svcInfo = reinterpret_cast<AppCommServiceInfo*>(requestObj->getServiceInfo());
 
@@ -251,8 +249,6 @@ int conv::AppCommServiceProvider::startRequest(Request* requestObj)
 
 int conv::AppCommServiceProvider::stopRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        _D("communcation/stop requested");
        AppCommServiceInfo *svcInfo = reinterpret_cast<AppCommServiceInfo*>(requestObj->getServiceInfo());
 
@@ -298,8 +294,6 @@ int conv::AppCommServiceProvider::stopRequest(Request* requestObj)
 
 int conv::AppCommServiceProvider::readRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        _D("communcation/get requested");
        AppCommServiceInfo *svcInfo = reinterpret_cast<AppCommServiceInfo*>(requestObj->getServiceInfo());
 
@@ -396,8 +390,6 @@ int conv::AppCommServiceProvider::sendReadResponse(Json payload, const char* rea
 
 int conv::AppCommServiceProvider::publishRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        _D("communcation/set requested");
        AppCommServiceInfo *svcInfo = reinterpret_cast<AppCommServiceInfo*>(requestObj->getServiceInfo());
 
@@ -446,8 +438,6 @@ int conv::AppCommServiceProvider::publishRequest(Request* requestObj)
 
 int conv::AppCommServiceProvider::registerRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        _D("communcation/recv requested");
        AppCommServiceInfo *svcInfo = reinterpret_cast<AppCommServiceInfo*>(requestObj->getServiceInfo());
 
@@ -476,8 +466,6 @@ int conv::AppCommServiceProvider::registerRequest(Request* requestObj)
 
 int conv::AppCommServiceProvider::getServiceInfoForDiscovery(Json* jsonObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_NOT_SUPPORTED, _E, "service provider is not activated");
-
        jsonObj->set(NULL, CONV_JSON_DISCOVERY_SERVICE_TYPE, CONV_SERVICE_APP_TO_APP_COMMUNICATION);
 
        // set data for service handle
index 598fad8..75887c8 100755 (executable)
@@ -61,10 +61,12 @@ conv::RemoteAppControlServiceProvider::RemoteAppControlServiceProvider()
        __resourceType = CONV_RESOURCE_TYPE_REMOTE_APP_CONTROL;
        __uri = CONV_URI_REMOTE_APP_CONTROL;
        iotcon_resource = NULL;
-       if (conv::util::isServiceActivated(CONV_INTERNAL_SERVICE_REMOTE_APP_CONTROL))
+
+       if (conv::util::isServiceActivated()) {
                __activationState = 1;
-       else
+       } else {
                __activationState = 0;
+       }
 
        vconf_notify_key_changed(VCONFKEY_SETAPPL_D2D_CONVERGENCE_SERVICE, vconf_update_cb, this);
 }
@@ -79,7 +81,7 @@ int conv::RemoteAppControlServiceProvider::handleVconfUpdate(keynode_t *node)
 {
        int current_state = vconf_keynode_get_int(node);
 
-       if ((CONV_INTERNAL_SERVICE_REMOTE_APP_CONTROL & current_state) > 0) {
+       if (current_state > 0) {
                __activationState = 1;
                init();
        } else {
@@ -428,6 +430,7 @@ int conv::RemoteAppControlServiceProvider::release()
                int error = iotcon_resource_destroy(iotcon_resource);
                IF_FAIL_RETURN_TAG(error == IOTCON_ERROR_NONE, CONV_ERROR_INVALID_OPERATION, _E, "resource destroy failed");
                iotcon_resource = NULL;
+               _D("RemoteAppControlServiceProvider release done");
        }
 
        return CONV_ERROR_NONE;
@@ -489,8 +492,6 @@ static void __on_access_response(iotcon_remote_resource_h resource, iotcon_error
 
 int conv::RemoteAppControlServiceProvider::startRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        _D("communcation/start requested");
        int error;
        Json result;
@@ -551,8 +552,6 @@ int conv::RemoteAppControlServiceProvider::startRequest(Request* requestObj)
 
 int conv::RemoteAppControlServiceProvider::stopRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        _D("communcation/stop requested");
        Json result;
 
@@ -573,8 +572,6 @@ int conv::RemoteAppControlServiceProvider::stopRequest(Request* requestObj)
 
 int conv::RemoteAppControlServiceProvider::readRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        return CONV_ERROR_NONE;
 }
 
@@ -658,8 +655,6 @@ static void __on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
 
 int conv::RemoteAppControlServiceProvider::publishRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        RemoteAppControlServiceInfo *svcInfo = reinterpret_cast<RemoteAppControlServiceInfo*>(requestObj->getServiceInfo());
        int error;
 
@@ -723,8 +718,6 @@ int conv::RemoteAppControlServiceProvider::publishRequest(Request* requestObj)
 
 int conv::RemoteAppControlServiceProvider::registerRequest(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        _D("communcation/recv requested");
        RemoteAppControlServiceInfo *svcInfo = reinterpret_cast<RemoteAppControlServiceInfo*>(requestObj->getServiceInfo());
 
@@ -755,8 +748,6 @@ int conv::RemoteAppControlServiceProvider::registerRequest(Request* requestObj)
 
 int conv::RemoteAppControlServiceProvider::loadServiceInfo(Request* requestObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_INVALID_OPERATION, _E, "service provider is not activated");
-
        string client;
        conv::ClientInfo* clientObj = NULL;
 
@@ -820,8 +811,6 @@ int conv::RemoteAppControlServiceProvider::loadServiceInfo(Request* requestObj)
 
 int conv::RemoteAppControlServiceProvider::getServiceInfoForDiscovery(Json* jsonObj)
 {
-       IF_FAIL_RETURN_TAG(__activationState == 1, CONV_ERROR_NOT_SUPPORTED, _E, "service provider is not activated");
-
        jsonObj->set(NULL, CONV_JSON_DISCOVERY_SERVICE_TYPE, CONV_SERVICE_REMOTE_APP_CONTROL);
 
        // set data for service handle