├── src ├── lib │ ├── iotkit-comm │ │ ├── plugin-interfaces │ │ │ ├── client-interface.json │ │ │ ├── enableiot-client-interface.json │ │ │ ├── enableiot-service-interface.json │ │ │ ├── service-interface.json │ │ │ └── interface-for-interfaces.json │ │ ├── libiotkit-comm.md │ │ ├── CMakeLists.txt │ │ ├── config.json │ │ ├── util.h │ │ └── iotkit-comm_mdns.h │ ├── CMakeLists.txt │ ├── cJSON │ │ ├── tests │ │ │ ├── test2 │ │ │ ├── test1 │ │ │ ├── test3 │ │ │ ├── test5 │ │ │ └── test4 │ │ └── LICENSE │ └── plugins │ │ ├── CMakeLists.txt │ │ ├── libenableiot │ │ ├── enableiot.md │ │ ├── CMakeLists.txt │ │ ├── enableiot-service.h │ │ └── enableiot-client.h │ │ ├── libzmqpubsub │ │ ├── zmqpubsub.md │ │ ├── CMakeLists.txt │ │ ├── zmqpubsub-client.h │ │ └── zmqpubsub-service.h │ │ ├── libzmqreqrep │ │ ├── zmqreqrep.md │ │ ├── CMakeLists.txt │ │ ├── zmqreqrep-client.h │ │ └── zmqreqrep-service.h │ │ ├── libmqttpubsub │ │ ├── CMakeLists.txt │ │ ├── mqttpubsub.md │ │ ├── mqtt-client.h │ │ └── mqtt-service.h │ │ └── inc │ │ └── common.h ├── tests │ ├── libiotkit-comm │ │ ├── iotkit-comm-client-interface.json │ │ ├── invalid-iotkit-comm-service-interface.json │ │ ├── invalidtemperatureServiceQueryMQTT.json │ │ ├── temperatureServiceQueryMQTT.json │ │ ├── temperatureServiceQueryZMQPUBSUB.json │ │ ├── temperatureServiceQueryZMQPUBSUB1.json │ │ ├── invalidtemperatureServiceMQTT.json │ │ ├── invalidtemperatureServiceZMQPUBSUB.json │ │ ├── temperatureServiceMQTT.json │ │ ├── temperatureServiceZMQPUBSUB.json │ │ ├── invalidconfig.json │ │ ├── test_iotkit-comm_parseconfigfile_fail.c │ │ ├── test_iotkit-comm_parseconfigfile_success.c │ │ ├── test_iotkit-comm_loadcommplugin_fail.c │ │ ├── test_iotkit-comm_loadcommplugin_success.c │ │ ├── test_iotkit-comm_parseplugininterfaces_success.c │ │ ├── test_iotkit-comm_parseplugininterfaces_fail.c │ │ ├── test_mdns_getaddressinfo_pass.c │ │ ├── test_mdns_parse_servicedesc_fail.c │ │ ├── test_mdns_parse_servicedesc_success.c │ │ ├── test_mdns_parse_servicequery_fail.c │ │ ├── test_mdns_parse_servicequery_success.c │ │ ├── test_iotkit-comm_createclient_fail.c │ │ ├── test_iotkit-comm_createclient_success.c │ │ ├── test_iotkit-comm_createservice_fail.c │ │ ├── test_iotkit-comm_createservice_success.c │ │ ├── test_iotkit-comm_loadcomminterfaces_success.c │ │ ├── test_iotkit-comm_loadcomminterfaces_fail.c │ │ ├── test_mdns_advertiseservice_fail.c │ │ ├── test_mdns_createclientforservice_success.c │ │ ├── test_mdns_createclientforservice_fail.c │ │ ├── test_mdns_advertiseservice_success.c │ │ ├── test_mdns_discoverservice_success.c │ │ └── test_mdns_discoverservice_fail.c │ ├── CMakeLists.txt │ ├── zmqpubsub │ │ ├── test_zmqpubsub_client_subscribe_fail.c │ │ ├── test_zmqpubsub_client_unsubscribe_fail.c │ │ ├── test_zmqpubsub_service_socket_connect_fail.c │ │ ├── test_zmqpubsub_service_socket_connect_success.c │ │ ├── test_zmqpubsub_service_publish_fail.c │ │ ├── test_zmqpubsub_client_subscribe_success.c │ │ ├── test_zmqpubsub_client_socket_connect_fail.c │ │ ├── test_zmqpubsub_client_unsubscribe_success.c │ │ ├── test_zmqpubsub_client_socket_connect_success.c │ │ └── test_zmqpubsub_client_receive_fail.c │ ├── zmqreqrep │ │ ├── test_zmqreqrep_req_send_fail.c │ │ ├── test_zmqreqrep_rep_socket_connect_fail.c │ │ ├── test_zmqreqrep_rep_socket_connect_success.c │ │ ├── test_zmqreqrep_req_socket_connect_success.c │ │ ├── test_zmqreqrep_req_socket_connect_fail.c │ │ ├── test_zmqreqrep_rep_sendTo_fail.c │ │ ├── test_zmqreqrep_req_receive_fail.c │ │ ├── test_zmqreqrep_rep_receive_success.c │ │ ├── test_zmqreqrep_rep_receive_fail.c │ │ ├── test_zmqreqrep_req_send_success.c │ │ └── test_zmqreqrep_rep_sendTo_success.c │ └── mqttpubsub │ │ ├── test_mqttpubsub_client_connect_success.c │ │ ├── test_mqttpubsub_client_publish_fail.c │ │ ├── test_mqttpubsub_client_publish_success.c │ │ ├── test_mqttpubsub_client_unsubscribe_success.c │ │ ├── test_mqttpubsub_client_subscribe_fail.c │ │ ├── test_mqttpubsub_client_subscribe_success.c │ │ └── CMakeLists.txt ├── examples │ ├── serviceQueries │ │ ├── thermostat-query.json │ │ ├── temperatureServiceQueryIoTKit.json │ │ ├── temperatureServiceQueryMQTT.json │ │ ├── temperatureServiceQueryZMQPUBSUB.json │ │ ├── temperatureServiceQueryZMQREQREP.json │ │ ├── temperature-sensor-query.json │ │ └── temperatureServiceQueryEnableIot.json │ ├── serviceSpecs │ │ ├── temperatureServiceZMQPUBSUB.json │ │ ├── thermostat-spec.json │ │ ├── temperatureServiceMQTT.json │ │ ├── temperatureServiceIoTKit.json │ │ ├── temperature-sensor-spec.json │ │ ├── temperatureServiceEnableIot.json │ │ └── temperatureServiceZMQREQREP.json │ ├── CMakeLists.txt │ ├── examples.md │ ├── .project │ ├── mqtt-apps │ │ ├── CMakeLists.txt │ │ ├── publisher.c │ │ └── subscriber.c │ ├── enableiot-apps │ │ ├── CMakeLists.txt │ │ └── enableiot-publisher.c │ ├── distributed-thermostat │ │ ├── CMakeLists.txt │ │ ├── temperatureSensor.c │ │ └── dashboard.c │ └── zmq-apps │ │ ├── CMakeLists.txt │ │ ├── sample_zmqpubsub-service.c │ │ ├── sample_zmqpubsub-client.c │ │ ├── sample_zmqreqrep-service.c │ │ └── sample_zmqreqrep-client.c └── CMakeLists.txt ├── .gitignore ├── tutorials ├── supported-plugins.md ├── start-here.md ├── index.md ├── plugin.md └── client.md ├── README.md └── COPYING /src/lib/iotkit-comm/plugin-interfaces/client-interface.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": ["send", "receive", "done"] 3 | } 4 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/plugin-interfaces/enableiot-client-interface.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": ["receive", "done"] 3 | } 4 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/plugin-interfaces/enableiot-service-interface.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": ["publish", "receive", "done"] 3 | } 4 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/plugin-interfaces/service-interface.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": ["sendTo", "publish", "receive", "done"] 3 | } 4 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/plugin-interfaces/interface-for-interfaces.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": ["interface", "provides_secure_comm"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea 4 | output/ 5 | *.iml 6 | .DS_Store 7 | 8 | *.so 9 | *.out 10 | *.swp 11 | *.o 12 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/iotkit-comm-client-interface.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": ["send", "subscribe", "unsubscribe", "receive", "done"] 3 | } 4 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/invalid-iotkit-comm-service-interface.json: -------------------------------------------------------------------------------- 1 | { 2 | "function": ["sendTo", "publish", "manageClient", "receive", "done"] 3 | } 4 | -------------------------------------------------------------------------------- /src/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ADD_SUBDIRECTORY(libiotkit-comm) 3 | ADD_SUBDIRECTORY(mqttpubsub) 4 | ADD_SUBDIRECTORY(zmqpubsub) 5 | ADD_SUBDIRECTORY(zmqreqrep) 6 | -------------------------------------------------------------------------------- /src/examples/serviceQueries/thermostat-query.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "/my/home/thermostat$", 3 | "type" : { 4 | "name": "zmqpubsub", 5 | "protocol" : "tcp" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | MESSAGE("Adding the sub-directory iotkit-comm & plugins") 3 | # add the sub-directories 4 | 5 | ADD_SUBDIRECTORY(iotkit-comm) 6 | ADD_SUBDIRECTORY(plugins) 7 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/invalidtemperatureServiceQueryMQTT.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : ".*temperature.*", 3 | "type" : { 4 | "name" "mqttpubsub", 5 | "protocol" : "tcp" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/examples/serviceSpecs/temperatureServiceZMQPUBSUB.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "/ndg/temperature/cpuTemp", 3 | "type": { 4 | "name": "zmqpubsub" 5 | }, 6 | "type_params": {"mustsecure": true} 7 | } 8 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/temperatureServiceQueryMQTT.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : ".*temperature.*", 3 | "type" : { 4 | "name": "mqttpubsub", 5 | "protocol" : "tcp" 6 | }, 7 | "type_params": {"mustsecure": true} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/serviceSpecs/thermostat-spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "/my/home/thermostat", 3 | "type": { 4 | "name": "zmqpubsub", 5 | "protocol": "tcp" 6 | }, 7 | "properties": {"dataType": "float", "unit": "F"} 8 | } 9 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/temperatureServiceQueryZMQPUBSUB.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : ".*temperature.*", 3 | "type" : { 4 | "name": "zmqpubsub", 5 | "protocol" : "tcp" 6 | }, 7 | "type_params": {"mustsecure": false} 8 | } 9 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/temperatureServiceQueryZMQPUBSUB1.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : ".*temperature.*", 3 | "type" : { 4 | "name": "zmqpubsub", 5 | "protocol" : "tcp" 6 | }, 7 | "type_params": {"mustsecure": true} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/serviceSpecs/temperatureServiceMQTT.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "/INTEL/NDG/temperature", 3 | "type" : { 4 | "name": "mqttpubsub" 5 | }, 6 | "port" : 8883, 7 | "type_params": {"mustsecure": true} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/serviceQueries/temperatureServiceQueryIoTKit.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "temperature.v1.0/garage_sensor", 3 | "type" : { 4 | "name": "iotkit-agent" 5 | }, 6 | "type_params": {"deviceid": "02-00-86-4b-b6-de"} 7 | } 8 | -------------------------------------------------------------------------------- /src/examples/serviceQueries/temperatureServiceQueryMQTT.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : ".*temperature.*", 3 | "type" : { 4 | "name": "mqttpubsub", 5 | "protocol" : "tcp" 6 | }, 7 | "type_params": {"mustsecure": true} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/serviceQueries/temperatureServiceQueryZMQPUBSUB.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : ".*temperature.*", 3 | "type" : { 4 | "name": "zmqpubsub", 5 | "protocol" : "tcp" 6 | }, 7 | "type_params": {"mustsecure": true} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/serviceQueries/temperatureServiceQueryZMQREQREP.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : ".*temperature.*", 3 | "type" : { 4 | "name": "zmqreqrep", 5 | "protocol" : "tcp" 6 | }, 7 | "type_params": {"mustsecure": true} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/serviceSpecs/temperatureServiceIoTKit.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "temperature.v1.0/garage_sensor", 3 | "type" : { 4 | "name": "iotkit-agent" 5 | }, 6 | "port" : 1884, 7 | "type_params": {"mustsecure": false} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/serviceQueries/temperature-sensor-query.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : ".*thermostat/sensor", 3 | "type" : { 4 | "name": "zmqpubsub", 5 | "protocol" : "tcp" 6 | }, 7 | "properties": {"dataType": "float", "sensorType": "ambient"} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | MESSAGE("Adding the sub-directory of sample apps") 3 | # add the sub-directories 4 | ADD_SUBDIRECTORY(distributed-thermostat) 5 | ADD_SUBDIRECTORY(enableiot-apps) 6 | ADD_SUBDIRECTORY(mqtt-apps) 7 | ADD_SUBDIRECTORY(zmq-apps) 8 | -------------------------------------------------------------------------------- /src/examples/serviceSpecs/temperature-sensor-spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "/my/home/thermostat/sensor", 3 | "type": { 4 | "name": "zmqpubsub", 5 | "protocol": "tcp" 6 | }, 7 | "properties": {"dataType": "float", "unit": "F", "sensorType": "ambient"} 8 | } 9 | -------------------------------------------------------------------------------- /src/examples/serviceSpecs/temperatureServiceEnableIot.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "temperature.v1.0/garage_sensor", 3 | "type" : { 4 | "name": "enableiot" 5 | }, 6 | "port": 34562, 7 | "type_params": {"deviceid":"02-00-86-4b-b6-de", "activationCode":"2sdf34sfeE"} 8 | } 9 | -------------------------------------------------------------------------------- /src/lib/cJSON/tests/test2: -------------------------------------------------------------------------------- 1 | {"menu": { 2 | "id": "file", 3 | "value": "File", 4 | "popup": { 5 | "menuitem": [ 6 | {"value": "New", "onclick": "CreateNewDoc()"}, 7 | {"value": "Open", "onclick": "OpenDoc()"}, 8 | {"value": "Close", "onclick": "CloseDoc()"} 9 | ] 10 | } 11 | }} 12 | -------------------------------------------------------------------------------- /src/examples/serviceQueries/temperatureServiceQueryEnableIot.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "temperature.v1.0/garage_sensor", 3 | "type" : { 4 | "name": "enableiot" 5 | }, 6 | "type_params": {"deviceid": "02-00-86-81-77-00", "activationCode":"2sdf34sfeE", "subscribeto": "02-00-86-4b-b6-de", "frequencyInterval": 5} 7 | } 8 | -------------------------------------------------------------------------------- /src/lib/plugins/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | MESSAGE("Adding all the plugins directories") 3 | # add the sub-directories 4 | 5 | ADD_SUBDIRECTORY(libenableiot) 6 | ADD_SUBDIRECTORY(libmqttpubsub) 7 | ADD_SUBDIRECTORY(libzmqpubsub) 8 | ADD_SUBDIRECTORY(libzmqreqrep) 9 | 10 | # set the compiler flags 11 | SET(CMAKE_C_FLAGS "-c -fPIC") 12 | -------------------------------------------------------------------------------- /src/examples/serviceSpecs/temperatureServiceZMQREQREP.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "/ndg/temperature/cpuTemp", 3 | "type": { 4 | "name": "zmqreqrep", 5 | "protocol": "tcp" 6 | }, 7 | "properties": { 8 | "dataType": "float", 9 | "unit": "F" 10 | }, 11 | "type_params": {"mustsecure": true } 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/invalidtemperatureServiceMQTT.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" "/INTEL/NDG/temperature" 3 | "type" { 4 | "name": "mqttpubsub", 5 | "protocol" : "tcp" 6 | }, 7 | "port" : 1883, 8 | "properties" : {"dataType": "float"}, 9 | "comm_params": {"ssl": false}, 10 | "advertise": {"locally": true, "cloud": false} 11 | } 12 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/invalidtemperatureServiceZMQPUBSUB.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "/ndg/temperature/cpuTemp", 3 | "type": { 4 | "name": "._zmqpubsub", 5 | "protocol": "" 6 | }, 7 | "address" : "127", 8 | "port": 0, 9 | "properties": {"dataType": "float", "unit": "F"}, 10 | "advertise": {"locally": true, "cloud": false} 11 | } 12 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/temperatureServiceMQTT.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "/INTEL/NDG/temperature", 3 | "type" : { 4 | "name": "mqttpubsub", 5 | "protocol" : "tcp" 6 | }, 7 | "port" : 8883, 8 | "properties" : {"dataType": "float"}, 9 | "comm_params": {"ssl": false}, 10 | "advertise": {"locally": true, "cloud": false}, 11 | "type_params": {"mustsecure": true} 12 | } 13 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/temperatureServiceZMQPUBSUB.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "/ndg/temperature/cpuTemp", 3 | "type": { 4 | "name": "zmqpubsub", 5 | "protocol": "tcp" 6 | }, 7 | "address" : "127.0.0.1", 8 | "port": 1884, 9 | "properties": {"dataType": "float", "unit": "F"}, 10 | "advertise": {"locally": true, "cloud": false}, 11 | "type_params": {"mustsecure": true} 12 | } 13 | -------------------------------------------------------------------------------- /tutorials/supported-plugins.md: -------------------------------------------------------------------------------- 1 | 2 | At the moment, iotkit-comm supports only few communication plugins. The following communication plugins are supported: 3 | 4 | a) mqtt
5 | b) zmqpubsub
6 | c) zmqreqrep
7 | d) enableiot (for publishing, subscribing and to perform other activities with Intel's enableiot cloud)
8 | 9 | Learn more
10 |    • Get an overview of [communication plugins](@ref plugin.md) 11 | -------------------------------------------------------------------------------- /src/examples/examples.md: -------------------------------------------------------------------------------- 1 | Examples are useful to learn something very fast. Here you will find the sample apps for various plugins 2 | such as IotKit, Mqtt, and ZeroMQ, where each will demonstrate in a simple manner. 3 | 4 | Documentation 5 | 6 | [enableiot](@ref enableiot-apps/iotkit-publisher.c)
7 | [iotkit](@ref enableiot-apps/iotkit-publisher.c)
8 | [mqtt](@ref mqtt-apps/publisher.c)
9 | [zeromq](@ref zmq-apps/sample_zmqpubsub-client.c)
10 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/libiotkit-comm.md: -------------------------------------------------------------------------------- 1 | The iotkit-comm allows one to discover and communicate with others. 2 | Additionally, iotkit-comm allows an application to conveniently publish its data to the cloud. The iotkit-comm is a library that comes in 3 | two flavors: C and NodeJS. 4 | 5 | This documentation focuses on the C version of the library. 6 | 7 | API Documentation 8 | 9 | [iotkit-comm](@ref iotkit-comm.c)
10 | [iotkit-comm-mdns](@ref iotkit-comm_mdns.c)
11 | -------------------------------------------------------------------------------- /src/lib/plugins/libenableiot/enableiot.md: -------------------------------------------------------------------------------- 1 | The enableiot plugin abstracts complexities of cloud connectivity. It allows developers to focus on application development 2 | and logic for their devices (sensors, actuators, and tags). enableiot plugin transparently implements the necessary message 3 | format and security during both the device registration and data submission. 4 | 5 | This documentation focuses on the Client side implementation of enableiot plugin. 6 | 7 | API Documentation 8 | 9 | [enableiot-client](@ref enableiot-client.c)
10 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | MESSAGE("Building the IoT communication Library") 3 | 4 | INCLUDE_DIRECTORIES( 5 | ../cJSON 6 | ) 7 | 8 | # Set the shared library name 9 | SET(IOTKIT_COMM_LIBRARY_NAME "iotkit-comm") 10 | 11 | # Create the shared library 12 | ADD_LIBRARY(${IOTKIT_COMM_LIBRARY_NAME} SHARED iotkit-comm.c iotkit-comm_mdns.c ../cJSON/cJSON.c) 13 | 14 | SET_TARGET_PROPERTIES(${IOTKIT_COMM_LIBRARY_NAME} PROPERTIES LINKER_LANGUAGE C) 15 | 16 | # Link the shared library 17 | TARGET_LINK_LIBRARIES(${IOTKIT_COMM_LIBRARY_NAME} paho-mqtt3as) 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DISCONTINUATION OF PROJECT # 2 | This project will no longer be maintained by Intel. 3 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 4 | Intel no longer accepts patches to this project. 5 | # iotkit-comm-c 6 | 7 | Iotkit-comm-c is a c/c++ library that allows network-connected devices to conveniently discover and communicate with each other and the cloud. 8 | 9 | ## EOL 10 | 11 | The iotkit-comm-c library has been EOL'ed. This github repo will remain available for historical build purposes. 12 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/invalidconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "pluginInterfaceDir": "plugin-interfaces", 3 | "pluginDir": "plugins", 4 | "superInterfaceName": "interface-for-interfaces", 5 | "serviceDir": "serviceSpecs", 6 | "communication": { 7 | "pluginFileSuffixes": { 8 | "clientFileSuffix": "client" 9 | "serverFileSuffix": "service" 10 | }, 11 | "plugins": 12 | [ 13 | {"pluginName": "zmqpubsub"}, 14 | {"pluginName": "mqtt"}, 15 | {"pluginName": "zmqreqrep"} 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/lib/plugins/libzmqpubsub/zmqpubsub.md: -------------------------------------------------------------------------------- 1 | ZeroMQ is a high-performance asynchronous messaging library aimed at use in scalable distributed or concurrent applications. 2 | It provides a message queue, but unlike message-oriented middleware, a ZeroMQ system can run without a dedicated message broker. 3 | The library is designed to have a familiar socket-style API. 4 | 5 | ZeroMQ publish/subscribe pattern connects a set of publishers to a set of subscribers. This is a data distribution pattern. 6 | 7 | API Documentation 8 | 9 | [zeromq-subscriber-client](@ref zmqpubsub-client.c)
10 | [zeromq-publisher-service](@ref zmqpubsub-service.c)
11 | -------------------------------------------------------------------------------- /src/lib/plugins/libzmqreqrep/zmqreqrep.md: -------------------------------------------------------------------------------- 1 | ZeroMQ is a high-performance asynchronous messaging library aimed at use in scalable, distributed, or concurrent applications. 2 | It provides a message queue, but unlike message-oriented middleware, a ZeroMQ system can run without a dedicated message broker. 3 | The library is designed to have a familiar socket-style API. 4 | 5 | ZeroMQ pattern request-reply which connects a set of clients to a set of services. This is a remote procedure call and 6 | task distribution pattern. 7 | 8 | API Documentation 9 | 10 | [zeromq-request-client](@ref zmqreqrep-client.c)
11 | [zeromq-reply-service](@ref zmqreqrep-service.c)
12 | -------------------------------------------------------------------------------- /src/lib/cJSON/tests/test1: -------------------------------------------------------------------------------- 1 | { 2 | "glossary": { 3 | "title": "example glossary", 4 | "GlossDiv": { 5 | "title": "S", 6 | "GlossList": { 7 | "GlossEntry": { 8 | "ID": "SGML", 9 | "SortAs": "SGML", 10 | "GlossTerm": "Standard Generalized Markup Language", 11 | "Acronym": "SGML", 12 | "Abbrev": "ISO 8879:1986", 13 | "GlossDef": { 14 | "para": "A meta-markup language, used to create markup languages such as DocBook.", 15 | "GlossSeeAlso": ["GML", "XML"] 16 | }, 17 | "GlossSee": "markup" 18 | } 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/lib/cJSON/tests/test3: -------------------------------------------------------------------------------- 1 | {"widget": { 2 | "debug": "on", 3 | "window": { 4 | "title": "Sample Konfabulator Widget", 5 | "name": "main_window", 6 | "width": 500, 7 | "height": 500 8 | }, 9 | "image": { 10 | "src": "Images/Sun.png", 11 | "name": "sun1", 12 | "hOffset": 250, 13 | "vOffset": 250, 14 | "alignment": "center" 15 | }, 16 | "text": { 17 | "data": "Click Here", 18 | "size": 36, 19 | "style": "bold", 20 | "name": "text1", 21 | "hOffset": 250, 22 | "vOffset": 100, 23 | "alignment": "center", 24 | "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" 25 | } 26 | }} -------------------------------------------------------------------------------- /src/lib/plugins/libmqttpubsub/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | MESSAGE("Building the mqtt plugin") 3 | 4 | INCLUDE_DIRECTORIES( 5 | ../../iotkit-comm 6 | ../inc/ 7 | ) 8 | 9 | # set the shared library name 10 | SET(MQTT_CLIENT_NAME "mqttpubsub-client") 11 | SET(MQTT_SERVICE_NAME "mqttpubsub-service") 12 | 13 | # create the shared library 14 | ADD_LIBRARY(${MQTT_CLIENT_NAME} SHARED mqtt-client.c mqtt-client.h) 15 | ADD_LIBRARY(${MQTT_SERVICE_NAME} SHARED mqtt-service.c mqtt-service.h) 16 | 17 | SET_TARGET_PROPERTIES(${MQTT_CLIENT_NAME} PROPERTIES LINKER_LANGUAGE C) 18 | SET_TARGET_PROPERTIES(${MQTT_SERVICE_NAME} PROPERTIES LINKER_LANGUAGE C) 19 | 20 | # Link the shared library 21 | TARGET_LINK_LIBRARIES(${MQTT_CLIENT_NAME} paho-mqtt3cs) 22 | TARGET_LINK_LIBRARIES(${MQTT_SERVICE_NAME} paho-mqtt3cs) 23 | -------------------------------------------------------------------------------- /src/lib/plugins/libmqttpubsub/mqttpubsub.md: -------------------------------------------------------------------------------- 1 | MQTT stands for MQ Telemetry Transport. It is a publish/subscribe extremely simple and lightweight messaging protocol 2 | designed for constrained devices and low-bandwidth, high-latency, or unreliable networks. The design principles are to 3 | minimize network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree 4 | of assurance of delivery. These principles make the protocol ideal of the emerging “machine-to-machine” (M2M) 5 | or “Internet of Things” world of connected devices, and for mobile applications, where bandwidth and battery power are at a premium. 6 | 7 | This documentation is about asynchronous implementation of MQTT pattern publish-subscribe. 8 | 9 | API Documentation 10 | 11 | [mqtt-client](@ref mqtt-client.c)
12 | -------------------------------------------------------------------------------- /src/lib/plugins/libzmqpubsub/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | MESSAGE("Building the zmq pubsub plugin") 3 | 4 | INCLUDE_DIRECTORIES( 5 | ../../iotkit-comm 6 | ../inc/ 7 | ) 8 | 9 | # set the shared library name 10 | SET(ZMQ_PUBSUB_CLIENT_NAME "zmqpubsub-client") 11 | SET(ZMQ_PUBSUB_SERVICE_NAME "zmqpubsub-service") 12 | 13 | # create the shared library 14 | ADD_LIBRARY(${ZMQ_PUBSUB_CLIENT_NAME} SHARED zmqpubsub-client.c zmqpubsub-client.h) 15 | ADD_LIBRARY(${ZMQ_PUBSUB_SERVICE_NAME} SHARED zmqpubsub-service.c zmqpubsub-service.h) 16 | 17 | SET_TARGET_PROPERTIES(${ZMQ_PUBSUB_CLIENT_NAME} PROPERTIES LINKER_LANGUAGE C) 18 | SET_TARGET_PROPERTIES(${ZMQ_PUBSUB_SERVICE_NAME} PROPERTIES LINKER_LANGUAGE C) 19 | 20 | # Link the shared library 21 | TARGET_LINK_LIBRARIES(${ZMQ_PUBSUB_CLIENT_NAME} zmq) 22 | TARGET_LINK_LIBRARIES(${ZMQ_PUBSUB_SERVICE_NAME} zmq) 23 | -------------------------------------------------------------------------------- /src/lib/plugins/libzmqreqrep/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | MESSAGE("Building the zmq reqrep plugin") 3 | 4 | INCLUDE_DIRECTORIES( 5 | ../../iotkit-comm 6 | ../inc/ 7 | ) 8 | 9 | # set the shared library name 10 | SET(ZMQ_REQREP_CLIENT_NAME "zmqreqrep-client") 11 | SET(ZMQ_REQREP_SERVICE_NAME "zmqreqrep-service") 12 | 13 | # create the shared library 14 | ADD_LIBRARY(${ZMQ_REQREP_CLIENT_NAME} SHARED zmqreqrep-client.c zmqreqrep-client.h) 15 | ADD_LIBRARY(${ZMQ_REQREP_SERVICE_NAME} SHARED zmqreqrep-service.c zmqreqrep-service.h) 16 | 17 | SET_TARGET_PROPERTIES(${ZMQ_REQREP_CLIENT_NAME} PROPERTIES LINKER_LANGUAGE C) 18 | SET_TARGET_PROPERTIES(${ZMQ_REQREP_SERVICE_NAME} PROPERTIES LINKER_LANGUAGE C) 19 | 20 | # Link the shared library 21 | TARGET_LINK_LIBRARIES(${ZMQ_REQREP_CLIENT_NAME} zmq) 22 | TARGET_LINK_LIBRARIES(${ZMQ_REQREP_SERVICE_NAME} zmq) 23 | -------------------------------------------------------------------------------- /src/examples/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | broker-discovery 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/lib/plugins/libenableiot/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | MESSAGE("Building the enableiot plugin") 3 | 4 | INCLUDE_DIRECTORIES( 5 | ../../iotkit-comm 6 | ../inc/ 7 | ../../cJSON 8 | ) 9 | 10 | # set the shared library name 11 | SET(ENABLEIOT_CLIENT_NAME "enableiot-client") 12 | SET(ENABLEIOT_SERVICE_NAME "enableiot-service") 13 | 14 | # create the shared library 15 | ADD_LIBRARY(${ENABLEIOT_CLIENT_NAME} SHARED enableiot-client.c enableiot-client.h) 16 | ADD_LIBRARY(${ENABLEIOT_SERVICE_NAME} SHARED enableiot-service.c enableiot-service.h) 17 | 18 | SET_TARGET_PROPERTIES(${ENABLEIOT_CLIENT_NAME} PROPERTIES LINKER_LANGUAGE C) 19 | SET_TARGET_PROPERTIES(${ENABLEIOT_SERVICE_NAME} PROPERTIES LINKER_LANGUAGE C) 20 | 21 | # Link the shared library 22 | TARGET_LINK_LIBRARIES(${ENABLEIOT_CLIENT_NAME} iotkit curl paho-mqtt3as) 23 | TARGET_LINK_LIBRARIES(${ENABLEIOT_SERVICE_NAME} iotkit curl paho-mqtt3as) 24 | -------------------------------------------------------------------------------- /src/examples/mqtt-apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | INCLUDE_DIRECTORIES( 3 | ../../lib/cJSON 4 | ../../lib 5 | ) 6 | 7 | # set the executable names 8 | SET(MQTT_CLIENT_NAME "subscriber") 9 | SET(MQTT_SERVICE_NAME "publisher") 10 | 11 | SET(CLIENT_LIST subscriber.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 12 | SET(SERVICE_LIST publisher.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 13 | 14 | ADD_EXECUTABLE(${MQTT_CLIENT_NAME} ${CLIENT_LIST}) 15 | ADD_EXECUTABLE(${MQTT_SERVICE_NAME} ${SERVICE_LIST}) 16 | 17 | SET_TARGET_PROPERTIES(${MQTT_CLIENT_NAME} PROPERTIES LINKER_LANGUAGE C) 18 | SET_TARGET_PROPERTIES(${MQTT_SERVICE_NAME} PROPERTIES LINKER_LANGUAGE C) 19 | 20 | # Link the shared library 21 | TARGET_LINK_LIBRARIES(${MQTT_CLIENT_NAME} paho-mqtt3as pthread dns_sd m dl) 22 | TARGET_LINK_LIBRARIES(${MQTT_SERVICE_NAME} paho-mqtt3as pthread dns_sd m dl) 23 | -------------------------------------------------------------------------------- /src/lib/cJSON/tests/test5: -------------------------------------------------------------------------------- 1 | {"menu": { 2 | "header": "SVG Viewer", 3 | "items": [ 4 | {"id": "Open"}, 5 | {"id": "OpenNew", "label": "Open New"}, 6 | null, 7 | {"id": "ZoomIn", "label": "Zoom In"}, 8 | {"id": "ZoomOut", "label": "Zoom Out"}, 9 | {"id": "OriginalView", "label": "Original View"}, 10 | null, 11 | {"id": "Quality"}, 12 | {"id": "Pause"}, 13 | {"id": "Mute"}, 14 | null, 15 | {"id": "Find", "label": "Find..."}, 16 | {"id": "FindAgain", "label": "Find Again"}, 17 | {"id": "Copy"}, 18 | {"id": "CopyAgain", "label": "Copy Again"}, 19 | {"id": "CopySVG", "label": "Copy SVG"}, 20 | {"id": "ViewSVG", "label": "View SVG"}, 21 | {"id": "ViewSource", "label": "View Source"}, 22 | {"id": "SaveAs", "label": "Save As"}, 23 | null, 24 | {"id": "Help"}, 25 | {"id": "About", "label": "About Adobe CVG Viewer..."} 26 | ] 27 | }} 28 | -------------------------------------------------------------------------------- /src/examples/enableiot-apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | INCLUDE_DIRECTORIES( 3 | ../../lib/cJSON 4 | ../../lib 5 | ) 6 | 7 | # set the executable names 8 | SET(ENABLEIOT_CLIENT_NAME "enableiotclient") 9 | SET(ENABLEIOT_SERVICE_NAME "enableiotservice") 10 | 11 | SET(CLIENT_LIST2 enableiot-subscriber.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 12 | SET(SERVICE_LIST2 enableiot-publisher.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 13 | 14 | ADD_EXECUTABLE(${ENABLEIOT_CLIENT_NAME} ${CLIENT_LIST2}) 15 | ADD_EXECUTABLE(${ENABLEIOT_SERVICE_NAME} ${SERVICE_LIST2}) 16 | 17 | SET_TARGET_PROPERTIES(${ENABLEIOT_CLIENT_NAME} PROPERTIES LINKER_LANGUAGE C) 18 | SET_TARGET_PROPERTIES(${ENABLEIOT_SERVICE_NAME} PROPERTIES LINKER_LANGUAGE C) 19 | 20 | # Link the shared library 21 | TARGET_LINK_LIBRARIES(${ENABLEIOT_CLIENT_NAME} curl pthread dns_sd m dl) 22 | TARGET_LINK_LIBRARIES(${ENABLEIOT_SERVICE_NAME} curl pthread dns_sd m dl) 23 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "pluginInterfaceDir": "plugin-interfaces", 3 | "pluginDir": "plugins", 4 | "superInterfaceName": "interface-for-interfaces", 5 | "serviceDir": "serviceSpecs", 6 | "communication": { 7 | "pluginFileSuffixes": { 8 | "clientFileSuffix": "client", 9 | "serverFileSuffix": "service" 10 | } 11 | }, 12 | "unusedPortDetectAttempts": 3, 13 | "stateDirName": "iotkit-comm", 14 | "stateMapName": "state.json", 15 | "localaddr": "127.0.0.1", 16 | "port_min": 1025, 17 | "port_max": 65535, 18 | "auth": { 19 | "keyDirSuffix": "_credentials", 20 | "keyDirName": "iotkit-comm", 21 | "CAName": "myca", 22 | "privateKeyNameSuffix": "_key", 23 | "hostKeyNameSuffix": "_host", 24 | "clientKeyNameSuffix": "_client", 25 | "SSLCertSuffix": ".crt", 26 | "SSLCertReqSuffix": ".csr", 27 | "SSHPubKeySuffix": ".pub", 28 | "defaultUser": "root", 29 | "SSHCertSuffix": "-cert" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright © 2014 Intel Corporation 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake settings 2 | 3 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0) 4 | 5 | # About this project 6 | PROJECT(IOTKIT-COMM-C-Library) 7 | 8 | MESSAGE("Building the root source C Folder") 9 | 10 | SET(CMAKE_BUILD_TYPE "Coverage") 11 | 12 | MESSAGE("Building the root source C Folder") 13 | 14 | # support for adding tests, adds another build target 'test' 15 | ENABLE_TESTING() 16 | 17 | # Adds some testing specific build targets e.g. make Experimental 18 | INCLUDE(CTest) 19 | 20 | SET(CMAKE_CXX_FLAGS_COVERAGE "-g -O0 -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual -Wwrite-strings -fprofile-arcs -ftest-coverage") 21 | 22 | SET(CMAKE_C_FLAGS_COVERAGE "-g -O0 -Wall -W -fprofile-arcs -ftest-coverage") 23 | 24 | SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE "-fprofile-arcs -ftest-coverage") 25 | 26 | # add the sub-directories 27 | ADD_SUBDIRECTORY(lib) 28 | ADD_SUBDIRECTORY(examples) 29 | ADD_SUBDIRECTORY(tests) 30 | 31 | SET (CTEST_BINARY_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/output/bin" ) 32 | MESSAGE (STATUS "Ctest Binary Directory set to: ${CTEST_BINARY_DIRECTORY}") 33 | -------------------------------------------------------------------------------- /src/lib/cJSON/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 Dave Gamble 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /src/examples/distributed-thermostat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | INCLUDE_DIRECTORIES( 3 | ../../lib/cJSON 4 | ../../lib 5 | ) 6 | 7 | # set the executable names 8 | SET(DASHBOARD dashboard) 9 | SET(SENSOR sensor) 10 | SET(THERMOSTAT thermostat) 11 | 12 | # set the source files list 13 | SET(DASHBOARD_LIST dashboard.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 14 | SET(SENSOR_LIST temperatureSensor.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 15 | SET(THERMOSTAT_LIST thermostat.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 16 | 17 | # create the executables 18 | ADD_EXECUTABLE(${DASHBOARD} ${DASHBOARD_LIST}) 19 | ADD_EXECUTABLE(${SENSOR} ${SENSOR_LIST}) 20 | ADD_EXECUTABLE(${THERMOSTAT} ${THERMOSTAT_LIST}) 21 | 22 | SET_TARGET_PROPERTIES(${DASHBOARD} PROPERTIES LINKER_LANGUAGE C) 23 | SET_TARGET_PROPERTIES(${SENSOR} PROPERTIES LINKER_LANGUAGE C) 24 | SET_TARGET_PROPERTIES(${THERMOSTAT} PROPERTIES LINKER_LANGUAGE C) 25 | 26 | # Link the executables 27 | TARGET_LINK_LIBRARIES(${DASHBOARD} zmq dns_sd m dl) 28 | TARGET_LINK_LIBRARIES(${SENSOR} zmq dns_sd m dl) 29 | TARGET_LINK_LIBRARIES(${THERMOSTAT} zmq dns_sd m dl) 30 | -------------------------------------------------------------------------------- /src/lib/plugins/inc/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | typedef struct _Context { 25 | char *name; 26 | char *value; 27 | } Context; 28 | -------------------------------------------------------------------------------- /tutorials/start-here.md: -------------------------------------------------------------------------------- 1 | To start working with the iotkit-comm library, you will need to: 2 | 3 | 1. Install it 4 | 2. Run a sample program (optional) 5 | 3. Learn more (optional) 6 | 7 | Install it 8 | 9 | No installation is reequired on the Intel® Edison device (support for other platforms coming soon). 10 | 11 | Run a sample program 12 | 13 | On the device, iotkit-comm sample programs can be found in /usr/share/iotkit-comm/examples/c. Here is how you run the 14 | distributed thermostat sample application included in the iotkit-comm sources: 15 | 16 | $ cd /usr/share/iotkit-comm/examples/c
17 | $ ./sensor
18 | Then, in another terminal: 19 | 20 | $ cd /usr/share/iotkit-comm/examples/c
21 | $ ./thermostat
22 | In the thermostat terminal, you will see output 23 | 24 | You can run multiple instances of './sensor'; the thermostat will find those sensors and include their temperature data in the mean. 25 | 26 | 27 | Learn More 28 | 29 | •  Write a [service](@ref service.md)
30 | •  Write a [client](@ref client.md)
31 | •  Understand [service specifications and queries] (@ref service-spec-query.md) (important)
32 | •  Learn to write a [distributed application](@ref application.md) using iotkit-comm
33 | •  Learn to publish data to the [cloud](@ref cloud.md) and subscribe to it
34 | •  Study the unit tests included in the iotkit-comm sources (coming soon)
35 | •  Understand the iotkit-comm architecture (coming soon)
36 | -------------------------------------------------------------------------------- /tutorials/index.md: -------------------------------------------------------------------------------- 1 | 2 | [Start Here](@ref start-here.md) to begin developing applications and plugins that use iotkit-comm connectivity library. Otherwise, continue 3 | reading to learn more. 4 | 5 | iotkit-comm allows network-connected devices to conveniently discover and communicate with each other and the cloud. More specifically, 6 | iotkit-comm library enables developers to write distributed applications composed of clients and servers. 7 | This library was designed primarily for Intel® Edison platform, but works well on other platforms too. iotkit-comm 8 | comes in two flavors: C and node.js. This documentation focuses on the C version of the library. 9 | 10 | How to read this documentation 11 | 12 |   • For tutorials on how to use the API, the entry point is the 'Tutorials' section (we suggest starting with the ['Start Here'](@ref start-here.md) tutorial).
13 | 14 |   • For browsing the library and plugins:
15 | 16 |    1) iotkit-comm
17 |    2) enableiot
18 |    3) mqttpubsub
19 |    4) zmqpubsub
20 |    5) zmqreqrep

