Modify Protocol Plugin Manager code files for CA adaptation
authorYounghyunJoo <yh_.joo@samsung.com>
Mon, 13 Apr 2015 08:19:17 +0000 (17:19 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 13 Apr 2015 08:40:25 +0000 (08:40 +0000)
    1. Modify SCons file align
    2. Modify Sample Application code to the latest version

Change-Id: I673fe819335230913aad90d069c13b8d443b987c
Signed-off-by: YounghyunJoo <yh_.joo@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/696
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/protocol-plugin/plugins/SConscript
service/protocol-plugin/sample-app/linux/SConscript
service/protocol-plugin/sample-app/linux/mqtt/mqttclient.cpp

index edde7b7..376fe96 100644 (file)
@@ -36,21 +36,21 @@ target_os = env.get('TARGET_OS')
 plugins_env.AppendUnique(CPPPATH = ['../lib/cpluff/libcpluff'])
 
 if target_os not in ['windows', 'winrt']:
-       plugins_env.AppendUnique(CXXFLAGS = ['-g3', '-Wall', '-pthread', '-std=c++0x'])
-       plugins_env.PrependUnique(CCFLAGS = ['-fPIC'])
-       plugins_env.AppendUnique(LINKFLAGS = ['-fPIC'])
+    plugins_env.AppendUnique(CXXFLAGS = ['-g3', '-Wall', '-pthread', '-std=c++0x'])
+    plugins_env.PrependUnique(CCFLAGS = ['-fPIC'])
+    plugins_env.AppendUnique(LINKFLAGS = ['-fPIC'])
 
 #plugins_env.AppendUnique(LIBS=['libconnectivity-abstraction'])
 
-       if target_os not in ['arduino', 'android']:
-               plugins_env.AppendUnique(LIBS = ['pthread'])
+    if target_os not in ['arduino', 'android']:
+        plugins_env.AppendUnique(LIBS = ['pthread'])
 
 if target_os == 'android':
-       plugins_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
-       plugins_env.AppendUnique(LIBS = ['gnustl_static'] )
+    plugins_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
+    plugins_env.AppendUnique(LIBS = ['gnustl_shared'])
 
 plugins_env.AppendUnique(LIBS = [File(env.get('BUILD_DIR') + '/libmosquitto.a'),
-               'mosquitto', 'ssl', 'rt'])
+        'mosquitto', 'ssl', 'rt'])
 
 
 ######################################################################
@@ -65,4 +65,3 @@ mqtt_light_src = Glob('mqtt-light/src/' + '*.cpp')
 lightserver = plugins_env.SharedLibrary('mqtt-light/lightserver_mqtt_plugin', mqtt_light_src)
 
 SConscript('mqtt-fan/lib/SConscript')
-
index 33f26ea..078522d 100644 (file)
@@ -20,7 +20,6 @@
 ##
 #sample-app build script
 ##
-
 Import('env')
 
 # Add third party libraries
@@ -28,7 +27,6 @@ lib_env = env.Clone()
 SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
 
 sample_env = lib_env.Clone()
-
 target_os = env.get('TARGET_OS')
 ######################################################################
 # Build flags
@@ -42,8 +40,8 @@ if target_os not in ['windows', 'winrt']:
 
 sample_env.AppendUnique(LIBS = ['pthread'])
 sample_env.AppendUnique(LIBS = ['oc', 'oc_logger', 'octbstack',
-                                                               'connectivity_abstraction', 'coap',
-                                                               'ppm', 'pmimpl', 'dl'])
+                                'connectivity_abstraction', 'coap',
+                                'ppm', 'pmimpl', 'dl'])
 
 if env.get('SECURED') == '1':
     sample_env.AppendUnique(LIBS = ['tinydtls'])
@@ -62,5 +60,3 @@ mqttclient = sample_env.Program('mqtt/mqttclient', 'mqtt/mqttclient.cpp')
 
 Alias('mqttclient', mqttclient)
 env.AppendTarget('mqttclient')
-
-
index 2114bad..67119d9 100644 (file)
 #include "OCPlatform.h"
 #include "PluginManager.h"
 #include "OCApi.h"
-#include <time.h>
 
 using namespace OC;
 using namespace OIC;
 
+const int SUCCESS_RESPONSE = 0;
 std::shared_ptr<OCResource> curFanResource;
-std::shared_ptr<OCResource> curLightResource;
 static ObserveType OBSERVE_TYPE_TO_USE = ObserveType::Observe;
