Added iotivity API interface. Build scripts updated.
authorLomtev Dmytro <d.lomtev@samsung.com>
Thu, 20 Apr 2017 07:26:49 +0000 (10:26 +0300)
committerLomtev Dmytro <d.lomtev@samsung.com>
Thu, 20 Apr 2017 07:32:03 +0000 (10:32 +0300)
15 files changed:
network-manager/NetworkManager.manifest
network-manager/nmdaemon/nmdaemon.manifest
network-manager/nmlib/CMakeLists.txt
network-manager/nmlib/IoT/inc/iotdevice_impl.h [new file with mode: 0644]
network-manager/nmlib/IoT/src/iotdevice_impl.cpp [new file with mode: 0644]
network-manager/nmlib/IoT/src/iotivity.cpp [new file with mode: 0644]
network-manager/nmlib/REST/src/rest_helper.cpp
network-manager/nmlib/include/iotdevice.h [new file with mode: 0644]
network-manager/nmlib/include/iotivity.h [new file with mode: 0644]
network-manager/nmlib/include/nmexceptions.h [new file with mode: 0644]
network-manager/nmlib/include/uuid.h [new file with mode: 0644]
network-manager/packaging/ioswsec.spec
network-manager/scripts/gbs.conf
network-manager/test/test_REST.cpp
network-manager/test/tests.manifest

index 75b0fa5..c51da48 100644 (file)
@@ -1,5 +1,5 @@
 <manifest>
     <request>
-        <domain name="_"/>
+        <domain name="_" />
     </request>
-</manifest>
+</manifest>
\ No newline at end of file
index 06c79f0..7286b99 100644 (file)
@@ -1,13 +1,16 @@
 <manifest>
     <define>
-        <domain name='nmdaemon' policy='shared' />
+        <domain name="nmdaemon" />
         <request>
             <smack request="device::app_logging" type="w"/>
-            <smack request="system::use_internet" type="rw"/>
-            <smack request="system::run" type="rwxat"/>
+            <smack request="System::Use_internet" type="rw"/>
+            <smack request="System::Run" type="rwxat"/>
         </request>
         <permit>
-            <smack permit="system::use_internet" type="rw"/>
+            <smack permit="System::Use_internet" type="rw"/>
         </permit>
     </define>
+    <request>
+        <domain name="nmdaemon" />
+    </request>
 </manifest>
index 16c003b..8c7da78 100644 (file)
@@ -6,12 +6,27 @@ add_definitions(-std=c++11)
 
 INCLUDE(FindPkgConfig)
 
+pkg_check_modules(pkgs REQUIRED iotivity>=1.2.1 boost)
+
+FOREACH(flag ${pkgs_CFLAGS})
+    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DTB_LOG -D__TIZEN__")
+
+
 pkg_check_modules(NMLIB_REQ_PKGS REQUIRED libcurl)
 pkg_check_modules(NMLIB_REQ_PKGS REQUIRED dpm)
 pkg_check_modules(NMLIB_REQ_PKGS REQUIRED dlog)
 
-include_directories(REST/inc dpm/inc)
-SET(LIB_SOURCES REST/src/rest_helper.cpp dpm/src/dpm.cpp)
+include_directories(include REST/inc dpm/inc IoT/inc)
+
+SET( LIB_SOURCES 
+    REST/src/rest_helper.cpp
+    dpm/src/dpm.cpp
+    IoT/src/iotivity.cpp
+    IoT/src/iotdevice_impl.cpp
+)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
@@ -26,9 +41,19 @@ ENDFOREACH(flag)
 
 add_library(${PROJECT_NAME} SHARED ${LIB_SOURCES})
 
-target_link_libraries(${PROJECT_NAME} ${NMLIB_REQ_PKGS_LIBRARIES})
-target_link_libraries (${PROJECT_NAME} dpm)
-#target_link_libraries(${PROJECT_NAME} curl)
+target_link_libraries(${PROJECT_NAME}
+    ${NMLIB_REQ_PKGS_LIBRARIES}
+    dpm
+
+    # SECURED=1 provisioning lib
+    ocpmapi ocprovision
+
+    # Easy-setup sdk lib
+    #ESMediatorRich
+    
+    # main iotivity libs
+    oc octbstack oc_logger connectivity_abstraction
+)
 
 
 install(TARGETS ${PROJECT_NAME} DESTINATION ${LIBDIR})
