[easysetup] C++ SDK support for mediator
authorlankamadan <lanka.madan@samsung.com>
Thu, 12 Nov 2015 10:09:58 +0000 (19:09 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 16 Nov 2015 00:51:20 +0000 (00:51 +0000)
1) Added support for C++ SDK API for mediator
2) Include folder changes for Mediator api

Change-Id: Ief135e439d40099e42e2aeef7ac7e3d7fb3b3e2a
Signed-off-by: lankamadan <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4181
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
19 files changed:
service/easy-setup/SConscript [changed mode: 0755->0644]
service/easy-setup/sampleapp/mediator/linux/SConscript [changed mode: 0755->0644]
service/easy-setup/sampleapp/mediator/linux/mediator.cpp [changed mode: 0755->0644]
service/easy-setup/sampleapp/mediator/linux/mediator_cpp.cpp [new file with mode: 0644]
service/easy-setup/sdk/common/escommon.h
service/easy-setup/sdk/enrollee/src/resourceHandler.cpp
service/easy-setup/sdk/mediator/include/ESException.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/include/EasySetup.h [new file with mode: 0644]
service/easy-setup/sdk/mediator/include/RemoteEnrollee.h [new file with mode: 0755]
service/easy-setup/sdk/mediator/src/ESException.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/src/EasySetup.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/src/RemoteEnrollee.cpp [new file with mode: 0644]
service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.cpp [new file with mode: 0755]
service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.h [new file with mode: 0755]
service/easy-setup/sdk/mediator/src/prov_adapter.cpp [changed mode: 0755->0644]
service/easy-setup/sdk/mediator/src/prov_adapter.h [moved from service/easy-setup/sdk/mediator/inc/prov_adapter.h with 95% similarity, mode: 0644]
service/easy-setup/sdk/mediator/src/provisioning.cpp [changed mode: 0755->0644]
service/easy-setup/sdk/mediator/src/provisioning.h [moved from service/easy-setup/sdk/mediator/inc/provisioning.h with 95% similarity, mode: 0644]
service/easy-setup/sdk/mediator/src/wifi_provisioning.cpp [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 4b4446a..58c498a
 #
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-##
+######################################################################
 # easy-setup project build script
-##
-
+######################################################################
 import os
-
 Import('env')
 
-transport = env.get('TARGET_TRANSPORT')
-
-env.AppendUnique(CPPDEFINES = ['EASY_SETUP_CA_INIT'])
+######################################################################
+#building Resource client, resourceBroker and resourceCache
+######################################################################
 
-easy_setup_env = env.Clone()
-#
-target_os = env.get('TARGET_OS')
+if env.get('RELEASE'):
+    env.AppendUnique(CCFLAGS = ['-Os'])
+    env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+    env.AppendUnique(CCFLAGS = ['-g'])
 
+if env.get('LOGGING'):
+    env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+    
+# Add third party libraries
 lib_env = env.Clone()
-if target_os == 'android':
-       SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', exports = 'lib_env')
+SConscript(env.get('SRC_DIR') + '/service/third_party_libs.scons', 'lib_env')
+
+easy_setup_env = lib_env.Clone()
+target_os = env.get('TARGET_OS')
 
 ######################################################################
 # Build flags
@@ -44,42 +50,49 @@ if target_os == 'android':
 easy_setup_env.AppendUnique(CPPPATH = ['sdk/inc', 'sdk/src', 'sdk/common'])
 
 if target_os not in ['windows', 'winrt']:
-    easy_setup_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall'])
-    if target_os not in ['android', 'arduino']:
-        easy_setup_env.AppendUnique(CXXFLAGS = ['-pthread'])
+    easy_setup_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x'])
+       
+if target_os == 'linux':
+   easy_setup_env.AppendUnique(LIBS = ['pthread'])
 
-if target_os in ['android', 'linux']:
+if target_os in ['android']:
        easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
        easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
        easy_setup_env.AppendUnique(CXXFLAGS = ['-frtti', '-fexceptions'])
-       if target_os not in ['linux', 'arduino']:
-               easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])      
-               if not env.get('RELEASE'):
-                       easy_setup_env.AppendUnique(LIBS = ['log'])
-       else:
-               easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
+       easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'gnustl_shared'])      
+       if not env.get('RELEASE'):
+               easy_setup_env.AppendUnique(LIBS = ['log'])
+
+if target_os == 'linux':
+       easy_setup_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
+       easy_setup_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
+       easy_setup_env.AppendUnique(CXXFLAGS = ['-pthread'])
+       easy_setup_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
+               
 if target_os == 'arduino':
        easy_setup_env.AppendUnique(CPPPATH = [
                               '../../resource/oc_logger/include',
                               '../../resource/csdk/logger/include',
                               '../../resource/csdk/stack/include',
                               '../../extlibs/cjson',
-                                  'sdk/enrollee/arduino/wifi',
-                                  'sdk/enrollee/api',
-                                  'sdk/enrollee/src',
+                              'sdk/enrollee/arduino/wifi',
+                              'sdk/enrollee/api',
+                              'sdk/enrollee/src',
                               'sdk/enrollee/inc'])
-       easy_setup_env.AppendUnique(CPPDEFINES = ['TB_LOG', 'ESWIFI'])
+       easy_setup_env.AppendUnique(CPPDEFINES = ['ESWIFI'])
+       
 if target_os in ['android','linux']:                                      
        easy_setup_env.PrependUnique(CPPPATH = [
                env.get('SRC_DIR') + '/resource/c_common/oic_malloc/include',           
-               env.get('SRC_DIR') + '/resource/csdk/connectivity/common/inc',
-               env.get('SRC_DIR') + '/resource/csdk/connectivity/api',
-        env.get('SRC_DIR') + '/resource/csdk/stack/include',
-        env.get('SRC_DIR') + '/resource/csdk/logger/include',
+               env.get('SRC_DIR') + '/resource/include',
+               env.get('SRC_DIR') + '/resource/csdk/logger/include',
+                env.get('SRC_DIR') + '/resource/csdk/stack/include',
+                env.get('SRC_DIR') + '/resource/csdk/logger/include',
                env.get('SRC_DIR') + '/resource/csdk/security/include',
                env.get('SRC_DIR') + '/extlibs/cjson',
-               'sdk/common',
-               'sdk/mediator/inc'])
+               '/ser/sdk/common',
+               'sdk/mediator/include',
+               'sdk/mediator/src'])
 
 ######################################################################
 # Source files and Targets
@@ -96,14 +109,18 @@ if target_os == 'android':
        es_sdk_shared = easy_setup_env.StaticLibrary('libESSDK',
                                        ['sdk/mediator/src/prov_adapter.cpp',
                                        'sdk/mediator/src/wifi_provisioning.cpp',
-                                        'sdk/mediator/src/provisioning.cpp'])
+                    'sdk/mediator/src/provisioning.cpp'])
        easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
 
 if target_os == 'linux':
        es_sdk_shared = easy_setup_env.SharedLibrary('ESSDKLibrary',
-                                       ['sdk/mediator/src/prov_adapter.cpp',
+                                       ['sdk/mediator/src/RemoteEnrollee.cpp',
+                                       'sdk/mediator/src/RemoteEnrolleeResource.cpp',
+                                       'sdk/mediator/src/EasySetup.cpp',
+                                       'sdk/mediator/src/prov_adapter.cpp',
+                                       'sdk/mediator/src/ESException.cpp',
                                        'sdk/mediator/src/wifi_provisioning.cpp',
-                                        'sdk/mediator/src/provisioning.cpp'])
+                    'sdk/mediator/src/provisioning.cpp'])
        easy_setup_env.InstallTarget(es_sdk_shared, 'libESSDK')
 
 #Go to build sample apps
old mode 100755 (executable)
new mode 100644 (file)
index 8522aaa..1af4df2
@@ -28,22 +28,35 @@ target_os = env.get('TARGET_OS')
 # Build flags
 ######################################################################
 mediator_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-mediator_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
+if env.get('RELEASE'):
+    mediator_env.AppendUnique(CCFLAGS = ['-Os'])
+    mediator_env.AppendUnique(CPPDEFINES = ['NDEBUG'])
+else:
+    mediator_env.AppendUnique(CCFLAGS = ['-g'])
+
+if env.get('LOGGING'):
+    env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+
+if target_os not in ['windows', 'winrt']:
+    mediator_env.AppendUnique(CXXFLAGS = ['-Wall', '-std=c++0x'])
+    
 mediator_env.PrependUnique(CPPPATH = [
+            env.get('SRC_DIR') + '/resource/include',
+            env.get('SRC_DIR') + '/resource/oc_logger/include',
                        env.get('SRC_DIR') + '/resource/csdk/ocmalloc/include',         
-                       env.get('SRC_DIR') + '/resource/csdk/connectivity/common/inc',
-                       env.get('SRC_DIR') + '/resource/csdk/connectivity/api',
                        env.get('SRC_DIR') + '/resource/csdk/stack/include',
                        env.get('SRC_DIR') + '/resource/csdk/logger/include',
                        env.get('SRC_DIR') + '/resource/csdk/security/include',
                        env.get('SRC_DIR') + '/extlibs/cjson',
-                       env.get('SRC_DIR') + '/service/easy-setup/sdk/mediator/inc',
+                       env.get('SRC_DIR') + '/service/easy-setup/sdk/mediator/include',
+                       env.get('SRC_DIR') + '/service/easy-setup/sdk/mediator/src',
                        env.get('SRC_DIR') + '/service/easy-setup/sdk/common'])
 
 mediator_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction', 'coap', 'ESSDKLibrary'])
 
