Change API spec
authorInkyun Kil <inkyun.kil@samsung.com>
Fri, 26 Oct 2018 02:01:14 +0000 (11:01 +0900)
committer길인균/Tizen Platform Lab(SR)/Engineer/삼성전자 <inkyun.kil@samsung.com>
Mon, 29 Oct 2018 07:05:34 +0000 (16:05 +0900)
- Remove Apis about Package infomation
- Add Apis about Application information

Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
include/capability_manager.h
src/client.cc
tools/capmgr_test.cc

index e7f1de5..a8affce 100644 (file)
@@ -25,10 +25,14 @@ extern "C" {
  * @since_tizen 5.0
  */
 typedef enum {
-  CAPMGR_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
-  CAPMGR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
-  CAPMGR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
-  CAPMGR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< Internal I/O error */
+  /**< Successful */
+  CAPMGR_ERROR_NONE = TIZEN_ERROR_NONE,
+  /**< Invalid parameter */
+  CAPMGR_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,
+  /**< Out of memory */
+  CAPMGR_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,
+  /**< Internal I/O error */
+  CAPMGR_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR,
 } capmgr_error_e;
 
 /**
@@ -52,10 +56,10 @@ typedef struct capmgr_device_s* capmgr_device_h;
 typedef struct capmgr_app_control_s* capmgr_app_control_h;
 
 /**
- * @brief Capability Manager package info handle.
+ * @brief Capability Manager application info handle.
  * @since_tizen 5.0
  */
-typedef struct capmgr_package_info_s* capmgr_package_info_h;
+typedef struct capmgr_application_info_s* capmgr_application_info_h;
 
 /**
  * @brief Called to retrieve information of devices currently discovered.
@@ -86,28 +90,16 @@ typedef int (*capmgr_app_control_reply_cb)(const capmgr_app_control_h request,
     void* user_data);
 
 /**
- * @brief Called for each remote package info.
+ * @brief Called for each remote application info.
  * @since_tizen 5.0
  *
- * @remarks The @a remote_package_info can be used only in the callback. To use outside, make a copy.
- * @param[in] remote_package_info  Capability Manager package info handle
- * @param[in] user_data            The user data to be passed to the callback function
- * @see capmgr_package_info_foreach_packages()
- */
-typedef int (*capmgr_package_info_foreach_package_cb)(
-    const capmgr_package_info_h remote_package_info, void* user_data);
-
-/**
- * @brief Called for each application of remote package.
- * @since_tizen 5.0
- *
- * @remarks The @a appid can be used only in the callback. To use outside, make a copy.
- * @param[in] appid           Application ID of remote application
+ * @remarks The @a remote_app_info can be used only in the callback. To use outside, make a copy.
+ * @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_package_info_foreach_applications()
+ * @see capmgr_application_info_foreach_applications()
  */
-typedef int (*capmgr_package_info_foreach_app_cb)(
-    const char* appid, void* user_data);
+typedef int (*capmgr_application_info_foreach_app_cb)(
+    const capmgr_application_info_h remote_app_info, void* user_data);
 
 /**
  * @brief Retrieves all remote device info stored on local device.
@@ -505,10 +497,10 @@ int capmgr_app_control_send(capmgr_app_control_h app_control,
     capmgr_app_control_reply_cb cb, void* user_data);
 
 /**
- * @brief Retrieves all packages installed at specified remote device and invoke callback each of it.
+ * @brief Retrieves all applications installed at specified remote device and invoke callback each of it.
  * @since_tizen 5.0
  * @param[in]   device         The remote device handle
- * @param[in]   cb             Callback to be invoked for each package
+ * @param[in]   cb             Callback to be invoked for each application
  * @param[in]   user_data      The user data to be passed to the callback function
  * @return      @c 0 on success,
  *              otherwise a negative error value
@@ -517,70 +509,70 @@ int capmgr_app_control_send(capmgr_app_control_h app_control,
  * @retval  #CAPMGR_ERROR_IO_ERROR           I/O error
  * @retval  #CAPMGR_ERROR_OUT_OF_MEMORY      Out of memory
  */
-int capmgr_package_info_foreach_packages(const capmgr_device_h device,
-    capmgr_package_info_foreach_package_cb cb, void* user_data);
+int capmgr_application_info_foreach_applications(
+    const capmgr_device_h device,
+    capmgr_application_info_foreach_app_cb cb,
+    void* user_data);
 
 /**
- * @brief Retrieves all applications belongs to given package and invoke callback each of it.
+ * @brief Gets the application ID from given remote application information.
  * @since_tizen 5.0
- * @param[in]   remote_package_info   The package information installed at specific remote device
- * @param[in]   cb                    Callback to be invoked for each application
- * @param[in]   user_data             The user data to be passed to the callback function
+ * @remarks     You must release @a appid using free().
+ * @param[in]   remote_app_info   The application information installed at specific remote device
+ * @param[out]  appid             The application ID
  * @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_IO_ERROR           I/O error
  * @retval  #CAPMGR_ERROR_OUT_OF_MEMORY      Out of memory
  */
-int capmgr_package_info_foreach_applications(
-    const capmgr_package_info_h remote_package_info,
-    capmgr_package_info_foreach_app_cb cb, void* user_data);
+int capmgr_application_info_get_appid(capmgr_application_info_h remote_app_info,
+    char** appid);
 
 /**
- * @brief Gets the package ID from given remote package information.
+ * @brief Gets the package ID from given remote application information.
  * @since_tizen 5.0
  * @remarks     You must release @a pkgid using free().
- * @param[in]   remote_package_info    The package information installed at specific remote device
- * @param[in]   pkgid                  The package ID
+ * @param[in]   remote_app_info   The application information installed at specific remote device
+ * @param[out]  pkgid             The package ID
  * @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_package_info_get_pkgid(capmgr_package_info_h remote_package_info,
+int capmgr_application_info_get_pkgid(capmgr_application_info_h remote_app_info,
     char** pkgid);
 
 /**
- * @brief Gets the label from given remote package information.
+ * @brief Gets the label from given remote application information.
  * @since_tizen 5.0
  * @remarks     You must release @a label using free().
- * @param[in]   remote_package_info    The package information installed at specific remote device
- * @param[in]   label                  The label of package
+ * @param[in]   remote_app_info   The application information installed at specific remote device
+ * @param[out]  label             The label of application
  * @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_package_info_get_label(capmgr_package_info_h remote_package_info,
+int capmgr_application_info_get_label(capmgr_application_info_h remote_app_info,
     char** label);
 
 /**
- * @brief Gets the version from given remote package information.
+ * @brief Gets the version from given remote application information.
  * @since_tizen 5.0
  * @remarks     You must release @a version using free().
- * @param[in]   remote_package_info      The package information installed at specific remote device
- * @param[in]   version                  The version of package
+ * @param[in]   remote_app_info   The application information installed at specific remote device
+ * @param[out]  version           The version of application
  * @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_package_info_get_version(capmgr_package_info_h remote_package_info,
-    char** version);
+int capmgr_application_info_get_version(
+    capmgr_application_info_h remote_app_info, char** version);
 
 #ifdef __cplusplus
 }
index 97a9d7e..de41c94 100644 (file)
@@ -42,11 +42,11 @@ struct capmgr_app_control_s {
   bundle* b;
 };
 
-struct capmgr_package_info_s {
+struct capmgr_application_info_s {
+  std::string appid;
   std::string pkgid;
   std::string label;
   std::string version;
-  std::vector<std::string> appid_list;
 };
 
 API int capmgr_device_foreach_devices(capmgr_device_foreach_cb cb,
@@ -543,50 +543,58 @@ API int capmgr_app_control_send(capmgr_app_control_h app_control,
   return CAPMGR_ERROR_NONE;
 }
 
-API int capmgr_package_info_get_pkgid(capmgr_package_info_h remote_package_info,
-    char** pkgid) {
-  if (!remote_package_info || !pkgid ||
-      remote_package_info->pkgid.empty())
+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())
     return CAPMGR_ERROR_INVALID_PARAMETER;
 
-  *pkgid = strdup(remote_package_info->pkgid.c_str());
+  *appid = strdup(remote_app_info->appid.c_str());
+  if (*appid == nullptr)
+    return CAPMGR_ERROR_OUT_OF_MEMORY;
+
+  return CAPMGR_ERROR_NONE;
+}
+
+API int capmgr_application_info_get_pkgid(
+    capmgr_application_info_h remote_app_info, char** pkgid) {
+  if (!remote_app_info || !pkgid || remote_app_info->pkgid.empty())
+    return CAPMGR_ERROR_INVALID_PARAMETER;
+
+  *pkgid = strdup(remote_app_info->pkgid.c_str());
   if (*pkgid == nullptr)
     return CAPMGR_ERROR_OUT_OF_MEMORY;
 
   return CAPMGR_ERROR_NONE;
 }
 
-API int capmgr_package_info_get_label(capmgr_package_info_h remote_package_info,
-    char** label) {
-  if (!remote_package_info || !label ||
-      remote_package_info->label.empty())
+API int capmgr_application_info_get_label(
+    capmgr_application_info_h remote_app_info, char** label) {
+  if (!remote_app_info || !label || remote_app_info->label.empty())
     return CAPMGR_ERROR_INVALID_PARAMETER;
 
-  *label = strdup(remote_package_info->label.c_str());
+  *label = strdup(remote_app_info->label.c_str());
   if (*label == nullptr)
     return CAPMGR_ERROR_OUT_OF_MEMORY;
 
   return CAPMGR_ERROR_NONE;
 }
 
-API int capmgr_package_info_get_version(
-    capmgr_package_info_h remote_package_info, char** version) {
-  if (!remote_package_info || !version ||
-      remote_package_info->version.empty())
+API int capmgr_application_info_get_version(
+    capmgr_application_info_h remote_app_info, char** version) {
+  if (!remote_app_info || !version || remote_app_info->version.empty())
     return CAPMGR_ERROR_INVALID_PARAMETER;
 
-  *version = strdup(remote_package_info->version.c_str());
+  *version = strdup(remote_app_info->version.c_str());
   if (*version == nullptr)
     return CAPMGR_ERROR_OUT_OF_MEMORY;
 
   return CAPMGR_ERROR_NONE;
 }
 
-API int capmgr_package_info_foreach_packages(const capmgr_device_h device,
-    capmgr_package_info_foreach_package_cb cb,
+API int capmgr_application_info_foreach_applications(
+    const capmgr_device_h device,
+    capmgr_application_info_foreach_app_cb cb,
     void* user_data) {
-  std::map<std::string, capmgr_package_info_s> pkg_map;
-
   if (!cb)
     return CAPMGR_ERROR_INVALID_PARAMETER;
 
@@ -604,40 +612,16 @@ API int capmgr_package_info_foreach_packages(const capmgr_device_h device,
 
   if (stmt->BindString(1, device->device_id)) {
     while (stmt->Step() == capmgr::SQLStatement::StepResult::ROW) {
-      struct capmgr_package_info_s info;
-      std::string appid;
+      struct capmgr_application_info_s info;
       int idx = 0;
-      appid = stmt->GetColumnString(idx++);
+      info.appid = stmt->GetColumnString(idx++);
       info.pkgid = stmt->GetColumnString(idx++);
       info.label = stmt->GetColumnString(idx++);
       info.version = stmt->GetColumnString(idx++);
-
-      auto search_info = pkg_map.find(appid);
-      if (search_info != pkg_map.end()) {
-        info.appid_list.emplace_back(appid);
-        pkg_map.emplace(appid, info);
-      } else {
-        struct capmgr_package_info_s found = search_info->second;
-        found.appid_list.emplace_back(appid);
-      }
+      if (cb(&info, user_data))
+        break;
     }
   }
 
-  for (auto it = pkg_map.begin(); it != pkg_map.end(); it++) {
-    struct capmgr_package_info_s info = it->second;
-    if (cb(&info, user_data))
-      break;
-  }
-
-  return CAPMGR_ERROR_NONE;
-}
-
-API int capmgr_package_info_foreach_applications(
-    const capmgr_package_info_h remote_pkg_info,
-    capmgr_package_info_foreach_app_cb cb,
-    void* user_data) {
-  if (!cb)
-    return CAPMGR_ERROR_INVALID_PARAMETER;
-
   return CAPMGR_ERROR_NONE;
 }
index 8c79856..6dad30b 100644 (file)
@@ -34,6 +34,7 @@ class Client {
   void SendAppControl(const std::string& device_id, const std::string& appid);
   void SendFile(const std::string& device_id, const std::string& file_path);
   void ListDevices();
+  void ListAppinfos(const std::string& device_id);
 
  private:
   GVariant* ProxyCallSync(const char* method, GVariant* params);
@@ -112,6 +113,48 @@ int DeviceForeachCb(const capmgr_device_h device, void* user_data) {
   return 0;
 }
 
+int AppForeachCb(const capmgr_application_info_h remote_app_info,
+    void* user_data) {
+  char* appid = nullptr;
+  char* pkgid = nullptr;
+  char* label = nullptr;
+  char* ver = nullptr;
+
+  int ret = capmgr_application_info_get_appid(remote_app_info, &appid);
+  if (ret != CAPMGR_ERROR_NONE)
+    std::cout << "Failed to get appid" << std::endl;
+
+  ret = capmgr_application_info_get_pkgid(remote_app_info, &pkgid);
+  if (ret != CAPMGR_ERROR_NONE)
+    std::cout << "Failed to get pkgid" << std::endl;
+
+  ret = capmgr_application_info_get_label(remote_app_info, &label);
+  if (ret != CAPMGR_ERROR_NONE)
+    std::cout << "Failed to get label" << std::endl;
+
+  ret = capmgr_application_info_get_version(remote_app_info, &ver);
+  if (ret != CAPMGR_ERROR_NONE)
+    std::cout << "Failed to get pkgid" << std::endl;
+
+  std::cout << "==============================================" << 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;
+  } catch (...) {
+    std::cout << "Exception occured" << std::endl;
+  }
+
+  free(appid);
+  free(pkgid);
+  free(label);
+  free(ver);
+
+  return 0;
+}
+
+
 Client::Client() {
   loop_ = g_main_loop_new(nullptr, FALSE);
 
@@ -211,6 +254,36 @@ void Client::ListDevices() {
               << std::endl;
 }
 
+void Client::ListAppinfos(const std::string& device_id) {
+  if (device_id.empty()) {
+    std::cout << "Target device is missing!" << std::endl;
+    return;
+  }
+
+  capmgr_device_h device = nullptr;
+  struct cbdata cbdata = {&device, device_id};
+  int ret = capmgr_device_foreach_devices(DeviceForeachCb, &cbdata);
+  if (ret != CAPMGR_ERROR_NONE) {
+    std::cout << "capmgr_device_foreach_devices() failed: " << ret
+              << std::endl;
+    return;
+  }
+
+  if (*cbdata.device == nullptr) {
+    std::cout << "There is no such device!" << std::endl;
+    return;
+  }
+
+  std::cout << "Target device is " <<device_id;
+  ret = capmgr_application_info_foreach_applications(device, AppForeachCb,
+      nullptr);
+  if (ret != CAPMGR_ERROR_NONE)
+    std::cout << "capmgr_application_info_foreach_applications() failed: "
+              << ret << std::endl;
+
+  capmgr_device_destroy(device);
+}
+
 void Client::SendFile(const std::string& device_id,
     const std::string& file_path) {
   if (device_id.empty()) {
@@ -358,6 +431,7 @@ int main(int argc, char* argv[]) {
         ("send-appcontrol,s", bpo::value<std::string>(),
             "send remote app-control")
         ("list-devices,l", "list remote devices")
+        ("list-appinfos,a", "list remote application infos")
         ("send-file,f", bpo::value<std::string>(), "send file");
     bpo::store(bpo::parse_command_line(argc, argv, options), opt_map);
 
@@ -370,6 +444,8 @@ int main(int argc, char* argv[]) {
           opt_map["send-appcontrol"].as<std::string>());
     else if (opt_map.count("list-devices"))
       client.ListDevices();
+    else if (opt_map.count("list-appinfos"))
+      client.ListAppinfos(opt_map["device"].as<std::string>());
     else if (opt_map.count("send-file"))
       client.SendFile(opt_map["device"].as<std::string>(),
           opt_map["send-file"].as<std::string>());