diff --git a/network-manager/nmlib/IoT/inc/iotdevice_impl.h b/network-manager/nmlib/IoT/inc/iotdevice_impl.h
new file mode 100644 (file)
index 0000000..06c032b
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef __IOTDEVICE_IMPL_H__
+#define __IOTDEVICE_IMPL_H__
+
+#include "iotdevice.h"
+#include <memory>
+#include <OCApi.h>
+#include <OCPlatform.h>
+
+namespace NetworkManager {
+
+class IoTDevice_impl: public IoTDevice
+{
+public:    
+    IoTDevice_impl(std::shared_ptr<OC::OCResource> device_resource);
+    ~IoTDevice_impl() override;
+
+    const UUID& getUUID() override;
+    
+    const std::string& getName() override;
+    
+    const std::string& getModel() override;
+    
+    const std::string& getType() override;
+    
+    void ownDevice() override;
+
+    void unOwnDevice() override;
+private:
+    std::shared_ptr<OC::OCResource> dev;
+    std::string name;
+    std::string model;
+    std::string type;
+    UUID uuid;
+};
+
+}
+
+#endif // __IOTDEVICE_IMPL_H__
\ No newline at end of file
diff --git a/network-manager/nmlib/IoT/src/iotdevice_impl.cpp b/network-manager/nmlib/IoT/src/iotdevice_impl.cpp
new file mode 100644 (file)
index 0000000..9ac1386
--- /dev/null
@@ -0,0 +1,46 @@
+#include "iotdevice_impl.h"
+
+namespace NetworkManager {
+
+
+IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OC::OCResource> device_resource)
+    : dev(device_resource), name("test iot device"), model("test model"), type("generic type"), uuid{0}
+{
+}
+
+IoTDevice_impl::~IoTDevice_impl() 
+{
+
+}
+
+const UUID& IoTDevice_impl::getUUID()
+{
+    return uuid;
+}
+
+const std::string& IoTDevice_impl::getName()
+{
+    return name;
+}
+
+const std::string& IoTDevice_impl::getModel()
+{
+    return model;
+}
+
+const std::string& IoTDevice_impl::getType()
+{
+    return type;
+}
+
+void IoTDevice_impl::ownDevice()
+{
+
+}
+
+void IoTDevice_impl::unOwnDevice()
+{
+
+}
+
+}
diff --git a/network-manager/nmlib/IoT/src/iotivity.cpp b/network-manager/nmlib/IoT/src/iotivity.cpp
new file mode 100644 (file)
index 0000000..9a30ee1
--- /dev/null
@@ -0,0 +1,41 @@
+#include "iotivity.h"
+#include "iotdevice_impl.h"
+
+namespace NetworkManager {
+
+
+IoTivity* IoTivity::instance = nullptr;
+
+IoTivity::IoTivity()
+{
+
+}
+
+IoTivity* IoTivity::getInstance()
+{
+    return instance;
+}
+
+void IoTivity::signIn(const std::string& host, const std::string& user, const std::string& password)
+{
+
+}
+
+void IoTivity::signOut()
+{
+
+}
+
+
+IoTDevicesVector IoTivity::getOwnedDevices()
+{
+    return IoTDevicesVector();
+}
+
+IoTDevicesVector IoTivity::getUnOwnedDevices()
+{
+    return IoTDevicesVector();
+}
+
+
+}
index d1f1c45..ad3bd8d 100644 (file)
@@ -103,19 +103,15 @@ RestHelper::ProcessRequest(const Params& params, const std::string& uri)
 
     for (auto i : params)
     {
-        if (strParam.empty())
-        {
-            strParam += "?";
-        }
-        else
-        {
-            strParam += "&";
-        }
-
-        strParam += (i.first + "=" + i.second);
+        strParam.push_back(strParam.empty() ? '?' : '&');
+        strParam.append(i.first);
+        strParam.push_back('=');
+        strParam.append(i.second);
     }
 