-
-time_t timer;                // Define the timer
-struct tm *tblock;           // Define a structure for time block
+int count = 0;
+void putFanRepresentation(std::shared_ptr<OCResource> resource);
 
 class Fan
 {
@@ -54,21 +52,6 @@ class Fan
 
 Fan myfan;
 
-class Light
-{
-    public:
-
-        bool m_state;
-        int m_power;
-        std::string m_name;
-
-        Light() : m_state(false), m_power(0), m_name("")
-        {
-        }
-};
-
-Light mylight;
-
 int observe_count()
 {
     static int oc = 0;
@@ -222,7 +205,7 @@ void onPut(const HeaderOptions &headerOptions, const OCRepresentation &rep, cons
         std::cout << "\tpower: " << myfan.m_power << std::endl;
         std::cout << "\tname: " << myfan.m_name << std::endl;
 
-        postFanRepresentation(curFanResource);
+        putFanRepresentation(curFanResource);
     }
     else
     {
@@ -241,8 +224,11 @@ void putFanRepresentation(std::shared_ptr<OCResource> resource)
         std::cout << "Putting fan representation..." << std::endl;
 
         myfan.m_state = true;
-        myfan.m_power = 15;
-
+        if (myfan.m_power == 1)
+            myfan.m_power = 0;
+        else
+            myfan.m_power = 1;
+        sleep(5);
         rep.setValue("state", myfan.m_state);
         rep.setValue("power", myfan.m_power);
 
@@ -276,28 +262,6 @@ void onFanGet(const HeaderOptions &headerOptions, const OCRepresentation &rep, c
     }
 }
 
-void onLightGet(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode)
-{
-    if (eCode == OC_STACK_OK)
-    {
-        std::cout << "GET Light request was successful" << std::endl;
-        std::cout << "Resource URI: " << rep.getUri() << std::endl;
-
-        rep.getValue("state", mylight.m_state);
-        rep.getValue("power", mylight.m_power);
-        rep.getValue("name", mylight.m_name);
-
-        std::cout << "\tstate: " << mylight.m_state << std::endl;
-        std::cout << "\tpower: " << mylight.m_power << std::endl;
-        std::cout << "\tname: " << mylight.m_name << std::endl;
-    }
-    else
-    {
-        std::cout << "onGET Response error: " << eCode << std::endl;
-        std::exit(-1);
-    }
-}
-
 
 // Local function to get representation of fan resource
 void getFanRepresentation(std::shared_ptr<OCResource> resource)
@@ -312,18 +276,6 @@ void getFanRepresentation(std::shared_ptr<OCResource> resource)
     }
 }
 
-void getLightRepresentation(std::shared_ptr<OCResource> resource)
-{
-    if (resource)
-    {
-        std::cout << "Getting Light Representation..." << std::endl;
-        // Invoke resource's get API with the callback parameter
-
-        QueryParamsMap test;
-        resource->get(test, &onLightGet);
-    }
-}
-
 // Callback to found resources
 void foundResourceFan(std::shared_ptr<OCResource> resource)
 {
@@ -366,7 +318,7 @@ void foundResourceFan(std::shared_ptr<OCResource> resource)
             {
                 curFanResource = resource;
                 // Call a local function which will internally invoke get API on the resource pointer
-                getFanRepresentation(resource);
+                putFanRepresentation(curFanResource);
             }
         }
         else
@@ -378,65 +330,7 @@ void foundResourceFan(std::shared_ptr<OCResource> resource)
     }
     catch (std::exception &e)
     {
-        std::cout<<"Exception in foundResourceFan: "<<e.what()<<std::endl;
-    }
-}
-
-// Callback to found resources
-void foundResourceLight(std::shared_ptr<OCResource> resource)
-{
-    if (curLightResource)
-    {
-        std::cout << "Found another resource, ignoring" << std::endl;
-    }
-
-    std::string resourceURI;
-    std::string hostAddress;
-    try
-    {
-        // Do some operations with resource object.
-        if (resource)
-        {
-            std::cout << "DISCOVERED Resource:" << std::endl;
-            // Get the resource URI
-            resourceURI = resource->uri();
-            std::cout << "\tURI of the resource: " << resourceURI << std::endl;
-
-            // Get the resource host address
-            hostAddress = resource->host();
-            std::cout << "\tHost address of the resource: " << hostAddress << std::endl;
-
-            // Get the resource types
-            std::cout << "\tList of resource types: " << std::endl;
-            for (auto &resourceTypes : resource->getResourceTypes())
-            {
-                std::cout << "\t\t" << resourceTypes << std::endl;
-            }
-
-            // Get the resource interfaces
-            std::cout << "\tList of resource interfaces: " << std::endl;
-            for (auto &resourceInterfaces : resource->getResourceInterfaces())
-            {
-                std::cout << "\t\t" << resourceInterfaces << std::endl;
-            }
-
-            if (resourceURI == "/a/light")
-            {
-                curLightResource = resource;
-                // Call a local function which will internally invoke get API on the resource pointer
-                getLightRepresentation(resource);
-            }
-        }
-        else
-        {
-            // Resource is invalid
-            std::cout << "Resource is invalid" << std::endl;
-        }
-
-    }
-    catch (std::exception &e)
-    {
-        std::cout<<"Exception in foundResourceLight:" <<e.what() << std::endl;
+        //log(e.what());
     }
 }
 
@@ -448,63 +342,6 @@ void PrintUsage()
     std::cout << "   ObserveType : 2 - ObserveAll" << std::endl;
 }
 
