namespace NMD
{
+/**
+ * @typedef EnforcePolicyHandler
+ * @brief Callback function for EnforcePolicy handling
+ * @param agentId [in] id of agent program that want to enforce policy
+ * @param jsonData [in] string that represent json data
+ */
typedef std::function<void(const std::string& agentId, const std::string& jsonData)> EnforcePolicyHandler;
/**
public:
/**
* @brief enforcePolicy method sends policy (json data) from calling process to service daemon.
- * @param agentId id of agent program that want to enforce policy
- * @param jsonData string that represent json data
+ * @param agentId [in] id of agent program that want to enforce policy
+ * @param jsonData [in] string that represent json data
* @return result code of type AgentPolicyResult
*/
virtual int enforcePolicy(const std::string& agentId, const std::string& jsonData);
namespace
{
- const int DLP_REPORT_TYPE = 1111;
- const int PAD_REPORT_TYPE = 1112;
- const int FIM_REPORT_TYPE = 1113;
+const int DLP_REPORT_TYPE = 1111;
+const int PAD_REPORT_TYPE = 1112;
+const int FIM_REPORT_TYPE = 1113;
}
namespace NMD
switch(type)
{
case DLP_REPORT_TYPE:
- {
- report_type = "dlp";
- log_type = "DLP";
- }
- break;
+ {
+ report_type = "dlp";
+ log_type = "DLP";
+ }
+ break;
case PAD_REPORT_TYPE:
- {
- report_type = "pad";
- log_type = "PAD";
- }
- break;
+ {
+ report_type = "pad";
+ log_type = "PAD";
+ }
+ break;
default:
- {
- report_type = "fim";
- log_type = "FIM";
- }
- break;
+ {
+ report_type = "fim";
+ log_type = "FIM";
+ }
+ break;
}
std::ostringstream os;
#include <audit-trail/mac.h>
#include <audit-trail/syscall.h>
#include <audit-trail/audit-trail.h>
- #ifdef PROFILE_MOBILE
+#ifdef PROFILE_MOBILE
#include <audit-trail/user.h>
- #endif
+#endif
#endif
#include "proxythread.h"
#include "reporthandler.h"
*/
ControlResource(ICommandHandler* handler);
+ /**
+ * @brief Not copyconstructible
+ */
ControlResource(const ControlResource& obj) = delete;
+ /**
+ * @brief Not copyconstructible
+ */
ControlResource& operator=(const ControlResource& obj) = delete;
/**
#include <vector>
/**
- * @brief A structure that contains info about device
+ * @brief A structure that contains info about a device
*/
struct DeviceInfo {
- std::string duid; /**< Device unique ID */
- std::string name; /**< Device name */
- std::string model; /**< Device model */
- std::string type; /**< Device type */
- bool is_owned; /**< Is the device owned */
+ std::string duid; /**< Device unique ID */
+ std::string name; /**< Device name */
+ std::string model; /**< Device model */
+ std::string type; /**< Device type */
+ bool is_owned; /**< Is the device owned */
- static const int fields_count = 5;
+ static const int fields_count = 5; /**< Number of significant fields */
- bool operator==(const DeviceInfo& r);
+ bool operator==(const DeviceInfo& r); /**< Equal operator */
};
/**
{
public:
- CommonPolicyEnforce(PolicyEnforce&); /**< Default constructor */
- virtual ~CommonPolicyEnforce(); /**< Destructor */
+ /**
+ * @brief Default Constructor
+ */
+ CommonPolicyEnforce(PolicyEnforce&);
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~CommonPolicyEnforce();
/**
* @brief Init function. Used to init context of TV extensions policy group
- * @param[in] PolicyContext instance
* @return bool. True in case of success, false otherwise
*/
- bool Init(/*PolicyContext&*/) override;
+ bool Init() override;
/**
* @brief De-Init function. Used to close tpm tvext context.
{
public:
- virtual ~IPolicyGroupEnforce() {}; /**< Destructor */
+ /**
+ * @brief Destructor
+ */
+ virtual ~IPolicyGroupEnforce() {};
/**
* @brief Init function. Used to init context of related module of policy group
namespace core
{
+/**
+ * @typedef PolicyGroupMap
+ * @brief Map of policy group appliers instances
+ */
typedef std::map<std::string, IPolicyGroupEnforcePtr> PolicyGroupMap;
/**
#include "iot_i_policy_group_enforce.h"
#include "iot_policy_enforce.h"
-
-
namespace iot
{
namespace core
{
public:
- TvExtPolicyEnforce(PolicyEnforce&); /**< Default constructor */
- virtual ~TvExtPolicyEnforce(); /**< Destructor */
+ /**
+ * @brief Default constructor
+ */
+ TvExtPolicyEnforce(PolicyEnforce&);
+
+ /**
+ * @brief Destructor
+ */
+ virtual ~TvExtPolicyEnforce();
/**
* @brief Init function. Used to init context of TV extensions policy group
*/
/**
* @file log.h
- * @brief //TODO: write brief file annotation
+ * @brief Logging macro
* @date Created May 19, 2017
* @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>
* @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
*/
#include <stdio.h>
-
+/**
+ * @brief Error logging
+ */
#ifndef LOG_ERR
#define LOG_ERR(format, args...) printf("ERR -- %s [%s:%d] " format "\n",__FILE__, __func__, __LINE__, ##args)
#endif
+/**
+ * @brief Debug logging
+ */
#ifndef LOG_DBG
#define LOG_DBG(format, args...) printf("DBG -- %s [%s:%d] " format "\n",__FILE__, __func__, __LINE__, ##args)
#endif
#define TAG "nmdaemon"
-const std::string PolicyResource::HUB_POLICY_RESOURCE_URI{"/a/policy"};
+const std::string PolicyResource::HUB_POLICY_RESOURCE_URI {
+ "/a/policy"
+};
const std::string PolicyResource::HUB_POLICY_RESORCE_TYPE{"core.policy"};
PolicyResource::PolicyResource(PolicyHandler* handler, const std::string& hub_device_id,
: NetworkManager::IotResourceServer(
HUB_POLICY_RESOURCE_URI,
HUB_POLICY_RESORCE_TYPE,
- {DEFAULT_INTERFACE},
- OC_DISCOVERABLE | OC_OBSERVABLE)
- , observers{}
- , policies{}
- , obs_mutex{}
- , hub_did(hub_device_id)
- , policy_handler(handler)
- , hub(hub)
- , proxy(proxy)
+{
+ DEFAULT_INTERFACE
+},
+OC_DISCOVERABLE | OC_OBSERVABLE)
+, observers{}
+, policies{}
+, obs_mutex{}
+, hub_did(hub_device_id)
+, policy_handler(handler)
+, hub(hub)
+, proxy(proxy)
{
assert(policy_handler != nullptr);
assert(hub != nullptr);
OC::QueryParamsMap proxy_params{{"did", did}, {"agent", agent}};
proxy->addDefferedTask(&PolicyHandler::pass, policy_handler, representation, proxy_params);
- } catch (std::out_of_range&){
+ } catch (std::out_of_range&) {
result = OC_EH_BAD_REQ;
}
} else {
result = OC_EH_BAD_OPT;
}
- } catch (std::out_of_range&){
+ } catch (std::out_of_range&) {
result = OC_EH_BAD_REQ;
}
* @return error code
*/
OCEntityHandlerResult getHandler(const OC::OCRepresentation& representation, const OC::QueryParamsMap& params,
- OC::OCRepresentation& response_body) override;
+ OC::OCRepresentation& response_body) override;
/**
* @brief OCResource POST method handler
* @return error code
*/
OCEntityHandlerResult postHandler(const OC::OCRepresentation& representation, const OC::QueryParamsMap& params,
- OC::OCRepresentation& response_body) override;
+ OC::OCRepresentation& response_body) override;
/**
* @brief OCResource OBSERV method handler
* @return error code
*/
OCEntityHandlerResult observHandler(const OC::OCRepresentation& representation,
- const OC::QueryParamsMap& params, const OC::ObservationInfo& obsInfo) override;
+ const OC::QueryParamsMap& params, const OC::ObservationInfo& obsInfo) override;
/**
* @brief Used to proxy policy updates from server to primitive devices
#define TAG "nmdaemon"
-const std::string ReportResource::HUB_REPORT_RESOURCE_URI{"/a/report"};
+const std::string ReportResource::HUB_REPORT_RESOURCE_URI {
+ "/a/report"
+};
const std::string ReportResource::HUB_REPORT_RESORCE_TYPE{"core.security"};
ReportResource::ReportResource(ReportHandler& handler, ProxyThread* proxy)
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file main_thread.h
- * @brief Main thread
- * @date Created Apr 18, 2017
- * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>
- */
+/**\r
+ * Samsung Ukraine R&D Center (SRK under a contract between)\r
+ * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)\r
+ * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ */\r
+/**\r
+ * @file main_thread.h\r
+ * @brief Main thread\r
+ * @date Created Apr 18, 2017\r
+ * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>\r
+ */\r
\r
#ifndef __MAIN_THREAD_H__\r
#define __MAIN_THREAD_H__\r
class MainThread : public ThreadBase\r
{\r
public:\r
- MainThread(const std::string& device_name = "", const std::string& device_model = "",\r
+ /**\r
+ * @brief Constructor\r
+ * @param device_name [in] the name of the device\r
+ * @param device_model [in] the model of the device\r
+ * @param device_type [in] the type of the device\r
+ */\r
+ MainThread(const std::string& device_name = "",\r
+ const std::string& device_model = "",\r
const std::string& device_type = "");\r
\r
+ /**\r
+ * @brief Sets the device name\r
+ * @param device_name [in] the name of the device\r
+ */\r
void set_device_name(const std::string& device_name) {\r
m_device_name = device_name;\r
}\r
\r
+ /**\r
+ * @brief Sets the device model\r
+ * @param device_model [in] the model of the device\r
+ */\r
void set_device_model(const std::string& device_model) {\r
m_device_model = device_model;\r
}\r
\r
+ /**\r
+ * @brief Sets the device type\r
+ * @param device_type [in] the type of the device\r
+ */\r
void set_device_type(const std::string& device_type) {\r
m_device_type = device_type;\r
}\r
\r
+ /**\r
+ * @brief Destructor\r
+ */\r
virtual ~MainThread();\r
\r
+ /**\r
+ * @brief Main routine\r
+ */\r
virtual void routine();\r
\r
private:\r
if (m_resource) {
QueryParamsMap query{{"did", iotivity->getDeviceID()}};
m_resource->observe(ObserveType::Observe, query, std::bind(&PolicyHandlerRes::observeCallback, this, PH::_1, PH::_2,
- PH::_3, PH::_4));
+ PH::_3, PH::_4));
} else {
LOG_D(TAG, "[RMI_THREADS] Policy resource not found");
}
class ProxyThread : public NMD::ThreadBase
{
public:
+ /**
+ * @brief Constructor
+ */
ProxyThread() {
}
+ /**
+ * @brief Adds a deferred task
+ * @param func [in] the task's routine function
+ * @param args [in] an arguments for this function
+ */
template<typename Func, typename... Args>
void addDefferedTask(Func&& func, Args&& ... args) {
addTask(std::async(std::launch::deferred, std::forward<Func>(func), std::forward<Args>(args)...));
}
+ /**
+ * @brief Adds a deferred task
+ * @param task [in] the task to add
+ */
void addTask(std::future<void>&& task)
{
std::unique_lock<std::mutex> lock{mtx};
notice.notify_one();
}
+ /**
+ * @brief Destructor
+ */
virtual ~ProxyThread() {
}
+ /**
+ * @brief Stops the proxy thread
+ */
void stop() override {
m_running = false;
notice.notify_all();
}
+ /**
+ * @brief Main routine
+ */
void routine() override {
std::unique_lock<std::mutex> lock{mtx};
/**
* @brief pass sends report representation to server
- * @param rep representation to send
- * @param params post query parameters
+ * @param rep [in] representation to send
+ * @param params [in] post query parameters
*/
virtual void pass(const OC::OCRepresentation& rep, const OC::QueryParamsMap& params) = 0;
public:
/**
* @brief ReportHandlerRes constructor
- * @param iotivity pointer to IoTivity instance
+ * @param iotivity [in] pointer to IoTivity instance
+ * @param server_id [in] server id
*/
ReportHandlerRes(NetworkManager::IoTivity* iotivity, const std::string& server_id = "");
/**
* @brief pass sends report representation to server
- * @param rep representation to send
- * @param params post query parameters
+ * @param rep [in] representation to send
+ * @param params [in] post query parameters
*/
void pass(const OC::OCRepresentation& rep, const OC::QueryParamsMap& params) override;
public:
/**
* @brief createWithResource creates ReportHandler using resource layer for communication
+ * @param iotivity [in] pointer to the IoTivity instance
* @param sid [in] optional server id (with id used for primitive devices)
* @return handler shared pointer
*/
/**
* @brief pass sends report representation to server
- * @param rep representation to send
- * @param params post query parameters
+ * @param rep [in] representation to send
+ * @param params [in] post query parameters
*/
void pass(const OC::OCRepresentation& rep, const OC::QueryParamsMap& params) override;
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file thread_base.cpp
- * @brief Base thread class
- * @date Created Jul 14, 2017
- * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
- */
+/**\r
+ * Samsung Ukraine R&D Center (SRK under a contract between)\r
+ * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)\r
+ * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ */\r
+/**\r
+ * @file thread_base.cpp\r
+ * @brief Base thread class\r
+ * @date Created Jul 14, 2017\r
+ * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>\r
+ */\r
\r
#include "thread_base.h"\r
\r
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file thread_base.h
- * @brief Base thread class
- * @date Created Jul 14, 2017
- * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
- */
+/**\r
+ * Samsung Ukraine R&D Center (SRK under a contract between)\r
+ * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)\r
+ * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.\r
+ */\r
+/**\r
+ * @file thread_base.h\r
+ * @brief Base thread class\r
+ * @date Created Jul 14, 2017\r
+ * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>\r
+ */\r
#ifndef __THREAD_BASE_H__\r
#define __THREAD_BASE_H__\r
\r
FILE* file = fopen(log_file_path_name.c_str(), "a+");
if (file) {
- res = (bool)vfprintf(file, _msg, _vl);
+ res = (bool)(vfprintf(file, _msg, _vl) > 0);
fclose(file);
}
namespace NMD
{
-extern std::string dat_file_path_name;
-extern std::string cfg_file_path_name;
-extern std::string log_file_path_name;
-extern std::string hub_file_path_name;
+extern std::string dat_file_path_name; /**< name of IoTivity's persistent storage file */
+extern std::string cfg_file_path_name; /**< name of config file */
+extern std::string log_file_path_name; /**< name of log file */
+extern std::string hub_file_path_name; /**< name of hub cache file */
/**
* @brief Returns current path
* @brief The structure contains configuration info for Network Manager daemon
*/
typedef struct {
- std::string host;
- std::string auth_provider;
- std::string auth_code;
- std::string uid;
- std::string access_token;
-
- std::string ssid;
- std::string pwd;
+ std::string host; /**< address of server. ex: "coap+tcp://106.125.46.44:5683" */
+ std::string auth_provider; /**< name of OAuth2 service provider */
+ std::string auth_code; /**< OAuth2 access token */
+ std::string uid; /**< ID used for iot cloud signIn method */
+ std::string access_token; /**< access token used for iot cloud signIn method */
+
+ std::string ssid; /**< server id */
+ std::string pwd; /**< password */
} nmdaemon_config;
/**
*/
const char* wmodeAsString();
+/**
+ * @brief Writes message to the log file named "log_file_path_name"
+ * @return true on success
+ */
bool write_log(const char* _msg, ...);
#if defined(__TIZEN__)
+/**
+ * @brief Returns a device model name
+ * @return device model name
+ */
std::string get_device_model_name();
#endif
}