-    std::string url = std::string(m_urlBase + uri + strParam);
+    std::string url = m_urlBase;
+    url.append(uri);
+    url.append(strParam);
 
     curl_easy_setopt(m_curlHandle, CURLOPT_URL, url.c_str());
 
diff --git a/network-manager/nmlib/include/iotdevice.h b/network-manager/nmlib/include/iotdevice.h
new file mode 100644 (file)
index 0000000..80caa4f
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef __IOTDEVICE_H__
+#define __IOTDEVICE_H__
+
+
+#include <string>
+#include "uuid.h"
+
+namespace NetworkManager {
+
+class IoTDevice
+{
+public:    
+    virtual ~IoTDevice() {}
+
+    virtual const UUID& getUUID() = 0;
+    
+    virtual const std::string& getName() = 0;
+    
+    virtual const std::string& getModel() = 0;
+    
+    virtual const std::string& getType() = 0;
+    
+    virtual void ownDevice() = 0;
+
+    virtual void unOwnDevice() = 0;
+};
+
+}
+
+#endif // __IOTDEVICE_H__
\ No newline at end of file
diff --git a/network-manager/nmlib/include/iotivity.h b/network-manager/nmlib/include/iotivity.h
new file mode 100644 (file)
index 0000000..5c366c0
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __NMLIB_H__
+#define __NMLIB_H__
+
+#include "nmexceptions.h"
+#include "iotdevice.h"
+#include <memory>
+#include <vector>
+
+namespace NetworkManager {
+
+typedef std::vector<std::shared_ptr<IoTDevice>> IoTDevicesVector;
+
+class IoTivity
+{
+private:
+    IoTivity();
+    static IoTivity* instance;
+public:
+    
+    static IoTivity* getInstance();
+
+    void signIn(const std::string& host, const std::string& user, const std::string& password);
+    
+    void signOut();
+    
+    /**
+     * @brief Get owned devices list from iotcloud server
+     */
+    IoTDevicesVector getOwnedDevices();
+    /**
+     * @brief Get unowned devices list from local network
+     */
+    IoTDevicesVector getUnOwnedDevices();              // discuss which is preferable
+};
+
+
+}
+
+#endif //__NMLIB_H__
diff --git a/network-manager/nmlib/include/nmexceptions.h b/network-manager/nmlib/include/nmexceptions.h
new file mode 100644 (file)
index 0000000..f66978f
--- /dev/null
@@ -0,0 +1,64 @@
+#ifndef __NMEXCEPTIONS_H__
+#define __NMEXCEPTIONS_H__
+
+#include <exception>
+#include <string>
+
+namespace NetworkManager {
+
+class NMexception: public std::exception
+{
+public:
+    NMexception(const std::string& msg): message(msg) {}
+
+    NMexception(const std::string& msg, const int error_code): code(error_code), message(msg) {}
+
+    const char* what() const noexcept override
+    {
+        return message.c_str();
+    }
+
+    virtual int errorCode() const noexcept
+    {
+        return code;
+    }
+protected:
+    int code;
+    std::string message;
+};
+
+class NotAuthorized: public NMexception
+{
+public:
+    NotAuthorized(const std::string& msg): NMexception(msg, -1) {}
+
+    NotAuthorized(const std::string& msg, const int error_code): NMexception(msg, error_code) {}
+};
+
+class SessionExpirted: public NMexception
+{
+public:
+    SessionExpirted(const std::string& msg): NMexception(msg, -1) {}
+
+    SessionExpirted(const std::string& msg, const int error_code): NMexception(msg, error_code) {}
+};
+
+class AuthException: public NMexception
+{
+public:
+    AuthException(const std::string& msg): NMexception(msg, -1) {}
+
+    AuthException(const std::string& msg, const int error_code): NMexception(msg, error_code) {}
+};
+
+class IoTInternalError: public NMexception
+{
+public:
+    IoTInternalError(const std::string& msg): NMexception(msg, -1) {}
+
+    IoTInternalError(const std::string& msg, const int error_code): NMexception(msg, error_code) {}
+};
+
+}
+
+#endif // __NMEXCEPTIONS_H__
\ No newline at end of file
diff --git a/network-manager/nmlib/include/uuid.h b/network-manager/nmlib/include/uuid.h
new file mode 100644 (file)
index 0000000..3f7dee2
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __UUID_H__
+#define __UUID_H__
+
+#include <stdint.h>
+
+
+struct UUID
+{
+    uint32_t timeLow;
+    uint16_t timeMid;
+    uint16_t timeHiAndVersion;
+    uint8_t clockSeqAndNode[8];
+};
+
+#endif // __UUID_H__
\ No newline at end of file
index 09a840e..296b27a 100644 (file)
@@ -8,6 +8,10 @@ Source0:    %{name}-%{version}.tar.gz
 
 BuildRequires: cmake
 BuildRequires: pkgconfig(libcurl)