-mediator = mediator_env.Program('mediator', 'mediator.cpp')
+mediator = mediator_env.Program('mediator', 'mediator_cpp.cpp')
 
 i_mediator = mediator_env.Install(env.get('BUILD_DIR'), mediator)
 
old mode 100755 (executable)
new mode 100644 (file)
index 50e7cb7..3ed1984
@@ -64,7 +64,7 @@ static void PrintUsage() {
 
 int main(int argc, char **argv) {
     int opt;
-    EnrolleeNWProvInfo_t netInfo;
+    EnrolleeNWProvInfo netInfo;
     PrintUsage();
     InitProvProcess();
 
diff --git a/service/easy-setup/sampleapp/mediator/linux/mediator_cpp.cpp b/service/easy-setup/sampleapp/mediator/linux/mediator_cpp.cpp
new file mode 100644 (file)
index 0000000..dcc105b
--- /dev/null
@@ -0,0 +1,192 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include <iostream>
+
+#include "oic_string.h"
+#include "EasySetup.h"
+#include "OCPlatform.h"
+#include "logger.h"
+
+#define ES_SAMPLE_APP_TAG "ES_SAMPLE_APP_TAG"
+#define DECLARE_MENU(FUNC, ...) { #FUNC, FUNC }
+
+using namespace OC;
+using namespace OIC::Service;
+
+static EasySetup *easySetupIntance = nullptr;
+static EnrolleeNWProvInfo netInfo;
+static RemoteEnrollee::shared_ptr remoteEnrollee = nullptr;
+
+struct CloseApp
+{
+};
+
+typedef void (*Runner)();
+
+Runner g_currentRun;
+
+int processUserInput(int min, int max)
+{
+    assert(min <= max);
+
+    int input;
+
+    std::cin >> input;
+
+    if (!std::cin.fail())
+    {
+        if(input == max + 1) throw CloseApp();
+        if(min <= input && input <= max) return input;
+    }
+
+    std::cin.clear();
+    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
+
+    throw std::runtime_error("Invalid Input, please try again");
+}
+
+void easySetupStatusCallback (std::shared_ptr< EasySetupStatus > easySetupStatus)
+{
+    OC_LOG_V(DEBUG, ES_SAMPLE_APP_TAG, "easySetupStatusCallback status is, IP = %s, Status = %d",
+            easySetupStatus->getEasySetupNWProvInfo().netAddressInfo.WIFI.ipAddress,
+            easySetupStatus->getEasySetupState());
+
+}
+
+void startProvisioning()
+{
+    try
+    {
+        remoteEnrollee->startProvisioning();
+    }
+    catch(OCException &exception)
+    {
+        std::cout << "Exception : " << exception.reason();
+    }
+}
+
+void initEasySetup()
+{
+
+    easySetupIntance = EasySetup::getInstance();
+
+    std::string ipaddress ("192.168.0.100");
+    std::cout << "Enter the target enrollee ipv4 address ";
+
+
+    std::string ssid;
+    std::cout << "Enter the ssid of the target Enrolleer ";
+    std:: cin >> ssid;
+
+    std::string pwd;
+    std::cout << "Enter the pwd of the target Enrolleer ";
+    std::cin >> pwd;
+
+    netInfo.connType = CT_ADAPTER_IP;
+    netInfo.isSecured = false;
+    OICStrcpy(netInfo.netAddressInfo.WIFI.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
+    OICStrcpy(netInfo.netAddressInfo.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
+    OICStrcpy(netInfo.netAddressInfo.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
+
+    try
+    {
+        remoteEnrollee = easySetupIntance->createEnrolleeDevice(netInfo);
+    }
+    catch (OCException &e)
+    {
+        std::cout << "Exception during createEnrolleeDevice call" << e.reason();
+        return;
+    }
+
+    remoteEnrollee->registerEasySetupStatusHandler(&easySetupStatusCallback);
+}
+void runEasySetupMenu()
+{
+    constexpr int EASY_SETUP_INIT = 1;
+    constexpr int START_PROVISIONING = 2;
+    constexpr int STOP_PROVISIONING = 3;
+    constexpr int STOP_EASY_SETUP = 4;
+
+    std::cout << "========================================================\n";
+    std::cout << EASY_SETUP_INIT << ". Easy Setup Init                    \n";
+    std::cout << START_PROVISIONING << ". Start Provisioning              \n";
+    std::cout << STOP_PROVISIONING << ". Stop Provisioning                \n";
+    std::cout << STOP_EASY_SETUP << ". Stop Easy Setup                    \n";
+    std::cout << STOP_EASY_SETUP + 1 << ". Quit                           \n";
+    std::cout << "========================================================\n";
+
+    int selection = processUserInput(EASY_SETUP_INIT, STOP_EASY_SETUP);
+
+    switch (selection)
+    {
+        case EASY_SETUP_INIT:
+            initEasySetup();
+            break;
+        case START_PROVISIONING:
+            startProvisioning();
+            break;
+        case STOP_PROVISIONING:
+            //stopProvisioning();
+            break;
+        case STOP_EASY_SETUP:
+            //stopEasySetup();
+            break;
+        default:
+            break;
+    };
+}
+
+void configurePlatform()
+{
+    PlatformConfig config
+    {
+        OC::ServiceType::InProc, ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos
+    };
+    OCPlatform::Configure(config);
+}
+
+int main()
+{
+    configurePlatform();
+
+    g_currentRun = runEasySetupMenu;
+
+    while (true)
+    {
+        try
+        {
+            g_currentRun();
+        }
+        catch (const std::exception& e)
+        {
+            std::cout << "Exception caught in main " << e.what() << std::endl;
+        }
+        catch (const CloseApp&)
+        {
+            break;
+        }
+    }
+
+    std::cout << "Stopping the client" << std::endl;
+
+    return 0;
+}
+
index 3375490..b428aea 100644 (file)
 #ifndef ES_COMMON_H_
 #define ES_COMMON_H_
 
+#ifndef WITH_ARDUINO
+#include <memory>
+#endif
+
 #include "ocstack.h"
 #include "octypes.h"
 
@@ -121,24 +125,30 @@ typedef struct {
     OCDevAddr * addr;
     /// Indicates adaptor type on which the response was received
     OCConnectivityType connType;
-} ProvDeviceInfo;
+} EasySetupDeviceInfo;
 
 /**
  * Provosioning Status
  */
-typedef enum {
-    DEVICE_PROVISIONED = 0, DEVICE_NOT_PROVISIONED
-} ProvStatus;
+typedef enum
+{
+    DEVICE_PROVISIONED = 0,
+    DEVICE_NOT_PROVISIONED,
+    DEVICE_OWNED,
+    DEVICE_NOT_OWNED
+} EasySetupState, ProvStatus;
+
+
 
 /**
  * Response from queries to remote servers.
  */
 typedef struct {
-    // Provisioning Status
-    ProvStatus provStatus;
-    // Provisioning Device Info
-    ProvDeviceInfo provDeviceInfo;
-} ProvisioningInfo;
+    // EasySetup Status
+    EasySetupState provStatus;
+    // EasySetup Device Info
+    EasySetupDeviceInfo provDeviceInfo;
+} EasySetupInfo, ProvisioningInfo;
 
 /**
  * @brief  Network information of the Enroller
@@ -170,7 +180,7 @@ typedef union
         char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
         char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
     } WIFI;
-} EnrolleeInfo_t;
+} EnrolleeInfo;
 
 
 /**
@@ -178,14 +188,88 @@ typedef union
  */
 typedef struct
 {
-    EnrolleeInfo_t netAddressInfo;          /**< Enroller Network Info**/
+    EnrolleeInfo netAddressInfo;          /**< Enroller Network Info**/
     OCConnectivityType connType;            /**< Connectivity Type**/
     bool isSecured;                         /**< Secure connection**/
-} EnrolleeNWProvInfo_t;
+} EnrolleeNWProvInfo;
 
 /**
  * Client applications implement this callback to consume responses received from Servers.
  */
-typedef void (*OCProvisioningStatusCB)(ProvisioningInfo *provInfo);
+typedef void (*OCProvisioningStatusCB)(EasySetupInfo *easySetupInfo);
+
+namespace OIC
+{
+    namespace Service
+    {
+        typedef enum
+        {
+            ES_PROVISIONING_ERROR = -1,
+            ES_NEED_PROVISIONING,
+            ES_PROVISIONED_ALREADY,
+            ES_PROVISIONING_SUCCESS
+        } ESState;
+
+        typedef enum
+        {
+            ES_UNKNOWN = 0,
+            ES_ONBOARDED,
+            ES_OWNED,
+            ES_PROVISIONED
+        } CurrentESState;
+
+#ifndef WITH_ARDUINO
+        class ProvisioningStatus
+        {
+        public:
+            std::shared_ptr< ProvisioningStatus > shared_ptr;
+            ProvisioningStatus(ESResult result, ESState esState) :
+                    m_result(result), m_esState(esState)
+            {
+
+            }
+
+            ESResult& getESResult()
+            {
+                return m_result;
+            }
+
+            ESState& getESState()
+            {
+                return m_esState;
+            }
+        private:
+            ESResult m_result;
+            ESState m_esState;
+        };
+
+        class EasySetupStatus
+        {
+        public:
+            std::shared_ptr< EasySetupStatus > shared_ptr;
+            EasySetupStatus(const EasySetupState& easySetupState,
+                    const EnrolleeNWProvInfo& enrolleeNWProvInfo) :
+                    m_easySetupState(easySetupState), m_enrolleeNWProvInfo(enrolleeNWProvInfo)
+            {
+
+            }
+
+            EnrolleeNWProvInfo& getEasySetupNWProvInfo()
+            {
+                return m_enrolleeNWProvInfo;
+            }
+
+            EasySetupState& getEasySetupState()
+            {
+                return m_easySetupState;
+            }
+        private:
+            EasySetupState m_easySetupState;
+            EnrolleeNWProvInfo m_enrolleeNWProvInfo;
+        };
+#endif
+
+    }
+}
 
 #endif
index 6c0fec2..383be91 100644 (file)
@@ -173,12 +173,16 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
         sprintf(g_prov.tnn, "%s", tnn);
     }
 
+    OC_LOG_V(INFO, ES_RH_TAG, "g_prov.tnn %s", g_prov.tnn);
+
     char* cd;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
     {
         sprintf(g_prov.cd, "%s", cd);
     }
 
+    OC_LOG_V(INFO, ES_RH_TAG, "g_prov.cd %s", g_prov.cd);
+
     g_flag = 1;
 
     OCRepPayload *getResp = constructResponse(ehRequest);
diff --git a/service/easy-setup/sdk/mediator/include/ESException.h b/service/easy-setup/sdk/mediator/include/ESException.h
new file mode 100644 (file)
index 0000000..78723d8
--- /dev/null
@@ -0,0 +1,147 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+/**
+ * @file
+ *
+ * This file contains the declaration of exception classes for easy setup
+ */
+#ifndef EASY_SETUP_EXCEPTION_H
+#define EASY_SETUP_EXCEPTION_H
+
+#include <string>
+#include <octypes.h>
+
+namespace OIC
+{
+    namespace Service
+    {
+
+        /**
+         * The base exception class for resource encapsulation.
+         *
+         */
+        class ESException: public std::exception
+        {
+        public:
+
+            /**
+             * Constructs an exception with an empty description.
+             */
+            ESException();
+
+            /**
+             * Constructs an exception with a description.
+             *
+             * @param what The description for the error.
+             */
+            explicit ESException(const std::string &what);
+
+            /**
+             * @overload
+             */
+            explicit ESException(std::string &&what);
+
+            virtual ~ESException() noexcept;
+
+            /**
+             * Returns the exception description.
+             *
+             */
+            virtual const char *what() const noexcept;
+
+        private:
+            /**
+             *  Exception description
+             */
+            const std::string m_what;
+        };
+
+        /**
+         * Thrown when OC layer returns an error.
+         *
+         */
+        class ESPlatformException: public ESException
+        {
+        public:
+            explicit ESPlatformException(OCStackResult reason);
+
+            /**
+             * Returns the reason.
+             *
+             */
+            OCStackResult getReasonCode() const;
+
+            /**
+             * Returns the reason description.
+             *
+             */
+            std::string getReason() const;
+
+        private:
+            OCStackResult m_reason;
+        };
+
+        /**
+         * Thrown when a request is not acceptable.
+         *
+         */
+        class ESBadRequestException: public ESException
+        {
+        public:
+            explicit ESBadRequestException(const std::string& what);
+            explicit ESBadRequestException(std::string&& what);
+        };
+
+        /**
+         * Thrown when a parameter is not valid.
+         *
+         */
+        class ESInvalidParameterException: public ESException
+        {
+        public:
+            explicit ESInvalidParameterException(const std::string& what);
+            explicit ESInvalidParameterException(std::string&& what);
+        };
+
+        /**
+         * Thrown when getting value with wrong template parameter.
+         */
+        class ESBadGetException: public ESException
+        {
+        public:
+            explicit ESBadGetException(const std::string& what);
+            explicit ESBadGetException(std::string&& what);
+        };
+
+        /**
+         * Thrown when a key is invalid.
+         *
+         */
+        class ESInvalidKeyException: public ESException
+        {
+        public:
+            explicit ESInvalidKeyException(const std::string& what);
+            explicit ESInvalidKeyException(std::string&& what);
+        };
+    }
+}
+
+#endif // EASY_SETUP_EXCEPTION_H
diff --git a/service/easy-setup/sdk/mediator/include/EasySetup.h b/service/easy-setup/sdk/mediator/include/EasySetup.h
new file mode 100644 (file)
index 0000000..600c158
--- /dev/null
@@ -0,0 +1,78 @@
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef EASYSETUP_H_\r
+#define EASYSETUP_H_\r
+\r
+#include <memory>\r
+#include <vector>\r
+\r
+#include "escommon.h"\r
+#include "RemoteEnrollee.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        class RemoteEnrollee;\r
+\r
+        /**\r
+         * This provides methods for Mediator devices to perform EasySetup of Enrollee devices.\r
+         * EasySetup involves\r
+         * 1) Ownership transfer for enabling secured communication between Mediator and Enrollee\r
+         * devices.\r
+         * 2) Provisioning of Enrollee devices using the credentails of target Enroller devices.\r
+         */\r
+        class EasySetup\r
+        {\r
+        public:\r
+            /**\r
+             * API for getting the instance of EasySetup singleton class.\r
+             * @return EasySetup instance.\r
+             */\r
+            static EasySetup* getInstance();\r
+\r
+            /**\r
+             * This API is used for creating a remote Enrollee device instance.\r
+             * @param enrolleeNWProvIndo Provisioning information for configuring the Enrollee.\r
+             *\r
+             * @throws ESBadRequestException If createEnrolleeDevice is invoked with the same\r
+             *         provisioning information.\r
+             *\r
+             * @return Pointer to RemoteEnrollee instance.\r
+             */\r
+            std::shared_ptr<RemoteEnrollee> createEnrolleeDevice (\r
+                                            const EnrolleeNWProvInfo& enrolleeNWProvInfo);\r
+        private:\r
+            EasySetup();\r
+            ~EasySetup();\r
+\r
+            RemoteEnrollee::shared_ptr findDeviceInProvisioningList(\r
+                                const EnrolleeNWProvInfo& enrolleeNWProvInfo);\r
+            bool addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee);\r
+            bool deleteDeviceFromProvisioningList (const EnrolleeNWProvInfo& enrolleeNWProvInfo);\r
+\r
+            std::vector< RemoteEnrollee::shared_ptr > m_activeEnrolleeList;\r
+            static EasySetup *s_instance;\r
+        };\r
+    }\r
+}\r
+\r
+#endif /* EASYSETUP_H_ */\r
diff --git a/service/easy-setup/sdk/mediator/include/RemoteEnrollee.h b/service/easy-setup/sdk/mediator/include/RemoteEnrollee.h
new file mode 100755 (executable)
index 0000000..b21d258
--- /dev/null
@@ -0,0 +1,115 @@
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef REMOTE_ENROLLEE_H_\r
+#define REMOTE_ENROLLEE_H_\r
+\r
+#include "escommon.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        class RemoteEnrolleeResource;\r
+\r
+        /**\r
+         * This class represents Remote Enrollee device instance.\r
+         * It will provide APIs for Mediator to perform operations to enable the Enrollee device\r
+         * to connect to the Enroller.\r
+         */\r
+        class RemoteEnrollee\r
+        {\r
+        public:\r
+            /**\r
+             * RemoteEnrollee constructor\r
+             *\r
+             * @param enrolleeNWProvInfo Provisioning information for the Enrollee\r
+             *\r
+             * @throw ESBadRequestException is thrown if the parameters are invalid\r
+             */\r
+            RemoteEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo) ;\r
+\r
+            ~RemoteEnrollee() = default;\r
+\r
+            typedef std::shared_ptr< RemoteEnrollee > shared_ptr;\r
+\r
+            /**\r
+             * Callback definition to be invoked when EasySetup status is changed.\r
+             * The same callback will be invoked when there is an error in the\r
+             * EasySetup process.\r
+             *\r
+             * @see registerResourceHandler\r
+             * @see ResourceState\r
+             */\r
+            typedef std::function< void(std::shared_ptr< EasySetupStatus >) >\r
+                                                                        EasySetupStatusCB;\r
+\r
+            /**\r
+             * Register EasySetup status handler.\r
+             *\r
+             * @param callback Callback to get EasySetup status.\r
+             *\r
+             * @throws InvalidParameterException If callback is an empty function or null.\r
+             * @throws ESBadRequestException If registration is already completed.\r
+             *\r
+             * @see EasySetupStatus\r
+             */\r
+            void registerEasySetupStatusHandler(EasySetupStatusCB callback);\r
+\r
+            /**\r
+             * Start provisioning of target Enrollers information to the Enrollee.\r
+             *\r
+             * @throws ESBadRequestException If RemoteEnrollee device not created prior to this call.\r
+             *\r
+             * @see RemoteEnrollee\r
+             */\r
+            virtual void startProvisioning();\r
+\r
+            /**\r
+             * Stop provisioning process that is currently in progress.\r
+             *\r
+             * @throws BadRequestException If provisioning is not in progress.\r
+             */\r
+            virtual void stopProvisioning();\r
+\r
+            /**\r
+             * Check if the Enrollee device provisioned.\r
+             */\r
+            virtual bool isEnrolleeProvisioned();\r
+\r
+            /**\r
+             * Get the Provisioning information provided for the current Enrollee.\r
+             *\r
+             * @return EnrolleeNWProvInfo Provisioning information provided for the current Enrollee.\r
+             */\r
+            virtual EnrolleeNWProvInfo& getEnrolleeProvisioningInfo ();\r
+\r
+        private:\r
+            std::shared_ptr< RemoteEnrolleeResource > m_remoteResource;\r
+            EasySetupStatusCB m_easySetupStatusCb;\r
+            EnrolleeNWProvInfo m_enrolleeNWProvInfo;\r
+            CurrentESState m_currentESState;\r
+\r
+            void provisioningStatusHandler (std::shared_ptr< ProvisioningStatus > provStatus);\r
+        };\r
+    }\r
+}\r
+\r
+#endif //REMOTE_ENROLLEE_H_\r
diff --git a/service/easy-setup/sdk/mediator/src/ESException.cpp b/service/easy-setup/sdk/mediator/src/ESException.cpp
new file mode 100644 (file)
index 0000000..9551a5a
--- /dev/null
@@ -0,0 +1,114 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "ESException.h"
+
+#include "OCException.h"
+
+namespace OIC
+{
+    namespace Service
+    {
+
+        ESException::ESException()
+        {
+        }
+
+        ESException::ESException(const std::string& what) :
+                m_what{ what }
+        {
+        }
+
+        ESException::ESException(std::string&& what) :
+                m_what{ std::move(what) }
+        {
+        }
+
+        ESException::~ESException() noexcept
+        {
+        }
+
+        const char* ESException::what() const noexcept
+        {
+            return m_what.c_str();
+        }
+
+
+        ESPlatformException::ESPlatformException(OCStackResult reason) :
+                ESException{ "Failed : " + OC::OCException::reason(reason) },
+                m_reason { reason }
+        {
+        }
+
+        OCStackResult ESPlatformException::getReasonCode() const
+        {
+            return m_reason;
+        }
+
+        std::string ESPlatformException::getReason() const
+        {
+            return  OC::OCException::reason(m_reason);
+        }
+
+
+        ESBadRequestException::ESBadRequestException(const std::string& what) :
+                ESException{ what }
+        {
+        }
+
+        ESBadRequestException::ESBadRequestException(std::string&& what) :
+                ESException{ std::move(what) }
+        {
+        }
+
+
+        ESInvalidParameterException::ESInvalidParameterException(const std::string& what) :
+                ESException{ what }
+        {
+        }
+
+        ESInvalidParameterException::ESInvalidParameterException(std::string&& what) :
+                ESException{ std::move(what) }
+        {
+        }
+
+
+        ESBadGetException::ESBadGetException(const std::string& what) :
+                ESException{ what }
+        {
+        }
+
+        ESBadGetException::ESBadGetException(std::string&& what) :
+                ESException{ std::move(what) }
+        {
+        }
+
+
+        ESInvalidKeyException::ESInvalidKeyException(const std::string& what) :
+                ESException{ what }
+        {
+        }
+
+        ESInvalidKeyException::ESInvalidKeyException(std::string&& what) :
+                ESException{ std::move(what) }
+        {
+        }
+    }
+}
diff --git a/service/easy-setup/sdk/mediator/src/EasySetup.cpp b/service/easy-setup/sdk/mediator/src/EasySetup.cpp
new file mode 100644 (file)
index 0000000..9adbad9
--- /dev/null
@@ -0,0 +1,114 @@
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#include "EasySetup.h"\r
+\r
+#include "logger.h"\r
+#include "ESException.h"\r
+#include "RemoteEnrollee.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        #define EASYSETUP_TAG "EASY_SETUP"\r
+\r
+        EasySetup * EasySetup::s_instance = nullptr;\r
+\r
+        EasySetup::EasySetup()\r
+        {\r
+\r
+        }\r
+\r
+        EasySetup* EasySetup::getInstance ()\r
+        {\r
+            if (s_instance == nullptr)\r
+            {\r
+                s_instance = new EasySetup ();\r
+            }\r
+            return s_instance;\r
+        }\r
+\r
+        RemoteEnrollee::shared_ptr EasySetup::findDeviceInProvisioningList (\r
+                            const EnrolleeNWProvInfo& enrolleeNWProvInfo)\r
+        {\r
+            OC_LOG(DEBUG,EASYSETUP_TAG,"Entered findDeviceInProvisioningList ()");\r
+\r
+            std::vector< std::shared_ptr< RemoteEnrollee > >::iterator it;\r
+\r
+            std::shared_ptr< RemoteEnrollee > remoteEnrollee = nullptr;\r
+            for(auto it : m_activeEnrolleeList)\r
+            {\r
+                OC_LOG_V(DEBUG,EASYSETUP_TAG,"entered the iterator");\r
+\r
+                if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo,\r
+                                &enrolleeNWProvInfo.netAddressInfo, sizeof(EnrolleeNWProvInfo)))\r
+                {\r
+                    remoteEnrollee = it;\r
+                    return remoteEnrollee;\r
+                }\r
+            }\r
+\r
+            OC_LOG_V(DEBUG,EASYSETUP_TAG,"Return nullptr for  findDeviceInProvisioningList call");\r
+            return remoteEnrollee;\r
+        }\r
+\r
+        bool EasySetup::addDeviceToProvisioningList(const RemoteEnrollee::shared_ptr remoteEnrollee)\r
+        {\r
+            for (auto it : m_activeEnrolleeList)\r
+            {\r
+                if (0 == memcmp(&it->getEnrolleeProvisioningInfo().netAddressInfo,\r
+                                &remoteEnrollee->getEnrolleeProvisioningInfo().netAddressInfo,\r
+                                sizeof(EnrolleeNWProvInfo)))\r
+                {\r
+                    return false;\r
+                }\r
+            }\r
+\r
+            OC_LOG_V(DEBUG,EASYSETUP_TAG,"Adding new device RemoteEnrollee list");\r
+            m_activeEnrolleeList.push_back(remoteEnrollee);\r
+            return true;\r
+        }\r
+\r
+        std::shared_ptr<RemoteEnrollee> EasySetup::createEnrolleeDevice (\r
+                                        const EnrolleeNWProvInfo& enrolleeNWProvInfo)\r
+        {\r
+            if (findDeviceInProvisioningList(enrolleeNWProvInfo) != nullptr)\r
+            {\r
+                throw ESBadRequestException { "Device already created exception" };\r
+            }\r
+\r
+            RemoteEnrollee::shared_ptr remoteEnrollee;\r
+\r
+            remoteEnrollee = std::make_shared< RemoteEnrollee > (enrolleeNWProvInfo);\r
+\r
+\r
+            if (!addDeviceToProvisioningList (remoteEnrollee))\r
+            {\r
+                return nullptr;\r
+            }\r
+\r
+            return remoteEnrollee;\r
+        }\r
+\r
+\r
+    }\r
+}\r
+\r
diff --git a/service/easy-setup/sdk/mediator/src/RemoteEnrollee.cpp b/service/easy-setup/sdk/mediator/src/RemoteEnrollee.cpp
new file mode 100644 (file)
index 0000000..81867ea
--- /dev/null
@@ -0,0 +1,190 @@
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#include "RemoteEnrollee.h"\r
+#include "RemoteEnrolleeResource.h"\r
+#include "ESException.h"\r
+#include "logger.h"\r
+\r
+namespace OIC\r
+{\r
+    #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"\r
+\r
+    namespace Service\r
+    {\r
+        RemoteEnrollee::RemoteEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo) :\r
+                m_enrolleeNWProvInfo(enrolleeNWProvInfo)\r
+        {\r
+            m_currentESState = CurrentESState::ES_UNKNOWN;\r
+\r
+            OC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Inside RemoteEnrollee constr");\r
+            if (m_easySetupStatusCb)\r
+            {\r
+                throw ESBadRequestException("Callback handler already registered");\r
+            }\r
+        }\r
+\r
+        void RemoteEnrollee::registerEasySetupStatusHandler(EasySetupStatusCB callback)\r
+        {\r
+            OC_LOG ( DEBUG, ES_REMOTE_ENROLLEE_TAG, "Entered registerStatusHandler");\r
+            if(!callback)\r
+            {\r
+                throw ESInvalidParameterException("Callback is empty");\r
+            }\r
+\r
+            if (m_easySetupStatusCb)\r
+            {\r
+                throw ESBadRequestException("Callback handler already registered");\r
+            }\r
+            else\r
+            {\r
+                m_easySetupStatusCb = callback;\r
+\r
+                m_remoteResource = std::make_shared< RemoteEnrolleeResource >(\r
+                        m_enrolleeNWProvInfo.netAddressInfo.WIFI.ipAddress,\r
+                        m_enrolleeNWProvInfo.connType);\r
+\r
+                m_remoteResource->constructResourceObject();\r
+            }\r
+        }\r
+\r
+        void RemoteEnrollee::provisioningStatusHandler(\r
+                std::shared_ptr< ProvisioningStatus > provStatus)\r
+        {\r
+            OC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering ProvisioningStatusHandler");\r
+\r
+            OC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"ProvStatus = %d", provStatus->getESResult());\r
+\r
+            std::shared_ptr< EasySetupStatus > easySetupStatus = nullptr;\r
+\r
+            if (m_enrolleeNWProvInfo.isSecured)\r
+            {\r
+                if (m_currentESState > CurrentESState::ES_OWNED)\r
+                {\r
+                    goto CALLBACK_CHECK;\r
+                }\r
+                else\r
+                {\r
+                    goto FAILURE;\r
+                }\r
+            }\r
+            else\r
+            {\r
+                goto CALLBACK_CHECK;\r
+            }\r
+\r
+            CALLBACK_CHECK:\r
+\r
+            if (provStatus->getESResult() == ES_OK)\r
+            {\r
+                if (provStatus->getESState() >= ESState::ES_PROVISIONED_ALREADY)\r
+                {\r
+                    easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_PROVISIONED,\r
+                            m_enrolleeNWProvInfo);\r
+                }\r
+                else\r
+                {\r
+                    easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,\r
+                            m_enrolleeNWProvInfo);\r
+                }\r
+            }\r
+            else\r
+            {\r
+                easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,\r
+                        m_enrolleeNWProvInfo);\r
+            }\r
+\r
+            if (m_easySetupStatusCb)\r
+            {\r
+                if (easySetupStatus)\r
+                {\r
+                    m_easySetupStatusCb(easySetupStatus);\r
+                }\r
+                else\r
+                {\r
+                    m_easySetupStatusCb(nullptr);\r
+                }\r
+            }\r
+\r
+            return;\r
+\r
+            FAILURE:\r
+\r
+            easySetupStatus = std::make_shared< EasySetupStatus >(DEVICE_NOT_PROVISIONED,\r
+                                    m_enrolleeNWProvInfo);\r
+\r
+            if (easySetupStatus)\r
+            {\r
+                m_easySetupStatusCb(easySetupStatus);\r
+            }\r
+            else\r
+            {\r
+                m_easySetupStatusCb(nullptr);\r
+            }\r
+            return;\r
+        }\r
+\r
+\r
+        void RemoteEnrollee::startProvisioning()\r
+        {\r
+            OC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Entering startProvisioning");\r
+            if (m_remoteResource == nullptr)\r
+            {\r
+                throw ESBadRequestException ("Device not created");\r
+            }\r
+            else\r
+            {\r
+                m_currentESState = CurrentESState::ES_ONBOARDED;\r
+\r
+                OC_LOG(DEBUG,ES_REMOTE_ENROLLEE_TAG,"Before ProvisionEnrollee");\r
+\r
+                RemoteEnrolleeResource::ProvStatusCb provStatusCb = std::bind(\r
+                        &RemoteEnrollee::provisioningStatusHandler, this, std::placeholders::_1);\r
+\r
+                m_remoteResource->registerProvStatusCallback(provStatusCb);\r
+                m_remoteResource->provisionEnrollee(m_enrolleeNWProvInfo);\r
+            }\r
+        }\r
+\r
+        void RemoteEnrollee::stopProvisioning()\r
+        {\r
+            m_currentESState = CurrentESState::ES_UNKNOWN;\r
+\r
+            m_remoteResource->unprovisionEnrollee();\r
+        }\r
+\r
+        bool RemoteEnrollee::isEnrolleeProvisioned()\r
+        {\r
+            if(m_currentESState >= CurrentESState::ES_PROVISIONED)\r
+            {\r
+                return true;\r
+            }\r
+            else\r
+            {\r
+                return false;\r
+            }\r
+        }\r
+\r
+        EnrolleeNWProvInfo& RemoteEnrollee::getEnrolleeProvisioningInfo ()\r
+        {\r
+            return m_enrolleeNWProvInfo;\r
+        }\r
+    }\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.cpp b/service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.cpp
new file mode 100755 (executable)
index 0000000..750f698
--- /dev/null
@@ -0,0 +1,293 @@
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#include <functional>\r
+\r
+#include "RemoteEnrolleeResource.h"\r
+\r
+#include "OCPlatform.h"\r
+#include "ESException.h"\r
+#include "OCResource.h"\r
+#include "logger.h"\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        #define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"\r
+        static const char ES_RES_URI[]  = "/oic/prov";\r
+        static const char ES_RES_TYPE[] = "oic.r.prov";\r
+\r
+        RemoteEnrolleeResource::RemoteEnrolleeResource(const std::string& host,\r
+                OCConnectivityType connectivityType) :\r
+                m_host(host), m_connectivityType(connectivityType)\r
+        {\r
+\r
+        }\r
+\r
+        void RemoteEnrolleeResource::onProvPostResource(const HeaderOptions& /*headerOptions*/,\r
+                const OCRepresentation& rep, const int eCode)\r
+        {\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvPostResource : %s, eCode = %d",\r
+                    rep.getUri().c_str(),\r
+                    eCode);\r
+\r
+            if(eCode != 0)\r
+            {\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+                        "onProvPostResource : Provisioning is failed ");\r
+                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
+                m_provStatusCb(provStatus);\r
+                return;\r
+            }\r
+\r
+            int ps = -1;\r
+            std::string tnn = "";\r
+            std::string cd = "";\r
+\r
+            rep.getValue(OC_RSRVD_ES_PS, ps);\r
+            rep.getValue(OC_RSRVD_ES_TNN, tnn);\r
+            rep.getValue(OC_RSRVD_ES_CD, cd);\r
+\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvPostResource : ps - %d",\r
+                    ps);OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : tnn - %s",\r
+                    tnn.c_str());OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : cd - %s",\r
+                    cd.c_str());\r
+\r
+            //Provisioning status check\r
+            if (ps == 0)\r
+            {\r
+                OC::QueryParamsMap query;\r
+                OC::OCRepresentation rep;\r
+\r
+                OCStackResult result = m_ocResource->get(m_ocResource->getResourceTypes().at(0),\r
+                        m_ocResource->getResourceInterfaces().at(0), query,\r
+                        std::function<\r
+                                void(const HeaderOptions& headerOptions,\r
+                                        const OCRepresentation& rep, const int eCode) >(\r
+                                std::bind(&RemoteEnrolleeResource::onProvResource, this,\r
+                                        std::placeholders::_1, std::placeholders::_2,\r
+                                        std::placeholders::_3)));\r
+\r
+                if(result != OCStackResult::OC_STACK_OK)\r
+                {\r
+                    std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+                            ProvisioningStatus >(ESResult::ES_ERROR,\r
+                            ESState::ES_PROVISIONING_ERROR);\r
+                    m_provStatusCb(provStatus);\r
+                    return;\r
+                }\r
+            }\r
+            else\r
+            {\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+                        "onProvResource : Provisioning is failed ");\r
+                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
+                m_provStatusCb(provStatus);\r
+                return;\r
+            }\r
+        }\r
+\r
+        void RemoteEnrolleeResource::onProvResource(const HeaderOptions& /*headerOptions*/,\r
+                                                    const OCRepresentation& rep,\r
+                                                    const int eCode)\r
+        {\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : %s, eCode = %d",\r
+                    rep.getUri().c_str(),\r
+                    eCode);\r
+\r
+            if (eCode != 0)\r
+            {\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+                                            "onProvResource : Provisioning is failed ");\r
+                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
+                m_provStatusCb(provStatus);\r
+                return;\r
+            }\r
+\r
+            int ps = -1;\r
+            std::string tnn = "";\r
+            std::string cd = "";\r
+\r
+            rep.getValue(OC_RSRVD_ES_PS, ps);\r
+            rep.getValue(OC_RSRVD_ES_TNN, tnn);\r
+            rep.getValue(OC_RSRVD_ES_CD, cd);\r
+\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : ps - %d",\r
+                                ps);\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : tnn - %s",\r
+                                            tnn.c_str());\r
+            OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : cd - %s",\r
+                                            cd.c_str());\r
+\r
+            if (ps == 1) //ps == 1 indicates the need for provisioning\r
+            {\r
+                OCRepresentation provisioningRepresentation;\r
+\r
+                provisioningRepresentation.setValue(OC_RSRVD_ES_TNN,\r
+                        m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid);\r
+                provisioningRepresentation.setValue(OC_RSRVD_ES_CD,\r
+                                        m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd);\r
+\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : ssid - %s",\r
+                                            m_enrolleeNWProvInfo.netAddressInfo.WIFI.ssid);\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onProvResource : pwd - %s",\r
+                                            m_enrolleeNWProvInfo.netAddressInfo.WIFI.pwd);\r
+\r
+                m_ocResource->put(provisioningRepresentation, QueryParamsMap(),\r
+                        std::function<\r
+                                void(const HeaderOptions& headerOptions,\r
+                                        const OCRepresentation& rep, const int eCode) >(\r
+                                std::bind(&RemoteEnrolleeResource::onProvPostResource, this,\r
+                                        std::placeholders::_1, std::placeholders::_2,\r
+                                        std::placeholders::_3)));\r
+            }\r
+            else if(ps == 0) //ps == 1 indicates that provisioning is completed\r
+            {\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+                        "onProvResource : Provisioning is successful");\r
+                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+                        ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONED_ALREADY);\r
+                m_provStatusCb(provStatus);\r
+            }\r
+        }\r
+\r
+        void RemoteEnrolleeResource::registerProvStatusCallback (ProvStatusCb provStatusCb)\r
+        {\r
+            m_provStatusCb = provStatusCb;\r
+        }\r
+\r
+        void RemoteEnrolleeResource::constructResourceObject()\r
+        {\r
+            if (m_ocResource != nullptr)\r
+            {\r
+                throw ESBadRequestException("Remote resource is already created");\r
+            }\r
+\r
+            try\r
+            {\r
+
+                std::vector< std::string > m_if = { DEFAULT_INTERFACE };\r
+                std::vector< std::string > m_resTypes = {ES_RES_TYPE};\r
+\r
+\r
+                OC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "Before OCPlatform::constructResourceObject");\r
+\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "m_host = %s", m_host.c_str());\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "ES_RES_URI = %s", ES_RES_URI);\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "m_connectivityType = %d",\r
+                                                            m_connectivityType);\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "m_resTypes = %s",\r
+                                                            m_resTypes.at(0).c_str());\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "m_if = %s", m_if.at(0).c_str());\r
+\r
+                std::string host;\r
+                if(m_enrolleeNWProvInfo.isSecured)\r
+                {\r
+                    host.append("coaps://");\r
+                }\r
+                else\r
+                {\r
+                    host.append("coap://");\r
+                }\r
+\r
+                if(m_connectivityType == CT_ADAPTER_IP)\r
+                {\r
+                    host.append(m_host);\r
+                    //TODO : If the target Enrollee is not a Arduino Wi-Fi device, then m_ocResource\r
+                    // will be discovered using findResource API of OCPlatform instead of using\r
+                    // constructResourceObject API. The port number thus will be found during\r
+                    // resource discovery instead of using 55555\r
+                    host.append(":55555");\r
+                }\r
+\r
+                OC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_TAG, "HOST = %s", host.c_str());\r
+\r
+                m_ocResource = OC::OCPlatform::constructResourceObject(host,\r
+                                                                   ES_RES_URI,\r
+                                                                   m_connectivityType,\r
+                                                                   true,\r
+                                                                   m_resTypes,\r
+                                                                   m_if);\r
+                OC_LOG_V(DEBUG, ES_REMOTE_ENROLLEE_TAG,\r
+                        "created OCResource : %s", m_ocResource->uri().c_str());\r
+            }\r
+            catch (OCException & e)\r
+            {\r
+                OC_LOG_V(ERROR, ES_REMOTE_ENROLLEE_TAG,\r
+                        "Exception for constructResourceObject : %s", e.reason().c_str());\r
+            }\r
+        }\r
+\r
+        void RemoteEnrolleeResource::provisionEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo)\r
+\r
+        {\r
+            if(m_ocResource == nullptr)\r
+            {\r
+                throw ESBadRequestException ("Resource is not initialized");\r
+            }\r
+\r
+            m_enrolleeNWProvInfo = enrolleeNWProvInfo;\r
+            OC::QueryParamsMap query;\r
+            OC::OCRepresentation rep;\r
+\r
+            OCStackResult result = m_ocResource->get(m_ocResource->getResourceTypes().at(0),\r
+                    m_ocResource->getResourceInterfaces().at(0), query,\r
+                    std::function<\r
+                            void(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+                                    const int eCode) >(\r
+                            std::bind(&RemoteEnrolleeResource::onProvResource, this,\r
+                                    std::placeholders::_1, std::placeholders::_2,\r
+                                    std::placeholders::_3)));\r
+\r
+            if (result != OCStackResult::OC_STACK_OK)\r
+            {\r
+                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<\r
+                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);\r
+                m_provStatusCb(provStatus);\r
+                return;\r
+            }\r
+        }\r
+\r
+        void RemoteEnrolleeResource::unprovisionEnrollee()\r
+        {\r
+            if (m_ocResource == nullptr)\r
+            {\r
+                throw ESBadRequestException("Resource is not initialized");\r
+            }\r
+\r
+            OCRepresentation provisioningRepresentation;\r
+\r
+            provisioningRepresentation.setValue(OC_RSRVD_ES_TNN, "");\r
+            provisioningRepresentation.setValue(OC_RSRVD_ES_CD, "");\r
+\r
+            m_ocResource->post(provisioningRepresentation, QueryParamsMap(),\r
+                    std::function<\r
+                            void(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+                                    const int eCode) >(\r
+                            std::bind(&RemoteEnrolleeResource::onProvPostResource, this,\r
+                                    std::placeholders::_1, std::placeholders::_2,\r
+                                    std::placeholders::_3)));\r
+        }\r
+    }\r
+}\r
diff --git a/service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.h b/service/easy-setup/sdk/mediator/src/RemoteEnrolleeResource.h
new file mode 100755 (executable)
index 0000000..84e1d3c
--- /dev/null
@@ -0,0 +1,120 @@
+//******************************************************************\r
+//\r
+// Copyright 2015 Samsung Electronics All Rights Reserved.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//      http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+//\r
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\r
+\r
+#ifndef REMOTE_ENROLLEE_RESOURCE_H_\r
+#define REMOTE_ENROLLEE_RESOURCE_H_\r
+\r
+#include <mutex>\r
+#include <memory>\r
+\r
+#include "escommon.h"\r
+\r
+#include "OCApi.h"\r
+\r
+using namespace OC;\r
+\r
+namespace OIC\r
+{\r
+    namespace Service\r
+    {\r
+        class OCResource;\r
+\r
+        /**\r
+         * This class contains the resource discovery methods.\r
+         *\r
+         * @see RemoteEnrolleeResource\r
+         */\r
+        class RemoteEnrolleeResource\r
+        {\r
+        public:\r
+            typedef std::shared_ptr< RemoteEnrolleeResource > Ptr;\r
+\r
+            typedef std::function< void(std::shared_ptr< ProvisioningStatus > provStatus) > ProvStatusCb;\r
+\r
+            /**\r
+             * RemoteEnrolleeResource constructor\r
+             *\r
+             * @param host Host information of the Enrollee device obtained from OnBoarding process.\r
+             * @param connectivityType Connectivity type on which OnBoarding is performed\r
+             *\r
+             * @throw ESBadRequestException is thrown if the parameters are invalid\r
+             */\r
+            RemoteEnrolleeResource(const std::string& host, OCConnectivityType connectivityType);\r
+\r
+            ~RemoteEnrolleeResource() = default;\r
+\r
+            /**\r
+             * Register provisioning status handler.\r
+             *\r
+             * @param callback Callback to get Provisioning status.\r
+             *\r
+             * @throws InvalidParameterException If callback is an empty function or null.\r
+             * @throws ESBadRequestException If registration is already completed.\r
+             *\r
+             * @see ProvisioningStatus\r
+             */\r
+            void registerProvStatusCallback (ProvStatusCb provStatusCb);\r
+\r
+            /**\r
+             * Construct Remote OIC resource using the enrollee host and connectivity information\r
+             * provided in the constructor of RemoteEnrolleeResource.\r
+             *\r
+             * @throws InvalidParameterException If the provided information is invalid.\r
+             * @throws ESBadRequestException If resource is already constructed.\r
+             *\r
+             * @see ProvisioningStatus\r
+             */\r
+            void constructResourceObject();\r
+\r
+            /**\r
+             * Function for provisioning of Remote Enrollee resource using the information provided.\r
+             *\r
+             * @param enrolleeNWProvInfo Provisioning information for the Enrollee\r
+             *\r
+             * @throws InvalidParameterException If cb is empty.\r
+             */\r
+            virtual void provisionEnrollee(const EnrolleeNWProvInfo& enrolleeNWProvInfo);\r
+\r
+            /**\r
+             * Function for unprovisioning of Remote Enrollee and bring to unprovisioned state\r
+             *\r
+             * @throws ESBadRequestException If device is not provisioned already.\r
+             */\r
+            virtual void unprovisionEnrollee();\r
+\r
+\r
+\r
+        private:\r
+            std::shared_ptr< OC::OCResource > m_ocResource;\r
+            std::mutex m_mutex;\r
+            std::string m_host;\r
+            OCConnectivityType m_connectivityType;\r
+            ProvStatusCb m_provStatusCb;\r
+            EnrolleeNWProvInfo m_enrolleeNWProvInfo;\r
+\r
+            void onProvResource(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+                    const int eCode);\r
+\r
+            void onProvPostResource(const HeaderOptions& headerOptions, const OCRepresentation& rep,\r
+                    const int eCode);\r
+        };\r
+    }\r
+}\r
+#endif\r
old mode 100755 (executable)
new mode 100644 (file)
index 98fe0fc..e600fac
@@ -43,10 +43,10 @@ OCStackResult InitProvProcess() {
 
     if (InitProvisioningHandler() == OC_STACK_OK) {
         result = OC_STACK_OK;
-        OIC_LOG(DEBUG, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned Success");
+        OC_LOG(DEBUG, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned Success");
     } else {
         result = OC_STACK_ERROR;
-        OIC_LOG_V(ERROR, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned error = %d",
+        OC_LOG_V(ERROR, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned error = %d",
                   result);
     }
 
@@ -65,7 +65,7 @@ OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback
     }
     else {
         result = OC_STACK_ERROR;
-        OIC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL");
+        OC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL");
     }
 
     return result;
@@ -77,7 +77,7 @@ void UnRegisterCallback() {
     }
 }
 
-OCStackResult StartProvisioning(const EnrolleeNWProvInfo_t *netInfo) {
+OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo) {
 
     char findQuery[64] = {0};
     snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY,
old mode 100755 (executable)
new mode 100644 (file)
similarity index 95%
rename from service/easy-setup/sdk/mediator/inc/prov_adapter.h
rename to service/easy-setup/sdk/mediator/src/prov_adapter.h
index fdd611f..77923c8
@@ -47,7 +47,7 @@ OCStackResult RegisterCallback(
 
 void UnRegisterCallback();
 
-OCStackResult StartProvisioning(const EnrolleeNWProvInfo_t *netInfo);
+OCStackResult StartProvisioning(const EnrolleeNWProvInfo *netInfo);
 
 OCStackResult StopProvisioning(OCConnectivityType connectivityType);
 
old mode 100755 (executable)
new mode 100644 (file)
index 26fb88e..b4d4b11
@@ -42,7 +42,7 @@
 
 bool g_provisioningCondFlag = false;
 
-static EnrolleeNWProvInfo_t *netProvInfo;
+static EnrolleeNWProvInfo *netProvInfo;
 
 char szFindResourceQueryUri[64] = {0};
 
@@ -64,7 +64,7 @@ OCStackResult InitProvisioningHandler() {
     OCStackResult ret = OC_STACK_ERROR;
     /* Initialize OCStack*/
     if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
-        OIC_LOG(ERROR, ES_PROV_TAG, "OCStack init error");
+        OC_LOG(ERROR, ES_PROV_TAG, "OCStack init error");
         return ret;
     }
 
@@ -72,7 +72,7 @@ OCStackResult InitProvisioningHandler() {
     pthread_t thread_handle;
 
     if (pthread_create(&thread_handle, NULL, listeningFunc, NULL)) {
-        OIC_LOG(DEBUG, ES_PROV_TAG, "Thread creation failed");
+        OC_LOG(DEBUG, ES_PROV_TAG, "Thread creation failed");
         return OC_STACK_ERROR;
     }
 
@@ -82,7 +82,7 @@ OCStackResult InitProvisioningHandler() {
 OCStackResult TerminateProvisioningHandler() {
     OCStackResult ret = OC_STACK_ERROR;
     if (OCStop() != OC_STACK_OK) {
-        OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
+        OC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
     }
 
     g_provisioningCondFlag = true;
@@ -98,7 +98,7 @@ void *listeningFunc(void* /*data*/) {
         result = OCProcess();
 
         if (result != OC_STACK_OK) {
-            OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
+            OC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
         }
 
         // To minimize CPU utilization we may wish to do this with sleep
@@ -110,7 +110,7 @@ void *listeningFunc(void* /*data*/) {
 
 OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*handle*/,
                                                    OCClientResponse *clientResponse) {
-    OIC_LOG_V(DEBUG, ES_PROV_TAG, "INSIDE ProvisionEnrolleeResponse");
+    OC_LOG_V(DEBUG, ES_PROV_TAG, "INSIDE ProvisionEnrolleeResponse");
 
     // If user stopped the process then return from this function;
     if (IsSetupStopped()) {
@@ -139,7 +139,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*h
                 continue;
             }
             else {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "PS is NOT proper");
+                OC_LOG_V(DEBUG, ES_PROV_TAG, "PS is NOT proper");
                 goto Error;
 
             }
@@ -147,24 +147,24 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*h
 
         if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) {
             if (!strcmp(tnn, netProvInfo->netAddressInfo.WIFI.ssid)) {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is proper");
+                OC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is proper");
                 input = input->next;
                 continue;
             }
             else {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is NOT proper");
+                OC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is NOT proper");
                 goto Error;
             }
         }
 
         if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) {
             if (!strcmp(cd, netProvInfo->netAddressInfo.WIFI.pwd)) {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "Password is proper");
+                OC_LOG_V(DEBUG, ES_PROV_TAG, "Password is proper");
                 input = input->next;
                 continue;
             }
             else {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "Password is NOT proper");
+                OC_LOG_V(DEBUG, ES_PROV_TAG, "Password is NOT proper");
                 goto Error;
             }
         }
@@ -193,7 +193,7 @@ OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*h
 
 }
 
-OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
+OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo *netInfo,
                                        OCProvisioningStatusCB provisioningStatusCallback,
                                        char *findResQuery) {
 
@@ -203,7 +203,7 @@ OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
     }
     else
     {
-        OIC_LOG(ERROR, ES_PROV_TAG, PCF("Find resource query is NULL"));
+        OC_LOG(ERROR, ES_PROV_TAG, PCF("Find resource query is NULL"));
         goto Error;
     }
 
@@ -215,7 +215,7 @@ OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
 
     if (!SetProgress(provisioningStatusCallback)) {
         // Device provisioning session is running already.
-        OIC_LOG(INFO, ES_PROV_TAG, PCF("Device provisioning session is running already"));
+        OC_LOG(INFO, ES_PROV_TAG, PCF("Device provisioning session is running already"));
         goto Error;
     }
 
@@ -249,28 +249,28 @@ void StopProvisioningProcess() {
 
 bool ClearMemory() {
 
-    OIC_LOG(DEBUG, ES_PROV_TAG, "thread_pool_add_task of FindProvisioningResource failed");
+    OC_LOG(DEBUG, ES_PROV_TAG, "thread_pool_add_task of FindProvisioningResource failed");
     OICFree(netProvInfo);
     return true;
 
 }
 
-bool ConfigEnrolleeObject(const EnrolleeNWProvInfo_t *netInfo) {
+bool ConfigEnrolleeObject(const EnrolleeNWProvInfo *netInfo) {
 
     //Copy Network Provisioning  Information
-    netProvInfo = (EnrolleeNWProvInfo_t *) OICCalloc(1, sizeof(EnrolleeNWProvInfo_t));
+    netProvInfo = (EnrolleeNWProvInfo *) OICCalloc(1, sizeof(EnrolleeNWProvInfo));
 
     if (netProvInfo == NULL) {
-        OIC_LOG(ERROR, ES_PROV_TAG, "Invalid input..");
+        OC_LOG(ERROR, ES_PROV_TAG, "Invalid input..");
         return false;
     }
 
-    memcpy(netProvInfo, netInfo, sizeof(EnrolleeNWProvInfo_t));
+    memcpy(netProvInfo, netInfo, sizeof(EnrolleeNWProvInfo));
 
-    OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. SSID = %s",
+    OC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. SSID = %s",
               netProvInfo->netAddressInfo.WIFI.ssid);
 
-    OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. PWD = %s",
+    OC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. PWD = %s",
               netProvInfo->netAddressInfo.WIFI.pwd);
 
     return true;
@@ -281,53 +281,53 @@ void LogProvisioningResponse(OCRepPayloadValue * val) {
 
     switch (val->type) {
         case OCREP_PROP_NULL:
-            OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s: NULL", val->name);
+            OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s: NULL", val->name);
             break;
         case OCREP_PROP_INT:
-            OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(int):%ld", val->name, val->i);
+            OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(int):%lld", val->name, val->i);
             break;
         case OCREP_PROP_DOUBLE:
-            OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(double):%f", val->name, val->d);
+            OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(double):%f", val->name, val->d);
             break;
         case OCREP_PROP_BOOL:
-            OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
+            OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(bool):%s", val->name, val->b ? "true" : "false");
             break;
         case OCREP_PROP_STRING:
-            OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(string):%s", val->name, val->str);
+            OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(string):%s", val->name, val->str);
             break;
         case OCREP_PROP_OBJECT:
             // Note: Only prints the URI (if available), to print further, you'll
             // need to dig into the object better!
-            OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
+            OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
             break;
         case OCREP_PROP_ARRAY:
             switch (val->arr.type) {
                 case OCREP_PROP_INT:
-                    OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(int array):%zu x %zu x %zu",
+                    OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(int array):%zu x %zu x %zu",
                               val->name,
                               val->arr.dimensions[0], val->arr.dimensions[1],
                               val->arr.dimensions[2]);
                     break;
                 case OCREP_PROP_DOUBLE:
-                    OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(double array):%zu x %zu x %zu",
+                    OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(double array):%zu x %zu x %zu",
                               val->name,
                               val->arr.dimensions[0], val->arr.dimensions[1],
                               val->arr.dimensions[2]);
                     break;
                 case OCREP_PROP_BOOL:
-                    OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
+                    OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
                               val->name,
                               val->arr.dimensions[0], val->arr.dimensions[1],
                               val->arr.dimensions[2]);
                     break;
                 case OCREP_PROP_STRING:
-                    OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(string array):%zu x %zu x %zu",
+                    OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(string array):%zu x %zu x %zu",
                               val->name,
                               val->arr.dimensions[0], val->arr.dimensions[1],
                               val->arr.dimensions[2]);
                     break;
                 case OCREP_PROP_OBJECT:
-                    OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
+                    OC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
                               val->name,
                               val->arr.dimensions[0], val->arr.dimensions[1],
                               val->arr.dimensions[2]);
@@ -344,7 +344,7 @@ void LogProvisioningResponse(OCRepPayloadValue * val) {
 OCStackResult FindNetworkResource() {
     OCStackResult ret = OC_STACK_ERROR;
     if (OCStop() != OC_STACK_OK) {
-        OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
+        OC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
     }
 
     return ret;
@@ -356,14 +356,14 @@ ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
     ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
 
     if (provInfo == NULL) {
-        OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
+        OC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
         return NULL;
     }
 
     OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr));
 
     if (devAddr == NULL) {
-        OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
+        OC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
         OICFree(provInfo);
         return NULL;
     }
@@ -384,7 +384,7 @@ bool InProgress() {
 
     // It means already Easy Setup provisioning session is going on.
     if (NULL != cbData) {
-        OIC_LOG(ERROR, ES_PROV_TAG, "Easy setup session is already in progress");
+        OC_LOG(ERROR, ES_PROV_TAG, "Easy setup session is already in progress");
         return true;
     }
 
@@ -413,14 +413,14 @@ ProvisioningInfo *CreateCallBackObject() {
     ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
 
     if (provInfo == NULL) {
-        OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
+        OC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
         return NULL;
     }
 
     OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr));
 
     if (devAddr == NULL) {
-        OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
+        OC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
         OICFree(provInfo);
         return NULL;
     }
@@ -457,7 +457,7 @@ bool ValidateFinddResourceResponse(OCClientResponse * clientResponse) {
 
     if (!(clientResponse) || !(clientResponse->payload)) {
 
-        OIC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
+        OC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
 
         return false;
 
@@ -469,7 +469,7 @@ bool ValidateEnrolleResponse(OCClientResponse * clientResponse) {
 
     if (!(clientResponse) || !(clientResponse->payload)) {
 
-        OIC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
+        OC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
 
         return false;
 
@@ -477,7 +477,7 @@ bool ValidateEnrolleResponse(OCClientResponse * clientResponse) {
 
     if (clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION) {
 
-        OIC_LOG_V(DEBUG, ES_PROV_TAG, "Incoming payload not a representation");
+        OC_LOG_V(DEBUG, ES_PROV_TAG, "Incoming payload not a representation");
         return false;
 
     }
@@ -504,7 +504,7 @@ void* FindProvisioningResource(void* /*data*/) {
 
     OCStackResult ret = OC_STACK_ERROR;
 
-    OIC_LOG_V(DEBUG, ES_PROV_TAG, "szFindResourceQueryUri = %s", szFindResourceQueryUri);
+    OC_LOG_V(DEBUG, ES_PROV_TAG, "szFindResourceQueryUri = %s", szFindResourceQueryUri);
 
     OCCallbackData ocCBData;
 
@@ -540,7 +540,7 @@ OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDev
                        &cbData, options, numOptions);
 
     if (ret != OC_STACK_OK) {
-        OIC_LOG_V(ERROR, ES_PROV_TAG, "OCDoResource returns error %d with method %d", ret, method);
+        OC_LOG_V(ERROR, ES_PROV_TAG, "OCDoResource returns error %d with method %d", ret, method);
     }
 
     return ret;
@@ -551,9 +551,9 @@ OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const
 
 
     // This sleep is required in case of BLE provisioning due to packet drop issue.
-    OIC_LOG_V(INFO, ES_PROV_TAG, "Sleeping for %d seconds", pauseBeforeStart);
+    OC_LOG_V(INFO, ES_PROV_TAG, "Sleeping for %d seconds", pauseBeforeStart);
     sleep(pauseBeforeStart);
-    OIC_LOG_V(INFO, ES_PROV_TAG, "\n\nExecuting ProvisionEnrollee%s", __func__);
+    OC_LOG_V(INFO, ES_PROV_TAG, "\n\nExecuting ProvisionEnrollee%s", __func__);
 
     OCRepPayload *payload = OCRepPayloadCreate();
 
@@ -561,7 +561,7 @@ OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_TNN, netProvInfo->netAddressInfo.WIFI.ssid);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CD, netProvInfo->netAddressInfo.WIFI.pwd);
 
-    OIC_LOG_V(DEBUG, ES_PROV_TAG, "OCPayload ready for ProvisionEnrollee");
+    OC_LOG_V(DEBUG, ES_PROV_TAG, "OCPayload ready for ProvisionEnrollee");
 
     OCStackResult ret = InvokeOCDoResource(query, OC_REST_PUT, destination, qos,
                                            ProvisionEnrolleeResponse, payload, NULL, 0);
old mode 100755 (executable)
new mode 100644 (file)
similarity index 95%
rename from service/easy-setup/sdk/mediator/inc/provisioning.h
rename to service/easy-setup/sdk/mediator/src/provisioning.h
index 058d975..9993537
@@ -64,7 +64,7 @@ OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDev
 OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
                                     const OCDevAddr *destination);
 
-OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo_t *netInfo,
+OCStackResult StartProvisioningProcess(const EnrolleeNWProvInfo *netInfo,
                                        OCProvisioningStatusCB provisioningStatusCallback,
                                        char *findResQuery);
 
@@ -82,7 +82,7 @@ ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
 
 void LogProvisioningResponse(OCRepPayloadValue * val);
 
-bool ConfigEnrolleeObject(const EnrolleeNWProvInfo_t *netInfo);
+bool ConfigEnrolleeObject(const EnrolleeNWProvInfo *netInfo);
 
 bool ClearMemory();
 
@@ -107,7 +107,7 @@ bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback);
 
 bool InProgress();
 
-bool ValidateEasySetupParams(const EnrolleeNWProvInfo_t *netInfo,
+bool ValidateEasySetupParams(const EnrolleeNWProvInfo *netInfo,
                              OCProvisioningStatusCB provisioningStatusCallback);
 
 bool IsSetupStopped();
old mode 100755 (executable)
new mode 100644 (file)
index aa8f161..92105e1
@@ -66,7 +66,7 @@ OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/,
     char resURI[MAX_URI_LENGTH] =
             {'\0'};
 
-    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", input->uri);
+    OC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", input->uri);
 
     strncpy(resURI, input->uri, sizeof(resURI) - 1);
 
@@ -75,7 +75,7 @@ OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/,
 
     if (ProvisionEnrollee(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, clientResponse->addr, 0)
         != OC_STACK_OK) {
-        OIC_LOG(INFO, ES_WIFI_PROV_TAG, "GetProvisioningStatusResponse received NULL clientResponse");
+        OC_LOG(INFO, ES_WIFI_PROV_TAG, "GetProvisioningStatusResponse received NULL clientResponse");
 
         ErrorCallback(DEVICE_NOT_PROVISIONED);
         ClearMemory();
@@ -91,7 +91,7 @@ OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
     OCStackResult ret = OC_STACK_ERROR;
     OCHeaderOption options[MAX_HEADER_OPTIONS];
 
-    OIC_LOG_V(INFO, ES_WIFI_PROV_TAG, "\n\nExecuting %s", __func__);
+    OC_LOG_V(INFO, ES_WIFI_PROV_TAG, "\n\nExecuting %s", __func__);
 
     uint8_t option0[] =
             {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@@ -118,7 +118,7 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/,
                                                             OCDoHandle /*handle*/,
                                                             OCClientResponse *clientResponse) {
 
-    OIC_LOG(INFO, ES_WIFI_PROV_TAG, PCF("Entering FindProvisioningResourceResponse"));
+    OC_LOG(INFO, ES_WIFI_PROV_TAG, PCF("Entering FindProvisioningResourceResponse"));
 
     // If user stopped the process then return from this function;
     if (IsSetupStopped()) {
@@ -137,12 +137,12 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/,
 
     OCDiscoveryPayload *discoveryPayload = (OCDiscoveryPayload * )(clientResponse->payload);
 
-    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri);
+    OC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri);
 
     snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY,
              clientResponse->devAddr.addr, IP_PORT, discoveryPayload->resources->uri);
 
-    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "query before GetProvisioningStatus call = %s", szQueryUri);
+    OC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "query before GetProvisioningStatus call = %s", szQueryUri);
 
     if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri, &clientResponse->devAddr) != OC_STACK_OK) {
         ErrorCallback(DEVICE_NOT_PROVISIONED);
@@ -153,16 +153,16 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/,
 
 }
 
-bool ValidateEasySetupParams(const EnrolleeNWProvInfo_t *netInfo,
+bool ValidateEasySetupParams(const EnrolleeNWProvInfo *netInfo,
                              OCProvisioningStatusCB provisioningStatusCallback) {
 
     if (netInfo == NULL || strlen(netInfo->netAddressInfo.WIFI.ipAddress) == 0) {
-        OIC_LOG(ERROR, ES_WIFI_PROV_TAG, "Request URI is NULL");
+        OC_LOG(ERROR, ES_WIFI_PROV_TAG, "Request URI is NULL");
         return false;
     }
 
     if (provisioningStatusCallback == NULL) {
-        OIC_LOG(ERROR, ES_WIFI_PROV_TAG, "ProvisioningStatusCallback is NULL");
+        OC_LOG(ERROR, ES_WIFI_PROV_TAG, "ProvisioningStatusCallback is NULL");
         return false;
     }