Commit 04471e61 authored by Jozef Kralik's avatar Jozef Kralik Committed by Kishen Maloor

[LITE-43] Implement Cloud service

Provides API for connect a device to the Cloud Interface.

Cloud Sample apps/cloud_linux.c
Cloud API: service/cloud/include/cloud.h

Limitations:
 * Cloud always try to connect to the Cloud Interface
 * Delays are not configurable (ping, publish resources, ...)
 * Sid isn't verified

Change-Id: I3faf440f0fd00648cf0e01f50763d80c785cd734
Signed-off-by: Jozef Kralik's avatarJozef Kralik <jojo.lwin@gmail.com>
parent 9ebd8821
......@@ -13,9 +13,17 @@ port/linux/multi_device_server
port/linux/onboarding_tool
port/linux/server_multithread_linux
port/linux/client_multithread_linux
port/linux/cloud_linux
port/linux/cloud_linux_creds/
port/linux/libiotivity-constrained-client.*
port/linux/libiotivity-constrained-server.*
port/linux/libiotivity-constrained-client-server.*
port/linux/iotivity-constrained-cloud.pc
port/linux/iotivity-constrained-cloud.a
port/linux/iotivity-constrained-cloud.so
port/linux/iotivity-constrained-rd-client.pc
port/linux/iotivity-constrained-rd-client.a
port/linux/iotivity-constrained-rd-client.so
port/linux/iotivity-constrained-server.pc
port/linux/iotivity-constrained-client.pc
port/linux/iotivity-constrained-client-server.pc
......@@ -40,10 +48,19 @@ port/openthread/output
*.o
*.cmd
*.tmp
*.gcda
*.gcno
.clang-format
_clang-format
port/linux/platformtest
port/linux/storage_test
port/linux/apitest
port/linux/cloudaccesstest
port/linux/messagingtest
port/linux/rdclienttest
port/linux/securitytest
port/linux/simpleserver_pki
port/linux/stapptest
#creds files
port/linux/client_creds
......@@ -59,5 +76,9 @@ port/linux/multi_device_server_creds
port/linux/server_multithread_linux_creds
port/linux/client_multithread_linux_creds
#service
service/cloud-access/unittest/obj
service/resource-directory/client/unittest/obj
#vscode setting files
.vscode
.vscode
\ No newline at end of file
......@@ -142,6 +142,9 @@ port/<OS>/*
apps/*
contains sample OCF applications.
service/*
contains OCF services
Setup source tree
-----------------
......@@ -168,6 +171,9 @@ Add ``TCP=1`` to include support for TCP endpoints and CoAP over TCP (RFC 8323).
Add ``IPV4=1`` to include IPv4 support in the build. Excluding ``IPV4=1``
produces an IPv6-only build.
Add ``CLOUD=1`` to include OCF Cloud in the build. TCP and IPv4
are included too.
Building sample applications on Windows
---------------------------------------
......
/****************************************************************************
*
* Copyright 2019 Jozef Kralik All Rights Reserved.
* Copyright 2018 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
#include "cloud.h"
#include "oc_api.h"
#include "oc_core_res.h"
#include "port/oc_clock.h"
#include "rd_client.h"
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
// define application specific values.
static const char *spec_version = "ocf.1.0.0";
static const char *data_model_version = "ocf.res.1.0.0";
static const char *resource_rt = "core.light";
static const char *device_rt = "oic.d.cloudDevice";
static const char *device_name = "Cloud Device";
static const char *manufacturer = "ocfcloud.com";
pthread_mutex_t mutex;
pthread_cond_t cv;
oc_resource_t *res1;
oc_resource_t *res2;
int quit = 0;
static void cloud_status_handler(cloud_status_t status, void *user_data) {
(void)user_data;
printf("cloud_status: %d\n", (int)status);
}
static int app_init(void) {
int ret = oc_init_platform(manufacturer, NULL, NULL);
ret |= oc_add_device("/oic/d", device_rt, device_name, spec_version,
data_model_version, NULL, NULL);
ret |= cloud_init(0, cloud_status_handler, NULL);
return ret;
}
struct light_t {
bool state;
int power;
};
struct light_t light1 = {0};
struct light_t light2 = {0};
static void get_handler(oc_request_t *request, oc_interface_mask_t interface,
void *user_data) {
struct light_t *light = (struct light_t *)user_data;
printf("get_handler:\n");
oc_rep_start_root_object();
switch (interface) {
case OC_IF_BASELINE:
oc_process_baseline_interface(request->resource);
/* fall through */
case OC_IF_RW:
oc_rep_set_boolean(root, state, light->state);
oc_rep_set_int(root, power, light->power);
oc_rep_set_text_string(root, name, "Light");
break;
default:
break;
}
oc_rep_end_root_object();
oc_send_response(request, OC_STATUS_OK);
}
static void post_handler(oc_request_t *request, oc_interface_mask_t iface_mask,
void *user_data) {
struct light_t *light = (struct light_t *)user_data;
(void)iface_mask;
printf("post_handler:\n");
oc_rep_t *rep = request->request_payload;
while (rep != NULL) {
char *key = oc_string(rep->name);
printf("key: %s ", key);
if (key && !strcmp(key, "state")) {
switch (rep->type) {
case OC_REP_BOOL:
light->state = rep->value.boolean;
printf("value: %d\n", light->state);
break;
default:
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
}
} else if (key && !strcmp(key, "power")) {
switch (rep->type) {
case OC_REP_INT:
light->power = rep->value.integer;
printf("value: %d\n", light->power);
break;
default:
oc_send_response(request, OC_STATUS_BAD_REQUEST);
return;
}
}
rep = rep->next;
}
oc_send_response(request, OC_STATUS_CHANGED);
oc_notify_observers(request->resource);
}
static void register_resources(void) {
res1 = oc_new_resource(NULL, "/light/1", 1, 0);
oc_resource_bind_resource_type(res1, resource_rt);
oc_resource_bind_resource_interface(res1, OC_IF_RW);
oc_resource_set_default_interface(res1, OC_IF_RW);
oc_resource_set_discoverable(res1, true);
oc_resource_set_observable(res1, true);
oc_resource_set_request_handler(res1, OC_GET, get_handler, &light1);
oc_resource_set_request_handler(res1, OC_POST, post_handler, &light1);
cloud_rd_publish(res1);
oc_add_resource(res1);
res2 = oc_new_resource(NULL, "/light/2", 1, 0);
oc_resource_bind_resource_type(res2, resource_rt);
oc_resource_bind_resource_interface(res2, OC_IF_RW);
oc_resource_set_default_interface(res2, OC_IF_RW);
oc_resource_set_discoverable(res2, true);
oc_resource_set_observable(res2, true);
oc_resource_set_request_handler(res2, OC_GET, get_handler, &light2);
oc_resource_set_request_handler(res2, OC_POST, post_handler, &light2);
cloud_rd_publish(res2);
oc_add_resource(res2);
}
static void signal_event_loop(void) {
pthread_mutex_lock(&mutex);
pthread_cond_signal(&cv);
pthread_mutex_unlock(&mutex);
}
void handle_signal(int signal) {
(void)signal;
signal_event_loop();
quit = 1;
}
int main(void) {
int init;
struct sigaction sa;
sigfillset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = handle_signal;
sigaction(SIGINT, &sa, NULL);
static const oc_handler_t handler = {.init = app_init,
.signal_event_loop = signal_event_loop,
.register_resources =
register_resources};
oc_storage_config("./cloud_linux_creds");
if (pthread_mutex_init(&mutex, NULL) < 0) {
printf("pthread_mutex_init failed!\n");
return -1;
}
init = oc_main_init(&handler);
if (init < 0)
return init;
while (quit != 1) {
oc_clock_time_t next_event = oc_main_poll();
pthread_mutex_lock(&mutex);
if (next_event == 0) {
pthread_cond_wait(&cv, &mutex);
} else {
struct timespec ts;
ts.tv_sec = (next_event / OC_CLOCK_SECOND);
ts.tv_nsec = (next_event % OC_CLOCK_SECOND) * 1.e09 / OC_CLOCK_SECOND;
pthread_cond_timedwait(&cv, &mutex, &ts);
}
pthread_mutex_unlock(&mutex);
}
cloud_shutdown(0);
oc_main_shutdown();
return 0;
}
......@@ -55,6 +55,17 @@ MESSAGING_TEST_DIR = $(ROOT_DIR)/messaging/coap/unittest
MESSAGING_TEST_OBJ_DIR = $(MESSAGING_TEST_DIR)/obj
MESSAGING_TEST_SRC_FILES := $(wildcard $(MESSAGING_TEST_DIR)/*.cpp)
MESSAGING_TEST_OBJ_FILES := $(patsubst $(MESSAGING_TEST_DIR)/%.cpp,$(MESSAGING_TEST_OBJ_DIR)/%.o,$(MESSAGING_TEST_SRC_FILES))
CLOUD_TEST_DIR = $(ROOT_DIR)/service/cloud/unittest
CLOUD_TEST_OBJ_DIR = $(CLOUD_TEST_DIR)/obj
CLOUD_TEST_SRC_FILES := $(wildcard $(CLOUD_TEST_DIR)/*.cpp)
CLOUD_TEST_OBJ_FILES := $(patsubst $(CLOUD_TEST_DIR)/%.cpp,$(CLOUD_TEST_OBJ_DIR)/%.o,$(CLOUD_TEST_SRC_FILES))
RD_CLIENT_TEST_DIR = $(ROOT_DIR)/service/resource-directory/client/unittest
RD_CLIENT_TEST_OBJ_DIR = $(RD_CLIENT_TEST_DIR)/obj
RD_CLIENT_TEST_SRC_FILES := $(wildcard $(RD_CLIENT_TEST_DIR)/*.cpp)
RD_CLIENT_TEST_OBJ_FILES := $(patsubst $(RD_CLIENT_TEST_DIR)/%.cpp,$(RD_CLIENT_TEST_OBJ_DIR)/%.o,$(RD_CLIENT_TEST_SRC_FILES))
UNIT_TESTS = apitest platformtest securitytest messagingtest
DTLS= aes.c aesni.c arc4.c asn1parse.c asn1write.c base64.c \
......@@ -78,6 +89,8 @@ CTIMESTAMP=../../api/c-timestamp/timestamp_format.c ../../api/c-timestamp/timest
SRC_COMMON=$(wildcard ../../util/*.c) ${CBOR} ${CTIMESTAMP}
SRC=$(wildcard ../../messaging/coap/*.c ../../api/*.c ../../port/linux/*.c)
SRC_CLOUD=$(wildcard ../../service/cloud/src/*.c)
SRC_RD_CLIENT=$(wildcard ../../service/resource-directory/client/src/*.c)
HEADERS = $(wildcard ../../include/*.h)
HEADERS += ../../port/linux/oc_config.h
......@@ -88,17 +101,29 @@ HEADERS_UTIL_PT = $(wildcard ../../util/pt/*.h)
HEADERS_PORT = $(wildcard ../../port/*.h)
HEADERS_TINYCBOR = $(wildcard ../../deps/tinycbor/src/*.h)
CFLAGS_CLOUD=-I../../service/cloud/include
CFLAGS_RD_CLIENT=-I../../service/resource-directory/client/include
CFLAGS=-fPIC -fno-asynchronous-unwind-tables -fno-omit-frame-pointer -ffreestanding -Os -fno-stack-protector -ffunction-sections -fdata-sections -fno-reorder-functions -fno-defer-pop -fno-strict-overflow -I./ -I../../include/ -I../../ -std=gnu99 -Wall -Wextra -Werror -pedantic #-Wl,-Map,client.map
OBJ_COMMON=$(addprefix obj/,$(notdir $(SRC_COMMON:.c=.o)))
OBJ_CLIENT=$(addprefix obj/client/,$(notdir $(SRC:.c=.o)))
OBJ_SERVER=$(addprefix obj/server/,$(filter-out oc_obt.o oc_obt_otm_justworks.o oc_obt_otm_randompin.o,$(notdir $(SRC:.c=.o))))
OBJ_CLIENT_SERVER=$(addprefix obj/client_server/,$(notdir $(SRC:.c=.o)))
VPATH=../../messaging/coap/:../../util/:../../api/:../../deps/tinycbor/src/:../../deps/mbedtls/library:../../api/c-timestamp:
OBJ_CLOUD=$(addprefix obj/cloud/,$(notdir $(SRC_CLOUD:.c=.o)))
OBJ_RD_CLIENT=$(addprefix obj/rd_client/,$(notdir $(SRC_RD_CLIENT:.c=.o)))
VPATH=../../messaging/coap/:../../util/:../../api/:../../deps/tinycbor/src/:../../deps/mbedtls/library:../../api/c-timestamp:../../service/cloud/src/:../../service/resource-directory/client/src/:
LIBS?= -lm -pthread -lrt
SAMPLES = server client temp_sensor simpleserver simpleserver_pki simpleclient client_collections_linux \
server_collections_linux server_block_linux client_block_linux smart_home_server_linux multi_device_server multi_device_client smart_lock server_multithread_linux client_multithread_linux
ifeq ($(CLOUD),1)
HEADERS += $(wildcard ../../service/cloud/include/*.h)
HEADERS += $(wildcard ../../service/resource-directory/client/include/*.h)
CFLAGS += -DOC_CLOUD
TCP=1
IPV4=1
endif
OBT = onboarding_tool
ifeq ($(DEBUG),1)
......@@ -141,6 +166,8 @@ ifeq ($(TCP),1)
EXTRA_CFLAGS += -DOC_TCP
endif
CFLAGS += $(EXTRA_CFLAGS)
ifeq ($(MEMTRACE),1)
......@@ -152,9 +179,18 @@ SAMPLES_CREDS = $(addsuffix _creds, ${SAMPLES} ${OBT})
CONSTRAINED_LIBS = libiotivity-constrained-server.a libiotivity-constrained-client.a \
libiotivity-constrained-server.so libiotivity-constrained-client.so \
libiotivity-constrained-client-server.so libiotivity-constrained-client-server.a
PC = iotivity-constrained-client.pc iotivity-constrained-server.pc \
iotivity-constrained-client-server.pc
ifeq ($(CLOUD),1)
CONSTRAINED_LIBS += libiotivity-constrained-cloud.a libiotivity-constrained-cloud.so \
libiotivity-constrained-rd-client.a libiotivity-constrained-rd-client.so
UNIT_TESTS += cloudtest rdclienttest
PC += iotivity-constrained-rd-client.pc iotivity-constrained-cloud.pc
SAMPLES += cloud_linux
endif
all: $(CONSTRAINED_LIBS) $(SAMPLES) $(PC)
test: $(UNIT_TESTS)
......@@ -186,6 +222,20 @@ $(PLATFORM_TEST_OBJ_DIR)/%.o: $(PLATFORM_TEST_DIR)/%.cpp
platformtest: $(PLATFORM_TEST_OBJ_FILES) libiotivity-constrained-client-server.a | $(GTEST)
$(CXX) $(GTEST_CPPFLAGS) $(TEST_CXXFLAGS) $(EXTRA_CFLAGS) $(HEADER_DIR) -l:gtest_main.a -liotivity-constrained-client-server -L$(OUT_DIR) -L$(GTEST_DIR)/make -lpthread $^ -o $@
$(CLOUD_TEST_OBJ_DIR)/%.o: $(CLOUD_TEST_DIR)/%.cpp
@mkdir -p ${@D}
$(CXX) $(GTEST_CPPFLAGS) $(TEST_CXXFLAGS) $(EXTRA_CFLAGS) $(HEADER_DIR) $(CFLAGS_CLOUD) -I$(ROOT_DIR)/service/cloud/src -I$(ROOT_DIR)/deps/tinycbor/src -c $< -o $@
cloudtest: $(CLOUD_TEST_OBJ_FILES) libiotivity-constrained-cloud.a libiotivity-constrained-rd-client.a libiotivity-constrained-client-server.a | $(GTEST)
$(CXX) $(GTEST_CPPFLAGS) $(TEST_CXXFLAGS) $(EXTRA_CFLAGS) $(HEADER_DIR) $(CFLAGS_CLOUD) -l:gtest_main.a -liotivity-constrained-cloud -liotivity-constrained-rd-client -liotivity-constrained-client-server -L$(OUT_DIR) -L$(GTEST_DIR)/make -lpthread $^ -o $@
$(RD_CLIENT_TEST_OBJ_DIR)/%.o: $(RD_CLIENT_TEST_DIR)/%.cpp
@mkdir -p ${@D}
$(CXX) $(GTEST_CPPFLAGS) $(TEST_CXXFLAGS) $(EXTRA_CFLAGS) $(HEADER_DIR) $(CFLAGS_RD_CLIENT) -I$(ROOT_DIR)/deps/tinycbor/src -c $< -o $@
rdclienttest: $(RD_CLIENT_TEST_OBJ_FILES) libiotivity-constrained-rd-client.a libiotivity-constrained-client-server.a | $(GTEST)
$(CXX) $(GTEST_CPPFLAGS) $(TEST_CXXFLAGS) $(EXTRA_CFLAGS) $(HEADER_DIR) $(CFLAGS_RD_CLIENT) -l:gtest_main.a -liotivity-constrained-rd-client -liotivity-constrained-client-server -L$(OUT_DIR) -L$(GTEST_DIR)/make -lpthread $^ -o $@
$(MESSAGING_TEST_OBJ_DIR)/%.o: $(MESSAGING_TEST_DIR)/%.cpp
@mkdir -p ${@D}
$(CXX) $(GTEST_CPPFLAGS) $(TEST_CXXFLAGS) $(EXTRA_CFLAGS) $(HEADER_DIR) $(MESSAGING_HEADERS) -c $< -o $@
......@@ -211,6 +261,14 @@ obj/client_server/%.o: %.c
@mkdir -p ${@D}
${CC} -c -o $@ $< ${CFLAGS} -DOC_CLIENT -DOC_SERVER
obj/cloud/%.o: %.c
@mkdir -p ${@D}
${CC} -c -o $@ $< ${CFLAGS} ${CFLAGS_CLOUD} ${CFLAGS_RD_CLIENT}
obj/rd_client/%.o: %.c
@mkdir -p ${@D}
${CC} -c -o $@ $< ${CFLAGS} ${CFLAGS_RD_CLIENT}
obj/server/oc_introspection.o: ../../include/server_introspection.dat.h
obj/client/oc_introspection.o: ../../include/server_introspection.dat.h
obj/client_server/oc_introspection.o: ../../include/server_introspection.dat.h
......@@ -233,6 +291,18 @@ libiotivity-constrained-client-server.a: $(OBJ_COMMON) $(OBJ_CLIENT_SERVER)
libiotivity-constrained-client-server.so: $(OBJ_COMMON) $(OBJ_CLIENT_SERVER)
$(CC) -shared -o $@ $(OBJ_COMMON) $(OBJ_CLIENT_SERVER) $(LIBS)
libiotivity-constrained-cloud.a: $(OBJ_CLOUD)
$(AR) -rcs $@ $(OBJ_COMMON) $(OBJ_CLOUD)
libiotivity-constrained-cloud.so: $(OBJ_CLOUD)
$(CC) -shared -o $@ $(OBJ_COMMON) $(OBJ_CLOUD) $(LIBS)
libiotivity-constrained-rd-client.a: $(OBJ_RD_CLIENT)
$(AR) -rcs $@ $(OBJ_COMMON) $(OBJ_RD_CLIENT)
libiotivity-constrained-rd-client.so: $(OBJ_RD_CLIENT)
$(CC) -shared -o $@ $(OBJ_COMMON) $(OBJ_RD_CLIENT) $(LIBS)
server: libiotivity-constrained-server.a $(ROOT_DIR)/apps/server_linux.c
@mkdir -p $@_creds
${CC} -o $@ ../../apps/server_linux.c libiotivity-constrained-server.a -DOC_SERVER ${CFLAGS} ${LIBS}
......@@ -287,6 +357,10 @@ multi_device_client: libiotivity-constrained-client.a $(ROOT_DIR)/apps/multi_dev
@mkdir -p $@_creds
${CC} -o $@ ../../apps/multi_device_client_linux.c libiotivity-constrained-client.a -DOC_CLIENT ${CFLAGS} ${LIBS}
cloud_linux: libiotivity-constrained-client-server.a libiotivity-constrained-cloud.a libiotivity-constrained-rd-client.a $(ROOT_DIR)/apps/cloud_linux.c
@mkdir -p $@_creds
${CC} -o $@ ../../apps/cloud_linux.c libiotivity-constrained-client-server.a libiotivity-constrained-cloud.a libiotivity-constrained-rd-client.a -DOC_CLIENT -DOC_SERVER ${CFLAGS} ${CFLAGS_CLOUD} ${CFLAGS_ST} ${CFLAGS_RD_CLIENT} ${LIBS}
${OBT}: libiotivity-constrained-client.a $(ROOT_DIR)/onboarding_tool/obtmain.c
@mkdir -p $@_creds
${CC} -o $@ ../../onboarding_tool/obtmain.c libiotivity-constrained-client.a -DOC_CLIENT ${CFLAGS} ${LIBS}
......@@ -326,6 +400,24 @@ iotivity-constrained-client-server.pc: iotivity-constrained-client-server.pc.in
-e 's,@version@,$(VERSION),' \
-e 's,@extra_cflags@,$(EXTRA_CFLAGS),'
iotivity-constrained-rd-client.pc: iotivity-constrained-rd-client.pc.in
$(SED) > $@ < $< \
-e 's,@prefix@,$(prefix),' \
-e 's,@exec_prefix@,$(exec_prefix),' \
-e 's,@libdir@,$(libdir),' \
-e 's,@includedir@,$(includedir),' \
-e 's,@version@,$(VERSION),' \
-e 's,@extra_cflags@,$(EXTRA_CFLAGS),'
iotivity-constrained-cloud.pc: iotivity-constrained-cloud.pc.in
$(SED) > $@ < $< \
-e 's,@prefix@,$(prefix),' \
-e 's,@exec_prefix@,$(exec_prefix),' \
-e 's,@libdir@,$(libdir),' \
-e 's,@includedir@,$(includedir),' \
-e 's,@version@,$(VERSION),' \
-e 's,@extra_cflags@,$(EXTRA_CFLAGS),'
ifneq ($(SECURE),0)
MBEDTLS_PATCHES ?= $(sort $(wildcard ../../patches/*.patch))
${MBEDTLS_DIR}/.git:
......@@ -345,7 +437,7 @@ $(MBEDTLS_PATCH_FILE): ${MBEDTLS_DIR}/.git ${MBEDTLS_PATCHES}
endif
clean:
rm -rf obj $(PC) $(CONSTRAINED_LIBS) $(API_TEST_OBJ_FILES) $(SECURITY_TEST_OBJ_FILES) $(PLATFORM_TEST_OBJ_FILES) $(MESSAGING_TEST_OBJ_FILES) $(UNIT_TESTS) $(STORAGE_TEST_DIR)
rm -rf obj $(PC) $(CONSTRAINED_LIBS) $(API_TEST_OBJ_FILES) $(SECURITY_TEST_OBJ_FILES) $(PLATFORM_TEST_OBJ_FILES) $(MESSAGING_TEST_OBJ_FILES) $(UNIT_TESTS) $(STORAGE_TEST_DIR) $(CLOUD_TEST_OBJ_FILES) $(RD_CLIENT_TEST_OBJ_FILES)
cleanall: clean
rm -rf ${all} $(SAMPLES) $(TESTS) ${OBT} ${SAMPLES_CREDS} $(MBEDTLS_PATCH_FILE)
......
# Copyright (c) 2019 Jozef Kralik
# Copyright (c) 2018 Samsung Electronics All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libiotivity-constrained-cloud
Description: Iotivity constrained resource directory client library
Version: @version@
Libs.private: -lm -pthread
Cflags: -I${includedir}/iotivity-constrained @extra_cflags@
Libs: -L${libdir} -liotivity-constrained-cloud
# Copyright (c) 2019 Jozef Kralik
# Copyright (c) 2018 Samsung Electronics All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libiotivity-constrained-rd-client
Description: Iotivity constrained resource directory client library
Version: @version@
Libs.private: -lm -pthread
Cflags: -I${includedir}/iotivity-constrained @extra_cflags@
Libs: -L${libdir} -liotivity-constrained-rd-client
/****************************************************************************
*
* Copyright 2019 Jozef Kralik All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/
/**
@brief Cloud API for start cloud service.
@file
*/
#ifndef CLOUD_H
#define CLOUD_H
#include <oc_api.h>
#include <stdbool.h>
#include <stddef.h>
/**
@brief Cloud connection status.
*/
typedef enum {
CLOUD_INITIALIZED = 0,
CLOUD_SIGNED_UP = 1 << 0,
CLOUD_SIGNED_IN = 1 << 1,
CLOUD_REFRESHED_TOKEN = 1 << 2,
CLOUD_FAILED = 1 << 5,
CLOUD_RECONNECTING = 1 << 6,
} cloud_status_t;
/**
@brief A function pointer for handling the cloud status.
@param status Current status of the cloud.
*/
typedef void (*cloud_cb_t)(cloud_status_t status, void *user_data);
#ifdef __cplusplus
extern "C" {
#endif
/**
@brief Function for create cloud service.
@param device_index Index of the device for an unique identifier.
@param cb Callback function to return the st cloud manager status.
@return Returns 0 if successful, or -1 otherwise.
*/
int cloud_init(size_t device_index, cloud_cb_t cb, void *user_data);
/**
@brief Function for stop cloud.
@param device_index Index of the device for an unique identifier.
*/
void cloud_shutdown(size_t device_index);
/**
@brief Publish RD resource to Cloud Resource Directory.
@param res The resource for publish to the Cloud RD.
@return Returns 0 if success, otherwise error.
*/
int cloud_rd_publish(oc_resource_t *res);
/**
@brief Delete RD resource from Cloud Resource Directory.
@param res The resource for delete from the Cloud RD.
*/
void cloud_rd_delete(oc_resource_t *res);
#ifdef __cplusplus
}
#endif
#endif /* CLOUD_H */
/****************************************************************************
*
* Copyright 2019 Jozef Kralik All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************/
#include "cloud.h"
#include "cloud_internal.h"
#include "oc_api.h"
#include "oc_collection.h"
#include "oc_core_res.h"
#include "oc_network_monitor.h"
#ifdef OC_SECURITY
#include "security/oc_tls.h"
#endif
OC_LIST(cloud_context_list);
OC_MEMB(cloud_context_pool, cloud_context_t, OC_MAX_NUM_DEVICES);
void cloud_manager_cb(cloud_context_t *ctx) {
OC_DBG("cloud manager status changed %d", (int)ctx->store.status);
cloud_rd_manager_status_changed(ctx);
if (ctx->callback) {
ctx->callback(ctx->store.status, ctx->user_data);
}
}
void cloud_set_string(oc_string_t *dst, const char *data, size_t len) {
if (oc_string(*dst)) {
oc_free_string(dst);
}
if (data && len) {
oc_new_string(dst, data, len);
} else {
memset(dst, 0, sizeof(*dst));
}
}
static oc_event_callback_retval_t start_manager(void *user_data) {
cloud_context_t *ctx = (cloud_context_t *)user_data;
oc_free_endpoint(ctx->cloud_ep);
ctx->cloud_ep = oc_new_endpoint();
cloud_manager_start(ctx);