Add metadata to pkginfo
[platform/core/appfw/pkgmgr-info.git] / include / pkgmgr-info.h
index 134af64..9a856d6 100644 (file)
@@ -2708,6 +2708,257 @@ static int list_plugin(const char *package)
 int pkgmgrinfo_pkginfo_foreach_plugin(pkgmgrinfo_pkginfo_h handle,
                        pkgmgrinfo_plugin_list_cb plugin_func, void *user_data);
 
+/**
+ * @fn int pkgmgrinfo_pkginfo_foreach_metadata(pkgmgrinfo_pkginfo_h handle,
+                       pkgmgrinfo_pkg_metadata_list_cb metadata_func, void *user_data);
+ * @brief      This API gets the list of metadata for a particular package
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ * @param[in]  handle          pointer to the package info handle.
+ * @param[in]  metadata_func           callback function for list
+ * @param[in] user_data        user data to be passed to callback function
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ERROR  internal error
+ * @pre                pkgmgrinfo_pkginfo_get_pkginfo()
+ * @post               pkgmgrinfo_pkginfo_destroy_pkginfo()
+ * @code
+int metadata_func(const char *key, const char *value, void *user_data)
+{
+       if (strcmp(key, (char *)user_data) == 0) {
+               printf("Value is %s\n", value);
+               return -1;
+       }
+       else
+               return 0;
+}
+
+static int list_metadata(const char *pkgid, char *key)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h handle;
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_pkginfo_foreach_metadata(handle, metadata_func, (void *)key);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_pkginfo_foreach_metadata(pkgmgrinfo_pkginfo_h handle,
+                       pkgmgrinfo_pkg_metadata_list_cb metadata_func, void *user_data);
+
+/**
+ * @fn int pkgmgrinfo_pkginfo_metadata_filter_create(pkgmgrinfo_pkginfo_metadata_filter_h *handle)
+ * @brief      This API creates the application's metadata  information filter handle from db.
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[out] handle          pointer to the package metadata info filter handle.
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ERROR  internal error
+ * @pre                None
+ * @post               pkgmgrinfo_pkginfo_metadata_filter_destroy()
+ * @see                pkgmgrinfo_pkginfo_metadata_filter_foreach()
+ * @code
+int pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       char *pkgid = NULL;
+       pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       printf("pkgid : %s\n", pkgid);
+       return 0;
+}
+
+static int get_pkg_list(const char *mkey, const char *mvalue)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_metadata_filter_h handle;
+       ret = pkgmgrinfo_pkginfo_metadata_filter_create(&handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_pkginfo_metadata_filter_add(handle, mkey, mvalue);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+       ret = pkgmgrinfo_pkginfo_metadata_filter_foreach(handle, pkg_list_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_pkginfo_metadata_filter_create(pkgmgrinfo_pkginfo_metadata_filter_h *handle);
+
+/**
+ * @fn int pkgmgrinfo_pkginfo_metadata_filter_destroy(pkgmgrinfo_pkginfo_metadata_filter_h handle)
+ * @brief      This API destroys the package's metadata  information filter handle.
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in] handle           pointer to the package metadata info filter handle.
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ERROR  internal error
+ * @pre                pkgmgrinfo_pkginfo_metadata_filter_create()
+ * @post               None
+ * @see                pkgmgrinfo_pkginfo_metadata_filter_foreach()
+ * @code
+int pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       char *pkgid = NULL;
+       pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       printf("pkgid : %s\n", pkgid);
+       return 0;
+}
+
+static int get_pkg_list(const char *mkey, const char *mvalue)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_metadata_filter_h handle;
+       ret = pkgmgrinfo_pkginfo_metadata_filter_create(&handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_pkginfo_metadata_filter_add(handle, mkey, mvalue);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+       ret = pkgmgrinfo_pkginfo_metadata_filter_foreach(handle, pkg_list_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_pkginfo_metadata_filter_destroy(pkgmgrinfo_pkginfo_metadata_filter_h handle);
+
+/**
+ * @fn int pkgmgrinfo_pkginfo_metadata_filter_add(pkgmgrinfo_pkginfo_metadata_filter_h handle, const char *key, const char *value)
+ * @brief      This API adds filter condition for the query API.  The query will search the entire package metadata  information collected from
+ * the manifest file of all the installed packages. You can specify value as NULL to search based on key only.
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in] handle           pointer to the package metadata info filter handle.
+ * @param[in] key                      pointer to metadata key
+ * @param[in] value                    pointer to metadata value
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ERROR  internal error
+ * @pre                pkgmgrinfo_pkginfo_metadata_filter_create()
+ * @post               pkgmgrinfo_pkginfo_metadata_filter_foreach(), pkgmgrinfo_pkginfo_metadata_filter_destroy()
+ * @see                pkgmgrinfo_pkginfo_metadata_filter_foreach()
+ * @code
+int pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       char *pkgid = NULL;
+       pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       printf("pkgid : %s\n", pkgid);
+       return 0;
+}
+
+static int get_pkg_list(const char *mkey, const char *mvalue)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_metadata_filter_h handle;
+       ret = pkgmgrinfo_pkginfo_metadata_filter_create(&handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_pkginfo_metadata_filter_add(handle, mkey, mvalue);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+       ret = pkgmgrinfo_pkginfo_metadata_filter_foreach(handle, pkg_list_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_pkginfo_metadata_filter_add(pkgmgrinfo_pkginfo_metadata_filter_h handle,
+               const char *key, const char *value);
+
+/**
+ * @fn int pkgmgrinfo_pkginfo_metadata_filter_foreach(pkgmgrinfo_pkginfo_metadata_filter_h handle, pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data)
+ * @fn int pkgmgrinfo_pkginfo_usr_metadata_filter_foreach(pkgmgrinfo_pkginfo_metadata_filter_h handle, pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid)
+ * @brief      This API executes the filter query. The query will search the entire package metadata  information collected from
+ * the manifest file of all the installed packages. For each package returned by the query, the callback will be called. If callback returns
+ * negative value, no more callbacks will be called and API will return.
+ *
+ * @par                This API is for package-manager client application
+ * @par Sync (or) Async : Synchronous API
+ *
+ * @param[in] handle           pointer to the package metadata info filter handle.
+ * @param[in] app_cb           function pointer to callback
+ * @param[in] user_data                pointer to user data
+ * @param[in]  uid     the addressee user id of the instruction
+ * @return     0 if success, error code(<0) if fail
+ * @retval     PMINFO_R_OK     success
+ * @retval     PMINFO_R_EINVAL invalid argument
+ * @retval     PMINFO_R_ERROR  internal error
+ * @pre                pkgmgrinfo_pkginfo_metadata_filter_create()
+ * @post               pkgmgrinfo_pkginfo_metadata_filter_destroy()
+ * @code
+int pkg_list_cb(pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       char *pkgid = NULL;
+       pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       printf("pkgid : %s\n", pkgid);
+       return 0;
+}
+
+static int get_pkg_list(const char *mkey, const char *mvalue)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_metadata_filter_h handle;
+       ret = pkgmgrinfo_pkginfo_metadata_filter_create(&handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+       ret = pkgmgrinfo_pkginfo_metadata_filter_add(handle, mkey, mvalue);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+       ret = pkgmgrinfo_pkginfo_metadata_filter_foreach(handle, pkg_list_cb, NULL);
+       if (ret != PMINFO_R_OK) {
+               pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_metadata_filter_destroy(handle);
+       return 0;
+}
+ * @endcode
+ */
+int pkgmgrinfo_pkginfo_metadata_filter_foreach(pkgmgrinfo_pkginfo_metadata_filter_h handle,
+               pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data);
+int pkgmgrinfo_pkginfo_usr_metadata_filter_foreach(pkgmgrinfo_pkginfo_metadata_filter_h handle,
+               pkgmgrinfo_pkg_list_cb pkg_cb, void *user_data, uid_t uid);
+
 /* TODO: add doxygen comment here */
 int pkgmgrinfo_pkginfo_is_for_all_users(pkgmgrinfo_pkginfo_h handle, bool *for_all_users);
 
@@ -6950,4 +7201,3 @@ int pkgmgrinfo_archiveinfo_foreach_dependency(pkgmgrinfo_archiveinfo_h handle,
  * @}
  * @}
  */
-