Skip to content

Commit

Permalink
Merge pull request #476 from Luos-io/fix/no_service
Browse files Browse the repository at this point in the history
Allow node to properly work without any services running
  • Loading branch information
nicolas-rabault authored Feb 12, 2024
2 parents 4ed1943 + 5689da2 commit 23dd45a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions engine/core/src/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ void Service_ClearId(void)
******************************************************************************/
uint16_t Service_GetIndex(service_t *service)
{
if (service_ctx.number == 0)
{
// We don't have any service just return 0 by default.
return 0;
}
LUOS_ASSERT((service >= service_ctx.list) && (service < &service_ctx.list[service_ctx.number]));
return ((uintptr_t)service - (uintptr_t)service_ctx.list) / sizeof(service_t);
}
Expand Down
9 changes: 7 additions & 2 deletions tool_services/gate/TinyJSON/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,13 @@ void Convert_RoutingTableData(service_t *service)

json_ptr += strlen(json_ptr);
i++;
bool find_service = false;
// Services loop
while (i < last_entry)
{
if (routing_table[i].mode == SERVICE)
{
find_service = true;
// Create service description
sprintf(json_ptr, "{\"type\":\"%s\",\"id\":%d,\"alias\":\"%s\"},", Convert_StringFromType(routing_table[i].type), routing_table[i].id, routing_table[i].alias);
json_ptr += strlen(json_ptr);
Expand All @@ -1062,8 +1064,11 @@ void Convert_RoutingTableData(service_t *service)
else
break;
}
// remove the last "," char
*(--json_ptr) = '\0';
if (find_service)
{
// remove the last "," char
*(--json_ptr) = '\0';
}
sprintf(json_ptr, "]},");
json_ptr += strlen(json_ptr);
}
Expand Down

0 comments on commit 23dd45a

Please sign in to comment.