namespace NetworkManager
{
+class IoTivity;
+
/**
* @brief The IoTDevice class represents iotivity device
*/
virtual void unOwnDevice() = 0;
/**
- * @brief deleteApp performes app uninstallation on remote device
- * @param app_name [in] application name
- */
- virtual void deleteApp(const std::string& app_name) = 0;
-
- /**
* @brief setState sets online/offline state for device
* @param state true if device is online
*/
virtual void deactivate()
{
}
+
+ /**
+ * @brief deleteApp performes app uninstallation on remote device
+ * @param duid [in] id of the device where application should be removed
+ * @param iotivity [in] pointer to the IoTivity instance
+ * @param app_name [in] application name
+ */
+ static void deleteApp(const std::string& duid, IoTivity* iotivity, const std::string& app_name);
+
+ // deleteApp: implemented in iotdevice_inpl.cpp
};
typedef std::shared_ptr<IoTDevice> IoTDevicePtr;
}
}
+void sendCommand(OCResource::Ptr ctrl, const OC::OCRepresentation& representation)
+{
+ NetworkManager::PostResourceCallback::Sptr callback = std::make_shared<NetworkManager::PostResourceCallback>();
+ auto result = ctrl->post(representation, QueryParamsMap{}, bind_callback(callback, PH::_1, PH::_2, PH::_3));
+
+ if (OC_STACK_OK != result)
+ {
+ throw NetworkManager::IoTInternalError("Post of \"unown\" request failed with code: ", result);
+ }
+
+ if (!callback->wait())
+ {
+ throw NetworkManager::IoTInternalError("Post of \"unown\" request error - callback not called", EC_UNAUTHORIZED);
+ }
+}
+
}
namespace NetworkManager
{
+/**
+ * @brief Implementation of static method IoTDevice::deleteApp
+ * @param duid [in] id of the device where application should be removed
+ * @param iotivity [in] pointer to the IoTivity instance
+ * @param app_name [in] application name
+ */
+void IoTDevice::deleteApp(const std::string& duid, IoTivity* iotivity, const std::string& app_name)
+{
+ OC::OCResource::Ptr ctrl_resource = iotivity->findResource(iotivity->host(), CTRL_RESOURCE_TYPE, OC_RSRVD_WELL_KNOWN_URI, duid);
+
+ if(!ctrl_resource)
+ {
+ throw IoTInternalError("Device not found", EC_ITEM_NOT_FOUND);
+ }
+
+ OC::OCRepresentation request;
+ request.setValue("command", int(DeviceCommands::UNINSTALL));
+ request.setValue("name", std::string{app_name});
+ sendCommand(ctrl_resource, request);
+}
+
IoTDevice_impl::IoTDevice_impl(std::shared_ptr<OCResource> device_resource, bool connected)
: dev(device_resource), name("unknown"), model("unknown"), type("unknown"), uuid(""), spec_ver("unknown"),
online(connected), cloud_accessibility(false)
return ctrl_resource;
}
-void IoTDevice_impl::sendCommand(OCResource::Ptr ctrl, const OC::OCRepresentation& representation)
-{
- PostResourceCallback::Sptr callback = std::make_shared<PostResourceCallback>();
- auto result = ctrl->post(representation, QueryParamsMap{}, bind_callback(callback, PH::_1, PH::_2, PH::_3));
-
- if (OC_STACK_OK != result)
- {
- throw IoTInternalError("Post of \"unown\" request failed with code: ", result);
- }
-
- if (!callback->wait())
- {
- throw IoTInternalError("Post of \"unown\" request error - callback not called", EC_UNAUTHORIZED);
- }
-}
-
void IoTDevice_impl::unOwnDevice()
{
auto ctrl_resource = getControlResource();
sendCommand(ctrl_resource, request);
}
-void IoTDevice_impl::deleteApp(const std::string& app_name)
-{
- if (app_name.empty())
- {
- throw NMexception("deleteApp called with empty pid or name", EC_BAD_PARAMETER);
- }
-
- auto ctrl_resource = getControlResource();
- OCRepresentation request;
- request.setValue("command", int(DeviceCommands::UNINSTALL));
- request.setValue("name", app_name);
- sendCommand(ctrl_resource, request);
-}
-
void IoTDevice_impl::setCloudProperties(const std::string& host, const std::string& provider, const std::string& token)
{
auto iotinst = IoTivity::getInstance();
switch (action)
{
case DeviceCommands::UNOWN:
+ LOG_D(TAG, "Unown command received");
return unOwnCommand(command);
case DeviceCommands::UNINSTALL:
+ LOG_D(TAG, "Uninstall command received");
return uninstallCommand(command);
default:
+ LOG_E(TAG, "Error: unknown command received");
return false;
}
}
bool CommandHandler::uninstallCommand(const OC::OCRepresentation& command)
{
std::string name = command.getValue<std::string>("name");
+ LOG_D(TAG, "Request to uninstall \"%s\"", name.c_str());
if (name.empty()) return false;