Store remote capabilities when exchange capabilities
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 19 Jun 2018 07:36:01 +0000 (16:36 +0900)
committer장상윤/Tizen Platform Lab(SR)/Engineer/삼성전자 <jeremy.jang@samsung.com>
Mon, 2 Jul 2018 01:42:56 +0000 (10:42 +0900)
Change-Id: I40d2450864a317ec5aa49c9e3907121b2964720d
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/mdg_manager.cc
src/common/remote_device.h
src/common/remote_device_manager.cc [new file with mode: 0644]
src/common/remote_device_manager.h

index c867900df16e97aadd28c532dc27fb14f609cc73..19934f74eda6db89aaf0b3a10363ff1c2cb2aaa0 100644 (file)
@@ -16,6 +16,7 @@
 #include "common/appcontrol_manager.h"
 #include "common/capability.h"
 #include "common/capability_manager.h"
+#include "common/remote_device_manager.h"
 #include "common/utils/glist_range.h"
 #include "common/utils/logging.h"
 
@@ -115,6 +116,7 @@ void MDGManager::RequestCb(char* cmd, char* device_id, unsigned char* arg,
           mdgmgr->capmgr_->UnpackCapabilities(caps_str);
       LOG(INFO) << "Received " << caps.size() << " capabilities from device "
                 << device_id;
+      RemoteDeviceManager::RegisterRemoteDevice(device_id, caps);
     } else if (cmd == Command::SEND_CAP) {
       std::string cap_str = std::string(reinterpret_cast<char*>(p));
       Capability cap(cap_str);
index bd41477d178a5f773814433e9b71a6b4378ffbf5..c8ff65baa3c5c1d910cc1527ce932fbca1b9df2c 100644 (file)
@@ -12,8 +12,8 @@ namespace capmgr {
 
 class RemoteDevice {
  public:
-  explicit RemoteDevice(const std::string& name, const std::string& profile_,
-                        const std::string& address, const std::string& uuid_)
+  explicit RemoteDevice(const std::string& name, const std::string& profile,
+                        const std::string& address, const std::string& uuid)
       : name_(std::move(name)), profile_(std::move(profile)),
         address_(std::move(address)), uuid_(std::move(uuid)) {}
 
diff --git a/src/common/remote_device_manager.cc b/src/common/remote_device_manager.cc
new file mode 100644 (file)
index 0000000..490eb59
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#include "common/remote_device_manager.h"
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "common/capability.h"
+#include "common/remote_device.h"
+#include "common/utils/logging.h"
+
+namespace capmgr {
+
+void RemoteDeviceManager::RegisterRemoteDevice(const std::string& device,
+    const std::vector<Capability>& capabilities) {
+  auto it = Instance().remote_device_info_.emplace(device, capabilities);
+  if (!it.second) {
+    auto p = it.first;
+    // replace capabilities (update)
+    p->second = capabilities;
+  }
+}
+
+RemoteDeviceManager& RemoteDeviceManager::Instance() {
+  static RemoteDeviceManager instance;
+  return instance;
+}
+
+}  // namespace capmgr
index 9dc648493ebb8f60950d867aa3f12ed8309f194d..e3b416045bd341fac5483457ed0183ede07c0e8a 100644 (file)
@@ -5,13 +5,27 @@
 #ifndef COMMON_REMOTE_DEVICE_MANAGER_H_
 #define COMMON_REMOTE_DEVICE_MANAGER_H_
 
+#include <map>
 #include <string>
+#include <vector>
+
+#include "common/capability.h"
+#include "common/remote_device.h"
 
 namespace capmgr {
 
 class RemoteDeviceManager {
  public:
+  static void RegisterRemoteDevice(const std::string& device_id,
+      const std::vector<Capability>& capabilities);
+
+  static RemoteDeviceManager& Instance();
+
  private:
+  RemoteDeviceManager() {}
+  ~RemoteDeviceManager() {}
+
+  std::map<std::string, std::vector<Capability>> remote_device_info_;
 };
 
 }  // namespace capmgr