<manifest>
<request>
- <domain name="_"/>
+ <domain name="_" />
</request>
-</manifest>
+</manifest>
\ No newline at end of file
<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>
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}")
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})
--- /dev/null
+#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
--- /dev/null
+#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()
+{
+
+}
+
+}
--- /dev/null
+#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();
+}
+
+
+}
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());
--- /dev/null
+#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
--- /dev/null
+#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__
--- /dev/null
+#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
--- /dev/null
+#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
BuildRequires: cmake
BuildRequires: pkgconfig(libcurl)
+BuildRequires: boost-devel
+BuildRequires: iotivity
+BuildRequires: iotivity-devel
+BuildRequires: iotivity-service
%ifarch armv7l
BuildRequires: pkgconfig(gtest_gmock)
%else
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
{
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¶m2=2¶m3=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¶m2=2¶m3=3";
+ network::RestHelper::Params params;//{{"values", "10"}, {"id", "321"}};
+ ASSERT_EQ(network::RestHelper::REST_SUCCESS, request.PutRequest(params, uri, put));
}
catch (exception& e)
{
<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