Check the maximum count of widgets before create a new instance.
authorSung-jae Park <nicesj.park@samsung.com>
Wed, 22 Apr 2015 07:17:04 +0000 (16:17 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Wed, 22 Apr 2015 07:17:04 +0000 (16:17 +0900)
[model] Redwood,Kiran,B3(Wearable)
[binary_type] AP
[customer] Docomo/Orange/ATT/Open
[issue#] N/A
[problem]
[cause]
[solution]
[team] HomeTF
[request]
[horizontal_expansion]

Change-Id: I939a321c7891ec21d30394ec9bbe6803c36c61b7

include/package.h
src/package.c
src/server.c

index dd5e35c..8fc5de6 100644 (file)
@@ -123,4 +123,5 @@ extern int package_faulted(struct pkg_info *info, int broadcast);
 extern char *package_get_pkgid(const char *appid);
 
 extern int package_del_instance_by_category(const char *category, const char *except_widget_id);
+extern int package_instance_count(struct pkg_info *info);
 /* End of a file */
index 048d49d..0481175 100644 (file)
@@ -1637,6 +1637,30 @@ HAPI int const package_fault_count(struct pkg_info *info)
        return info ? info->fault_count : 0;
 }
 
+HAPI int package_instance_count(struct pkg_info *info)
+{
+       Eina_List *l;
+       struct inst_info *inst;
+       int count = 0;
+
+       EINA_LIST_FOREACH(info->inst_list, l, inst) {
+               switch (instance_state(inst)) {
+               case INST_INIT:
+               case INST_ACTIVATED:
+               case INST_REQUEST_TO_ACTIVATE:
+               case INST_REQUEST_TO_REACTIVATE:
+                       count++;
+                       break;
+               case INST_DESTROYED:
+               case INST_REQUEST_TO_DESTROY:
+               default:
+                       break;
+               }
+       }
+
+       return count;
+}
+
 HAPI int package_is_enabled(const char *appid)
 {
        pkgmgrinfo_appinfo_h handle;
index 201885a..9a3fec7 100644 (file)
@@ -1308,6 +1308,7 @@ static struct packet *client_new(pid_t pid, int handle, const struct packet *pac
        int height;
        char *widget_id;
        char *mainappid;
+       int max_count;
 
        client = client_find_by_rpc_handle(handle);
        if (!client) {
@@ -1362,6 +1363,12 @@ static struct packet *client_new(pid_t pid, int handle, const struct packet *pac
                DbgFree(pkgid);
        }
 
+       max_count = widget_service_get_widget_max_count(widget_id);
+       if (max_count < 0) {
+               ErrPrint("Failed to get max_count[%s] = %d\n", widget_id, max_count);
+               max_count = 0;
+       }
+
        if (!info) {
                ret = WIDGET_ERROR_FAULT;
        } else if (package_is_fault(info)) {
@@ -1369,6 +1376,9 @@ static struct packet *client_new(pid_t pid, int handle, const struct packet *pac
        } else if (util_free_space(WIDGET_CONF_IMAGE_PATH) <= WIDGET_CONF_MINIMUM_SPACE) {
                ErrPrint("Not enough space\n");
                ret = WIDGET_ERROR_FILE_NO_SPACE_ON_DEVICE;
+       } else if (max_count && max_count <= package_instance_count(info)) {
+               ErrPrint("Reached to the max count of widgets %d, %d\n", max_count, package_instance_count(info));
+               ret = WIDGET_ERROR_CANCELED;
        } else {
                struct inst_info *inst;