Add device handle to application information handle
authorInkyun Kil <inkyun.kil@samsung.com>
Wed, 7 Nov 2018 06:35:54 +0000 (15:35 +0900)
committer길인균/Tizen Platform Lab(SR)/Engineer/삼성전자 <inkyun.kil@samsung.com>
Mon, 12 Nov 2018 01:22:00 +0000 (10:22 +0900)
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
include/capability_manager.h
src/client.cc
tools/capmgr_test.cc

index 4f7019b..e5b0a44 100644 (file)
@@ -97,6 +97,7 @@ typedef int (*capmgr_app_control_reply_cb)(const capmgr_app_control_h request,
  * @param[in] remote_app_info Capability Manager Application Info handle
  * @param[in] user_data       The user data to be passed to the callback function
  * @see capmgr_application_info_foreach_applications()
+ * @see capmgr_application_info_clone()
  */
 typedef int (*capmgr_application_info_foreach_app_cb)(
     const capmgr_application_info_h remote_app_info, void* user_data);
@@ -524,6 +525,7 @@ int capmgr_application_info_foreach_applications(
  * @retval  #CAPMGR_ERROR_NONE               Successful
  * @retval  #CAPMGR_ERROR_INVALID_PARAMETER  Invalid parameter
  * @retval  #CAPMGR_ERROR_OUT_OF_MEMORY      Out of memory
+ * @see capmgr_application_info_destroy()
  */
 int capmgr_application_info_clone(
     const capmgr_application_info_h remote_app_info,
@@ -589,6 +591,33 @@ int capmgr_application_info_get_label(capmgr_application_info_h remote_app_info,
 int capmgr_application_info_get_version(
     capmgr_application_info_h remote_app_info, char** version);
 
+/**
+ * @brief Gets the remote device handle from the given remote application info context.
+ * @since_tizen 5.0
+ * @remarks     You must release @a device using capmgr_device_destroy().
+ * @param[in]   remote_app_info   The application information installed at specific remote device
+ * @param[out]  device            The remote device handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ * @retval  #CAPMGR_ERROR_NONE               Successful
+ * @retval  #CAPMGR_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval  #CAPMGR_ERROR_OUT_OF_MEMORY      Out of memory
+ */
+int capmgr_application_info_get_device(
+    capmgr_application_info_h remote_app_info, capmgr_device_h* device);
+
+/**
+ * @brief Destroys the remote application information handle and releases all its resources.
+ * @since_tizen 5.0
+ * @param[in]   remote_app_info  The remote application information handle
+ * @return      @c 0 on success,
+ *              otherwise a negative error value
+ * @retval  #CAPMGR_ERROR_NONE               Successful
+ * @retval  #CAPMGR_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @see capmgr_application_info_clone()
+ */
+int capmgr_application_info_destroy(capmgr_application_info_h remote_app_info);
+
 #ifdef __cplusplus
 }
 #endif
index a6a08b7..7e64cb1 100644 (file)
@@ -47,6 +47,7 @@ struct capmgr_application_info_s {
   std::string pkgid;
   std::string label;
   std::string version;
+  capmgr_device_h device;
 };
 
 API int capmgr_device_foreach_devices(capmgr_device_foreach_cb cb,
@@ -562,11 +563,29 @@ API int capmgr_application_info_clone(
   clone->label = remote_app_info->label;
   clone->version = remote_app_info->version;
 
+  int ret = capmgr_device_clone(remote_app_info->device, &(clone->device));
+  if (ret != CAPMGR_ERROR_NONE) {
+    LOG(ERROR) << "Failed to clone capmgr device";
+    delete clone;
+    return ret;
+  }
+
   *remote_app_info_clone = clone;
 
   return CAPMGR_ERROR_NONE;
 }
 
+API int capmgr_application_info_destroy(
+    capmgr_application_info_h remote_app_info) {
+  if (!remote_app_info)
+    return CAPMGR_ERROR_INVALID_PARAMETER;
+
+  capmgr_device_destroy(remote_app_info->device);
+  delete remote_app_info;
+
+  return CAPMGR_ERROR_NONE;
+}
+
 API int capmgr_application_info_get_appid(
     capmgr_application_info_h remote_app_info, char** appid) {
   if (!remote_app_info || !appid || remote_app_info->appid.empty())
@@ -615,6 +634,19 @@ API int capmgr_application_info_get_version(
   return CAPMGR_ERROR_NONE;
 }
 
+API int capmgr_application_info_get_device(
+    capmgr_application_info_h remote_app_info,
+    capmgr_device_h* device) {
+  if (!remote_app_info || !device)
+    return CAPMGR_ERROR_INVALID_PARAMETER;
+
+  int ret = capmgr_device_clone(remote_app_info->device, device);
+  if (ret != CAPMGR_ERROR_NONE)
+    return ret;
+
+  return CAPMGR_ERROR_NONE;
+}
+
 API int capmgr_application_info_foreach_applications(
     const capmgr_device_h device,
     capmgr_application_info_foreach_app_cb cb,
@@ -642,6 +674,7 @@ API int capmgr_application_info_foreach_applications(
       info.pkgid = stmt->GetColumnString(idx++);
       info.label = stmt->GetColumnString(idx++);
       info.version = stmt->GetColumnString(idx++);
+      info.device = device;
       if (cb(&info, user_data))
         break;
     }
index 6dad30b..b2adec7 100644 (file)
@@ -119,6 +119,8 @@ int AppForeachCb(const capmgr_application_info_h remote_app_info,
   char* pkgid = nullptr;
   char* label = nullptr;
   char* ver = nullptr;
+  capmgr_device_h device = nullptr;
+  char* device_id = nullptr;
 
   int ret = capmgr_application_info_get_appid(remote_app_info, &appid);
   if (ret != CAPMGR_ERROR_NONE)
@@ -136,12 +138,22 @@ int AppForeachCb(const capmgr_application_info_h remote_app_info,
   if (ret != CAPMGR_ERROR_NONE)
     std::cout << "Failed to get pkgid" << std::endl;
 
+  ret = capmgr_application_info_get_device(remote_app_info, &device);
+  if (ret != CAPMGR_ERROR_NONE)
+    std::cout << "Failed to get device" << std::endl;
+
   std::cout << "==============================================" << std::endl;
+
+  ret = capmgr_device_get_device_id(device, &device_id);
+  if (ret != CAPMGR_ERROR_NONE)
+    std::cout << "Failed to get device id" << std::endl;
+
   try {
     std::cout << "APPID: " << std::string(appid) << std::endl
               << "PKGID: " << std::string(pkgid) << std::endl
               << "Label: " << std::string(label) << std::endl
-              << "Version: " << std::string(ver) << std::endl;
+              << "Version: " << std::string(ver) << std::endl
+              << "Device ID: " << std::string(device_id) << std::endl;
   } catch (...) {
     std::cout << "Exception occured" << std::endl;
   }
@@ -150,6 +162,7 @@ int AppForeachCb(const capmgr_application_info_h remote_app_info,
   free(pkgid);
   free(label);
   free(ver);
+  capmgr_device_destroy(device);
 
   return 0;
 }