std::shared_ptr<ReportResource> report_hub_resorce;
std::shared_ptr<PolicyResource> policy_hub_resource;
- PolicyHandler policy_handler{iotivity, config.ssid};
+ PolicyHandler *policy_handler;
ReportHandler *report_handler;
- if(with_cloud) {
+ if(with_cloud)
+ {
report_handler = new ReportHandlerMQ();
- } else {
- report_handler = new ReportHandlerRes(config.ssid);
+ policy_handler = new PolicyHandlerMQ();
}
-
- while (!policy_handler.findResource())
+ else
{
- write_log("[MAIN_THREADS] Policy resource not found\n");
- std::this_thread::sleep_for(std::chrono::seconds(10));
+ report_handler = new ReportHandlerRes(config.ssid);
+ policy_handler = new PolicyHandler(config.ssid);
+ while (!policy_handler->findResource())
+ {
+ write_log("[MAIN_THREADS] Policy resource not found\n");
+ std::this_thread::sleep_for(std::chrono::seconds(10));
+ }
}
+
if (g_working_mode == WorkingMode::Hub)
{
proxy_thread = std::make_shared<ProxyThread>();
report_hub_resorce = std::make_shared<ReportResource>(*report_handler, proxy_thread);
report_hub_resorce->registerResource();
- policy_hub_resource = std::make_shared<PolicyResource>(&policy_handler, iotivity->getDeviceID(), proxy_thread);
+ policy_hub_resource = std::make_shared<PolicyResource>(policy_handler, iotivity->getDeviceID(), proxy_thread);
policy_hub_resource->registerResource();
}
iotivity->publishResources(rhandles);
}
- AgentPolicyService agent_policy_service(std::bind(&PolicyHandler::enforceCallback, &policy_handler, PH::_1, PH::_2));
+ AgentPolicyService agent_policy_service(std::bind(&PolicyHandler::enforceCallback, policy_handler, PH::_1, PH::_2));
std::thread rmi_thread(&AgentPolicyService::run, &agent_policy_service);
std::srand(time(NULL));
using namespace NetworkManager;
namespace PH = std::placeholders;
-PolicyHandler::PolicyHandler(NetworkManager::IoTivity* iotivity, const std::string& server_id)
- : iotivity(iotivity), sid(server_id)
+PolicyHandler::PolicyHandler(const std::string& server_id)
+ : sid(server_id)
{
+ iotivity = NetworkManager::IoTivity::getInstance();
device_id = iotivity->getDeviceID();
}
}
}
+void PolicyHandlerMQ::pass(const OCRepresentation& rep, const QueryParamsMap& params)
+{
+ NetworkManager::IoTivity::getInstance()->getMqHandler()->publish("/srv/policy", rep);
+}
+
void PolicyHandler::observeCallback(const HeaderOptions& head_options, const OCRepresentation& rep, const int& ecode, const int& seq_number)
{
if (ecode == OC_STACK_OK)
void PolicyHandler::enforceCallback(const std::string& agentId, const std::string& jsonData)
{
- LOG_D(TAG, "Enfore request from agent: %s\n%s", agentId.c_str(), jsonData.c_str());
+ LOG_D(TAG, "Enforce request from agent: %s\n%s", agentId.c_str(), jsonData.c_str());
OCRepresentation rep;
rep.setValue("policy", jsonData);
* @brief PolicyHandler constructor
* @param iotivity [in] pointer to iotivity instance
*/
- PolicyHandler(NetworkManager::IoTivity* iotivity, const std::string& server_id = "");
+ PolicyHandler(const std::string& server_id = "");
/**
* @brief setObserver set proxy observe callback
* @param rep [in] represantation of policy
* @param params [in] query parameters
*/
- void pass(const OC::OCRepresentation& rep, const OC::QueryParamsMap& params);
+ virtual void pass(const OC::OCRepresentation& rep, const OC::QueryParamsMap& params);
/**
* @brief enforceCallback callback for agent eforced policies
*/
bool findResource();
+ virtual ~PolicyHandler() {};
+
private:
ObserverCallback callback;
std::shared_ptr<OC::OCResource> resource;
void observeCallback(const OC::HeaderOptions& head_options, const OC::OCRepresentation& rep, const int& ecode, const int& seq_number);
};
+class PolicyHandlerMQ : public PolicyHandler
+{
+public:
+ void pass(const OC::OCRepresentation& rep, const OC::QueryParamsMap& params) override;
+ ~PolicyHandlerMQ() override {};
+};
+
#endif // POLICYHANDLER_H
write_log("[RMI_THREADS] started\n");
try
{
- PolicyHandler policy_proxy{iotivity};
+ PolicyHandler policy_proxy;
std::shared_ptr<PolicyResource> policy_resource;
while (!policy_proxy.findResource())