21 | 22 | Note: For the purposes of this documentation, a module is a logical grouping of functions and variables. Please be aware 23 | that this is the logical structure of the documentation only and not iotkit-comm codebase. 24 | 25 | Prerequisites
26 | 27 | This document assumes that:
28 | 29 | 1. Your Edison has Internet connectivity
30 | 2. The included sample programs and commands are run on Edison
31 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_client_subscribe_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_client_subscribe_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | int result = subscribe("service"); 35 | if (result == 0) { 36 | puts("Subscribed Successfully"); 37 | exit(EXIT_FAILURE); 38 | } else { 39 | puts("Failed: Subscription"); 40 | exit(EXIT_SUCCESS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_client_unsubscribe_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_client_unsubscribe_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | int result = unsubscribe("service"); 35 | if (result == 0) { 36 | puts("UnSubscribed Successfully"); 37 | exit(EXIT_FAILURE); 38 | } else { 39 | puts("Failed: UnSubscription"); 40 | exit(EXIT_SUCCESS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_parseconfigfile_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_parseconfigfile_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | if (parseConfigFile("./libiotkit-comm/invalidconfig.json")) { 35 | puts("Success: Parsed Config File"); 36 | exit(EXIT_FAILURE); 37 | } else { 38 | puts("Failed: Parsing Config File"); 39 | exit(EXIT_SUCCESS); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_parseconfigfile_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_parseconfigfile_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | if (parseConfigFile("/etc/iotkit-comm/config.json")) { 35 | puts("Success: Parsed Config File"); 36 | exit(EXIT_SUCCESS); 37 | } else { 38 | puts("Failed: Parsing Config File"); 39 | exit(EXIT_FAILURE); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_loadcommplugin_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_loadcommplugin_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | CommHandle *plugin = loadCommPlugin("/usr/lib/libpubsub-client.so"); 35 | if (plugin) { 36 | puts("Success: Plugin Loaded"); 37 | exit(EXIT_FAILURE); 38 | } else { 39 | puts("Failed: Plugin Load"); 40 | exit(EXIT_SUCCESS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_loadcommplugin_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_loadcommplugin_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | CommHandle *plugin = loadCommPlugin("/usr/lib/libzmqpubsub-client.so"); 35 | if (plugin) { 36 | puts("Success: Plugin Loaded"); 37 | exit(EXIT_SUCCESS); 38 | } else { 39 | puts("Failed: Plugin Load"); 40 | exit(EXIT_FAILURE); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_parseplugininterfaces_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_parseplugininterfaces_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | if (parsePluginInterfaces("./iotkit-comm-client-interface.json")) { 35 | puts("Success: Parsed Config File"); 36 | exit(EXIT_SUCCESS); 37 | } else { 38 | puts("Failed: Parsing Config File"); 39 | exit(EXIT_FAILURE); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_parseplugininterfaces_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_parseplugininterfaces_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | if (parsePluginInterfaces("./invalid-iotkit-comm-service-interface.json")) { 35 | puts("Success: Parsed Config File"); 36 | exit(EXIT_FAILURE); 37 | } else { 38 | puts("Failed: Parsing Config File"); 39 | exit(EXIT_SUCCESS); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_getaddressinfo_pass.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_getaddressinfo_pass.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | char *ipaddress = getIPAddressFromHostName("localhost","1080"); 35 | if (ipaddress != NULL) { 36 | printf("Success: IPAddress is %s\n",ipaddress); 37 | exit(EXIT_SUCCESS); 38 | } else { 39 | puts("Failure: Retrieving IPAddress Failed"); 40 | exit(EXIT_FAILURE); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_parse_servicedesc_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_parse_servicedesc_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | char *filepath = "./invalidtemperatureServiceMQTT.json"; 35 | if (parseServiceSpec(filepath) != NULL) { 36 | puts("Success: Parse Service Specification"); 37 | exit(EXIT_FAILURE); 38 | } else { 39 | puts("Failure: Parse Service Specification"); 40 | exit(EXIT_SUCCESS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_parse_servicedesc_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_parse_servicedesc_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | char *filepath = "./temperatureServiceMQTT.json"; 35 | if (parseServiceSpec(filepath) != NULL) { 36 | puts("Success: Parse Service Specification"); 37 | exit(EXIT_SUCCESS); 38 | } else { 39 | puts("Failure: Parse Service Specification"); 40 | exit(EXIT_FAILURE); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_parse_servicequery_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_parse_servicequery_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | char *filepath = "./invalidtemperatureServiceQueryMQTT.json"; 35 | if (parseServiceQuery(filepath) != NULL) { 36 | puts("Success: Parse Client Service Query"); 37 | exit(EXIT_FAILURE); 38 | } else { 39 | puts("Failure: Parse Client Service Query"); 40 | exit(EXIT_SUCCESS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_parse_servicequery_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_parse_servicequery_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | char *filepath = "./temperatureServiceQueryMQTT.json"; 35 | if (parseServiceQuery(filepath) != NULL) { 36 | puts("Success: Parse Client Service Query"); 37 | exit(EXIT_SUCCESS); 38 | } else { 39 | puts("Failure: Parse Client Service Query"); 40 | exit(EXIT_FAILURE); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_createclient_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_createclient_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceQuery *query = (ServiceQuery *) parseServiceQuery("./invalidtemperatureServiceZMQPUBSUB.json"); 35 | if (query && createClient(query)) { 36 | puts("Success: Created Client"); 37 | exit(EXIT_FAILURE); 38 | } else { 39 | puts("Failed: Create Client"); 40 | exit(EXIT_SUCCESS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/examples/zmq-apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | INCLUDE_DIRECTORIES( 3 | ../../lib/cJSON 4 | ../../lib 5 | ) 6 | 7 | # set the executable names 8 | SET(ZMQ_SUB_CLIENT zmqsubclient) 9 | SET(ZMQ_PUB_SERVICE zmqpubservice) 10 | SET(ZMQ_REQ_CLIENT zmqreqclient) 11 | SET(ZMQ_REP_SERVICE zmqrepservice) 12 | 13 | # set the source files list 14 | SET(SUB_CLIENT_LIST sample_zmqpubsub-client.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 15 | SET(PUB_SERVICE_LIST sample_zmqpubsub-service.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 16 | SET(REQ_CLIENT_LIST sample_zmqreqrep-client.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 17 | SET(REP_SERVICE_LIST sample_zmqreqrep-service.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 18 | 19 | # create the executables 20 | ADD_EXECUTABLE(${ZMQ_SUB_CLIENT} ${SUB_CLIENT_LIST}) 21 | ADD_EXECUTABLE(${ZMQ_PUB_SERVICE} ${PUB_SERVICE_LIST}) 22 | ADD_EXECUTABLE(${ZMQ_REQ_CLIENT} ${REQ_CLIENT_LIST}) 23 | ADD_EXECUTABLE(${ZMQ_REP_SERVICE} ${REP_SERVICE_LIST}) 24 | 25 | SET_TARGET_PROPERTIES(${ZMQ_SUB_CLIENT} PROPERTIES LINKER_LANGUAGE C) 26 | SET_TARGET_PROPERTIES(${ZMQ_PUB_SERVICE} PROPERTIES LINKER_LANGUAGE C) 27 | SET_TARGET_PROPERTIES(${ZMQ_REQ_CLIENT} PROPERTIES LINKER_LANGUAGE C) 28 | SET_TARGET_PROPERTIES(${ZMQ_REP_SERVICE} PROPERTIES LINKER_LANGUAGE C) 29 | 30 | # Link the executables 31 | TARGET_LINK_LIBRARIES(${ZMQ_SUB_CLIENT} zmq pthread dns_sd m dl) 32 | TARGET_LINK_LIBRARIES(${ZMQ_PUB_SERVICE} zmq pthread dns_sd m dl) 33 | TARGET_LINK_LIBRARIES(${ZMQ_REQ_CLIENT} zmq pthread dns_sd m dl) 34 | TARGET_LINK_LIBRARIES(${ZMQ_REP_SERVICE} zmq pthread dns_sd m dl) 35 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_createclient_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_createclient_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceQuery *query = (ServiceQuery *) parseServiceQuery("./temperatureServiceQueryZMQPUBSUB.json"); 35 | if (query && createClient(query)) { 36 | puts("Success: Created Client"); 37 | exit(EXIT_SUCCESS); 38 | } else { 39 | puts("Failed: Create Client"); 40 | exit(EXIT_FAILURE); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_createservice_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_createservice_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./invalidtemperatureServiceZMQPUBSUB.json"); 35 | if (serviceSpec && createService(NULL, serviceSpec)) { 36 | puts("Success: Created Service"); 37 | exit(EXIT_FAILURE); 38 | } else { 39 | puts("Failed: Create Service"); 40 | exit(EXIT_SUCCESS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_createservice_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_createservice_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./temperatureServiceZMQPUBSUB.json"); 35 | if (serviceSpec && createService(NULL, serviceSpec)) { 36 | puts("Success: Created Service"); 37 | exit(EXIT_SUCCESS); 38 | } else { 39 | puts("Failed: Create Service"); 40 | exit(EXIT_FAILURE); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_loadcomminterfaces_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_loadcomminterfaces_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | CommHandle *plugin = loadCommPlugin("/usr/lib/libzmqpubsub-client.so"); 35 | if (plugin && loadCommInterfaces(plugin)) { 36 | puts("Success: Plugin Communication Interfaces Loaded"); 37 | exit(EXIT_SUCCESS); 38 | } else { 39 | puts("Failed: Plugin Communication Interfaces Load"); 40 | exit(EXIT_FAILURE); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_iotkit-comm_loadcomminterfaces_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_iotkit-comm_loadcomminterfaces_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | CommHandle *plugin = loadCommPlugin("/usr/lib/libzmqpubsub-client.so"); 35 | if (plugin && !loadCommInterfaces(plugin)) { //loadCommInterfaces() is not returning false in negative scenario, always returning true 36 | puts("Success: Plugin Communication Interfaces Loaded"); 37 | exit(EXIT_FAILURE); 38 | } else { 39 | puts("Failed: Plugin Communication Interfaces Load"); 40 | exit(EXIT_SUCCESS); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_advertiseservice_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_advertiseservice_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | 34 | int main(void) { 35 | ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./invalidtemperatureServiceZMQPUBSUB.json"); 36 | if (serviceSpec) { 37 | printf("Waiting for the Service to Advertise\n"); 38 | if (advertiseService(serviceSpec)) { 39 | puts("Success: Service Advertised"); 40 | exit(EXIT_FAILURE); 41 | } else { 42 | puts("Failed: Service Advertise"); 43 | exit(EXIT_SUCCESS); 44 | } 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_service_socket_connect_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_service_socket_connect_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 35 | if (serviceSpec != NULL) { 36 | serviceSpec->address = "invalidaddress"; 37 | serviceSpec->port = 100; 38 | int result = init(serviceSpec, NULL); 39 | done(); 40 | free(serviceSpec); 41 | if (result == 0) { 42 | puts("Publisher Socket Successfully Binded"); 43 | } else { 44 | puts("Failed: Publisher Socket Binding"); 45 | exit(EXIT_SUCCESS); 46 | } 47 | } 48 | exit(EXIT_FAILURE); 49 | } 50 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_service_socket_connect_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_service_socket_connect_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 35 | if (serviceSpec != NULL) { 36 | serviceSpec->address = "127.0.0.1"; 37 | serviceSpec->port = 1080; 38 | int result = init(serviceSpec, NULL); 39 | done(); 40 | free(serviceSpec); 41 | if (result == 0) { 42 | puts("Publisher Socket Successfully Binded"); 43 | exit(EXIT_SUCCESS); 44 | } else { 45 | puts("Failed: Publisher Socket Binding"); 46 | } 47 | } 48 | exit(EXIT_FAILURE); 49 | } 50 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_service_publish_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_service_publish_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 35 | if (serviceSpec != NULL) { 36 | serviceSpec->address = "127.0.0.1"; 37 | serviceSpec->port = 123423; 38 | init(serviceSpec, NULL); 39 | int result = publish("Hello World",NULL); 40 | done(); 41 | free(serviceSpec); 42 | if (result == 0) { 43 | puts("Published Message Successfully"); 44 | } else { 45 | puts("Failed: Publishing Message"); 46 | exit(EXIT_SUCCESS); 47 | } 48 | } 49 | exit(EXIT_FAILURE); 50 | } 51 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_createclientforservice_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_createclientforservice_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | 34 | void callback(ServiceQuery *queryDesc, int32_t error_code, CommHandle *clientHandle) { 35 | if (clientHandle != NULL) { 36 | puts("\nSuccess: Client Created for the Given Service\n"); 37 | exit(EXIT_SUCCESS); 38 | } else { 39 | puts("\nFail: Client Creation for the Given Service\n"); 40 | exit(EXIT_FAILURE); 41 | } 42 | } 43 | 44 | int main(void) { 45 | ServiceQuery *query = (ServiceQuery *)parseServiceQuery("./temperatureServiceQueryZMQPUBSUB.json"); 46 | if (query) { 47 | query->port = 1080; 48 | createClientForGivenService(query, callback); 49 | } 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_client_subscribe_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_client_subscribe_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 35 | if (serviceQuery != NULL) { 36 | serviceQuery->service_name = strdup("/foo"); 37 | serviceQuery->address = strdup("localhost"); 38 | serviceQuery->port = 1234; 39 | init(serviceQuery, NULL); 40 | int result = subscribe("flower"); 41 | done(); 42 | free(serviceQuery); 43 | if (result == 0) { 44 | puts("Subscribed Successfully"); 45 | exit(EXIT_SUCCESS); 46 | } else { 47 | puts("Failed: Subscription"); 48 | } 49 | } 50 | exit(EXIT_FAILURE); 51 | } 52 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_req_send_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_req_send_fail.c 25 | 26 | This file tests whether ZMQ Requester socket fails while sending message. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | int main(void) { 35 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 36 | if (serviceQuery != NULL) { 37 | serviceQuery->address = "127.0.0.1"; 38 | serviceQuery->port = 123423; 39 | init(serviceQuery, NULL); 40 | int result = send("Hello World",NULL); 41 | free(serviceQuery); 42 | if (result == 0) { 43 | puts("Requester Sent Message Successfully"); 44 | } else { 45 | puts("Failed: Requester Sending Message"); 46 | exit(EXIT_SUCCESS); 47 | } 48 | } 49 | exit(EXIT_FAILURE); 50 | } 51 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_rep_socket_connect_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_rep_socket_connect_fail.c 25 | 26 | This file tests whether ZMQ Responder socket fails when we pass Invalid IP Address. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | int main(void) { 35 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 36 | if (serviceSpec != NULL) { 37 | serviceSpec->address = "invalidaddress"; 38 | serviceSpec->port = 100; 39 | int result = init(serviceSpec, NULL); 40 | done(); 41 | free(serviceSpec); 42 | if (result == 0) { 43 | puts("Publisher Socket Successfully Binded"); 44 | } else { 45 | puts("Failed: Publisher Socket Binding"); 46 | exit(EXIT_SUCCESS); 47 | } 48 | } 49 | exit(EXIT_FAILURE); 50 | } 51 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_rep_socket_connect_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_rep_socket_connect_success.c 25 | 26 | This file tests whether ZMQ Responder socket is able to successfully connect. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | int main(void) { 35 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 36 | if (serviceSpec != NULL) { 37 | serviceSpec->address = "127.0.0.1"; 38 | serviceSpec->port = 1080; 39 | int result = init(serviceSpec, NULL); 40 | done(); 41 | free(serviceSpec); 42 | if (result == 0) { 43 | puts("Publisher Socket Successfully Binded"); 44 | exit(EXIT_SUCCESS); 45 | } else { 46 | puts("Failed: Publisher Socket Binding"); 47 | } 48 | } 49 | exit(EXIT_FAILURE); 50 | } 51 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_client_socket_connect_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_client_socket_connect_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 35 | if (serviceQuery != NULL) { 36 | serviceQuery->service_name = strdup("/foo"); 37 | serviceQuery->address = strdup("invalidaddress"); 38 | serviceQuery->port = 100; 39 | int result = init(serviceQuery, NULL); 40 | done(); 41 | free(serviceQuery); 42 | if (result == 0) { 43 | puts("Subscriber Socket Successfully Connected"); 44 | } else { 45 | puts("Failed: Subscriber Socket Initialization"); 46 | exit(EXIT_SUCCESS); 47 | } 48 | } 49 | exit(EXIT_FAILURE); 50 | } 51 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_client_unsubscribe_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_client_unsubscribe_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 35 | if (serviceQuery != NULL) { 36 | serviceQuery->service_name = strdup("/foo"); 37 | serviceQuery->address = strdup("localhost"); 38 | serviceQuery->port = 1234; 39 | init(serviceQuery, NULL); 40 | int result = unsubscribe("flower"); 41 | done(); 42 | free(serviceQuery); 43 | if (result == 0) { 44 | puts("UnSubscribed Successfully"); 45 | exit(EXIT_SUCCESS); 46 | } else { 47 | puts("Failed: UnSubscription"); 48 | } 49 | } 50 | exit(EXIT_FAILURE); 51 | } 52 | -------------------------------------------------------------------------------- /src/tests/mqttpubsub/test_mqttpubsub_client_connect_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mqttpubsub_client_connect_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include "iotkit-comm.h" 31 | 32 | int main(void) { 33 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 34 | if (serviceQuery != NULL) { 35 | serviceQuery->service_name = strdup("/foo"); 36 | serviceQuery->address = strdup("localhost"); 37 | serviceQuery->port = 1883; 38 | int result = init(serviceQuery, NULL); 39 | if (result == MQTTASYNC_SUCCESS) { 40 | puts("Test Passed: Successfully Connected to an MQTT Broker"); 41 | exit(EXIT_SUCCESS); 42 | } else { 43 | puts("Test Failed: Could not connect to MQTT Broker"); 44 | } 45 | done(); 46 | free(serviceQuery); 47 | } 48 | exit(EXIT_FAILURE); 49 | } 50 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_client_socket_connect_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_client_socket_connect_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | int main(void) { 34 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 35 | if (serviceQuery != NULL) { 36 | serviceQuery->service_name = strdup("/foo"); 37 | serviceQuery->address = strdup("localhost"); 38 | serviceQuery->port = 1234; 39 | int result = init(serviceQuery, NULL); 40 | done(); 41 | free(serviceQuery); 42 | if (result == 0) { 43 | puts("Subscriber Socket Successfully Connected"); 44 | exit(EXIT_SUCCESS); 45 | } else { 46 | puts("Failed: Subscriber Socket Initialization"); 47 | } 48 | } 49 | exit(EXIT_FAILURE); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_req_socket_connect_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_req_socket_connect_success.c 25 | 26 | This file tests whether ZMQ Requester socket is able to successfully connect. 27 | 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include "iotkit-comm.h" 34 | 35 | int main(void) { 36 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 37 | if (serviceQuery != NULL) { 38 | serviceQuery->address = "localhost"; 39 | serviceQuery->port = 1234; 40 | int result = init(serviceQuery, NULL); 41 | done(); 42 | free(serviceQuery); 43 | if (result == 0) { 44 | puts("Requester Socket Successfully Connected"); 45 | exit(EXIT_SUCCESS); 46 | } else { 47 | puts("Failed: Requester Socket Initialization"); 48 | } 49 | } 50 | exit(EXIT_FAILURE); 51 | } 52 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_req_socket_connect_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_req_socket_connect_fail.c 25 | 26 | This file tests whether ZMQ Requester socket fails when we pass the Invalid IP Address. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | int main(void) { 35 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 36 | if (serviceQuery != NULL) { 37 | serviceQuery->address = "127.0.0.123232132321323123232233"; 38 | serviceQuery->port = 100; 39 | int result = init(serviceQuery, NULL); 40 | done(); 41 | free(serviceQuery); 42 | if (result == 0) { 43 | puts("Requester Socket Successfully Connected"); 44 | } else { 45 | puts("Failed: Requester Socket Binding"); 46 | exit(EXIT_SUCCESS); 47 | } 48 | } 49 | exit(EXIT_FAILURE); 50 | } 51 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_rep_sendTo_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_rep_sendTo_fail.c 25 | 26 | This file tests whether ZMQ Responder socket fails while sending message. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | int main(void) { 35 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 36 | if (serviceSpec != NULL) { 37 | serviceSpec->address = "127.0.0.1"; 38 | serviceSpec->port = 1234; 39 | init(serviceSpec, NULL); 40 | int result = sendTo(NULL,"Hello World",NULL); 41 | if (result == 0) { 42 | puts("Sended Message Successfully"); 43 | done(); 44 | free(serviceSpec); 45 | } else { 46 | puts("Failed: Sending Message"); 47 | done(); 48 | free(serviceSpec); 49 | exit(EXIT_SUCCESS); 50 | } 51 | } 52 | exit(EXIT_FAILURE); 53 | } 54 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_req_receive_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_req_send_fail.c 25 | 26 | This file tests whether ZMQ Requester socket fails while sending message. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | void handler(char *message,Context context) { 35 | if (message == NULL) { 36 | exit(EXIT_SUCCESS); 37 | } else { 38 | exit(EXIT_FAILURE); 39 | } 40 | } 41 | 42 | int main(void) { 43 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 44 | if (serviceQuery != NULL) { 45 | serviceQuery->address = "127.0.0.1"; 46 | serviceQuery->port = 5560; 47 | int result = init(serviceQuery, NULL); 48 | if (result == -1) 49 | puts("Requester init failed"); 50 | puts("waiting for message"); 51 | receive(handler); 52 | done(); 53 | free(serviceQuery); 54 | } 55 | exit(EXIT_FAILURE); 56 | } 57 | -------------------------------------------------------------------------------- /src/lib/plugins/libzmqreqrep/zmqreqrep-client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file zmqreqrep-client.h 25 | Header file. Lists all those functions in implementing ZMQ requester. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include "iotkit-comm.h" 33 | 34 | #ifndef DEBUG 35 | #define DEBUG 0 36 | #endif 37 | 38 | /** @defgroup zmqreqrepclient 39 | * 40 | * @{ 41 | */ 42 | 43 | char *interface = "client-interface"; /**< specifies the plugin interface json */ 44 | bool provides_secure_comm = false; 45 | 46 | /** Structure holds the context and requester handler 47 | */ 48 | struct ZMQReqRepClient { 49 | void *context; /**< context handler */ 50 | void *requester; /**< requester handler */ 51 | }; 52 | 53 | /** An Global ZMQReqRepClient Object. 54 | */ 55 | struct ZMQReqRepClient zmqContainer; 56 | 57 | int init(void *requestClientQuery, Crypto *crypto); 58 | int send(char *message, Context); 59 | int receive(void (*requestClientHandler)(char *message, Context context)); 60 | int done(); 61 | /** @} */ // end of zmqreqrepclient 62 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_createclientforservice_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_createclientforservice_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | 34 | /** Callback function. Once the service is discovered this callback function will be invoked 35 | * @param servQuery the service query object 36 | * @param error_code the error code 37 | * @param commHandle the communication handle used to invoke the interfaces 38 | */ 39 | void callback(ServiceQuery *servQuery, int32_t error_code, CommHandle *clientHandle) { 40 | if (clientHandle != NULL) { 41 | puts("Success: Service Advertised"); 42 | exit(EXIT_FAILURE); 43 | } else { 44 | puts("Fail: Service Not Advertised"); 45 | exit(EXIT_SUCCESS); 46 | } 47 | } 48 | 49 | int main(void) { 50 | ServiceQuery *servQuery = (ServiceQuery *)parseServiceQuery("./temperatureServiceQueryMQTT.json"); 51 | if (servQuery) { 52 | createClientForGivenService(servQuery, callback); 53 | } 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /src/lib/plugins/libzmqpubsub/zmqpubsub-client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file zmqpubsub-client.h 25 | Header file. List of all functions in zmq subscribe client. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "../inc/zhelpers.h" 32 | 33 | #ifndef DEBUG 34 | #define DEBUG 0 35 | #endif 36 | 37 | #include "iotkit-comm.h" 38 | 39 | /** @defgroup zmqpubsubclient 40 | * 41 | * @{ 42 | */ 43 | 44 | char *interface = "client-interface"; /**< specifies the plugin interface json */ 45 | bool provides_secure_comm = false; 46 | 47 | /** Structure holds the context and subscriber handler 48 | */ 49 | struct ZMQPubSubClient { 50 | void *context; /**< context handler */ 51 | void *subscriber; /**< subscriber handler */ 52 | }; 53 | 54 | /** An Global ZMQPubSubClient Object. 55 | */ 56 | struct ZMQPubSubClient zmqContainer; 57 | 58 | int init(void *ClientServiceQuery, Crypto *crypto); 59 | int send(char *message,Context context); 60 | int receive(void (*subscribeClientHandler)(char *message, Context context)); 61 | int done(); 62 | 63 | /** @} */ // end of zmqpubsubclient 64 | -------------------------------------------------------------------------------- /src/lib/plugins/libenableiot/enableiot-service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file iotkit-agent-service.h 26 | * @brief Headers of iotkit Async Service plugin for iotkit-comm API. 27 | * 28 | * Provides features to connect to an MQTT Broker and publish a topic. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "iotkit-comm.h" 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #ifndef DEBUG 45 | #define DEBUG 0 46 | #endif 47 | 48 | char *interface = "enableiot-service-interface"; // specifies the plugin interface json 49 | bool provides_secure_comm = true; 50 | bool communicates_via_proxy = true; 51 | 52 | char *deviceID = NULL; 53 | char *activationCode = NULL; 54 | char *sensorName = NULL; 55 | char *sensorType = NULL; 56 | 57 | int init(void *serviceDesc, Crypto *crypto); 58 | char *activateDevice(); 59 | char *registerSensor(); 60 | int publish(char *message,Context context); 61 | int receive(void (*) (char *topic, Context context)); 62 | int done(); 63 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_advertiseservice_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_advertiseservice_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | 34 | /** Callback function. Once the service is discovered this callback function will be invoked 35 | * @param servQuery the service query object 36 | * @param error_code the error code 37 | * @param commHandle the communication handle used to invoke the interfaces 38 | */ 39 | void subDiscoveryCallback(ServiceQuery *servQuery, int32_t error_code, CommHandle *serviceHandle) { 40 | if (serviceHandle != NULL) { 41 | puts("Success: Service Advertised"); 42 | exit(EXIT_SUCCESS); 43 | } else { 44 | puts("Fail: Service Not Advertised"); 45 | exit(EXIT_FAILURE); 46 | } 47 | } 48 | 49 | int main(void) { 50 | ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./temperatureServiceZMQPUBSUB.json"); 51 | if (serviceSpec) { 52 | puts("Waiting for the Service to Advertise"); 53 | advertiseServiceBlocking(serviceSpec, subDiscoveryCallback); 54 | } 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /src/lib/plugins/libzmqreqrep/zmqreqrep-service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file zmqreqrep-service.h 25 | Header file. Lists all those functions in implementing ZMQ replier. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "../inc/zhelpers.h" 32 | 33 | #include "iotkit-comm.h" 34 | 35 | #ifndef DEBUG 36 | #define DEBUG 0 37 | #endif 38 | 39 | /** @defgroup zmqreqrepservice 40 | * 41 | * @{ 42 | */ 43 | char *interface = "service-interface"; /**< specifies the plugin interface json */ 44 | bool provides_secure_comm = false; 45 | 46 | /** Structure holds the context and responder handler 47 | */ 48 | struct ZMQReqRepService { 49 | void *context; /**< context handler */ 50 | void *responder; /**< responder handler */ 51 | }; 52 | 53 | /** An Global ZMQReqRepService Object. 54 | */ 55 | struct ZMQReqRepService zmqContainer; 56 | 57 | int init(void *responseServiceDesc, Crypto *crypto); 58 | int sendTo(void *client,char *message,Context context); 59 | int publish(char *message,Context context); 60 | int receive(void (*responseServiceHandler)(void *client,char *message,Context context)); 61 | int done(); 62 | /** @} */ // end of zmqreqrepservice 63 | -------------------------------------------------------------------------------- /src/lib/plugins/libzmqpubsub/zmqpubsub-service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file zmqpubsub-service.h 25 | Header file. List of all functions in zmq publish service. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "../inc/zhelpers.h" 32 | 33 | #include "iotkit-comm.h" 34 | 35 | #ifndef DEBUG 36 | #define DEBUG 0 37 | #endif 38 | 39 | 40 | 41 | /** @defgroup zmqpubsubservice 42 | * 43 | * @{ 44 | */ 45 | 46 | char *interface = "service-interface"; /**< specifies the plugin interface json */ 47 | bool provides_secure_comm = false; 48 | 49 | /** Structure holds the context and publisher handler 50 | */ 51 | struct ZMQPubSubService { 52 | void *context; /**< context handler */ 53 | void *publisher; /**< publisher handler */ 54 | }; 55 | 56 | /** An Global ZMQPubSubService Object. 57 | */ 58 | struct ZMQPubSubService zmqContainer; 59 | 60 | int init(void *publishServiceDesc, Crypto *crypto); 61 | int sendTo(void *client, char *message, Context context); 62 | int publish(char *message,Context context); 63 | int receive(void (*publishServiceHandler)(void *client,char *message,Context context)); 64 | int done(); 65 | 66 | /** @} */ // end of zmqpubsubservice 67 | -------------------------------------------------------------------------------- /src/tests/mqttpubsub/test_mqttpubsub_client_publish_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mqttpubsub_client_publish_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include "iotkit-comm.h" 31 | 32 | int main(void) { 33 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 34 | if (serviceQuery != NULL) { 35 | serviceQuery->service_name = strdup("/foo"); 36 | serviceQuery->address = strdup("localhost"); 37 | serviceQuery->port = 1883; 38 | int result = init(serviceQuery, NULL); 39 | if (result == MQTTASYNC_SUCCESS) { 40 | puts("Successfully Connected to an MQTT Broker"); 41 | Context context; 42 | context.name = "topic"; 43 | context.value = NULL; 44 | result = send("This is a test message", context); 45 | if(result != MQTTASYNC_SUCCESS) { 46 | puts("Test Passed: Could not publish message as expected"); 47 | exit(EXIT_SUCCESS); 48 | } 49 | } else { 50 | puts("Test Failed: Could not connect to MQTT Broker"); 51 | } 52 | done(); 53 | free(serviceQuery); 54 | } 55 | exit(EXIT_FAILURE); 56 | } 57 | -------------------------------------------------------------------------------- /src/tests/mqttpubsub/test_mqttpubsub_client_publish_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mqttpubsub_client_publish_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include "iotkit-comm.h" 31 | 32 | int main(void) { 33 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 34 | if (serviceQuery != NULL) { 35 | serviceQuery->service_name = strdup("/foo"); 36 | serviceQuery->address = strdup("localhost"); 37 | serviceQuery->port = 1883; 38 | int result = init(serviceQuery, NULL); 39 | if (result == MQTTASYNC_SUCCESS) { 40 | puts("Successfully Connected to an MQTT Broker"); 41 | 42 | Context context; 43 | context.name = "topic"; 44 | context.value = "/foo"; 45 | result = send("This is a test message", context); 46 | if(result == MQTTASYNC_SUCCESS) { 47 | puts("Test Passed: Successfully published message"); 48 | exit(EXIT_SUCCESS); 49 | } 50 | } else { 51 | puts("Test Failed: Could not connect to MQTT Broker"); 52 | } 53 | done(); 54 | free(serviceQuery); 55 | } 56 | exit(EXIT_FAILURE); 57 | } 58 | -------------------------------------------------------------------------------- /src/tests/zmqpubsub/test_zmqpubsub_client_receive_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqpubsub_client_subscribe_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | void handler() { 35 | puts("Didn't receive message"); 36 | exit(EXIT_SUCCESS); 37 | } 38 | 39 | int main(void) { 40 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 41 | if (serviceQuery != NULL) { 42 | serviceQuery->service_name = strdup("/foo"); 43 | serviceQuery->address = strdup("localhost"); 44 | serviceQuery->port = 5563; 45 | int result = init(serviceQuery, NULL); 46 | if (result == -1) 47 | puts("client init failed"); 48 | result = subscribe("flower"); 49 | if (result == -1) 50 | puts("client subscribe failed"); 51 | /* Establish a handler for SIGALRM signals. */ 52 | signal(SIGALRM, handler); 53 | /* Set an alarm to go off*/ 54 | alarm(3); 55 | result = receive(handler); 56 | if (result == -1) 57 | puts("receive failed"); 58 | done(); 59 | free(serviceQuery); 60 | } 61 | exit(EXIT_FAILURE); 62 | } 63 | -------------------------------------------------------------------------------- /src/lib/plugins/libmqttpubsub/mqtt-client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file mqtt-client.h 26 | * @brief Headers of MQTT Async Client plugin for iotkit-comm API. 27 | * 28 | * Provides features to connect to an MQTT Broker and subscribe to a topic. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "iotkit-comm.h" 38 | 39 | #define CLIENTID "MQTTClient" 40 | #define QOS 1 41 | #define TIMEOUT 10000L 42 | 43 | #ifndef DEBUG 44 | #define DEBUG 0 45 | #endif 46 | 47 | void *handle = NULL; 48 | char *err = NULL; 49 | 50 | char clientID[256]; 51 | 52 | MQTTClient client; 53 | MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; 54 | MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer; 55 | 56 | char *interface = "client-interface"; // specifies the plugin interface json 57 | bool provides_secure_comm = true; 58 | bool communicates_via_proxy = true; 59 | 60 | int init(void *serviceDesc, Crypto *crypto); 61 | int send(char *message, Context context); 62 | int subscribe(char *topic); 63 | int unsubscribe(char *topic); 64 | int receive(void (*) (char *topic, Context context)); 65 | int done(); 66 | 67 | void (*msgArrhandler) (char *topic, Context context) = NULL; 68 | -------------------------------------------------------------------------------- /src/lib/plugins/libenableiot/enableiot-client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file enableiot-client.h 26 | * @brief Headers of enableiot plugin for iotkit-comm API. 27 | * 28 | * Provides features to connect to enableiot cloud and subscribe to a device 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "iotkit-comm.h" 38 | #include "util.h" 39 | 40 | #include 41 | #include 42 | 43 | #ifndef DEBUG 44 | #define DEBUG 0 45 | #endif 46 | 47 | char *interface = "enableiot-client-interface"; // specifies the plugin interface json 48 | bool provides_secure_comm = true; 49 | bool communicates_via_proxy = true; 50 | 51 | char *deviceID = NULL; 52 | char *activationCode = NULL; 53 | char *address = NULL; 54 | int port = 0; 55 | char *username = NULL; // aka device ID 56 | char *password = NULL; // aka device Token 57 | char *data_account_id = NULL; // data account ID 58 | char *sensorName = NULL; 59 | char *sensorType = NULL; 60 | char *targetDeviceId = NULL; 61 | int frequencyInterval; 62 | 63 | void (*msgArrhandler) (char *topic, Context context) = NULL; 64 | 65 | int init(void *serviceDesc, Crypto *crypto); 66 | int receive(void (*) (char *topic, Context context)); 67 | int done(); 68 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_rep_receive_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_rep_sendTo_fail.c 25 | 26 | This file tests whether ZMQ Responder socket fails while sending message. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | void handler(void *client,char *message,Context context) { 35 | printf("Received message: %s\n",message); 36 | exit(EXIT_SUCCESS); 37 | } 38 | 39 | int main(void) { 40 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 41 | if (serviceSpec != NULL) { 42 | serviceSpec->address = "127.0.0.1"; 43 | serviceSpec->port = 1234; 44 | init(serviceSpec, NULL); 45 | void *ctx = zmq_ctx_new(); 46 | void *req = zmq_socket(ctx, ZMQ_REQ); 47 | int rc = zmq_connect(req, "tcp://127.0.0.1:1234"); 48 | if (rc == -1) 49 | puts("client connect failed"); 50 | // Send message from client to server 51 | rc = zmq_send(req, "rose", 4, 0); 52 | if (rc == -1) 53 | puts("client send failed"); 54 | puts("waitng for message"); 55 | receive(handler); 56 | done(); 57 | free(serviceSpec); 58 | zmq_close(req); 59 | zmq_ctx_term(ctx); 60 | } 61 | exit(EXIT_FAILURE); 62 | } 63 | -------------------------------------------------------------------------------- /src/lib/plugins/libmqttpubsub/mqtt-service.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file mqtt-service.h 26 | * @brief Headers of MQTT Async Service plugin for iotkit-comm API. 27 | * 28 | * Provides features to connect to an MQTT Broker and publish a topic. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "iotkit-comm.h" 38 | 39 | #define CLIENTID "MQTTClient" 40 | #define QOS 1 41 | #define TIMEOUT 10000L 42 | 43 | #ifndef DEBUG 44 | #define DEBUG 0 45 | #endif 46 | 47 | void *handle = NULL; 48 | char *err = NULL; 49 | 50 | char clientID[256]; 51 | 52 | MQTTClient client; 53 | MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; 54 | MQTTClient_SSLOptions sslopts = MQTTClient_SSLOptions_initializer; 55 | 56 | char *interface = "service-interface"; // specifies the plugin interface json 57 | bool provides_secure_comm = true; 58 | bool communicates_via_proxy = true; 59 | 60 | /** 61 | * Topic to publish or subscribe data to. This is the only topic 62 | * the cloud supports. 63 | */ 64 | char *default_topic = NULL; 65 | 66 | int init(void *publishServiceDesc, Crypto *crypto); 67 | int sendTo(void *client, char *message, Context context); 68 | int publish(char *message,Context context); 69 | int receive(void (*publishServiceHandler)(void *client,char *message,Context context)); 70 | int done(); 71 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_discoverservice_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_discoverservice_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm.h" 32 | 33 | 34 | /** Callback function. Once the service is discovered this callback function will be invoked 35 | * @param servQuery the service query object 36 | * @param error_code the error code 37 | * @param commHandle the communication handle used to invoke the interfaces 38 | */ 39 | void subDiscoveryCallback(ServiceQuery *servQuery, int32_t error_code, CommHandle *commHandle) { 40 | if (commHandle != NULL) { 41 | puts("Success: Service Found"); 42 | exit(EXIT_SUCCESS); 43 | } else { 44 | puts("Fail: Service Not Found"); 45 | exit(EXIT_FAILURE); 46 | } 47 | } 48 | 49 | int main(void) { 50 | ServiceQuery *servQuery = (ServiceQuery *) parseServiceQuery("./temperatureServiceQueryZMQPUBSUB1.json"); 51 | ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./temperatureServiceZMQPUBSUB.json"); 52 | 53 | if (serviceSpec) { 54 | if (servQuery && advertiseService(serviceSpec)) { 55 | fprintf(stderr,"query host address %s\n",servQuery->address); 56 | fprintf(stderr,"query host port %d\n",servQuery->port); 57 | fprintf(stderr,"query service name %s\n",servQuery->service_name); 58 | discoverServicesBlocking(servQuery, subDiscoveryCallback); 59 | } 60 | } 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_rep_receive_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_rep_sendTo_fail.c 25 | 26 | This file tests whether ZMQ Responder socket fails while sending message. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "iotkit-comm.h" 34 | 35 | void handler(void *client,char *message,Context context) { 36 | printf("Received message: %s\n",message); 37 | exit(EXIT_FAILURE); 38 | } 39 | 40 | void alarmHandler() { 41 | exit(EXIT_SUCCESS); 42 | } 43 | 44 | int main(void) { 45 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 46 | if (serviceSpec != NULL) { 47 | serviceSpec->address = "127.0.0.1"; 48 | serviceSpec->port = 1234; 49 | init(serviceSpec, NULL); 50 | void *ctx = zmq_ctx_new(); 51 | void *req = zmq_socket(ctx, ZMQ_REQ); 52 | int rc = zmq_connect(req, "tcp://127.0.0.1:1234"); 53 | if (rc == -1) 54 | puts("client connect failed"); 55 | // Send message from client to server 56 | rc = zmq_send(req, "rose", 4, -1); 57 | if (rc == -1) 58 | puts("client send failed"); 59 | /* Establish a handler for SIGALRM signals. */ 60 | signal(SIGALRM, alarmHandler); 61 | /* Set an alarm to go off*/ 62 | alarm(3); 63 | puts("waiting for message"); 64 | receive(handler); 65 | done(); 66 | free(serviceSpec); 67 | exit(EXIT_SUCCESS); 68 | } else { 69 | exit(EXIT_FAILURE); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/tests/libiotkit-comm/test_mdns_discoverservice_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mdns_discoverservice_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "iotkit-comm.h" 34 | 35 | 36 | /** Callback function. Once the service is discovered this callback function will be invoked 37 | * @param servQuery the service query object 38 | * @param error_code the error code 39 | * @param commHandle the communication handle used to invoke the interfaces 40 | */ 41 | void subDiscoveryCallback(ServiceQuery *servQuery, int32_t error_code, CommHandle *commHandle) { 42 | puts("Fail: Service Not Found"); 43 | exit(EXIT_SUCCESS); 44 | } 45 | 46 | int main(void) { 47 | ServiceQuery *servQuery = (ServiceQuery *) parseServiceQuery("./temperatureServiceQueryMQTT.json"); 48 | ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./temperatureServiceMQTT.json"); 49 | /* Establish a handler for SIGALRM signals. */ 50 | signal(SIGALRM, subDiscoveryCallback); 51 | /* Set an alarm to go off*/ 52 | alarm(5); 53 | if (serviceSpec) { 54 | if (servQuery) { 55 | fprintf(stderr,"query host address %s\n",servQuery->address); 56 | fprintf(stderr,"query host port %d\n",servQuery->port); 57 | fprintf(stderr,"query service name %s\n",servQuery->service_name); 58 | printf("Waiting for the Service Upto 5 Seconds\n"); 59 | discoverServicesBlocking(servQuery, subDiscoveryCallback); 60 | } 61 | } 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file util.h 26 | * @brief Helper class for JSON Parsing. 27 | * 28 | * Utility class for parsing JSON Objects. 29 | */ 30 | 31 | #ifndef __CJSON_UTIL_H 32 | #define __CJSON_UTIL_H 33 | 34 | #include 35 | #include "cJSON.h" 36 | 37 | /** Check whether JSON item is a boolean false */ 38 | static inline bool isJsonBooleanFalse(cJSON *item) { 39 | if (item == NULL || item->type != cJSON_False) { 40 | return false; 41 | } 42 | return true; 43 | } 44 | 45 | /** Check whether JSON item is a boolean true */ 46 | static inline bool isJsonBooleanTrue(cJSON *item) { 47 | if (item == NULL || item->type != cJSON_True) { 48 | return false; 49 | } 50 | return true; 51 | } 52 | 53 | /** Check whether JSON item is a string. */ 54 | static inline bool isJsonString(cJSON *item) { 55 | if (item == NULL || item->type != cJSON_String) { 56 | return false; 57 | } 58 | return true; 59 | } 60 | 61 | /** Check whether JSON item is a number. */ 62 | static inline bool isJsonNumber(cJSON *item) { 63 | if (item == NULL || item->type != cJSON_Number) { 64 | return false; 65 | } 66 | return true; 67 | } 68 | 69 | /** Check whether JSON item is an object. */ 70 | static inline bool isJsonObject(cJSON *item) { 71 | if (item == NULL || item->type != cJSON_Object) { 72 | return false; 73 | } 74 | return true; 75 | } 76 | 77 | /** Check whether JSON item is an array. */ 78 | static inline bool isJsonArray(cJSON *item) { 79 | if (item == NULL || item->type != cJSON_Array) { 80 | return false; 81 | } 82 | return true; 83 | } 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_req_send_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_req_send_fail.c 25 | 26 | This file tests whether ZMQ Requester socket fails while sending message. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "iotkit-comm.h" 34 | 35 | void handler(char *message,Context context) { 36 | printf("Received message: %s\n",message); 37 | } 38 | 39 | int main(void) { 40 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 41 | if (serviceQuery != NULL) { 42 | serviceQuery->address = "127.0.0.1"; 43 | serviceQuery->port = 5560; 44 | int result = init(serviceQuery, NULL); 45 | if (result == -1) 46 | puts("Requester init failed"); 47 | void *ctx = zmq_ctx_new(); 48 | assert (ctx); 49 | void *pub = zmq_socket(ctx, ZMQ_REP); 50 | assert (pub); 51 | int rc = zmq_bind(pub, "tcp://127.0.0.1:5560"); 52 | assert (rc == 0); 53 | result = send("apple",NULL); 54 | if (result == -1) { 55 | puts("send failed"); 56 | rc = zmq_close(pub); 57 | assert(rc == 0); 58 | rc = zmq_ctx_term(ctx); 59 | assert(rc == 0); 60 | free(serviceQuery); 61 | } else { 62 | puts("Requester Sent Message Successfully"); 63 | rc = zmq_close(pub); 64 | assert (rc == 0); 65 | rc = zmq_ctx_term(ctx); 66 | assert(rc == 0); 67 | free(serviceQuery); 68 | exit(EXIT_SUCCESS); 69 | } 70 | } 71 | exit(EXIT_FAILURE); 72 | } 73 | -------------------------------------------------------------------------------- /src/tests/mqttpubsub/test_mqttpubsub_client_unsubscribe_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mqttpubsub_client_unsubscribe_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include "iotkit-comm.h" 31 | 32 | bool receivedMessage = false; 33 | 34 | void message_callback(char *message, Context context) { 35 | printf("Message received:%s\n", message); 36 | receivedMessage = true; 37 | } 38 | 39 | int main(void) { 40 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 41 | if (serviceQuery != NULL) { 42 | serviceQuery->service_name = strdup("/foo"); 43 | serviceQuery->address = strdup("localhost"); 44 | serviceQuery->port = 1883; 45 | int result = init(serviceQuery, NULL); 46 | if (result == MQTTASYNC_SUCCESS) { 47 | puts("Successfully Connected to an MQTT Broker"); 48 | receive(message_callback); 49 | result = subscribe("/foo"); //correct topic 50 | if (result == 0) { 51 | puts("Subscribed Successfully"); 52 | puts("Waiting for messages on subscribed topic"); 53 | result = unsubscribe("/foo"); 54 | if(result == MQTTASYNC_SUCCESS) { 55 | puts("Test Passed: Successfully unsubscribed topic"); 56 | exit(EXIT_SUCCESS); 57 | } else { 58 | puts("Test Failed: Topic not found"); 59 | } 60 | } else { 61 | puts("Test Failed: Could not subscribe"); 62 | } 63 | } else { 64 | puts("Test Failed: Could not connect to MQTT Broker"); 65 | } 66 | done(); 67 | free(serviceQuery); 68 | } 69 | exit(EXIT_FAILURE); 70 | } 71 | -------------------------------------------------------------------------------- /src/lib/iotkit-comm/iotkit-comm_mdns.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file iotkit-comm_mdns.h 26 | * @brief Header file of iotkit-comm MDNS. 27 | * 28 | * DataStructure of DiscoverContext and ServiceCache. 29 | */ 30 | 31 | #ifndef __IOTKIT_COMM_MDNS_H 32 | #define __IOTKIT_COMM_MDNS_H 33 | 34 | #include "iotkit-comm.h" 35 | 36 | #ifndef DEBUG 37 | #define DEBUG 0 38 | #endif 39 | 40 | #define LOCAL_ADDRESS "127.0.0.1" 41 | #define MAX_PROPERTIES 128 42 | 43 | #define LONG_TIME 100000000 44 | #define SHORT_TIME 10000 45 | 46 | static uint32_t opinterface = kDNSServiceInterfaceIndexAny; 47 | static volatile int timeOut = LONG_TIME; 48 | int stopBlockingState = 0; 49 | 50 | static char lastError[256]; 51 | 52 | /** Discover context to be passed around, which contains function pointers to 53 | * callback and user filter callback methods. 54 | */ 55 | typedef struct _DiscoverContext { 56 | bool (*userFilterCB) (ServiceQuery *); 57 | void (*callback) (void *, int32_t, void *); 58 | void *serviceSpec; 59 | CommHandle *commHandle; 60 | } DiscoverContext; 61 | 62 | 63 | /** Service cache to hold list of services discovered via DNS. 64 | */ 65 | typedef struct _ServiceCache { 66 | char *servicename; 67 | char *address; 68 | struct ServiceCache *next; 69 | } ServiceCache; 70 | 71 | 72 | ServiceCache *serviceCache = NULL; 73 | int myaddressesCount = 0; 74 | char **myaddresses = NULL; 75 | 76 | 77 | bool serviceQueryFilter(ServiceQuery *srvQry, char *fullname, uint16_t PortAsNumber, uint16_t txtLen, const unsigned char *txtRecord); 78 | char* serviceAddressFilter(ServiceQuery *srvQry, const char *hosttarget, const char *fullname, uint16_t portAsNumber); 79 | bool extractNameFromServiceRecord(char *fullservicename, char *servicename); 80 | bool isServiceLocal(const char *address); 81 | bool setMyAddresses(void); 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/tests/zmqreqrep/test_zmqreqrep_rep_sendTo_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_zmqreqrep_rep_sendTo_fail.c 25 | 26 | This file tests whether ZMQ Responder socket fails while sending message. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm.h" 33 | 34 | void handler(void *client,char *message,Context context) { 35 | printf("Received message: %s\n",message); 36 | } 37 | 38 | int main(void) { 39 | ServiceSpec *serviceSpec = (ServiceSpec *)malloc(sizeof(ServiceSpec)); 40 | if (serviceSpec != NULL) { 41 | serviceSpec->address = "127.0.0.1"; 42 | serviceSpec->port = 1234; 43 | init(serviceSpec, NULL); 44 | void *ctx = zmq_ctx_new(); 45 | void *req = zmq_socket(ctx, ZMQ_REQ); 46 | int result = zmq_connect(req, "tcp://127.0.0.1:1234"); 47 | if (result == -1) 48 | puts("request connect failed"); 49 | // Send message from client to server 50 | int rc = zmq_send(req, "rose", 4, 0); 51 | if (rc == -1) 52 | puts("client send failed"); 53 | puts("waitng for message"); 54 | receive(handler); 55 | // send message from server to client 56 | result = sendTo(NULL,"Hello World",NULL); 57 | if (result == -1) 58 | puts("sendTo failed"); 59 | 60 | // Receive message at client side 61 | char buffer [12]; 62 | rc = zmq_recv(req, buffer, 11, 0); 63 | if (rc == -1) { 64 | puts("receive failed"); 65 | zmq_close(req); 66 | zmq_ctx_term(ctx); 67 | } else { 68 | buffer[rc] = '\0'; 69 | printf("message received is %s\n",buffer); 70 | zmq_close(req); 71 | zmq_ctx_term(ctx); 72 | exit(EXIT_SUCCESS); 73 | } 74 | } 75 | exit(EXIT_FAILURE); 76 | } 77 | -------------------------------------------------------------------------------- /src/tests/mqttpubsub/test_mqttpubsub_client_subscribe_fail.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mqttpubsub_client_subscribe_fail.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include "iotkit-comm.h" 31 | 32 | bool receivedMessage = false; 33 | 34 | void message_callback(char *message, Context context) { 35 | printf("Message received:%s\n", message); 36 | receivedMessage = true; 37 | } 38 | 39 | int main(void) { 40 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 41 | if (serviceQuery != NULL) { 42 | serviceQuery->service_name = strdup("/foo"); 43 | serviceQuery->address = strdup("localhost"); 44 | serviceQuery->port = 1883; 45 | int result = init(serviceQuery, NULL); 46 | if (result == MQTTASYNC_SUCCESS) { 47 | puts("Successfully Connected to an MQTT Broker"); 48 | receive(message_callback); 49 | result = subscribe("/topicnotfound"); //wrong topic 50 | if (result == 0) { 51 | puts("Subscribed Successfully"); 52 | puts("Waiting for messages on subscribed topic"); 53 | int timerIndex = 0; 54 | while(timerIndex < 10 && !receivedMessage) { // Wait for 10 seconds 55 | sleep(1); 56 | timerIndex ++; 57 | } 58 | if(receivedMessage) { 59 | puts("Test Failed: received message on subscribed topic"); 60 | } else { 61 | puts("Test Passed: No message received on subscribed topic"); 62 | exit(EXIT_SUCCESS); 63 | } 64 | } else { 65 | puts("Test Failed: Could not subscribe"); 66 | } 67 | } else { 68 | puts("Test Failed: Could not connect to MQTT Broker"); 69 | } 70 | done(); 71 | free(serviceQuery); 72 | } 73 | exit(EXIT_FAILURE); 74 | } 75 | -------------------------------------------------------------------------------- /tutorials/plugin.md: -------------------------------------------------------------------------------- 1 | 2 | At the moment, iotkit-comm supports only communication plugins. Thus the following topics will be specific to these plugins: 3 | 4 | a) About communication plugins
5 | b) How communication plugins are instantiated
6 | c) Learn more 7 | 8 | About communication plugins 9 | 10 | A communication plugin abstracts away the details of how messages are sent (or received), allowing developers to focus 11 | on the contents of messages. These plugins provide functions like send and receive. The major difference is how the 12 | send and receive are implemented: In one plugin, the underlying protocol might be MQTT, while in another plugin zeromq 13 | sockets might be used. This gives developers the flexibility to switch the underlying communication protocol 14 | (e.g. MQTT or zeromq) with minor code changes and without the need to learn the details of these underlying protocols. 15 | 16 | Plugins will appear in code in the CommHandle * field of the service or client object. If you have not gone through the 17 | tutorials for building a client or service, we suggest you do that before continuing further. Coming back to the 18 | CommHandle * field, here's how a client would send a message to the server using the zmqreqrep plugin: 19 | 20 | int (**send)(char *, Context context); 21 | Context context; 22 | 23 | send = commInterfacesLookup(commHandle, "send"); 24 | (*send)("toys",context); 25 | 26 | 27 | Each plugin will document the functions it provides. For a list of plugins and their API, see the [supported plugins] 28 | (@ref supported-plugins.md) Supported Plugins page. At this point, it might be worth spending some time understanding 29 | how plugins get instantiated in the .comm field; that is the topic of the next section. 30 | 31 | How communication plugins are instantiated 32 | 33 | This section assumes that you know how to write a client application using iotkit-comm. If not, please go through the client 34 | tutorial first. 35 | 36 | The service's CommHandle * or client's CommHandle * field is instantiated automatically. iotkit-comm knows which plugin to 37 | use from the type.name field of the service specification or query. Let's consider the example of a client that wants 38 | to connect to a service providing temperature readings; this is the service query it might issue: 39 | 40 | { 41 | "name" : ".*temperature_sensor", 42 | "type" : { 43 | "name": "zmqpubsub", 44 | "protocol" : "tcp" 45 | } 46 | } 47 | 48 | The above query says that this client is looking for a service which uses the zmqpubsub communication plugin. The 49 | likely implication is that the client uses the same plugin to communicate. Now when a matching service is found, iotkit-comm 50 | will pass the corresponding service specification to the client side constructor of the zmqpubsub plugin. The 51 | constructor will then connect to the service. If all goes well, iotkit-comm will set the client's CommHandle * field to this 52 | newly created plugin object. 53 | 54 | Learn more 55 | 56 | 1) Write a communication plugin (coming soon).
57 | 2) Browse the list of [supported plugins](@ref supported-plugins.md) and their respective APIs. 58 | -------------------------------------------------------------------------------- /src/examples/distributed-thermostat/temperatureSensor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file temperatureSensor.c 25 | 26 | Sample client program of temperature sensor based on ZMQ Pub/Sub 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "iotkit-comm/iotkit-comm.h" 34 | #include "iotkit-comm/util.h" 35 | 36 | char *topic = NULL; 37 | 38 | /** Callback function. Once the service is advertised this callback function will be invoked 39 | 40 | * @param servSpec left for future purpose, currently unused 41 | * @param error_code the error code 42 | * @param serviceHandle the communication handle used to invoke the interfaces 43 | */ 44 | void pubServiceCallback(ServiceSpec *servSpec, int32_t error_code, CommHandle *serviceHandle) { 45 | 46 | if (serviceHandle != NULL) { 47 | int (**publish)(char *,Context context); 48 | publish = commInterfacesLookup(serviceHandle, "publish"); 49 | if (publish != NULL) { 50 | Context context; 51 | while(1) { // Infinite Event Loop 52 | char addr[128]; 53 | double random = floor(rand() % 90 + 60); 54 | sprintf(addr, "%s: %f",topic, random); 55 | printf("Publishing ... %s\n", addr); 56 | (*publish)(addr,context); 57 | sleep(2); 58 | } 59 | } else { 60 | fprintf(stderr, "Interface lookup failed\n"); 61 | } 62 | } else { 63 | fprintf(stderr, "Comm Handle is NULL\n"); 64 | } 65 | } 66 | 67 | /** The starting point. Starts to advertise the given Service 68 | */ 69 | int main(void) { 70 | 71 | puts("Temperature sensor publishing its temperature data !!"); 72 | ServiceSpec *serviceSpec = (ServiceSpec *) parseServiceSpec("./serviceSpecs/temperature-sensor-spec.json"); 73 | if (serviceSpec) { 74 | topic = serviceSpec->service_name; 75 | advertiseServiceBlocking(serviceSpec, pubServiceCallback); 76 | } 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /src/tests/mqttpubsub/test_mqttpubsub_client_subscribe_success.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file test_mqttpubsub_client_subscribe_success.c 25 | 26 | */ 27 | 28 | #include 29 | #include 30 | #include "iotkit-comm.h" 31 | 32 | bool receivedMessage = false; 33 | 34 | void message_callback(char *message, Context context) { 35 | printf("Message received:%s\n", message); 36 | receivedMessage = true; 37 | } 38 | 39 | int main(void) { 40 | ServiceQuery *serviceQuery = (ServiceQuery *)malloc(sizeof(ServiceQuery)); 41 | if (serviceQuery != NULL) { 42 | serviceQuery->service_name = strdup("/foo"); 43 | serviceQuery->address = strdup("localhost"); 44 | serviceQuery->port = 1883; 45 | int result = init(serviceQuery, NULL); 46 | if (result == MQTTASYNC_SUCCESS) { 47 | puts("Successfully Connected to an MQTT Broker"); 48 | receive(message_callback); 49 | result = subscribe("/foo"); //correct topic 50 | if (result == 0) { 51 | puts("Subscribed Successfully"); 52 | puts("Waiting for messages on subscribed topic"); 53 | Context context; 54 | context.name = "topic"; 55 | context.value = "/foo"; 56 | send("This is a test message", context); 57 | int timerIndex = 0; 58 | while(timerIndex < 10 && !receivedMessage) { // Wait for 10 seconds 59 | sleep(1); 60 | timerIndex ++; 61 | } 62 | if(receivedMessage) { 63 | puts("Test Passed: Successfully received message on subscribed topic"); 64 | exit(EXIT_SUCCESS); 65 | } else { 66 | puts("Test Failed: No message received on subscribed topic"); 67 | } 68 | } else { 69 | puts("Test Failed: Could not subscribe"); 70 | } 71 | } else { 72 | puts("Test Failed: Could not connect to MQTT Broker"); 73 | } 74 | done(); 75 | free(serviceQuery); 76 | } 77 | exit(EXIT_FAILURE); 78 | } 79 | -------------------------------------------------------------------------------- /src/examples/distributed-thermostat/dashboard.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file dashboard.c 25 | 26 | Sample client program of dashboard based on ZMQ Pub/Sub 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include "iotkit-comm/iotkit-comm.h" 33 | #include "iotkit-comm/util.h" 34 | 35 | /** Callback function. To to be invoked when it receives any messages for the subscribed topic 36 | * @param message the message received from service/publisher 37 | * @param context a context object 38 | */ 39 | void clientMessageCallback(char *message, Context context) { 40 | 41 | // remove the topic from the message content (the temperature) 42 | char *temperature = strstr(message,":"); 43 | if (temperature != NULL) { 44 | temperature++; 45 | fprintf(stdout,"Received mean temperature : %s\n", temperature); 46 | } 47 | } 48 | 49 | /** Callback function. Once the service is discovered this callback function will be invoked 50 | * @param queryDesc left for future purpose, currently unused 51 | * @param error_code the error code 52 | * @param commHandle the communication handle used to invoke the interfaces 53 | */ 54 | void subDiscoveryCallback(ServiceQuery *queryDesc, int32_t error_code, CommHandle *commHandle) { 55 | 56 | int (**receive)(void (*)(char *, Context)); 57 | if (commHandle != NULL) { 58 | receive = commInterfacesLookup(commHandle, "receive"); 59 | if (receive != NULL) { 60 | while (1) { // Infinite Event Loop 61 | (*receive)(clientMessageCallback); 62 | sleep(2); 63 | } 64 | } else { 65 | fprintf(stderr, "Interface lookup failed\n"); 66 | } 67 | } else { 68 | fprintf(stderr, "Comm Handle is NULL\n"); 69 | } 70 | } 71 | 72 | 73 | /** The starting point. Starts browsing for the given Service name 74 | */ 75 | int main(void) { 76 | 77 | puts("Dashboard reading the mean temperature from thermostat"); 78 | ServiceQuery *query = (ServiceQuery *) parseServiceQuery("./serviceQueries/thermostat-query.json"); 79 | if (query) { 80 | discoverServicesBlocking(query, subDiscoveryCallback); 81 | } 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /src/examples/zmq-apps/sample_zmqpubsub-service.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file sample_zmqpubsub-service.c 25 | Sample service program of ZMQ publisher. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm/iotkit-comm.h" 32 | #include "iotkit-comm/util.h" 33 | 34 | ServiceSpec *serviceSpec = NULL; 35 | char *topic = NULL; 36 | 37 | /** Callback function. Once the service is advertised, this callback function will be invoked. 38 | * @param[in] handle left for future purpose, currently unused 39 | * @param error_code the error code 40 | * @param serviceHandle the communication handle used to invoke the interfaces 41 | */ 42 | void pubServiceCallback(void *handle, int32_t error_code, CommHandle *serviceHandle) { 43 | if (serviceHandle != NULL) { 44 | int (**publish)(char *,Context context); 45 | int i = 0; 46 | 47 | publish = commInterfacesLookup(serviceHandle, "publish"); 48 | if (publish != NULL) { 49 | Context context; 50 | char message[256]; 51 | int temp[] = {70, 73, 64, 67, 71, 72, 78, 67, 66, 75}; 52 | while(i < 10) { // Event Loop 53 | sprintf(message, "%s: %d", topic, temp[i]); 54 | printf("Publishing ... %s\n", message); 55 | (*publish)(message,context); 56 | sleep(2); 57 | 58 | i ++; 59 | } 60 | 61 | // clean the service specification object 62 | cleanUpService(&serviceSpec, &serviceHandle); 63 | exit(0); 64 | } else { 65 | puts("Interface lookup failed"); 66 | } 67 | } else { 68 | puts("\nComm Handle is NULL\n"); 69 | } 70 | } 71 | 72 | /** The starting point. Starts to advertise the given Service. 73 | */ 74 | int main(void) { 75 | puts("Sample program to test the iotkit-comm ZMQ pub/sub plugin !!"); 76 | serviceSpec = (ServiceSpec *) parseServiceSpec("./serviceSpecs/temperatureServiceZMQPUBSUB.json"); 77 | 78 | if (serviceSpec) { 79 | topic = serviceSpec->service_name; 80 | advertiseServiceBlocking(serviceSpec, pubServiceCallback); 81 | } 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /src/examples/zmq-apps/sample_zmqpubsub-client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file sample_zmqpubsub-client.c 25 | Sample client program of ZMQ subscriber. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm/iotkit-comm.h" 32 | #include "iotkit-comm/util.h" 33 | 34 | ServiceQuery *servQuery = NULL; 35 | 36 | /** Callback function. To to be invoked when it receives any messages for the subscribed topic. 37 | * @param message the message received from service/publisher 38 | * @param context a context object 39 | */ 40 | void clientMessageCallback(char *message, Context context) { 41 | fprintf(stderr,"Message received in Client: %s\n", message); 42 | } 43 | 44 | /** Callback function. Once the service is discovered, this callback function will be invoked. 45 | * @param[in] handle left for future purpose, currently unused 46 | * @param error_code the error code 47 | * @param commHandle the communication handle used to invoke the interfaces 48 | */ 49 | void subDiscoveryCallback(void *handle, int32_t error_code, CommHandle *commHandle) { 50 | int (**receive)(void (*)(char *, Context)); 51 | int i = 0, j = 0; 52 | 53 | if (commHandle != NULL) { 54 | receive = commInterfacesLookup(commHandle, "receive"); 55 | 56 | if (receive != NULL) { 57 | while (j < 5) { // Event Loop 58 | i++; 59 | if (i < 5) { 60 | (*receive)(clientMessageCallback); 61 | } 62 | 63 | sleep(2); 64 | 65 | j ++; 66 | } 67 | 68 | // clean the service query object 69 | cleanUpService(&servQuery, &commHandle); 70 | exit(0); 71 | } else { 72 | puts("Interface lookup failed"); 73 | } 74 | } else { 75 | puts("\nComm Handle is NULL\n"); 76 | } 77 | } 78 | 79 | /** The starting point. Starts browsing for the given Service name. 80 | */ 81 | int main(void) { 82 | puts("Sample program to test the iotkit-comm ZMQ pub/sub plugin !!"); 83 | servQuery = (ServiceQuery *) parseServiceQuery("./serviceQueries/temperatureServiceQueryZMQPUBSUB.json"); 84 | 85 | if (servQuery) { 86 | fprintf(stderr,"query host address %s\n",servQuery->address); 87 | fprintf(stderr,"query host port %d\n",servQuery->port); 88 | fprintf(stderr,"query service name %s\n",servQuery->service_name); 89 | discoverServicesBlocking(servQuery, subDiscoveryCallback); 90 | } 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /src/examples/zmq-apps/sample_zmqreqrep-service.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file sample_zmqreqrep-service.c 25 | Sample service program of ZMQ replier. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm/iotkit-comm.h" 32 | #include "iotkit-comm/util.h" 33 | 34 | ServiceSpec *serviceSpec = NULL; 35 | 36 | /** Callback function. To to be invoked when it receives any messages from the Client. 37 | * @param client the client object 38 | * @param message the message received from client 39 | * @param context a context object 40 | */ 41 | void repMessageCallback(void *client, char *message, Context context) { 42 | fprintf(stderr,"Message received in Server: %s\n", message); 43 | } 44 | 45 | /** Callback function. Once the service is advertised, this callback function will be invoked. 46 | * @param[in] handle left for future purpose, currently unused 47 | * @param error_code the error code 48 | * @param serviceHandle the communication handle used to invoke the interfaces 49 | */ 50 | void repAdvertiseCallback(void *handle, int32_t error_code,CommHandle *serviceHandle) { 51 | if (serviceHandle != NULL) { 52 | void *client = NULL; 53 | Context context; 54 | void (**sendTo)(void *, char *, Context context); 55 | int (**receive)(void (*)(void *, char *, Context context)); 56 | int i = 0; 57 | 58 | sendTo = commInterfacesLookup(serviceHandle, "sendTo"); 59 | receive = commInterfacesLookup(serviceHandle, "receive"); 60 | if (sendTo != NULL && receive != NULL) { 61 | while(i < 10) { // Event Loop 62 | (*sendTo)(client,"train bike car",context); 63 | (*receive)(repMessageCallback); 64 | sleep(2); 65 | 66 | i ++; 67 | } 68 | 69 | // clean the service specification object 70 | cleanUpService(&serviceSpec, &serviceHandle); 71 | exit(0); 72 | } else { 73 | puts("Interface lookup failed"); 74 | } 75 | } else { 76 | puts("\nComm Handle is NULL\n"); 77 | } 78 | } 79 | 80 | /** The starting point. Starts to advertise the given Service. 81 | */ 82 | int main(void) { 83 | puts("Sample program to test the iotkit-comm ZMQ req/rep plugin !!"); 84 | serviceSpec = (ServiceSpec *) parseServiceSpec("./serviceSpecs/temperatureServiceZMQREQREP.json"); 85 | 86 | if (serviceSpec) { 87 | advertiseServiceBlocking(serviceSpec, repAdvertiseCallback); 88 | } 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /src/examples/zmq-apps/sample_zmqreqrep-client.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** @file sample_zmqreqrep-client.c 25 | Sample client program of ZMQ requester. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include "iotkit-comm/iotkit-comm.h" 32 | #include "iotkit-comm/util.h" 33 | 34 | ServiceQuery *query = NULL; 35 | 36 | /** Callback function. To be invoked when it receives any messages from the Service. 37 | * @param message the message received from service 38 | * @param context a context object 39 | */ 40 | void reqMessageCallback(char *message, Context context) { 41 | fprintf(stderr,"Message received in Client: %s\n", message); 42 | } 43 | 44 | /** Callback function. Once the service is discovered, this callback function will be invoked. 45 | * @param[in] handle left for future purpose, currently unused 46 | * @param error_code the error code 47 | * @param commHandle the communication handle used to invoke the interfaces 48 | */ 49 | void reqDiscoveryCallback(void *handle, int32_t error_code, CommHandle *commHandle) { 50 | if (commHandle != NULL) { 51 | int (**send)(char *, Context context); 52 | int (**receive)(void (*)(char *, Context)); 53 | Context context; 54 | int i = 0; 55 | 56 | send = commInterfacesLookup(commHandle, "send"); 57 | receive = commInterfacesLookup(commHandle, "receive"); 58 | if (send != NULL && receive != NULL) { 59 | while (i < 9) { // Event Loop 60 | (*send)("toys",context); 61 | (*receive)(reqMessageCallback); 62 | sleep(2); 63 | 64 | i ++; 65 | } 66 | 67 | // clean the service query object 68 | cleanUpService(&query, &commHandle); 69 | exit(0); 70 | } else { 71 | puts("Interface lookup failed"); 72 | } 73 | } else { 74 | puts("\nComm Handle is NULL\n"); 75 | } 76 | } 77 | 78 | /** The starting point. Starts browsing for the given Service name. 79 | */ 80 | int main(void) { 81 | puts("Sample program to test the iotkit-comm ZMQ req/rep plugin !!"); 82 | query = (ServiceQuery *) parseServiceQuery("./serviceQueries/temperatureServiceQueryZMQREQREP.json"); 83 | 84 | if (query) { 85 | fprintf(stderr,"query host address %s\n",query->address); 86 | fprintf(stderr,"query host port %d\n",query->port); 87 | fprintf(stderr,"query service name %s\n",query->service_name); 88 | discoverServicesBlocking(query, reqDiscoveryCallback); 89 | } 90 | 91 | return 0; 92 | } 93 | -------------------------------------------------------------------------------- /src/lib/cJSON/tests/test4: -------------------------------------------------------------------------------- 1 | {"web-app": { 2 | "servlet": [ 3 | { 4 | "servlet-name": "cofaxCDS", 5 | "servlet-class": "org.cofax.cds.CDSServlet", 6 | "init-param": { 7 | "configGlossary:installationAt": "Philadelphia, PA", 8 | "configGlossary:adminEmail": "ksm@pobox.com", 9 | "configGlossary:poweredBy": "Cofax", 10 | "configGlossary:poweredByIcon": "/images/cofax.gif", 11 | "configGlossary:staticPath": "/content/static", 12 | "templateProcessorClass": "org.cofax.WysiwygTemplate", 13 | "templateLoaderClass": "org.cofax.FilesTemplateLoader", 14 | "templatePath": "templates", 15 | "templateOverridePath": "", 16 | "defaultListTemplate": "listTemplate.htm", 17 | "defaultFileTemplate": "articleTemplate.htm", 18 | "useJSP": false, 19 | "jspListTemplate": "listTemplate.jsp", 20 | "jspFileTemplate": "articleTemplate.jsp", 21 | "cachePackageTagsTrack": 200, 22 | "cachePackageTagsStore": 200, 23 | "cachePackageTagsRefresh": 60, 24 | "cacheTemplatesTrack": 100, 25 | "cacheTemplatesStore": 50, 26 | "cacheTemplatesRefresh": 15, 27 | "cachePagesTrack": 200, 28 | "cachePagesStore": 100, 29 | "cachePagesRefresh": 10, 30 | "cachePagesDirtyRead": 10, 31 | "searchEngineListTemplate": "forSearchEnginesList.htm", 32 | "searchEngineFileTemplate": "forSearchEngines.htm", 33 | "searchEngineRobotsDb": "WEB-INF/robots.db", 34 | "useDataStore": true, 35 | "dataStoreClass": "org.cofax.SqlDataStore", 36 | "redirectionClass": "org.cofax.SqlRedirection", 37 | "dataStoreName": "cofax", 38 | "dataStoreDriver": "com.microsoft.jdbc.sqlserver.SQLServerDriver", 39 | "dataStoreUrl": "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon", 40 | "dataStoreUser": "sa", 41 | "dataStorePassword": "dataStoreTestQuery", 42 | "dataStoreTestQuery": "SET NOCOUNT ON;select test='test';", 43 | "dataStoreLogFile": "/usr/local/tomcat/logs/datastore.log", 44 | "dataStoreInitConns": 10, 45 | "dataStoreMaxConns": 100, 46 | "dataStoreConnUsageLimit": 100, 47 | "dataStoreLogLevel": "debug", 48 | "maxUrlLength": 500}}, 49 | { 50 | "servlet-name": "cofaxEmail", 51 | "servlet-class": "org.cofax.cds.EmailServlet", 52 | "init-param": { 53 | "mailHost": "mail1", 54 | "mailHostOverride": "mail2"}}, 55 | { 56 | "servlet-name": "cofaxAdmin", 57 | "servlet-class": "org.cofax.cds.AdminServlet"}, 58 | 59 | { 60 | "servlet-name": "fileServlet", 61 | "servlet-class": "org.cofax.cds.FileServlet"}, 62 | { 63 | "servlet-name": "cofaxTools", 64 | "servlet-class": "org.cofax.cms.CofaxToolsServlet", 65 | "init-param": { 66 | "templatePath": "toolstemplates/", 67 | "log": 1, 68 | "logLocation": "/usr/local/tomcat/logs/CofaxTools.log", 69 | "logMaxSize": "", 70 | "dataLog": 1, 71 | "dataLogLocation": "/usr/local/tomcat/logs/dataLog.log", 72 | "dataLogMaxSize": "", 73 | "removePageCache": "/content/admin/remove?cache=pages&id=", 74 | "removeTemplateCache": "/content/admin/remove?cache=templates&id=", 75 | "fileTransferFolder": "/usr/local/tomcat/webapps/content/fileTransferFolder", 76 | "lookInContext": 1, 77 | "adminGroupID": 4, 78 | "betaServer": true}}], 79 | "servlet-mapping": { 80 | "cofaxCDS": "/", 81 | "cofaxEmail": "/cofaxutil/aemail/*", 82 | "cofaxAdmin": "/admin/*", 83 | "fileServlet": "/static/*", 84 | "cofaxTools": "/tools/*"}, 85 | 86 | "taglib": { 87 | "taglib-uri": "cofax.tld", 88 | "taglib-location": "/WEB-INF/tlds/cofax.tld"}}} -------------------------------------------------------------------------------- /src/tests/mqttpubsub/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | INCLUDE_DIRECTORIES( 3 | ../../lib/cJSON 4 | ../../lib/iotkit-comm 5 | ../inc/ 6 | ) 7 | 8 | # set the source files list 9 | SET(MQTTPUBSUB_CLIENT_PUBLISH_SUCCESS test_mqttpubsub_client_publish_success.c ../../lib/plugins/libmqttpubsub/mqtt-client.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 10 | SET(MQTTPUBSUB_CLIENT_PUBLISH_FAIL test_mqttpubsub_client_publish_fail.c ../../lib/plugins/libmqttpubsub/mqtt-client.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 11 | SET(MQTTPUBSUB_CLIENT_CONNECT_SUCCESS test_mqttpubsub_client_connect_success.c ../../lib/plugins/libmqttpubsub/mqtt-client.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 12 | SET(MQTTPUBSUB_CLIENT_SUBSCRIBE_FAIL test_mqttpubsub_client_subscribe_fail.c ../../lib/plugins/libmqttpubsub/mqtt-client.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 13 | SET(MQTTPUBSUB_CLIENT_SUBSCRIBE_SUCCESS test_mqttpubsub_client_subscribe_success.c ../../lib/plugins/libmqttpubsub/mqtt-client.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 14 | SET(MQTTPUBSUB_CLIENT_UNSUBSCRIBE_SUCCESS test_mqttpubsub_client_unsubscribe_success.c ../../lib/plugins/libmqttpubsub/mqtt-client.c ../../lib/cJSON/cJSON.c ../../lib/iotkit-comm/iotkit-comm.c ../../lib/iotkit-comm/iotkit-comm_mdns.c) 15 | 16 | # create the executables 17 | ADD_EXECUTABLE(mqttpubsub_client_publish_success ${MQTTPUBSUB_CLIENT_PUBLISH_SUCCESS}) 18 | ADD_EXECUTABLE(mqttpubsub_client_publish_fail ${MQTTPUBSUB_CLIENT_PUBLISH_FAIL}) 19 | ADD_EXECUTABLE(mqttpubsub_client_connect_success ${MQTTPUBSUB_CLIENT_CONNECT_SUCCESS}) 20 | ADD_EXECUTABLE(mqttpubsub_client_subscribe_fail ${MQTTPUBSUB_CLIENT_SUBSCRIBE_FAIL}) 21 | ADD_EXECUTABLE(mqttpubsub_client_subscribe_success ${MQTTPUBSUB_CLIENT_SUBSCRIBE_SUCCESS}) 22 | ADD_EXECUTABLE(mqttpubsub_client_unsubscribe_success ${MQTTPUBSUB_CLIENT_UNSUBSCRIBE_SUCCESS}) 23 | 24 | 25 | SET_TARGET_PROPERTIES(mqttpubsub_client_publish_success PROPERTIES LINKER_LANGUAGE C) 26 | SET_TARGET_PROPERTIES(mqttpubsub_client_publish_fail PROPERTIES LINKER_LANGUAGE C) 27 | SET_TARGET_PROPERTIES(mqttpubsub_client_connect_success PROPERTIES LINKER_LANGUAGE C) 28 | SET_TARGET_PROPERTIES(mqttpubsub_client_subscribe_fail PROPERTIES LINKER_LANGUAGE C) 29 | SET_TARGET_PROPERTIES(mqttpubsub_client_subscribe_success PROPERTIES LINKER_LANGUAGE C) 30 | SET_TARGET_PROPERTIES(mqttpubsub_client_unsubscribe_success PROPERTIES LINKER_LANGUAGE C) 31 | 32 | 33 | # Link the executables 34 | TARGET_LINK_LIBRARIES(mqttpubsub_client_publish_success paho-mqtt3cs dns_sd m dl gcov) 35 | TARGET_LINK_LIBRARIES(mqttpubsub_client_publish_fail paho-mqtt3cs dns_sd m dl gcov) 36 | TARGET_LINK_LIBRARIES(mqttpubsub_client_connect_success paho-mqtt3cs dns_sd m dl gcov) 37 | TARGET_LINK_LIBRARIES(mqttpubsub_client_subscribe_fail paho-mqtt3cs dns_sd m dl gcov) 38 | TARGET_LINK_LIBRARIES(mqttpubsub_client_subscribe_success paho-mqtt3cs dns_sd m dl gcov) 39 | TARGET_LINK_LIBRARIES(mqttpubsub_client_unsubscribe_success paho-mqtt3cs dns_sd m dl gcov) 40 | 41 | 42 | # Add the Test 43 | ADD_TEST(mqttpubsub_client_publish_success ${CTEST_BINARY_DIRECTORY}/mqttpubsub_client_publish_success) 44 | ADD_TEST(mqttpubsub_client_publish_fail ${CTEST_BINARY_DIRECTORY}/mqttpubsub_client_publish_fail) 45 | ADD_TEST(mqttpubsub_client_connect_success ${CTEST_BINARY_DIRECTORY}/mqttpubsub_client_connect_success) 46 | ADD_TEST(mqttpubsub_client_subscribe_fail ${CTEST_BINARY_DIRECTORY}/mqttpubsub_client_subscribe_fail) 47 | ADD_TEST(mqttpubsub_client_subscribe_success ${CTEST_BINARY_DIRECTORY}/mqttpubsub_client_subscribe_success) 48 | ADD_TEST(mqttpubsub_client_unsubscribe_success ${CTEST_BINARY_DIRECTORY}/mqttpubsub_client_unsubscribe_success) 49 | -------------------------------------------------------------------------------- /src/examples/mqtt-apps/publisher.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file publisher.c 26 | * @brief Sample to demonstrate MQTT publisher through iotkit-comm API. 27 | * 28 | * Provides features to connect to an MQTT Broker and publish a topic. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include "iotkit-comm/iotkit-comm.h" 35 | #include "iotkit-comm/util.h" 36 | 37 | #ifndef DEBUG 38 | #define DEBUG 0 39 | #endif 40 | 41 | ServiceSpec *srvSpec = NULL; 42 | int msgnumber = 0; 43 | 44 | /** 45 | * @name Callback to handle the communication 46 | * @brief Handles the communication with an MQTT broker once the connection is established. 47 | * @param[in] handle left for future purpose, currently unused 48 | * @param[in] error_code specifies the error code is any 49 | * @param[in] serviceHandle is the client object initialized with the required APIs 50 | * 51 | * Handles the communication such as publishing data to an MQTT broker once the connection is established. 52 | */ 53 | void callback(void *handle, int32_t error_code, void *serviceHandle) { 54 | Context context; 55 | char msg[256]; 56 | int i = 0; 57 | CommHandle *commHandle = NULL; 58 | 59 | if (serviceHandle != NULL) { 60 | commHandle = (CommHandle *)serviceHandle; 61 | 62 | int (**send)(char *, Context context); 63 | 64 | send = commInterfacesLookup(commHandle, "publish"); 65 | if(send == NULL) { 66 | printf("Function \'send\' is not available; please verify the Plugin documentation !!\n"); 67 | return; 68 | } 69 | 70 | context.name = NULL; // use topic defined in service specification 71 | context.value = NULL; // use topic defined in service specification 72 | 73 | while(i < 10) { // Event Loop 74 | sprintf(msg, "This is a test message %d", msgnumber++); 75 | printf("Publishing msg:%s\n", msg); 76 | 77 | (*send)(msg, context); 78 | sleep(2); 79 | 80 | i ++; 81 | } 82 | } 83 | 84 | // clean the objects 85 | cleanUpService(&srvSpec, &commHandle); 86 | exit(0); 87 | } 88 | 89 | /** 90 | * @name Starts the application 91 | * @brief Starts the application to publish for a topic. 92 | * 93 | * Establishes the connection with an MQTT broker. 94 | */ 95 | int main(void) { 96 | 97 | puts("Sample program to publish topic \'/foo\' !!"); 98 | 99 | srvSpec = (ServiceSpec *) parseServiceSpec("./serviceSpecs/temperatureServiceMQTT.json"); 100 | 101 | if (srvSpec) { 102 | advertiseServiceBlocking(srvSpec, callback); 103 | } 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /src/examples/enableiot-apps/enableiot-publisher.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file enableiot-publisher.c 26 | * @brief Sample to demonstrate data publish through iotkit-comm API. 27 | * 28 | * Provides features to publish data to enableiot cloud 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include "iotkit-comm/iotkit-comm.h" 35 | #include "iotkit-comm/util.h" 36 | 37 | #ifndef DEBUG 38 | #define DEBUG 0 39 | #endif 40 | 41 | ServiceSpec *srvSpec = NULL; 42 | int msgnumber = 13; // iotkit-agent does not accept zero as sensor value; so assigning a non-zero value 43 | 44 | /** 45 | * @name Callback to handle the communication 46 | * @brief Handles the communication with enableiot cloud once the connection is established. 47 | * @param[in] handle left for future purpose, currently unused 48 | * @param[in] error_code specifies the error code any 49 | * @param[in] serviceHandle is the client object initialized with the required APIs 50 | * 51 | * Handles the communication, such as publishing data once the connection is established. 52 | */ 53 | void callback(void *handle, int32_t error_code, void *serviceHandle) { 54 | Context context; 55 | char msg[256]; 56 | int i = 0; 57 | CommHandle *commHandle = NULL; 58 | 59 | if(serviceHandle != NULL) { 60 | commHandle = (CommHandle *) serviceHandle; 61 | 62 | int (**publish) (char *message,Context context); 63 | 64 | publish = commInterfacesLookup(commHandle, "publish"); 65 | if(publish == NULL) { 66 | fprintf(stderr, "Function \'publish\' is not available; please verify the Plugin documentation !!\n"); 67 | return; 68 | } 69 | 70 | context.name = "topic"; 71 | context.value = "data"; 72 | 73 | while(i < 10) { // Event Loop 74 | sprintf(msg, "{\"name\": \"garage_sensor\", \"value\": %d}", msgnumber++); 75 | printf("Publishing msg:%s\n", msg); 76 | 77 | (*publish)(msg, context); 78 | sleep(2); 79 | 80 | i ++; 81 | } 82 | } 83 | 84 | // clean the objects 85 | cleanUpService(&srvSpec, &commHandle); 86 | exit(0); 87 | } 88 | 89 | /** 90 | * @name Starts the application 91 | * @brief Starts the application to publish data 92 | * 93 | * Establishes the connection with enableiot cloud 94 | */ 95 | int main(void) { 96 | puts("Sample program to publish data to IoT Cloud !!"); 97 | 98 | srvSpec = (ServiceSpec *) parseServiceSpec("./serviceSpecs/temperatureServiceEnableIot.json"); 99 | 100 | if (srvSpec){ 101 | advertiseServiceBlocking(srvSpec, callback); 102 | } 103 | 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /src/examples/mqtt-apps/subscriber.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | /** 25 | * @file subscriber.c 26 | * @brief Sample to demonstrate MQTT subscriber through iotkit-comm API. 27 | * 28 | * Provides features to connect to an MQTT Broker and subscribe to a topic. 29 | */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include "iotkit-comm/iotkit-comm.h" 35 | #include "iotkit-comm/util.h" 36 | 37 | ServiceQuery *query = NULL; 38 | CommHandle *commHandle = NULL; 39 | int i = 0; 40 | 41 | /** 42 | * @name Message handler 43 | * @brief Callback invoked upon receiving a message from an MQTT broker. 44 | * @param[in] message received from an MQTT broker 45 | * @param[in] context with the topic information 46 | * 47 | * Callback invoked upon receiving a message from an MQTT broker. 48 | */ 49 | void message_callback(char *message, Context context) { 50 | printf("Message received:%s\n", message); 51 | 52 | i ++; 53 | 54 | if(i >= 5) { 55 | // clean the service query object 56 | cleanUpService(&query, &commHandle); 57 | exit(0); 58 | } 59 | } 60 | 61 | int serviceStarted = 0; 62 | 63 | /** 64 | * @name Callback to handle the communication 65 | * @brief Handles the communication with an MQTT broker once the connection is established. 66 | * @param[in] handle left for future purpose, currently unused 67 | * @param[in] error_code specifies the error code is any 68 | * @param[in] serviceHandle is the client object initialized with the required APIs 69 | * 70 | * Handles the communication with an MQTT broker once the connection is established. 71 | */ 72 | void callback(void *handle, int32_t error_code, void *serviceHandle) { 73 | if (serviceHandle != NULL && !serviceStarted) { 74 | commHandle = (CommHandle *) serviceHandle; 75 | int (**receive)(void (*)(char *, Context)) = NULL; 76 | 77 | receive = commInterfacesLookup(commHandle, "receive"); 78 | if (receive == NULL) { 79 | printf("Function \'receive\' is not available; please verify the Plugin documentation !!\n"); 80 | return; 81 | } 82 | 83 | (*receive)(message_callback); 84 | 85 | serviceStarted = 1; 86 | } 87 | } 88 | 89 | /** 90 | * @name Callback to filter discovered services 91 | * @brief Handles service filtering after discovery 92 | * @param[in] srvQuery service query object 93 | * 94 | * Handles service filtering after discovery 95 | */ 96 | bool serviceFilter(ServiceQuery *srvQuery) { 97 | printf("Got into Service Filter\n"); 98 | return true; 99 | } 100 | 101 | /** 102 | * @name Starts the application 103 | * @brief Starts the application to subscribe to a topic. 104 | * 105 | * Establishes the connection with an MQTT broker. 106 | */ 107 | int main(void) { 108 | 109 | puts("Sample program to test the iotkit-comm MQTT pub/sub plugin !!"); 110 | query = (ServiceQuery *) parseServiceQuery("./serviceQueries/temperatureServiceQueryMQTT.json"); 111 | 112 | if (query) { 113 | discoverServicesBlockingFiltered(query, serviceFilter, callback); 114 | } 115 | 116 | return 0; 117 | } 118 | -------------------------------------------------------------------------------- /tutorials/client.md: -------------------------------------------------------------------------------- 1 | 2 | Writing a client using iotkit-comm requires three fundamental steps:
3 | 1) Write a service query
4 | 2) Create a client that queries for the service
5 | 3) Compile the client
6 | 4) Run the client
7 | 8 | Write a service query 9 | 10 | A service query is a JSON string that specifies the attributes of the service a client wishes to connect to. In 11 | this example, the service query similar to the service specification shown in the [service](@ref service.md) 12 | tutorial. It is assumed that the service query is written into file client-query.json 13 | 14 | { 15 | "name": "/ndg/temperature/cpuTemp", 16 | "type": { 17 | "name": "zmqreqrep", 18 | "protocol": "tcp" 19 | }, 20 | "properties": {"dataType": "float", "unit": "F"}, 21 | } 22 | 23 | Create a client that queries for the service 24 | 25 | Now here's the source code for the client (place in file zmqreqrep-client.c): 26 | 27 | #include 28 | #include 29 | #include 30 | #include "iotkit-comm/iotkit-comm.h" 31 | #include "iotkit-comm/util.h" 32 | 33 | ServiceQuery *query = NULL; 34 | 35 | void reqMessageCallback(char *message, Context context) { 36 | fprintf(stderr,"Message received in Client: %s\n", message); 37 | } 38 | 39 | void reqDiscoveryCallback(void *handle, int32_t error_code, CommHandle *commHandle) { 40 | if (commHandle != NULL) { 41 | int (**send)(char *, Context context); 42 | int (**receive)(void (*)(char *, Context)); 43 | Context context; 44 | int i = 0; 45 | 46 | send = commInterfacesLookup(commHandle, "send"); 47 | receive = commInterfacesLookup(commHandle, "receive"); 48 | if (send != NULL && receive != NULL) { 49 | while (i < 9) { // Event Loop 50 | (*send)("toys",context); 51 | (*receive)(reqMessageCallback); 52 | sleep(2); 53 | 54 | i ++; 55 | } 56 | 57 | // clean the service query object 58 | cleanUpService(&query, &commHandle); 59 | exit(0); 60 | } else { 61 | puts("Interface lookup failed"); 62 | } 63 | } else { 64 | puts("\nComm Handle is NULL\n"); 65 | } 66 | } 67 | 68 | int main(void) { 69 | puts("Sample program to test the iotkit-comm ZMQ req/rep plugin !!"); 70 | query = (ServiceQuery *) parseServiceQuery("./serviceQueries/temperatureServiceQueryZMQREQREP.json"); 71 | 72 | if (query) { 73 | discoverServicesBlocking(query, reqDiscoveryCallback); 74 | } 75 | 76 | return 0; 77 | } 78 | 79 | Notice that the client does not need to know the IP address of the service or even how to communicate with it. Instead, 80 | the service query takes care of such details. For example, this client specifies the name of the service and the 81 | protocol the service should be speaking (zmqreqrep). When the service is found, iotkit-comm returns a client object with an 82 | appropriately initialized communication handle client.comm. This handle is an instance of the zmqreqrep plugin 83 | connected to the service. More on communication plugins later, but for now a brief note, 84 | on communication plugins is they provide functions like send and receive. The main difference 85 | between the various communication plugins is how the send and receive happen (e.g. different packet format and headers). 86 | Note that iotkit-comm comes bundled with a few default communication plugins, but its also easy to write your own if necessary. 87 | 88 | Compile the client 89 | 90 | $ cc -o client zmqreqrep-client.c -liotkit-comm -ldns_sd -ldl -lm
91 | 92 | Run the client 93 | 94 | $ ./client 95 | 96 | Learn More 97 | 98 | • Write the corresponding [service](@ref service.md)
99 | • Understand service [specifications and queries](@ref service-spec-query.md) (important)
100 | • Learn to write a more comprehensive [distributed application](@ref application.md)
101 | • Understand and write [communication plugins](@ref plugin.md)
102 | --------------------------------------------------------------------------------