"showNotification",
"showInformation",
"application-list-changed",
+ "registerShortcut",
+ "updateShortcut",
+ "setDestination",
+ "cancelDestination",
+ "startNavigation",
+ "stopNavigation",
"reserved"
};
*
* #### Return
* 0 : read success
- * 1 : read fail
+ * -1 : read fail
*
*/
int readJsonFile(const char* file, struct json_object **obj)
{
- *obj = nullptr;
int ret = -1;
FILE *fp = fopen(file, "rb");
if(fp == nullptr) {
return ret;
}
+ *obj = nullptr;
const int buf_size = 128;
char buf[buf_size];
struct json_tokener *tokener = json_tokener_new();
json_tokener_free(tokener);
return ret;
}
+
+/**
+ * write to json file
+ *
+ * #### Parameters
+ * - file : output file name
+ * - obj : json_object
+ *
+ * #### Return
+ * 0 : write success
+ * -1 : write fail
+ *
+ */
+int writeJsonFile(const char* file, struct json_object *obj)
+{
+ int ret = -1;
+ 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 = strlen(str);
+ size_t cnt = fwrite(str, len, 1, fp);
+ if(cnt == 1) {
+ ret = 0;
+ fflush(fp);
+ fsync(fileno(fp));
+ }
+ else {
+ AFB_WARNING("write to %s failed.cnt=%d,len=%d,str=%s", file, cnt, len, str);
+ }
+
+ fclose(fp);
+ return ret;
+}
\ No newline at end of file