-void client1()
-{
-    std::cout << "in client1\n";
-
-    // OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo",
-    //                                 foundResource1);
-
-    std::string requestURI = OC_WELL_KNOWN_QUERY;
-    requestURI += "?rt=core.fan";
-
-    std::cout << "starting findResource = core.fan" << std::endl;
-    // Find all resources
-    OCPlatform::findResource("", requestURI, OC_WIFI,
-            &foundResourceFan);
-    // Get time of day
-    timer = time(NULL);
-    // Converts date/time to a structure
-    tblock = localtime(&timer);
-    std::cout << "Finding Fan Resource... time : " << asctime(tblock) << std::endl;
-    while (1)
-    {
-        std::cout << "Get Fan Resource....." << std::endl;
-        sleep(5);
-        getFanRepresentation(curFanResource);
-    }
-}
-
-void client2()
-{
-    std::cout << "in client2\n";
-
-    // OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.foo",
-    //             foundResource2);
-
-    std::string requestURI = OC_WELL_KNOWN_QUERY;
-    requestURI += "?rt=core.light";
-
-    std::cout << "starting findResource = core.light" << std::endl;
-    // Find all resources
-    OCPlatform::findResource("", requestURI, OC_WIFI,
-            &foundResourceLight);
-    // Get time of day
-    timer = time(NULL);
-    // Converts date/time to a structure
-    tblock = localtime(&timer);
-    std::cout << "Finding Light Resource... time : " << asctime(tblock) << std::endl;
-
-
-
-    while (1)
-    {
-        std::cout << "Get Light Resource....." << std::endl;
-        sleep(5);
-        getLightRepresentation(curLightResource);
-    }
-}
-
 
 
 int main(int argc, char *argv[])
@@ -548,86 +385,15 @@ int main(int argc, char *argv[])
 
     try
     {
-
-        std::cout << "Created Platform..." << std::endl;
-
         PluginManager *m_pm = new PluginManager();
-
-        std::cout << "==== 1st TEST CASE ===" << std::endl;
-        std::cout << "======================" << std::endl;
         std::cout << "start light Plugin by Resource Type"  << std::endl;
-
-        m_pm->startPlugins("ResourceType", "oic.light");
-
+        m_pm->startPlugins("ResourceType", "oic.fan");
         sleep(2);
-
-        std::cout << "\n==== 2nd TEST CASE =====" << std::endl;
-        std::cout << "======================" << std::endl;
-        std::cout << "Get Plugin List\n" << std::endl;
-        std::vector<Plugin> user_plugin;
-
-        user_plugin = m_pm->getPlugins();
-
-        for (unsigned int i = 0; i < user_plugin.size(); i++)
-        {
-            std::cout << "value Name = " << user_plugin[i].getName() << std::endl;
-            std::cout << "value ID = " << user_plugin[i].getID() << std::endl;
-            id =  user_plugin[i].getID();
-        }
-        std::cout << "\n===== 3rd TEST CASE =====" << std::endl;
-        std::cout << "======================" << std::endl;
-        std::cout << "Start Fan Plugin by Name\n" << std::endl;
-
-        name = user_plugin[0].getName();
-        m_pm->startPlugins(key, name);
-
-        sleep(5);
-
-        std::cout << "\n====== 4th TEST CASE ======" << std::endl;
-        std::cout << "========================" << std::endl;
-        std::cout << "Get Plugin Status\n" << std::endl;
-
-        state = m_pm->getState(id);
-
-        std::cout << "last plugin status :  " << state << std::endl;
-        std::cout << "sleep 15 seconds please add new plugin in the plugin folder  " << std::endl;
-
-        sleep(15);
-
-        std::cout << "\n====  5th TEST CASE  ====" << std::endl;
-        std::cout << "========================" << std::endl;
-        std::cout << "Rescan Plugins.........\n" << std::endl;
-
-        m_pm->rescanPlugin();
-
-        std::cout << "\n====  6th TEST CASE  ====" << std::endl;
-        std::cout << "========================" << std::endl;
-        std::cout << "Try to start new resource type.........\n" << std::endl;
-        std::cout << "start oic.test resource" <<  std::endl;
-
-        sleep(5);
-
-        int flag = m_pm->startPlugins("ResourceType", "oic.test");
-
-        if (!flag)
-            std::cout << "There are no resouce type. Start plugin failed" << std::endl;
-        // Start each client in a seperate thread
-
-        sleep(10);
-
-        std::cout << "\n====== 7th TEST CASE =======" << std::endl;
-        std::cout << "========================" << std::endl;
-        std::cout << " start client to find resource" << std::endl;
-
-        std::thread t1(client1);
-        t1.detach();
-
-        sleep(5);
-
-        // Start each client in a seperate thread
-        std::thread t2(client2);
-        t2.detach();
-
+        // makes it so that all boolean values are printed as 'true/false' in this stream
+        std::cout.setf(std::ios::boolalpha);
+        // Find all resources
+        OCPlatform::findResource("", "coap://224.0.1.187/oc/core?rt=core.fan", OC_WIFI, &foundResourceFan);
+        std::cout << "Finding Resource... " << std::endl;
         while (true)
         {
             // some operations
@@ -636,10 +402,8 @@ int main(int argc, char *argv[])
     }
     catch (OCException &e)
     {
-        std::cout<<"Exception in main: "<<e.what() << std::endl;
+        //log(e.what());
     }
 
     return 0;
 }
-
-