[SECIOTSRK-352] Implement API for uninstall app command from server
authori.metelytsia <i.metelytsia@samsung.com>
Tue, 1 Aug 2017 08:27:28 +0000 (11:27 +0300)
committeri.metelytsia <i.metelytsia@samsung.com>
Tue, 1 Aug 2017 08:27:28 +0000 (11:27 +0300)
device_core/nmdaemon/control_resource.h
device_core/nmdaemon/notification_handler.cpp
device_core/utest/test_iot_dev_manager.cpp

index d9efc45..4fe4080 100644 (file)
@@ -7,8 +7,8 @@
  *         Copyright: (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
  * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
  */
-#ifndef __IOT_PRIMITIVE_RESOURCE_H__
-#define __IOT_PRIMITIVE_RESOURCE_H__
+#ifndef __IOT_CONTROL_RESOURCE_H__
+#define __IOT_CONTROL_RESOURCE_H__
 
 #include <memory>
 #include <string>
@@ -42,4 +42,4 @@ private:
 
 } // namespace NMD
 
-#endif /* __IOT_PRIMITIVE_RESOURCE_H__ */
+#endif /* __IOT_CONTROL_RESOURCE_H__ */
index 14c81a8..5ca9707 100644 (file)
@@ -4,6 +4,7 @@
 #include "logging.h"
 #include "iotutils.h"
 
+#include "application_service.h"
 #include "notification_handler.h"
 
 #define TAG "nmdaemon"
@@ -15,32 +16,30 @@ namespace NMD
 
 void NotificationHandler::observeCallback(const HeaderOptions& head_options, const OCRepresentation& rep, const int& ecode, const int& seq_number)
 {
-    std::cout << "========== NotificationHandler::observeCallback" << std::endl;
-    NetworkManager::printRepresentation(rep);
-
-#if 0
     if (ecode == OC_STACK_OK)
     {
-        std::string policy = rep.getValue<std::string>("policy");
-        std::string did = rep.getValue<std::string>("did");
-        LOG_D(TAG, "[Recieved Policy for %s]\n%s\n", did.c_str(), policy.c_str());
+        std::string duid = rep.getValue<std::string>("duid");
+        std::string ppid_comm = rep.getValue<std::string>("ppid_comm");
+        std::string comm = rep.getValue<std::string>("comm");
+
+        LOG_D(TAG, "[Notification recieved] : duid [%s], ppid_comm [%s], comm [%s]\n", duid, ppid_comm.c_str(), comm.c_str());
+
         const std::string& device_id = NetworkManager::IoTivity::getInstance()->getDeviceID();
 
-        if (did == device_id)
+        if(duid == device_id)
         {
-            iot::core::PolicyEnforce::GetInstance().ParsePolicy(policy);
-        }
-        else if (callback)
-        {
-            callback(head_options, rep, ecode, seq_number);
+            if(ppid_comm == "smack_test")
+            {
+                std::string pack_full_name = ApplicationService::find_package_by_app_name(ppid_comm);
+                if(!pack_full_name.empty())
+                    ApplicationService::uninstall(pack_full_name);
+            }
         }
     }
     else
     {
         LOG_D(TAG, "[NotificationHandler] Observe error: %d", ecode);
     }
-#endif
-
 }
 
 } // namespace NMD
index be3e786..88d8860 100644 (file)
@@ -360,7 +360,8 @@ TEST_F(IoTDevManagerTest, DISABLED_own_device)
                 std::cout << "Try to own:" << std::endl;
                 std::cout << "\t\tDevice uid: " << uid << std::endl;
                 std::cout << "\t\tDevice name: " << info.name << std::endl;
-                ASSERT_EQ(EC_OK, NM_ownDevice(dev_list, uid));
+//                ASSERT_EQ(EC_OK, NM_ownDevice(dev_list, uid));
+                ASSERT_EQ(EC_OK, NM_ownDeviceEx(ctx, uid));
             }
 
             NM_freeDeviceInfo(&info);