Add codes for sending updated package info
authorInkyun Kil <inkyun.kil@samsung.com>
Wed, 5 Sep 2018 05:22:53 +0000 (14:22 +0900)
committer길인균/Tizen Platform Lab(SR)/Engineer/삼성전자 <inkyun.kil@samsung.com>
Wed, 19 Sep 2018 05:02:32 +0000 (14:02 +0900)
Change-Id: Ie9e558bc23834d15d7a84e14bdcc767c0601f784
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/common/mdg_manager.cc
src/common/package_manager.cc
src/common/package_manager.h

index 2488d4d0936b534321fdbc885f04115c17a576e4..a6c411624c0a440eaff1c073f3f1a6db8e820882 100755 (executable)
@@ -242,7 +242,13 @@ void MDGManager::ReceiveDataCb(int result, char* device_id, char* channel_id,
 
     mdgmgr->pm_->RemoveRemotePackage(std::string(device_id), pkgid);
   } else if (cmd == Command::UPDATE_PACKAGEINFO) {
-    // TODO(inkyun.kil)
+    std::string packages_str = std::string(p, p + datasize);
+
+    RemotePackageInfo package(packages_str);
+    LOG(INFO) << "Package[" << package.pkgid()
+              << "] is updated at device " << device_id;
+
+    mdgmgr->pm_->UpdateRemotePackage(std::string(device_id), package);
   }
 
   // FIXME(jeremy.jang): temporary code. need to send proper reply packet.
@@ -442,12 +448,9 @@ void MDGManager::HandlePackageEvent(const std::string& pkgid,
   LOG(DEBUG) << "Event received: " << pkgid << " "
              << static_cast<int>(event_type);
 
-  unsigned char* package_data;
+  unsigned char* package_data = nullptr;
   std::string packed;
-  if (event_type == PackageEventListener::EventType::UNINSTALL) {
-    package_data = new unsigned char[pkgid.size()];
-    memcpy(package_data, pkgid.c_str(), pkgid.size());
-  } else {
+  if (event_type == PackageEventListener::EventType::INSTALL) {
     RemotePackageInfo* info = this->pm_->GetInfo(pkgid);
     if (info == nullptr) {
       LOG(ERROR) << "Failed to get packageinfo :" << pkgid;
@@ -460,6 +463,20 @@ void MDGManager::HandlePackageEvent(const std::string& pkgid,
     package_data = new unsigned char[packed.size()];
     memcpy(package_data, packed.c_str(), packed.size());
     delete info;
+  } else if (event_type == PackageEventListener::EventType::UNINSTALL) {
+    package_data = new unsigned char[pkgid.size()];
+    memcpy(package_data, pkgid.c_str(), pkgid.size());
+  } else if (event_type == PackageEventListener::EventType::UPDATE) {
+    RemotePackageInfo* info = this->pm_->GetInfo(pkgid);
+    if (info == nullptr) {
+      LOG(ERROR) << "Failed to get packageinfo :" << pkgid;
+      return;
+    }
+
+    packed = info->Serialize();
+    package_data = new unsigned char[packed.size()];
+    memcpy(package_data, packed.c_str(), packed.size());
+    delete info;
   }
 
   std::vector<RemoteDevice> dev_list = DBManager::SelectDevices();
@@ -486,7 +503,6 @@ void MDGManager::HandlePackageEvent(const std::string& pkgid,
   delete package_data;
 }
 
-
 bool MDGManager::AddDevice(const mdg_device_h device) {
   // critical section: appending device list
   std::mutex lock;
index fb40b727e5e7265bd8c160baffb775628167c012..ac4ac7a7d3ac627cb30e3f7dd28a4b27dde6d12d 100644 (file)
@@ -125,6 +125,21 @@ void PackageManager::StoreRemotePackages(const std::string& device_id,
   }
 }
 
+void PackageManager::UpdateRemotePackage(const std::string& device_id,
+    const RemotePackageInfo& package) {
+  LOG(INFO) << "Update package[" << package.pkgid() << "] into DB";
+
+  if (!DBManager::DeleteRemotePackage(device_id, package.pkgid())) {
+    LOG(ERROR) << "Failed to delete package[" << package.pkgid()
+               << "] into DB";
+    return;
+  }
+
+  if (!DBManager::InsertRemotePackage(device_id, package))
+    LOG(ERROR) << "Failed to insert package[" << package.pkgid()
+      << "] into DB";
+}
+
 void PackageManager::RemoveRemotePackage(const std::string& device_id,
     const std::string& pkgid) {
   if (!DBManager::DeleteRemotePackage(device_id, pkgid))
index fd8b01ba79a6bd5bb1bd9992b02f030239c6e565..2b6c669349e172f67ba3b0ac111737c1d9e1923d 100644 (file)
@@ -26,6 +26,8 @@ class PackageManager {
   std::vector<RemotePackageInfo> LoadLocalPackages();
   void StoreRemotePackages(const std::string& device_id,
     const std::vector<RemotePackageInfo>& packages);
+  void UpdateRemotePackage(const std::string& device_id,
+    const RemotePackageInfo& package);
   void RemoveRemotePackage(const std::string& device_id,
     const std::string& pkgid);
   RemotePackageInfo* GetInfo(const std::string &pkgid);