CT1
January 9, 2022, 6:32am
1
Does this API work? Currently testing with it, and it is marked experimental, but I can’t get a callback to my handler functions, and the le_json_GetBytesRead function indicates zero bytes were read from the input (I’ve tried both a string input and a file descriptor input). The API page indicates it should start reading bytes as soon as the function is called. Anyone know what’s happening here? I’m running 19.11.5
#include "legato.h"
#include "interfaces.h"
#define LE_FULL_API
#define LE_API_JSON
#define LE_API_FILESYSTEM
le_result_t result;
static void jsonHandler(le_json_Event_t event){
LE_INFO("jsonHandler function call, type: %d", (int)event);
}
static void jsonError(le_json_Error_t error, const char msg[]){
LE_INFO("jsonError function call, type: %d", (int)error);
LE_INFO(msg);
}
COMPONENT_INIT{
const char str[] = "{\"result\":\"failure\"}";
LE_INFO("init'd at least");
int fd = open("/home/root/result.json", O_RDONLY | O_EXCL);
LE_INFO("opened file");
LE_INFO("file descriptor %d",fd);
// le_json_ParsingSessionRef_t JsonParsingSessionRef = le_json_Parse(fd,jsonHandler,jsonError, NULL);
le_json_ParsingSessionRef_t JsonParsingSessionRef = le_json_ParseString(str,jsonHandler,jsonError, NULL);
LE_INFO(str);
LE_INFO("parse");
sleep(1);
size_t bytesRead = le_json_GetBytesRead(JsonParsingSessionRef);
LE_INFO("Bytes read: %d",bytesRead);
le_json_Cleanup(JsonParsingSessionRef);
close(fd);
LE_INFO("**** Done");
sleep(1);
exit(0);
}
jyijyi
January 10, 2022, 4:19am
2
I tried with attached Desktop.rar project in legato 20.08 in WP76, I can see it calls the callback function.
Desktop.rar (4.6 KB)
Jan 1 08:15:29 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c _hello1Component_COMPONENT_INIT() 33 | init'd at least
Jan 1 08:15:29 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c _hello1Component_COMPONENT_INIT() 36 | opened file
Jan 1 08:15:29 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c _hello1Component_COMPONENT_INIT() 38 | file descriptor 8
Jan 1 08:15:29 swi-mdm9x28-wp user.debug Legato: DBUG | hello1[3503]/framework T=main | fdMonitor.c fa_fdMon_Create() 369 | fd 8 doesn't support epoll(), assuming always readable and writeable.
Jan 1 08:15:29 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c _hello1Component_COMPONENT_INIT() 43 | {"result":"failure"}
Jan 1 08:15:29 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c _hello1Component_COMPONENT_INIT() 44 | parse
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c _hello1Component_COMPONENT_INIT() 47 | Bytes read: 0
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c _hello1Component_COMPONENT_INIT() 51 | **** Done
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 0
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 0
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 0
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 0
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 0
Jan 1 08:15:30 swi-mdm9x28-wp user.debug Legato: DBUG | hello1[3503]/framework T=main | mem.c le_mem_ForceAlloc() 1172 | Memory pool 'framework.JSONContext' overflowed. Expanded to 11 blocks.
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.debug Legato: DBUG | hello1[3503]/framework T=main | mem.c le_mem_ForceAlloc() 1172 | Memory pool 'framework.JSONContext' overflowed. Expanded to 12 blocks.
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 0
Jan 1 08:15:30 swi-mdm9x28-wp user.debug Legato: DBUG | hello1[3503]/framework T=main | mem.c le_mem_ForceAlloc() 1172 | Memory pool 'framework.JSONContext' overflowed. Expanded to 13 blocks.
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.debug Legato: DBUG | hello1[3503]/framework T=main | mem.c le_mem_ForceAlloc() 1172 | Memory pool 'framework.JSONContext' overflowed. Expanded to 14 blocks.
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 1
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 3
Jan 1 08:15:30 swi-mdm9x28-wp user.debug Legato: DBUG | hello1[3503]/framework T=main | mem.c le_mem_ForceAlloc() 1172 | Memory pool 'framework.JSONContext' overflowed. Expanded to 15 blocks.
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 5
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 4
Jan 1 08:15:30 swi-mdm9x28-wp user.info Legato: INFO | hello1[3503]/hello1Component T=main | hello1Component.c jsonHandler() 20 | jsonHandler function call, type: 2
CT1
January 10, 2022, 5:25am
3
Thank you jyijyi, from your code I figured out what’s going on here.
The COMPONENT_INIT loop is a blocking loop. It doesn’t allow the handler functions to be called until it is done.
Consequently the parser does not run instantly (contrary to the documentation). It is only run after the entire COMPONENT_INIT loop has been run through. My code had already closed the file descriptor, cleaned up the parser resources, and exited by that time.