Skip to content

Commit

Permalink
Merge branch 'dev' of git01.iis.fhg.de:ks-ip-lib/software/libjapi int…
Browse files Browse the repository at this point in the history
…o 44-libjapi-doxydir-example-out-of-date
  • Loading branch information
Michael-M-Baron committed Jul 5, 2023
2 parents d5fc519 + 6abff0b commit b4f8648
Show file tree
Hide file tree
Showing 22 changed files with 487 additions and 39 deletions.
20 changes: 20 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Copyright (c) 2023 Fraunhofer IIS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
next
=====
* Add MIT license
* ...

0.3.2
Expand Down
149 changes: 148 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,155 @@ You can clone the [demo project](https://git01.iis.fhg.de/ks-ip-lib/software/lib

$ git clone --recurse-submodules git@git01.iis.fhg.de:ks-ip-lib/software/libjapi-demo.git

<<<<<<< HEAD
## References
* https://github.com/json-c/json-c
* http://json-c.github.io/json-c/
* https://en.wikipedia.org/wiki/JSON
* https://alan-mushi.github.io/2014/10/28/json-c-tutorial-part-1.html
* https://alan-mushi.github.io/2014/10/28/json-c-tutorial-part-1.html
=======
## Usage & Examples
* Create a JAPI context
* Write application specific functions
* Register these application specific functions to libjapi
* Start a JAPI server
* Enjoy the flexibility

### Server example

#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h> /* sleep */

#include <japi.h>
#include <japi_pushsrv.h>
#include <japi_utils.h>

/* User defined push service routine */
int push_counter(japi_pushsrv_context *psc)
{
json_object *jmsg;
int i;

assert(psc != NULL);

i = 0;
jmsg = json_object_new_object();

while (psc->enabled) {
/* Create JSON response string */
json_object_object_add(jmsg,"counter",json_object_new_int(i));

/* Push message */
japi_pushsrv_sendmsg(psc,jmsg);

i++;
sleep(1);
}
json_object_put(jmsg);

return 0;
}

static void rnf_handler(japi_context *ctx, json_object *request, json_object *response)
{
json_object_object_add(response, "japi_response_msg", json_object_new_string("ERROR: No request handler found!"));
}

static void get_temperature(japi_context *ctx, json_object *request, json_object *response)
{
double temperature;
const char *unit;

/*
* TODO: Read the temperature from a sensor...
*/
temperature = 27.0;

/* Provide the temperature in KELVIN (if requested)
* or CELSIUS (default) */
unit = japi_get_value_as_str(request, "unit");
if (unit != NULL && strcmp(unit, "kelvin") == 0) {
temperature += 273;
} else {
unit = "celsius";
}

/* Prepare and provide response */
json_object_object_add(response, "temperature", json_object_new_double(temperature));
json_object_object_add(response, "unit", json_object_new_string(unit));
}

int main(int argc, char *argv[])
{
int ret;
japi_context *ctx;
japi_pushsrv_context *psc_counter;

/* Read port */
if (argc != 2) {
fprintf(stderr, "ERROR: Missing argument or wrong amount of arguments.\n" \
"Usage:\n\t%s <port>\n", argv[0]);
return -1;
}

/* Create JSON API context */
ctx = japi_init(NULL);
if (ctx == NULL) {
fprintf(stderr, "ERROR: Failed to create japi context\n");
return -1;
}

/* Register JSON API request */
japi_register_request(ctx, "get_temperature", &get_temperature);

/* Register push service */
psc_counter = japi_pushsrv_register(ctx, "push_counter");

/* Start push thread */
japi_pushsrv_start(psc_counter,&push_counter);

/* Provide JSON API interface via TCP */
ret = japi_start_server(ctx, argv[1]);

/* Wait for the thread to finish */
japi_pushsrv_stop(psc_counter);

/* Destroy JAPI context */
japi_destroy(ctx);

return ret;
}

### Client JSON request examples

{
"japi_request": "get_temperature",
"args": {
"unit": "kelvin"
}
}

{
"japi_request": "japi_pushsrv_list",
}

{
"japi_request": "japi_pushsrv_subscribe",
"args": {
"service": "push_counter"
}
}

{
"japi_request": "japi_pushsrv_unsubscribe",
"args": {
"service": "push_counter"
}
}

## License

Copyright (c) 2023 Fraunhofer IIS. Released under the [MIT License](COPYING).
>>>>>>> 6abff0ba518e9eafb6f4798c12025bbb40517218
1 change: 1 addition & 0 deletions gitlab-ci/docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# Copyright (c) 2023 Fraunhofer IIS

set -e

Expand Down
1 change: 1 addition & 0 deletions gitlab-ci/docker-upload.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# Copyright (c) 2023 Fraunhofer IIS

# see https://git01.iis.fhg.de/ks-ip-lib/software/libjapi/container_registry

Expand Down
23 changes: 20 additions & 3 deletions include/creadline.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,26 @@
* This readline implementation reads a single line from a file descriptor
* (e.g. a socket). Two versions are provided.
*
* \copyright
* Copyright (c) 2018 Fraunhofer IIS.
* All rights reserved.
*\copyright
* Copyright (c) 2023 Fraunhofer IIS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __CREADLINE_H__
Expand Down
23 changes: 20 additions & 3 deletions include/japi.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,26 @@
* \details
* libjapi is a universal JSON API library.
*
* \copyright
* Copyright (c) 2018 Fraunhofer IIS.
* All rights reserved.
*\copyright
* Copyright (c) 2023 Fraunhofer IIS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __JAPI_H__
Expand Down
21 changes: 19 additions & 2 deletions include/japi_pushsrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,25 @@
* japi_pushsrv is a universal JSON API library.
*
* \copyright
* Copyright (c) 2019 Fraunhofer IIS.
* All rights reserved.
* Copyright (c) 2023 Fraunhofer IIS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __JAPI_PUSHSRV_H__
Expand Down
23 changes: 20 additions & 3 deletions include/japi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,26 @@
* \details
* libjapi is a universal JSON API library.
*
* \copyright
* Copyright (c) 2018 Fraunhofer IIS.
* All rights reserved.
*\copyright
* Copyright (c) 2023 Fraunhofer IIS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __JAPI_UTILS_H__
Expand Down
23 changes: 20 additions & 3 deletions include/networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,26 @@
* \details
* This module collects networking helper functions like tcp_start_server().
*
* \copyright
* Copyright (c) 2018 Fraunhofer IIS.
* All rights reserved.
*\copyright
* Copyright (c) 2023 Fraunhofer IIS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __NETWORKING_H__
Expand Down
23 changes: 20 additions & 3 deletions include/rw_n.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,26 @@
* Use read_n() to read or write_n() to write a fixed number of bytes from or
* to a file descriptor.
*
* \copyright
* Copyright (c) 2018 Fraunhofer IIS.
* All rights reserved.
*\copyright
* Copyright (c) 2023 Fraunhofer IIS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the “Software”), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#ifndef __RW_N_H__
Expand Down
1 change: 1 addition & 0 deletions package/create_rpm.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
# Copyright (c) 2023 Fraunhofer IIS

###---------------------------------------------------
# 0. change to target directory and cleanup environment
Expand Down
Loading

0 comments on commit b4f8648

Please sign in to comment.