+BuildRequires: boost-devel
+BuildRequires: iotivity
+BuildRequires: iotivity-devel
+BuildRequires: iotivity-service
 %ifarch armv7l
 BuildRequires: pkgconfig(gtest_gmock)
 %else
index 1f83366..d6b0c74 100644 (file)
@@ -13,6 +13,7 @@ url=http://10.103.211.119/tizen-rsa/tizen-3.0-base-main2017/standard/latest/repo
 url=~/GBS_ROOT_3.0/local/repos/Main2017/armv7l
 [repo.product_Main2017_KantM]
 url=http://10.103.211.119/releases/tizen-3.0-product-main2017/product/KantM/latest/repos/product/armv7l/packages/
+url=http://10.103.211.119/releases/tizen-3.0-product-main2017/product/KantM/TIZEN-3.0-MAIN2017-KantM-RELEASE_20170419.1/repos/product/armv7l/packages/
 
 [profile.Main2017_KantM]
 obs = obs.tizentv
index 5a631ce..ddf2c10 100644 (file)
@@ -11,12 +11,43 @@ TEST(test_REST, simple_get)
 {
     try
     {
-        network::RestHelper get_request("http://172.217.25.3:80");
+        network::RestHelper request("http://example.com");
         string uri("");
         string response;
         network::RestHelper::Params params;
-        ASSERT_EQ(network::RestHelper::REST_SUCCESS, get_request.GetRequest(params, uri, response));
-        cout << response << endl;
+        ASSERT_EQ(network::RestHelper::REST_SUCCESS, request.GetRequest(params, uri, response));
+    }
+    catch (exception& e)
+    {
+        cerr << "EXCEPTION: " << e.what() << endl;
+    }
+}
+
+TEST(test_REST, simple_post)
+{
+    try
+    {
+        network::RestHelper request("http://example.com");
+        string uri("/");
+        string post = "param2=1&param2=2&param3=3";
+        network::RestHelper::Params params{{"user", "anon"}, {"id", "123"}};
+        ASSERT_EQ(network::RestHelper::REST_SUCCESS, request.PostRequest(params, uri, post));
+    }
+    catch (exception& e)
+    {
+        cerr << "EXCEPTION: " << e.what() << endl;
+    }
+}
+
+TEST(test_REST, simple_put)
+{
+    try
+    {
+        network::RestHelper request("http://example.com");
+        string uri("/");
+        string put = "param2=1&param2=2&param3=3";
+        network::RestHelper::Params params;//{{"values", "10"}, {"id", "321"}};
+        ASSERT_EQ(network::RestHelper::REST_SUCCESS, request.PutRequest(params, uri, put));
     }
     catch (exception& e)
     {
index 75b0fa5..68e460e 100644 (file)
@@ -1,5 +1,18 @@
 <manifest>
+    <define>
+        <domain name="iot-sec-test" />
+        <request>
+            <smack request="device::app_logging" type="w"/>
+            <smack request="System::Use_internet" type="rw"/>
+            <smack request="System::Privileged" type="rwxat"/>
+            <smack request="System::Run" type="rwxat"/>
+        </request>
+        <permit>
+            <smack permit="System::Use_internet" type="rw"/>
+            <smack permit="System::Privileged" type="rwxat"/>
+        </permit>
+    </define>
     <request>
-        <domain name="_"/>
+        <domain name="iot-sec-test" />
     </request>
-</manifest>
+</manifest>
\ No newline at end of file