add register/update shortcut
[apps/agl-service-homescreen.git] / src / hs-helper.cpp
index 30b53b2..780b7d4 100644 (file)
@@ -30,6 +30,8 @@ const char* evlist[] = {
     "showNotification",
     "showInformation",
     "application-list-changed",
+    "registerShortcut",
+    "updateShortcut",
     "reserved"
   };
 
@@ -337,22 +339,22 @@ int readJsonFile(const char* file, struct json_object **obj)
 int writeJsonFile(const char* file,  struct json_object *obj)
 {
     int ret = -1;
-    FILE *fp = fopen(file, "wb");
+    FILE *fp = fopen(file, "w+");
     if(fp == nullptr) {
         AFB_ERROR("open %s failed", file);
         return ret;
     }
 
     const char *str = json_object_to_json_string(obj);
-    size_t len = sizeof(str);
+    size_t len = strlen(str);
     size_t cnt = fwrite(str, len, 1, fp);
-    if(cnt == len) {
+    if(cnt == 1) {
         ret = 0;
         fflush(fp);
         fsync(fileno(fp));
     }
     else {
-        AFB_WARNING("write to %s failed.", file);
+        AFB_WARNING("write to %s failed.cnt=%d,len=%d,str=%s", file, cnt, len, str);
     }
 
     fclose(fp);