Fraunhofer-IIS / libjapi

libjapi is a universal JSON to C API library. It receives newline-delimited JSON (NDJSON) messages via TCP and calls registered C functions. A JSON response is returned for each request. Furthermore, it is also possible to create push services, which asynchronously push JSON messages to the clients subscribed to them.
MIT License
3 stars 1 forks source link

dynamic creation of push service during runtime #47

Open fraunhofer-iis-bot opened 1 year ago

fraunhofer-iis-bot commented 1 year ago

In GitLab by @Michael-M-Baron on Apr 18, 2023, 09:07

The intended use of the push services is to specify some predefined services and activate them with japi_pushsrv_start() before the libjapi-server is started and deactive them afterwards with japi_pushsrv_stop(). The push services are fixed for the complete runtime and are embedded in the server-software. For every new push-service, the server-software has to be updated with the new services. We found out during the development of the Interstellar-DAC-GUI, that it could be very usefull to decouple the push-service from the server-development and move it to the client-development, so that the GUI can for example create new push services on the fly during runtime with the desired JAPI-Requests.

We therefore implemented JAPI-Requests which can add and remove push-services during runtime. The code is written in a generic way and can be found in the Interstellar control software dbcd and server_common in the file jr_general.c starting at line 363. The Request for adding a push service works as following:

{ 
  "japi_request": "add_push_service",
  "args": 
  {          
    "SERVICE": "push_temperature",    
    "INTERVAL": 5,           
    "WRAPPER": 
    {                 
      "japi_request": "get_temperature",         
      "args": 
      {                       
        "DEVICE": "device1",    
        "UNIT": "KELVIN"  
      }         
    }    
  }
}

The client specifes the push-Service with the desired JAPI-Request and sets a time-interval in which the request should be repeated. The Push-Service is then started and calls the given JAPI-Request with parameters in an endless loop with a waiting time specified in INTERVAL. More detailled documentation can be found under add_push_service and remove_push_service.

Discussion:

fraunhofer-iis-bot commented 1 year ago

In GitLab by @Michael-M-Baron on Jul 5, 2023, 10:55

The API of japi_pushsrv_destroy has changed. See #43 for details. The Remove japi_push_service request can be shortened. The request does not has to update the ctx push service list anymore.