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.
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;
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();
delete package_data;
}
-
bool MDGManager::AddDevice(const mdg_device_h device) {
// critical section: appending device list
std::mutex lock;
}
}
+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))
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);