CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(iotcon C)
+PROJECT(org.tizen.iotcon-ptc-test C)
-INCLUDE(FindPkgConfig)
-
-SET(EXTRA_CFLAGS "-Wall -Werror-implicit-function-declaration -fvisibility=hidden")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-
-SET(CLIENT ${PROJECT_NAME})
-SET(DAEMON "${PROJECT_NAME}-daemon")
-
-IF(NOT DEFINED DBUS_INTERFACE)
- MESSAGE("No DBUS_INTERFACE. Check build system")
- SET(DBUS_INTERFACE "org.tizen.${PROJECT_NAME}.dbus")
-ENDIF(NOT DEFINED DBUS_INTERFACE)
-
-IF(TZ_VER_3)
- ADD_DEFINITIONS("-DTZ_VER_3")
-ENDIF(TZ_VER_3)
-
-ADD_SUBDIRECTORY(common)
-ADD_SUBDIRECTORY(lib)
-ADD_SUBDIRECTORY(daemon)
-ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(src1)
+ADD_SUBDIRECTORY(src2)
+++ /dev/null
-Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- 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.
-
+++ /dev/null
-Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
-Except as noted, this software is licensed under Apache License, Version 2.
-Please, see the LICENSE.APLv2 file for Apache license, version 2 terms and conditions.
+++ /dev/null
-SET(IC_DBUS "ic-dbus")
-STRING(REPLACE ".dbus" "." INTERFACE_PREFIX ${DBUS_INTERFACE})
-
-FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
-
-ADD_CUSTOM_COMMAND(
- OUTPUT dbus
- COMMAND ${GDBUS_CODEGEN} --generate-c-code ${IC_DBUS}
- --interface-prefix ${INTERFACE_PREFIX}
- --c-namespace ic
- ${IC_DBUS}.xml
- DEPENDS ${IC_DBUS}.xml)
-
-ADD_CUSTOM_TARGET(GENERATED_DBUS_CODE DEPENDS dbus)
+++ /dev/null
-#!/bin/sh
-
-DIR_PATH=`dirname $0`
-
-gdbus-codegen --generate-c-code "$DIR_PATH"/ic-dbus\
- --interface-prefix org.tizen.iotcon.\
- --c-namespace ic\
- "$DIR_PATH"/ic-dbus.xml
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__
-#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__
-
-#include "iotcon-errors.h"
-
-#ifndef IOTCON_DBUS_INTERFACE
-#define IOTCON_DBUS_INTERFACE "org.tizen.iotcon.dbus"
-#warning "IOTCON_DBUS_INTERFACE is redefined"
-#endif
-
-#define IOTCON_DBUS_OBJPATH "/org/tizen/iotcon/dbus"
-
-#define IC_DBUS_SIGNAL_LENGTH 30
-
-#define IC_DBUS_SIGNAL_REQUEST_HANDLER "REQ"
-#define IC_DBUS_SIGNAL_FOUND_RESOURCE "RES"
-#define IC_DBUS_SIGNAL_OBSERVE "OBSERVE"
-#define IC_DBUS_SIGNAL_DEVICE "DEVICE"
-#define IC_DBUS_SIGNAL_PLATFORM "PLATFORM"
-#define IC_DBUS_SIGNAL_PRESENCE "PRESENCE"
-#define IC_DBUS_SIGNAL_MONITORING "MONITORING"
-#define IC_DBUS_SIGNAL_CACHING "CACHING"
-
-#define IC_FEATURE_OIC "http://tizen.org/feature/iot.oic"
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_H__ */
+++ /dev/null
-<node>
- <interface name="org.tizen.iotcon.dbus">
- <method name="registerResource">
- <arg type="s" name="uri_path" direction="in"/>
- <arg type="as" name="resource_types" direction="in"/>
- <arg type="as" name="ifaces" direction="in"/>
- <arg type="i" name="properties" direction="in"/>
- <arg type="b" name="is_lite" direction="in"/>
- <arg type="x" name="signal_number" direction="out"/>
- <arg type="x" name="resource" direction="out"/>
- </method>
- <method name="unregisterResource">
- <arg type="x" name="resource" direction="in"/>
- </method>
- <method name="bindInterface">
- <arg type="x" name="resource" direction="in"/>
- <arg type="s" name="iface" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="bindType">
- <arg type="x" name="resource" direction="in"/>
- <arg type="s" name="type" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="bindResource">
- <arg type="x" name="parent" direction="in"/>
- <arg type="x" name="child" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="unbindResource">
- <arg type="x" name="parent" direction="in"/>
- <arg type="x" name="child" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="notify">
- <arg type="x" name="resource" direction="in"/>
- <arg type="av" name="notify_msg" direction="in"/>
- <arg type="ai" name="observers" direction="in"/>
- <arg type="i" name="qos" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="sendResponse">
- <arg type="(a(qs)ivxx)" name="response" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="findResource">
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="connectivity" direction="in"/>
- <arg type="s" name="type" direction="in"/>
- <arg type="b" name="is_secure" direction="in"/>
- <arg type="i" name="timeout" direction="in"/>
- <arg type="x" name="signal_number" direction="out"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="get">
- <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
- <arg type="a(ss)" name="query" direction="in"/>
- <arg type="(a(qs)vi)" name="ret" direction="out"/>
- </method>
- <method name="put">
- <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
- <arg type="(sasasa{sv}av)" name="repr" direction="in"/>
- <arg type="a(ss)" name="query" direction="in"/>
- <arg type="(a(qs)vi)" name="ret" direction="out"/>
- </method>
- <method name="post">
- <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
- <arg type="(sasasa{sv}av)" name="repr" direction="in"/>
- <arg type="a(ss)" name="query" direction="in"/>
- <arg type="(a(qs)vi)" name="ret" direction="out"/>
- </method>
- <method name="delete">
- <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
- <arg type="(a(qs)i)" name="ret" direction="out"/>
- </method>
- <method name="observerStart">
- <arg type="(ssba(qs)i)" name="remote_resource" direction="in"/>
- <arg type="i" name="observe_type" direction="in"/>
- <arg type="a(ss)" name="query" direction="in"/>
- <arg type="x" name="signal_number" direction="out"/>
- <arg type="x" name="observe_h" direction="out"/>
- </method>
- <method name="observerStop">
- <arg type="x" name="observe_h" direction="in"/>
- <arg type="a(qs)" name="options" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="getDeviceInfo">
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="connectivity" direction="in"/>
- <arg type="i" name="timeout" direction="in"/>
- <arg type="x" name="signal_number" direction="out"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="getPlatformInfo">
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="connectivity" direction="in"/>
- <arg type="i" name="timeout" direction="in"/>
- <arg type="x" name="signal_number" direction="out"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="subscribePresence">
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="connectivity" direction="in"/>
- <arg type="s" name="type" direction="in"/>
- <arg type="x" name="presence_h" direction="out"/>
- </method>
- <method name="unsubscribePresence">
- <arg type="x" name="presence_h" direction="in"/>
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="startPresence">
- <arg type="u" name="time_to_live" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="stopPresence">
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="startMonitoring">
- <arg type="s" name="uri_path" direction="in"/>
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="connectivity" direction="in"/>
- <arg type="x" name="signal_number" direction="out"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="stopMonitoring">
- <arg type="s" name="uri_path" direction="in"/>
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="startCaching">
- <arg type="s" name="uri_path" direction="in"/>
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="connectivity" direction="in"/>
- <arg type="x" name="signal_number" direction="out"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="stopCaching">
- <arg type="s" name="uri_path" direction="in"/>
- <arg type="s" name="host_address" direction="in"/>
- <arg type="i" name="ret" direction="out"/>
- </method>
- <method name="encapGetTimeInterval">
- <arg type="i" name="time_interval" direction="out"/>
- </method>
- <method name="encapSetTimeInterval">
- <arg type="i" name="time_interval" direction="in"/>
- </method>
- </interface>
-</node>
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_LOG_H__
-#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_LOG_H__
-
-#define IC_LOG_RED "\033[0;31m"
-#define IC_LOG_GREEN "\033[0;32m"
-#define IC_LOG_BROWN "\033[0;33m"
-#define IC_LOG_BLUE "\033[0;34m"
-#define IC_LOG_END "\033[0;m"
-
-#undef _DBG
-#undef _INFO
-#undef _WARN
-#undef _ERR
-
-#undef DBG
-#undef INFO
-#undef WARN
-#undef ERR
-
-#define TIZEN_DEBUG_ENABLE
-#define LOG_TAG "IOTCON"
-#include <dlog.h>
-
-#ifdef IC_DAEMON
-
-#define _DBG(fmt, arg...) SLOGD(IC_LOG_GREEN "<Daemon>" IC_LOG_END fmt, ##arg)
-#define _INFO(fmt, arg...) SLOGI(IC_LOG_GREEN "<Daemon>" IC_LOG_END fmt, ##arg)
-#define _WARN(fmt, arg...) SLOGW(IC_LOG_GREEN "<Daemon>" IC_LOG_END fmt, ##arg)
-#define _ERR(fmt, arg...) SLOGE(IC_LOG_GREEN "<Daemon>" IC_LOG_END fmt, ##arg)
-
-#else /* IC_DAEMON */
-
-#define _DBG(fmt, arg...) SLOGD(fmt, ##arg)
-#define _INFO(fmt, arg...) SLOGI(fmt, ##arg)
-#define _WARN(fmt, arg...) SLOGW(fmt, ##arg)
-#define _ERR(fmt, arg...) SLOGE(fmt, ##arg)
-
-#endif /* IC_DAEMON */
-
-#if 0
-#define _DBG(fmt, arg...) \
- printf("[IoTCon]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
-#define _INFO(fmt, arg...) \
- printf("[IoTCon]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
-#define _WARN(fmt, arg...) \
- printf("[IoTCon]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
-#define _ERR(fmt, arg...) \
- printf("[IoTCon]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
-#endif
-
-#define IC_DEBUGGING
-
-#ifdef IC_DEBUGGING
-
-#define FN_CALL _INFO(">>>>>>>> called")
-#define FN_END _INFO("<<<<<<<< ended")
-#define DBG(fmt, arg...) _DBG(fmt, ##arg)
-#define WARN(fmt, arg...) _WARN(IC_LOG_BROWN fmt IC_LOG_END, ##arg)
-#define ERR(fmt, arg...) _ERR(IC_LOG_RED fmt IC_LOG_END, ##arg)
-#define INFO(fmt, arg...) _INFO(IC_LOG_BLUE fmt IC_LOG_END, ##arg)
-#define SECURE_DBG(fmt, arg...) SECURE_SLOGD(fmt, ##arg)
-#define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
-
-#if __WORDSIZE == 64
-#define DBG_HANDLE(handle) _DBG("handle : %lld", #handle)
-#else
-#define DBG_HANDLE(handle) _DBG("handle : %d", #handle)
-#endif
-
-#else /* IC_DEBUGGING */
-
-#define FN_CALL
-#define FN_END
-#define DBG(fmt, arg...)
-#define WARN(fmt, arg...)
-#define ERR(fmt, arg...) _ERR(fmt, ##arg)
-#define INFO(fmt, arg...)
-#define SECURE_DBG(fmt, arg...)
-#define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
-
-#endif /* IC_DEBUGGING */
-
-#define RET_IF(expr) \
- do { \
- if (expr) { \
- ERR("(%s)", #expr); \
- return; \
- }\
- } while(0)
-
-#define RETV_IF(expr, val) \
- do {\
- if (expr) { \
- ERR("(%s)", #expr); \
- return (val); \
- } \
- } while(0)
-
-#define RETM_IF(expr, fmt, arg...) \
- do {\
- if (expr) { \
- ERR(fmt, ##arg); \
- return; \
- }\
- } while(0)
-
-#define RETVM_IF(expr, val, fmt, arg...) \
- do {\
- if (expr) { \
- ERR(fmt, ##arg); \
- return (val); \
- } \
- } while(0)
-
-#define ERR_IF(expr) \
- do { \
- if (expr) { \
- ERR("(%s)", #expr); \
- } \
- } while (0)
-
-#define WARN_IF(expr, fmt, arg...) \
- do { \
- if (expr) { \
- WARN(fmt, ##arg); \
- } \
- } while (0)
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_LOG_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-#include <system_info.h>
-
-#include "iotcon-types.h"
-#include "ic-common.h"
-#include "ic-log.h"
-#include "ic-utils.h"
-
-#ifdef TZ_VER_3
-static int _ic_oic_feature_supported = -1;
-#endif
-
-char* ic_utils_strdup(const char *src)
-{
- char *dest = NULL;
-
- RETV_IF(NULL == src, NULL);
-
- errno = 0;
- dest = strdup(src);
- if (NULL == dest) {
- ERR("strdup() Fail(%d)", errno);
- return NULL;
- }
-
- return dest;
-}
-
-
-const char* ic_utils_dbus_encode_str(const char *src)
-{
- return (src) ? src : IC_STR_NULL;
-}
-
-
-char* ic_utils_dbus_decode_str(char *src)
-{
- RETV_IF(NULL == src, NULL);
-
- if (IC_STR_EQUAL == strcmp(IC_STR_NULL, src))
- return NULL;
- else
- return src;
-}
-
-
-void ic_utils_gvariant_array_free(GVariant **value)
-{
- int i;
-
- for (i = 0; value[i]; i++)
- g_variant_unref(value[i]);
-
- free(value);
-}
-
-bool ic_utils_check_oic_feature_supported()
-{
-#ifdef TZ_VER_3
- if (_ic_oic_feature_supported < 0) {
- bool feature_supported = false;
- system_info_get_platform_bool(IC_FEATURE_OIC, &feature_supported);
- _ic_oic_feature_supported = feature_supported ? 1 : 0;
- }
- return _ic_oic_feature_supported;
-#else
- return true;
-#endif
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_UTILITY_H__
-#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_UTILITY_H__
-
-#include <glib.h>
-
-#include "iotcon-types.h"
-
-#define IC_EQUAL 0
-#define IC_STR_EQUAL 0
-#define IC_STR_NULL "(NULL)"
-
-char* ic_utils_strdup(const char *src);
-const char* ic_utils_dbus_encode_str(const char *src);
-char* ic_utils_dbus_decode_str(char *src);
-void ic_utils_gvariant_array_free(GVariant **value);
-bool ic_utils_check_oic_feature_supported();
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_COMMON_UTILITY_H__ */
+++ /dev/null
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common)
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/include)
-
-FILE(GLOB DAEMON_SRCS *.c ${CMAKE_SOURCE_DIR}/common/*.c)
-SET(DAEMON_SRCS ${DAEMON_SRCS} ${CMAKE_SOURCE_DIR}/common/ic-dbus.c)
-
-SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/ic-dbus.c
- PROPERTIES GENERATED TRUE)
-
-SET(PKG_MODULES gio-2.0 dlog gio-unix-2.0 capi-system-system-settings capi-system-info
- iotivity)
-
-IF(TZ_VER_3)
- SET(PKG_MODULES ${PKG_MODULES} cynara-client cynara-session cynara-creds-gdbus)
-ENDIF(TZ_VER_3)
-
-pkg_check_modules(daemon_pkgs REQUIRED ${PKG_MODULES})
-
-FOREACH(flag ${daemon_pkgs_CFLAGS_OTHER})
- IF(${flag} MATCHES "\\-D+")
- ADD_DEFINITIONS(${flag})
- ENDIF(${flag} MATCHES "\\-D+")
-ENDFOREACH(flag)
-
-INCLUDE_DIRECTORIES(${daemon_pkgs_INCLUDE_DIRS})
-LINK_DIRECTORIES(${daemon_pkgs_LIBRARY_DIRS})
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
-SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--hash-style=both -pie")
-ADD_DEFINITIONS("-DIOTCON_DBUS_INTERFACE=\"${DBUS_INTERFACE}\"")
-
-ADD_EXECUTABLE(${DAEMON} ${DAEMON_SRCS})
-ADD_DEPENDENCIES(${DAEMON} GENERATED_DBUS_CODE)
-
-TARGET_LINK_LIBRARIES(${DAEMON} ${daemon_pkgs_LIBRARIES})
-
-INSTALL(TARGETS ${DAEMON} DESTINATION ${BIN_INSTALL_DIR})
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-#include <gio/gio.h>
-#ifdef TZ_VER_3
-#include <cynara-client.h>
-#include <cynara-session.h>
-#include <cynara-creds-gdbus.h>
-#endif
-
-#include "iotcon.h"
-#include "ic-common.h"
-#include "icd.h"
-#include "icd-cynara.h"
-
-static const char *_icd_privileges_network[] = {
- /* network */
- "http://tizen.org/privilege/network.get",
- /* data */
- "http://tizen.org/privilege/d2d.datasharing",
- NULL,
-};
-
-#ifdef TZ_VER_3
-static cynara *_cynara;
-#endif
-
-int icd_cynara_init()
-{
-#ifdef TZ_VER_3
- int ret;
- ret = cynara_initialize(&_cynara, NULL);
-
- if (CYNARA_API_SUCCESS != ret) {
- ERR("cynara_initialize() Fail(%d)", ret);
- return IOTCON_ERROR_SYSTEM;
- }
-#endif
-
- return IOTCON_ERROR_NONE;
-}
-
-void icd_cynara_deinit()
-{
-#ifdef TZ_VER_3
- if (_cynara)
- cynara_finish(_cynara);
-
- _cynara = NULL;
-#endif
-}
-
-
-static int _icd_cynara_check(GDBusMethodInvocation *invocation, const char **privileges)
-{
-#ifdef TZ_VER_3
- FN_CALL;
- int i = 0;
- int ret;
- pid_t pid;
- char *user = NULL;
- char *client = NULL;
- char *session = NULL;
- const char *sender = NULL;
- GDBusConnection *conn = NULL;
-
- RETV_IF(NULL == _cynara, IOTCON_ERROR_SYSTEM);
- RETV_IF(NULL == invocation, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == privileges, IOTCON_ERROR_INVALID_PARAMETER);
-
- conn = g_dbus_method_invocation_get_connection(invocation);
- if (NULL == conn) {
- ERR("g_dbus_method_invocation_get_connection() return NULL");
- return IOTCON_ERROR_SYSTEM;
- }
-
- sender = g_dbus_method_invocation_get_sender(invocation);
- if (NULL == sender) {
- ERR("g_dbus_method_invocation_get_sender() return NULL");
- return IOTCON_ERROR_SYSTEM;
- }
-
- ret = cynara_creds_gdbus_get_client(conn, sender, CLIENT_METHOD_SMACK, &client);
- if (CYNARA_API_SUCCESS != ret) {
- ERR("cynara_creds_dbus_get_client() Fail(%d)", ret);
- return IOTCON_ERROR_SYSTEM;
- }
-
- ret = cynara_creds_gdbus_get_user(conn, sender, USER_METHOD_UID, &user);
- if (CYNARA_API_SUCCESS != ret) {
- ERR("cynara_creds_dbus_get_user() Fail(%d)", ret);
- free(client);
- return IOTCON_ERROR_SYSTEM;
- }
-
- ret = cynara_creds_gdbus_get_pid(conn, sender, &pid);
- if (CYNARA_API_SUCCESS != ret) {
- ERR("cynara_creds_gdbus_get_pid() Fail(%d)", ret);
- free(user);
- free(client);
- return IOTCON_ERROR_SYSTEM;
- }
-
- session = cynara_session_from_pid(pid);
- if (NULL == session) {
- ERR("cynara_session_from_pid() return NULL");
- free(user);
- free(client);
- return IOTCON_ERROR_SYSTEM;
- }
-
- while (privileges[i]) {
- SECURE_DBG("privileges[%d]: %s, user: %s, client: %s", i, privileges[i], user, client);
- ret = cynara_check(_cynara, client, session, user, privileges[i]);
- if (CYNARA_API_ACCESS_DENIED == ret) {
- ERR("Denied (%s)", privileges[i]);
- free(session);
- free(user);
- free(client);
- return IOTCON_ERROR_PERMISSION_DENIED;
- } else if (CYNARA_API_ACCESS_ALLOWED != ret) {
- ERR("cynara_check(%s) Fail(%d)", privileges[i], ret);
- free(session);
- free(user);
- free(client);
- return IOTCON_ERROR_SYSTEM;
- }
- i++;
- }
- free(session);
- free(user);
- free(client);
-#endif
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_cynara_check_network(GDBusMethodInvocation *invocation)
-{
- int ret;
-
- ret = _icd_cynara_check(invocation, _icd_privileges_network);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_icd_cynara_check() Fail(%d)", ret);
-
- return ret;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_CYNARA_H__
-#define __IOT_CONNECTIVITY_MANAGER_DAEMON_CYNARA_H__
-
-#include <gio/gio.h>
-
-int icd_cynara_init();
-void icd_cynara_deinit();
-int icd_cynara_check_network(GDBusMethodInvocation *invocation);
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_CYNARA_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdint.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-
-#include <octypes.h>
-
-#include "iotcon.h"
-#include "ic-common.h"
-#include "ic-utils.h"
-#include "ic-dbus.h"
-#include "icd.h"
-#include "icd-ioty.h"
-#include "icd-cynara.h"
-#include "icd-dbus.h"
-
-static icDbus *icd_dbus_object;
-
-/* global list to care resource handle for each client */
-static GList *icd_dbus_client_list;
-static GMutex icd_dbus_client_list_mutex;
-
-typedef struct _icd_dbus_client_s {
- gchar *bus_name;
- GList *resource_list;
- GList *presence_list;
- GList *observe_list;
- GList *encap_list;
-} icd_dbus_client_s;
-
-typedef struct _icd_resource_handle {
- OCResourceHandle handle;
- int64_t signal_number;
-} icd_resource_handle_s;
-
-typedef struct _icd_presence_handle {
- OCDoHandle handle;
- char *host_address;
-} icd_presence_handle_s;
-
-typedef struct _icd_encap_handle {
- int type;
- char *host_address;
- char *uri_path;
-} icd_encap_handle_s;
-
-icDbus* icd_dbus_get_object()
-{
- return icd_dbus_object;
-}
-
-
-int64_t icd_dbus_generate_signal_number()
-{
- static int64_t i = 0;
-
- return i++;
-}
-
-
-int icd_dbus_client_list_get_resource_info(OCResourceHandle handle,
- int64_t *signal_number, gchar **bus_name)
-{
- icd_dbus_client_s *client;
- GList *cur_client, *cur_hd;
- icd_resource_handle_s *rsrc_handle;
-
- RETV_IF(NULL == signal_number, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == bus_name, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- cur_client = icd_dbus_client_list;
- while (cur_client) {
- client = cur_client->data;
- if (NULL == client) {
- ERR("client is NULL");
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return IOTCON_ERROR_NO_DATA;
- }
-
- cur_hd = client->resource_list;
- while (cur_hd) {
- rsrc_handle = cur_hd->data;
-
- if (rsrc_handle->handle == handle) {
- DBG_HANDLE(handle);
- DBG("signal_number(%llx) found", rsrc_handle->signal_number);
- *signal_number = rsrc_handle->signal_number;
- *bus_name = ic_utils_strdup(client->bus_name);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return IOTCON_ERROR_NONE;
- }
- cur_hd = cur_hd->next;
- }
-
- cur_client = cur_client->next;
- }
-
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return IOTCON_ERROR_NO_DATA;
-}
-
-int icd_dbus_emit_signal(const char *dest, const char *signal_name, GVariant *value)
-{
- gboolean ret;
- GError *error = NULL;
- GDBusConnection *conn;
- icDbusSkeleton *skeleton;
-
- DBG("SIG : %s, %s", signal_name, g_variant_print(value, FALSE));
-
- skeleton = IC_DBUS_SKELETON(icd_dbus_get_object());
- conn = g_dbus_interface_skeleton_get_connection(G_DBUS_INTERFACE_SKELETON(skeleton));
-
- ret = g_dbus_connection_emit_signal(conn,
- dest,
- IOTCON_DBUS_OBJPATH,
- IOTCON_DBUS_INTERFACE,
- signal_name,
- value,
- &error);
- if (FALSE == ret) {
- ERR("g_dbus_connection_emit_signal() Fail(%s)", error->message);
- g_error_free(error);
- g_variant_unref(value);
- return IOTCON_ERROR_DBUS;
- }
-
- if (FALSE == g_dbus_connection_flush_sync(conn, NULL, &error)) {
- ERR("g_dbus_connection_flush_sync() Fail(%s)", error->message);
- g_error_free(error);
- g_variant_unref(value);
- return IOTCON_ERROR_DBUS;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_dbus_cleanup_resource_list(void *data)
-{
- int ret;
- icd_resource_handle_s *resource_handle = data;
-
- RET_IF(NULL == resource_handle);
- RET_IF(NULL == resource_handle->handle);
-
- DBG("Deregistering resource handle");
- DBG_HANDLE(resource_handle->handle);
-
- ret = icd_ioty_unregister_resource(resource_handle->handle);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_unregister_resource() Fail(%d)", ret);
-
- free(resource_handle);
-}
-
-
-static void _icd_dbus_cleanup_presence_list(void *data)
-{
- int ret;
- icd_presence_handle_s *presence_handle = data;
-
- RET_IF(NULL == presence_handle);
- RET_IF(NULL == presence_handle->handle);
-
- DBG("Deregistering presence handle");
- DBG_HANDLE(presence_handle->handle);
-
- ret = icd_ioty_unsubscribe_presence(presence_handle->handle,
- presence_handle->host_address);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_unsubscribe_presence() Fail(%d)", ret);
-
- free(presence_handle->host_address);
- free(presence_handle);
-}
-
-
-static void _icd_dbus_cleanup_observe_list(OCDoHandle data)
-{
- int ret;
-
- DBG("Deregistering observe handle");
- DBG_HANDLE(data);
-
- ret = icd_ioty_observer_stop(data, NULL);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_observer_stop() Fail(%d)", ret);
-}
-
-
-static void _icd_dbus_cleanup_encap_list(void *data)
-{
- int ret;
- icd_encap_handle_s *encap_handle = data;
-
- RET_IF(NULL == encap_handle);
-
- DBG("Deregistering encapsulation");
-
- ret = icd_ioty_stop_encap(encap_handle->type, encap_handle->uri_path,
- encap_handle->host_address);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_stop_encap() Fail(%d)", ret);
-
- free(encap_handle->uri_path);
- free(encap_handle->host_address);
- free(encap_handle);
-}
-
-
-static int _icd_dbus_client_list_cleanup_handle_list(GList *client_list)
-{
- FN_CALL;
- icd_dbus_client_s *client;
-
- RETV_IF(NULL == client_list, IOTCON_ERROR_INVALID_PARAMETER);
-
- client = client_list->data;
-
- /* resource list */
- g_list_free_full(client->resource_list, _icd_dbus_cleanup_resource_list);
- /* presence list */
- g_list_free_full(client->presence_list, _icd_dbus_cleanup_presence_list);
- /* observe list */
- g_list_free_full(client->observe_list, _icd_dbus_cleanup_observe_list);
- /* encapsulation list */
- g_list_free_full(client->encap_list, _icd_dbus_cleanup_encap_list);
-
- free(client->bus_name);
- client->bus_name = NULL;
- free(client);
- g_list_free(client_list);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _icd_dbus_client_list_compare_bus_name(const void *a, const void *b)
-{
- const icd_dbus_client_s *client = a;
-
- return g_strcmp0(client->bus_name, b);
-}
-
-
-static inline GList* _icd_dbus_client_list_find_client(const gchar *owner)
-{
- return g_list_find_custom(icd_dbus_client_list, owner,
- _icd_dbus_client_list_compare_bus_name);
-}
-
-
-static int _icd_dbus_client_list_get_client(const gchar *bus_name,
- icd_dbus_client_s **ret_client)
-{
- GList *found_client = NULL;
- icd_dbus_client_s *client = NULL;
-
- RETV_IF(NULL == bus_name, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == ret_client, IOTCON_ERROR_INVALID_PARAMETER);
-
- found_client = _icd_dbus_client_list_find_client(bus_name);
- if (found_client) {
- *ret_client = found_client->data;
- return IOTCON_ERROR_NONE;
- }
-
- client = calloc(1, sizeof(icd_dbus_client_s));
- if (NULL == client) {
- ERR("calloc(client) Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- client->bus_name = ic_utils_strdup(bus_name);
- if (NULL == client->bus_name) {
- ERR("ic_utils_strdup() Fail");
- free(client);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- DBG("new client(%s) added", bus_name);
- icd_dbus_client_list = g_list_append(icd_dbus_client_list, client);
- *ret_client = client;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_dbus_name_owner_changed_cb(GDBusConnection *conn,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- int ret;
- GList *client = NULL;
- gchar *name, *old_owner, *new_owner;
-
- g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner);
-
- if (0 == strlen(new_owner)) {
- g_mutex_lock(&icd_dbus_client_list_mutex);
- client = _icd_dbus_client_list_find_client(old_owner);
- if (client) { /* found bus name in our bus list */
- DBG("bus(%s) stopped", old_owner);
- icd_dbus_client_list = g_list_remove_link(icd_dbus_client_list, client);
- }
- g_mutex_unlock(&icd_dbus_client_list_mutex);
-
- if (client) {
- ret = _icd_dbus_client_list_cleanup_handle_list(client);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_icd_dbus_client_list_cleanup_handle_list() Fail(%d)", ret);
- }
- }
-}
-
-
-static int _icd_dbus_subscribe_name_owner_changed(GDBusConnection *conn)
-{
- FN_CALL;
- unsigned int id;
-
- id = g_dbus_connection_signal_subscribe(conn,
- "org.freedesktop.DBus", /* bus name */
- "org.freedesktop.DBus", /* interface */
- "NameOwnerChanged", /* member */
- "/org/freedesktop/DBus", /* path */
- NULL, /* arg0 */
- G_DBUS_SIGNAL_FLAGS_NONE,
- _icd_dbus_name_owner_changed_cb,
- NULL,
- NULL);
- if (0 == id) {
- ERR("g_dbus_connection_signal_subscribe() Fail");
- return IOTCON_ERROR_DBUS;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-static int _icd_dbus_resource_list_add(const gchar *bus_name, OCResourceHandle handle,
- int64_t signal_number)
-{
- int ret;
- icd_dbus_client_s *client = NULL;
- icd_resource_handle_s *resource_handle;
-
- RETV_IF(NULL == bus_name, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == handle, IOTCON_ERROR_INVALID_PARAMETER);
-
- resource_handle = calloc(1, sizeof(icd_resource_handle_s));
- if (NULL == resource_handle) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- resource_handle->handle = handle;
- resource_handle->signal_number = signal_number;
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- ret = _icd_dbus_client_list_get_client(bus_name, &client);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_client_list_get_client() Fail");
- free(resource_handle);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return ret;
- }
-
- DBG("Resource handle added in the client(%s)", bus_name);
- DBG_HANDLE(handle);
-
- client->resource_list = g_list_append(client->resource_list, resource_handle);
-
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_dbus_resource_list_remove(const gchar *bus_name, OCResourceHandle handle)
-{
- GList *cur_hd;
- GList *client_list = NULL;
- icd_dbus_client_s *client = NULL;
- icd_resource_handle_s *resource_handle;
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- client_list = _icd_dbus_client_list_find_client(bus_name);
- if (NULL == client_list) {
- ERR("_icd_dbus_client_list_find_client() Fail");
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return;
- }
-
- client = client_list->data;
- cur_hd = client->resource_list;
- while (cur_hd) {
- resource_handle = cur_hd->data;
-
- if (resource_handle->handle == handle) {
- DBG("Resource handle is removed");
- DBG_HANDLE(handle);
- client->resource_list = g_list_delete_link(client->resource_list, cur_hd);
- free(resource_handle);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return;
- }
- cur_hd = cur_hd->next;
- }
- g_mutex_unlock(&icd_dbus_client_list_mutex);
-}
-
-
-static int _icd_dbus_presence_list_add(const gchar *bus_name,
- OCDoHandle handle, const char *host_address)
-{
- int ret;
- icd_dbus_client_s *client = NULL;
- icd_presence_handle_s *presence_handle;
-
- RETV_IF(NULL == bus_name, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == handle, IOTCON_ERROR_INVALID_PARAMETER);
-
- presence_handle = calloc(1, sizeof(icd_presence_handle_s));
- if (NULL == presence_handle) {
- ERR("calloc(handle) Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- presence_handle->handle = handle;
- presence_handle->host_address = ic_utils_strdup(host_address);
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- ret = _icd_dbus_client_list_get_client(bus_name, &client);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_client_list_get_client() Fail(%d)", ret);
- free(presence_handle->host_address);
- free(presence_handle);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return ret;
- }
-
- DBG("Presence handle added in the client(%s)", bus_name);
- DBG_HANDLE(handle);
-
- client->presence_list = g_list_append(client->presence_list, presence_handle);
-
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_dbus_presence_list_remove(const gchar *bus_name,
- OCDoHandle handle)
-{
- GList *cur_hd;
- GList *client_list = NULL;
- icd_dbus_client_s *client = NULL;
- icd_presence_handle_s *presence_handle;
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- client_list = _icd_dbus_client_list_find_client(bus_name);
- if (NULL == client_list) {
- ERR("_icd_dbus_client_list_find_client() Fail");
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return;
- }
-
- client = client_list->data;
- cur_hd = client->presence_list;
- while (cur_hd) {
- presence_handle = cur_hd->data;
-
- if (presence_handle->handle == handle) {
- DBG("Presence handle is removed");
- DBG_HANDLE(handle);
- client->presence_list = g_list_delete_link(client->presence_list, cur_hd);
- free(presence_handle->host_address);
- free(presence_handle);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return;
- }
- cur_hd = cur_hd->next;
- }
- g_mutex_unlock(&icd_dbus_client_list_mutex);
-}
-
-
-static int _icd_dbus_observe_list_add(const gchar *bus_name, OCDoHandle handle)
-{
- int ret;
- icd_dbus_client_s *client = NULL;
-
- RETV_IF(NULL == bus_name, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == handle, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- ret = _icd_dbus_client_list_get_client(bus_name, &client);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_client_list_get_client() Fail(%d)", ret);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return ret;
- }
-
- DBG("Observe handle added in the client(%s)", bus_name);
- DBG_HANDLE(handle);
-
- client->observe_list = g_list_append(client->observe_list, handle);
-
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_dbus_observe_list_remove(const gchar *bus_name,
- OCDoHandle handle)
-{
- GList *cur_hd;
- GList *client_list = NULL;
- OCDoHandle observe_handle;
- icd_dbus_client_s *client = NULL;
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- client_list = _icd_dbus_client_list_find_client(bus_name);
- if (NULL == client_list) {
- ERR("_icd_dbus_client_list_find_client() Fail");
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return;
- }
-
- client = client_list->data;
- cur_hd = client->observe_list;
- while (cur_hd) {
- observe_handle = cur_hd->data;
-
- if (observe_handle == handle) {
- DBG("Observe handle is removed");
- DBG_HANDLE(handle);
- client->observe_list = g_list_delete_link(client->observe_list, cur_hd);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return;
- }
- cur_hd = cur_hd->next;
- }
- g_mutex_unlock(&icd_dbus_client_list_mutex);
-}
-
-
-static int _icd_dbus_encap_list_add(const gchar *bus_name, int type,
- const char *host_address, const char *uri_path)
-{
- int ret;
- icd_dbus_client_s *client = NULL;
- icd_encap_handle_s *encap_handle;
-
- RETV_IF(NULL == bus_name, IOTCON_ERROR_INVALID_PARAMETER);
-
- encap_handle = calloc(1, sizeof(icd_encap_handle_s));
- if (NULL == encap_handle) {
- ERR("calloc(handle) Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- encap_handle->type = type;
- encap_handle->host_address = ic_utils_strdup(host_address);
- encap_handle->uri_path = ic_utils_strdup(uri_path);
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- ret = _icd_dbus_client_list_get_client(bus_name, &client);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_client_list_get_client() Fail(%d)", ret);
- free(encap_handle->uri_path);
- free(encap_handle->host_address);
- free(encap_handle);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return ret;
- }
-
- DBG("encap info added in the client(%s)", bus_name);
-
- client->encap_list = g_list_append(client->encap_list, encap_handle);
-
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_dbus_encap_list_remove(const gchar *bus_name, int type,
- const char *host_address, const char *uri_path)
-{
- GList *cur_hd;
- GList *client_list = NULL;
- icd_dbus_client_s *client = NULL;
- icd_encap_handle_s *encap_handle;
-
- g_mutex_lock(&icd_dbus_client_list_mutex);
- client_list = _icd_dbus_client_list_find_client(bus_name);
- if (NULL == client_list) {
- ERR("_icd_dbus_client_list_find_client() Fail");
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return;
- }
-
- client = client_list->data;
- cur_hd = client->encap_list;
- while (cur_hd) {
- encap_handle = cur_hd->data;
-
- if (type == encap_handle->type
- && IC_STR_EQUAL == g_strcmp0(encap_handle->host_address, host_address)
- && IC_STR_EQUAL == g_strcmp0(encap_handle->uri_path, uri_path)) {
- DBG("encap info(%s, %s) removed", host_address, uri_path);
- client->encap_list = g_list_delete_link(client->encap_list, cur_hd);
- free(encap_handle->uri_path);
- free(encap_handle->host_address);
- free(encap_handle);
- g_mutex_unlock(&icd_dbus_client_list_mutex);
- return;
- }
- cur_hd = cur_hd->next;
- }
- g_mutex_unlock(&icd_dbus_client_list_mutex);
-}
-
-
-static gboolean _dbus_handle_register_resource(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *uri_path,
- const gchar* const *resource_types,
- const gchar* const *ifaces,
- gint properties,
- gboolean is_lite)
-{
- FN_CALL;
- int ret;
- const gchar *sender;
- OCResourceHandle handle;
- int64_t signal_number = 0;
-
- if (true == is_lite) {
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_register_resource(object, invocation, signal_number, ret);
- return TRUE;
- }
- }
-
- handle = icd_ioty_register_resource(uri_path, resource_types, ifaces, properties);
- if (handle) {
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- signal_number = icd_dbus_generate_signal_number();
- ret = _icd_dbus_resource_list_add(sender, handle, signal_number);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_resource_list_add() Fail(%d)", ret);
-
- ret = icd_ioty_unregister_resource(handle);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_unregister_resource() Fail(%d)", ret);
-
- handle = NULL;
- }
- } else {
- ERR("icd_ioty_register_resource() Fail");
- }
-
- ic_dbus_complete_register_resource(object, invocation, signal_number,
- ICD_POINTER_TO_INT64(handle));
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_unregister_resource(icDbus *object,
- GDBusMethodInvocation *invocation, gint64 resource)
-{
- int ret;
- const gchar *sender;
-
- sender = g_dbus_method_invocation_get_sender(invocation);
- _icd_dbus_resource_list_remove(sender, ICD_INT64_TO_POINTER(resource));
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_unregister_resource(object, invocation);
- return TRUE;
- }
-
- ret = icd_ioty_unregister_resource(ICD_INT64_TO_POINTER(resource));
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_unregister_resource() Fail(%d)", ret);
-
- ic_dbus_complete_unregister_resource(object, invocation);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_bind_interface(icDbus *object,
- GDBusMethodInvocation *invocation, gint64 resource, const gchar *iface)
-{
- int ret;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_bind_interface(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_bind_interface(ICD_INT64_TO_POINTER(resource), iface);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_bind_interface() Fail(%d)", ret);
-
- ic_dbus_complete_bind_interface(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_bind_type(icDbus *object,
- GDBusMethodInvocation *invocation, gint64 resource, const gchar *type)
-{
- int ret;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_bind_type(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_bind_type(ICD_INT64_TO_POINTER(resource), type);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_bind_type() Fail(%d)", ret);
-
- ic_dbus_complete_bind_type(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_bind_resource(icDbus *object,
- GDBusMethodInvocation *invocation, gint64 parent, gint64 child)
-{
- int ret;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_bind_resource(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_bind_resource(ICD_INT64_TO_POINTER(parent),
- ICD_INT64_TO_POINTER(child));
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_bind_resource() Fail(%d)", ret);
-
- ic_dbus_complete_bind_resource(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_unbind_resource(icDbus *object,
- GDBusMethodInvocation *invocation, gint64 parent, gint64 child)
-{
- int ret;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_unbind_resource(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_unbind_resource(ICD_INT64_TO_POINTER(parent),
- ICD_INT64_TO_POINTER(child));
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_unbind_resource() Fail(%d)", ret);
-
- ic_dbus_complete_unbind_resource(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_find_resource(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *host_address,
- gint connectivity,
- const gchar *type,
- bool is_secure,
- gint timeout)
-{
- int ret;
- const gchar *sender;
- int64_t signal_number;
-
- signal_number = icd_dbus_generate_signal_number();
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_find_resource(object, invocation, signal_number, ret);
- return TRUE;
- }
-
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- ret = icd_ioty_find_resource(host_address, connectivity, type, is_secure, timeout,
- signal_number, sender);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_find_resource() Fail(%d)", ret);
-
- ic_dbus_complete_find_resource(object, invocation, signal_number, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_observer_start(icDbus *object,
- GDBusMethodInvocation *invocation,
- GVariant *resource,
- gint observe_policy,
- GVariant *query)
-{
- int ret;
- const gchar *sender;
- int64_t signal_number;
- OCDoHandle observe_h = 0;
-
- signal_number = icd_dbus_generate_signal_number();
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_observer_start(object, invocation, signal_number,
- ICD_POINTER_TO_INT64(observe_h));
- return TRUE;
- }
-
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- observe_h = icd_ioty_observer_start(resource, observe_policy, query,
- signal_number, sender);
- if (observe_h) {
- ret = _icd_dbus_observe_list_add(sender, observe_h);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_observe_list_add() Fail(%d)", ret);
-
- ret = icd_ioty_observer_stop(ICD_INT64_TO_POINTER(observe_h), NULL);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_observer_stop() fail(%d)", ret);
-
- observe_h = NULL;
- }
- } else {
- ERR("icd_ioty_observer_start() Fail");
- }
-
- ic_dbus_complete_observer_start(object, invocation, signal_number,
- ICD_POINTER_TO_INT64(observe_h));
-
- /* observe_h will be freed in _dbus_handle_observer_stop() */
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_observer_stop(icDbus *object,
- GDBusMethodInvocation *invocation,
- gint64 observe_h,
- GVariant *options)
-{
- int ret;
- const gchar *sender;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_observer_stop(object, invocation, ret);
- return TRUE;
- }
-
- sender = g_dbus_method_invocation_get_sender(invocation);
- _icd_dbus_observe_list_remove(sender, ICD_INT64_TO_POINTER(observe_h));
-
- ret = icd_ioty_observer_stop(ICD_INT64_TO_POINTER(observe_h), options);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_observer_stop() Fail(%d)", ret);
-
- ic_dbus_complete_observer_stop(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_notify(icDbus *object,
- GDBusMethodInvocation *invocation,
- gint64 resource,
- GVariant *notify_msg,
- GVariant *observers,
- gint qos)
-{
- int ret;
-
- /* iotcon_resource_notify()
- * iotcon_lite_resource_update_state() */
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_notify(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_notify(ICD_INT64_TO_POINTER(resource), notify_msg, observers, qos);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_notify() Fail(%d)", ret);
-
- ic_dbus_complete_notify(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_send_response(icDbus *object,
- GDBusMethodInvocation *invocation, GVariant *response)
-{
- int ret;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_send_response(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_send_response(response);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_send_response() Fail(%d)", ret);
-
- ic_dbus_complete_send_response(object, invocation, ret);
-
- return TRUE;
-}
-
-static gboolean _dbus_handle_get_device_info(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *host_address,
- gint connectivity,
- gint timeout)
-{
- int ret;
- const gchar *sender;
- int64_t signal_number;
-
- signal_number = icd_dbus_generate_signal_number();
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_get_device_info(object, invocation, signal_number, ret);
- return TRUE;
- }
-
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- ret = icd_ioty_get_info(ICD_DEVICE_INFO, host_address, connectivity, timeout,
- signal_number, sender);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_get_info(device info) Fail(%d)", ret);
-
- ic_dbus_complete_get_device_info(object, invocation, signal_number, ret);
-
- return TRUE;
-}
-
-static gboolean _dbus_handle_get_platform_info(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *host_address,
- gint connectivity,
- gint timeout)
-{
- int ret;
- const gchar *sender;
- int64_t signal_number;
-
- signal_number = icd_dbus_generate_signal_number();
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_get_platform_info(object, invocation, signal_number, ret);
- return TRUE;
- }
-
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- ret = icd_ioty_get_info(ICD_PLATFORM_INFO, host_address, connectivity, timeout,
- signal_number, sender);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_get_info(platform info) Fail(%d)", ret);
-
- ic_dbus_complete_get_platform_info(object, invocation, signal_number, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_start_presence(icDbus *object,
- GDBusMethodInvocation *invocation,
- guint time_to_live)
-{
- int ret;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_start_presence(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_start_presence(time_to_live);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_start_presence() Fail(%d)", ret);
-
- ic_dbus_complete_start_presence(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_stop_presence(icDbus *object,
- GDBusMethodInvocation *invocation)
-{
- int ret;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_start_presence(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_stop_presence();
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_stop_presence() Fail(%d)", ret);
-
- ic_dbus_complete_stop_presence(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_subscribe_presence(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *host_address,
- gint connectivity,
- const gchar *type)
-{
- int ret;
- const gchar *sender;
- OCDoHandle presence_h = NULL;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_subscribe_presence(object, invocation,
- ICD_POINTER_TO_INT64(presence_h));
- return TRUE;
- }
-
- presence_h = icd_ioty_subscribe_presence(ICD_PRESENCE, host_address, connectivity,
- type, NULL);
- if (presence_h) {
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- ret = _icd_dbus_presence_list_add(sender, presence_h, host_address);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_presence_list_add() Fail(%d)", ret);
-
- ret = icd_ioty_unsubscribe_presence(presence_h, host_address);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_unsubscribe_presence(%u) Fail(%d)", presence_h, ret);
-
- presence_h = NULL;
- }
- } else {
- ERR("icd_ioty_subscribe_presence() Fail");
- }
-
- ic_dbus_complete_subscribe_presence(object, invocation,
- ICD_POINTER_TO_INT64(presence_h));
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_unsubscribe_presence(icDbus *object,
- GDBusMethodInvocation *invocation,
- gint64 presence_h,
- const gchar *host_address)
-{
- int ret;
- const gchar *sender;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_unsubscribe_presence(object, invocation, ret);
- return TRUE;
- }
-
- sender = g_dbus_method_invocation_get_sender(invocation);
- _icd_dbus_presence_list_remove(sender, ICD_INT64_TO_POINTER(presence_h));
-
- ret = icd_ioty_unsubscribe_presence(ICD_INT64_TO_POINTER(presence_h), host_address);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_unsubscribe_presence() Fail(%d)", ret);
-
- ic_dbus_complete_unsubscribe_presence(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_encap_get_time_interval(icDbus *object,
- GDBusMethodInvocation *invocation)
-{
- int time_interval;
-
- time_interval = icd_ioty_encap_get_time_interval();
-
- ic_dbus_complete_encap_get_time_interval(object, invocation, time_interval);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_encap_set_time_interval(icDbus *object,
- GDBusMethodInvocation *invocation,
- gint time_interval)
-{
- icd_ioty_encap_set_time_interval(time_interval);
-
- ic_dbus_complete_encap_set_time_interval(object, invocation);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_start_monitoring(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *uri_path,
- const gchar *host_address,
- gint connectivity)
-{
- int ret;
- const gchar *sender;
- int64_t signal_number = 0;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_start_monitoring(object, invocation, signal_number, ret);
- return TRUE;
- }
-
- ret = icd_ioty_start_encap(ICD_ENCAP_MONITORING, uri_path, host_address, connectivity,
- &signal_number);
- if (IOTCON_ERROR_NONE == ret) {
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- ret = _icd_dbus_encap_list_add(sender, ICD_ENCAP_MONITORING, host_address,
- uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_encap_list_add() Fail(%d)", ret);
-
- ret = icd_ioty_stop_encap(ICD_ENCAP_MONITORING, uri_path, host_address);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_stop_encap() Fail(%d)", ret);
-
- signal_number = 0;
- }
- } else {
- ERR("icd_ioty_start_encap() Fail(%d)", ret);
- }
-
- ic_dbus_complete_start_monitoring(object, invocation, signal_number, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_stop_monitoring(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *uri_path,
- const gchar *host_address)
-{
- int ret;
- const gchar *sender;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_stop_monitoring(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_stop_encap(ICD_ENCAP_MONITORING, uri_path, host_address);
- if (IOTCON_ERROR_NONE == ret) {
- sender = g_dbus_method_invocation_get_sender(invocation);
- _icd_dbus_encap_list_remove(sender, ICD_ENCAP_MONITORING, host_address, uri_path);
- } else {
- ERR("icd_ioty_stop_encap() Fail(%d)", ret);
- }
-
- ic_dbus_complete_stop_monitoring(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_start_caching(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *uri_path,
- const gchar *host_address,
- gint connectivity)
-{
- int ret;
- const gchar *sender;
- int64_t signal_number = 0;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_start_monitoring(object, invocation, signal_number, ret);
- return TRUE;
- }
-
- ret = icd_ioty_start_encap(ICD_ENCAP_CACHING, uri_path, host_address, connectivity,
- &signal_number);
- if (IOTCON_ERROR_NONE == ret) {
- sender = g_dbus_method_invocation_get_sender(invocation);
-
- ret = _icd_dbus_encap_list_add(sender, ICD_ENCAP_CACHING, host_address, uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_encap_list_add() Fail(%d)", ret);
-
- ret = icd_ioty_stop_encap(ICD_ENCAP_CACHING, uri_path, host_address);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icd_ioty_stop_encap() Fail(%d)", ret);
-
- signal_number = 0;
- }
- } else {
- ERR("icd_ioty_start_encap() Fail(%d)", ret);
- }
-
- ic_dbus_complete_start_caching(object, invocation, signal_number, ret);
-
- return TRUE;
-}
-
-
-static gboolean _dbus_handle_stop_caching(icDbus *object,
- GDBusMethodInvocation *invocation,
- const gchar *uri_path,
- const gchar *host_address)
-{
- int ret;
- const gchar *sender;
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- ic_dbus_complete_stop_monitoring(object, invocation, ret);
- return TRUE;
- }
-
- ret = icd_ioty_stop_encap(ICD_ENCAP_CACHING, uri_path, host_address);
- if (IOTCON_ERROR_NONE == ret) {
- sender = g_dbus_method_invocation_get_sender(invocation);
- _icd_dbus_encap_list_remove(sender, ICD_ENCAP_CACHING, host_address, uri_path);
- } else {
- ERR("icd_ioty_stop_encap() Fail(%d)", ret);
- }
-
- ic_dbus_complete_stop_caching(object, invocation, ret);
-
- return TRUE;
-}
-
-
-static void _dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name,
- gpointer user_data)
-{
- gboolean ret;
- GError *error = NULL;
-
- icd_dbus_object = ic_dbus_skeleton_new();
- if (NULL == icd_dbus_object) {
- ERR("ic_iotcon_skeletion_new() Fail");
- return;
- }
-
- g_signal_connect(icd_dbus_object, "handle-register-resource",
- G_CALLBACK(_dbus_handle_register_resource), NULL);
- g_signal_connect(icd_dbus_object, "handle-unregister-resource",
- G_CALLBACK(_dbus_handle_unregister_resource), NULL);
- g_signal_connect(icd_dbus_object, "handle-bind-interface",
- G_CALLBACK(_dbus_handle_bind_interface), NULL);
- g_signal_connect(icd_dbus_object, "handle-bind-type",
- G_CALLBACK(_dbus_handle_bind_type), NULL);
- g_signal_connect(icd_dbus_object, "handle-bind-resource",
- G_CALLBACK(_dbus_handle_bind_resource), NULL);
- g_signal_connect(icd_dbus_object, "handle-unbind-resource",
- G_CALLBACK(_dbus_handle_unbind_resource), NULL);
- g_signal_connect(icd_dbus_object, "handle-find-resource",
- G_CALLBACK(_dbus_handle_find_resource), NULL);
- g_signal_connect(icd_dbus_object, "handle-get",
- G_CALLBACK(icd_ioty_get), NULL);
- g_signal_connect(icd_dbus_object, "handle-put",
- G_CALLBACK(icd_ioty_put), NULL);
- g_signal_connect(icd_dbus_object, "handle-post",
- G_CALLBACK(icd_ioty_post), NULL);
- g_signal_connect(icd_dbus_object, "handle-delete",
- G_CALLBACK(icd_ioty_delete), NULL);
- g_signal_connect(icd_dbus_object, "handle-observer-start",
- G_CALLBACK(_dbus_handle_observer_start), NULL);
- g_signal_connect(icd_dbus_object, "handle-observer-stop",
- G_CALLBACK(_dbus_handle_observer_stop), NULL);
- g_signal_connect(icd_dbus_object, "handle-notify",
- G_CALLBACK(_dbus_handle_notify), NULL);
- g_signal_connect(icd_dbus_object, "handle-send-response",
- G_CALLBACK(_dbus_handle_send_response), NULL);
- g_signal_connect(icd_dbus_object, "handle-get-device-info",
- G_CALLBACK(_dbus_handle_get_device_info), NULL);
- g_signal_connect(icd_dbus_object, "handle-get-platform-info",
- G_CALLBACK(_dbus_handle_get_platform_info), NULL);
- g_signal_connect(icd_dbus_object, "handle-start-presence",
- G_CALLBACK(_dbus_handle_start_presence), NULL);
- g_signal_connect(icd_dbus_object, "handle-stop-presence",
- G_CALLBACK(_dbus_handle_stop_presence), NULL);
- g_signal_connect(icd_dbus_object, "handle-subscribe-presence",
- G_CALLBACK(_dbus_handle_subscribe_presence), NULL);
- g_signal_connect(icd_dbus_object, "handle-unsubscribe-presence",
- G_CALLBACK(_dbus_handle_unsubscribe_presence), NULL);
- g_signal_connect(icd_dbus_object, "handle-encap-get-time-interval",
- G_CALLBACK(_dbus_handle_encap_get_time_interval), NULL);
- g_signal_connect(icd_dbus_object, "handle-encap-set-time-interval",
- G_CALLBACK(_dbus_handle_encap_set_time_interval), NULL);
- g_signal_connect(icd_dbus_object, "handle-start-monitoring",
- G_CALLBACK(_dbus_handle_start_monitoring), NULL);
- g_signal_connect(icd_dbus_object, "handle-stop-monitoring",
- G_CALLBACK(_dbus_handle_stop_monitoring), NULL);
- g_signal_connect(icd_dbus_object, "handle-start-caching",
- G_CALLBACK(_dbus_handle_start_caching), NULL);
- g_signal_connect(icd_dbus_object, "handle-stop-caching",
- G_CALLBACK(_dbus_handle_stop_caching), NULL);
-
- ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(icd_dbus_object),
- conn, IOTCON_DBUS_OBJPATH, &error);
- if (FALSE == ret) {
- ERR("g_dbus_interface_skeleton_export() Fail(%s)", error->message);
- g_error_free(error);
- }
-
- ret = _icd_dbus_subscribe_name_owner_changed(conn);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_dbus_subscribe_name_owner_changed() Fail(%d)", ret);
- return;
- }
-
-}
-
-
-static void _dbus_on_name_lost(GDBusConnection *conn, const gchar *name,
- gpointer user_data)
-{
- DBG("Lost the name %s", name);
-}
-
-
-static void _dbus_on_name_acquired(GDBusConnection *conn, const gchar *name,
- gpointer user_data)
-{
- DBG("Acquired the name %s", name);
-}
-
-
-unsigned int icd_dbus_init()
-{
- guint id;
-
- id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
- IOTCON_DBUS_INTERFACE,
- G_BUS_NAME_OWNER_FLAGS_REPLACE,
- _dbus_on_bus_acquired,
- _dbus_on_name_acquired,
- _dbus_on_name_lost,
- NULL,
- NULL);
- if (0 == id) {
- ERR("g_bus_own_name() Fail");
- return 0;
- }
-
- return id;
-}
-
-
-void icd_dbus_deinit(unsigned int id)
-{
- g_bus_unown_name(id);
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_DBUS_H__
-#define __IOT_CONNECTIVITY_MANAGER_DAEMON_DBUS_H__
-
-#include <stdint.h>
-#include <glib.h>
-#include "ic-dbus.h"
-
-#define ICD_INT64_TO_POINTER(i) ((void*)(intptr_t)(i))
-#define ICD_POINTER_TO_INT64(p) ((int64_t)(intptr_t)(p))
-
-icDbus* icd_dbus_get_object();
-int64_t icd_dbus_generate_signal_number();
-int icd_dbus_client_list_get_resource_info(void *handle, int64_t *signal_number,
- gchar **bus_name);
-int icd_dbus_emit_signal(const char *dest, const char *signal_name,
- GVariant *value);
-unsigned int icd_dbus_init();
-void icd_dbus_deinit(unsigned int id);
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_DBUS_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdint.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <glib.h>
-
-#include <ocstack.h>
-#include <octypes.h>
-#include <ocpayload.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "icd.h"
-#include "icd-payload.h"
-#include "icd-dbus.h"
-#include "icd-ioty.h"
-#include "icd-ioty-type.h"
-#include "icd-ioty-ocprocess.h"
-
-static int icd_ioty_alive;
-
-typedef int (*_ocprocess_cb)(void *user_data);
-typedef void (*_free_context)(void *context);
-
-struct icd_ioty_worker {
- void *ctx;
- _ocprocess_cb cb;
- _free_context free_ctx;
-};
-
-
-struct icd_worker_context {
- GMutex icd_worker_mutex;
-};
-
-
-struct icd_req_context {
- GMutex icd_worker_mutex;
- int64_t signal_number;
- char *bus_name;
- int request_type;
- int observe_id;
- int observe_type;
- OCRequestHandle request_h;
- OCResourceHandle resource_h;
- GVariant *payload;
- GVariantBuilder *options;
- GVariantBuilder *query;
- OCDevAddr dev_addr;
-};
-
-
-struct icd_find_context {
- GMutex icd_worker_mutex;
- int64_t signal_number;
- char *bus_name;
- int conn_type;
- GVariant **payload;
-};
-
-
-struct icd_crud_context {
- GMutex icd_worker_mutex;
- int res;
- int crud_type;
- GVariant *payload;
- GVariantBuilder *options;
- GDBusMethodInvocation *invocation;
-};
-
-
-struct icd_info_context {
- GMutex icd_worker_mutex;
- int64_t signal_number;
- int info_type;
- char *bus_name;
- GVariant *payload;
-};
-
-
-struct icd_observe_context {
- GMutex icd_worker_mutex;
- int64_t signal_number;
- int res;
- int seqnum;
- char *bus_name;
- GVariant *payload;
- GVariantBuilder *options;
-};
-
-
-struct icd_presence_context {
- GMutex icd_worker_mutex;
- OCDoHandle handle;
- int result;
- unsigned int nonce;
- OCDevAddr dev_addr;
- iotcon_presence_trigger_e trigger;
- char *resource_type;
-};
-
-
-struct icd_encap_get_context {
- GMutex icd_worker_mutex;
- OCRepPayload *oic_payload;
- OCStackResult ret;
- OCDevAddr dev_addr;
- char *uri_path;
-};
-
-
-void icd_ioty_ocprocess_stop()
-{
- icd_ioty_alive = 0;
-}
-
-
-static void* _ocprocess_worker_thread(void *data)
-{
- int ret;
- struct icd_ioty_worker *worker = data;
- struct icd_worker_context *ctx;
-
- RETV_IF(NULL == worker, NULL);
-
- ctx = worker->ctx;
-
- g_mutex_lock(&ctx->icd_worker_mutex);
- ret = worker->cb(worker->ctx);
- if (IOTCON_ERROR_NONE != ret)
- ERR("cb() Fail(%d)", ret);
- g_mutex_unlock(&ctx->icd_worker_mutex);
-
- if (worker->free_ctx)
- worker->free_ctx(worker->ctx);
-
- /* worker was allocated from _ocprocess_worker_start() */
- free(worker);
-
- /* GCC warning happen if use g_thread_exit() */
- return NULL;
-}
-
-
-static int _ocprocess_worker_start(_ocprocess_cb cb, void *ctx, _free_context free_ctx)
-{
- GError *error;
- GThread *thread;
- struct icd_ioty_worker *worker;
-
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- worker = calloc(1, sizeof(struct icd_ioty_worker));
- if (NULL == worker) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- worker->cb = cb;
- worker->ctx = ctx;
- worker->free_ctx = free_ctx;
-
- /* TODO : consider thread pool mechanism */
- thread = g_thread_try_new("worker_thread", _ocprocess_worker_thread, worker, &error);
- if (NULL == thread) {
- ERR("g_thread_try_new() Fail(%s)", error->message);
- g_error_free(error);
- free(worker);
- return IOTCON_ERROR_SYSTEM;
- }
-
- /* DO NOT join thread. It was already detached by calling g_thread_unref() */
- g_thread_unref(thread);
-
- /* DO NOT FREE worker. It MUST be freed in the _ocprocess_worker_thread() */
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _ocprocess_response_signal(const char *dest, const char *signal_prefix,
- int64_t signal_number, GVariant *value)
-{
- int ret;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- ret = snprintf(signal_name, sizeof(signal_name), "%s_%llx", signal_prefix, signal_number);
- if (ret <= 0 || sizeof(signal_name) <= ret) {
- ERR("snprintf() Fail(%d)", ret);
- g_variant_unref(value);
- return IOTCON_ERROR_IO_ERROR;
- }
-
- ret = icd_dbus_emit_signal(dest, signal_name, value);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_dbus_emit_signal() Fail(%d)", ret);
- return ret;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static inline GVariantBuilder* _ocprocess_parse_header_options(
- OCHeaderOption *oic_option, int option_size)
-{
- int i;
- GVariantBuilder *options;
-
- options = g_variant_builder_new(G_VARIANT_TYPE("a(qs)"));
- for (i = 0; i < option_size; i++) {
- g_variant_builder_add(options, "(qs)", oic_option[i].optionID,
- oic_option[i].optionData);
- }
-
- return options;
-}
-
-static int _ioty_oic_action_to_ioty_action(int oic_action)
-{
- int action;
-
- switch (oic_action) {
- case OC_OBSERVE_REGISTER:
- action = IOTCON_OBSERVE_REGISTER;
- break;
- case OC_OBSERVE_DEREGISTER:
- action = IOTCON_OBSERVE_DEREGISTER;
- break;
- case OC_OBSERVE_NO_OPTION:
- default:
- ERR("Invalid action (%d)", oic_action);
- action = IOTCON_OBSERVE_NO_TYPE;
- }
- return action;
-}
-
-
-static void _icd_req_context_free(void *ctx)
-{
- struct icd_req_context *req_ctx = ctx;
-
- free(req_ctx->bus_name);
- if (req_ctx->payload)
- g_variant_unref(req_ctx->payload);
- g_variant_builder_unref(req_ctx->options);
- g_variant_builder_unref(req_ctx->query);
- free(req_ctx);
-}
-
-
-static int _worker_req_handler(void *context)
-{
- GVariant *value;
- char *host_address;
- int ret, conn_type;
- GVariantBuilder payload_builder;
- struct icd_req_context *ctx = context;
-
- RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_variant_builder_init(&payload_builder, G_VARIANT_TYPE("av"));
- if (ctx->payload) {
- g_variant_builder_add(&payload_builder, "v", ctx->payload);
- ctx->payload = NULL;
- }
-
- ret = icd_ioty_get_host_address(&ctx->dev_addr, &host_address, &conn_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_get_host_address() Fail(%d)", ret);
- g_variant_builder_clear(&payload_builder);
- return ret;
- }
-
- value = g_variant_new("(siia(qs)a(ss)iiavxx)",
- host_address,
- conn_type,
- ctx->request_type,
- ctx->options,
- ctx->query,
- ctx->observe_type,
- ctx->observe_id,
- &payload_builder,
- ICD_POINTER_TO_INT64(ctx->request_h),
- ICD_POINTER_TO_INT64(ctx->resource_h));
-
- free(host_address);
-
- ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_REQUEST_HANDLER,
- ctx->signal_number, value);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
-
- return ret;
-}
-
-
-OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest *request, void *user_data)
-{
- FN_CALL;
- int ret;
- int64_t signal_number;
- char *query_str, *query_key, *query_value;
- char *token, *save_ptr1, *save_ptr2;
- char *bus_name = NULL;
- struct icd_req_context *req_ctx;
-
- RETV_IF(NULL == request, OC_EH_ERROR);
-
- req_ctx = calloc(1, sizeof(struct icd_req_context));
- if (NULL == req_ctx) {
- ERR("calloc() Fail(%d)", errno);
- return OC_EH_ERROR;
- }
-
- /* handle */
- req_ctx->request_h = request->requestHandle;
- req_ctx->resource_h = request->resource;
-
- ret = icd_dbus_client_list_get_resource_info(req_ctx->resource_h, &signal_number,
- &bus_name);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_dbus_client_list_get_resource_info() Fail(%d)", ret);
- free(req_ctx);
- return OC_EH_ERROR;
- }
-
- /* signal number & bus_name */
- req_ctx->signal_number = signal_number;
- req_ctx->bus_name = bus_name;
-
- memcpy(&req_ctx->dev_addr, &request->devAddr, sizeof(OCDevAddr));
-
- /* request type */
- if (OC_REQUEST_FLAG & flag) {
- switch (request->method) {
- case OC_REST_GET:
- req_ctx->request_type = IOTCON_REQUEST_GET;
- req_ctx->payload = NULL;
- break;
- case OC_REST_PUT:
- req_ctx->request_type = IOTCON_REQUEST_PUT;
- req_ctx->payload = icd_payload_to_gvariant(request->payload);
- break;
- case OC_REST_POST:
- req_ctx->request_type = IOTCON_REQUEST_POST;
- req_ctx->payload = icd_payload_to_gvariant(request->payload);
- break;
- case OC_REST_DELETE:
- req_ctx->request_type = IOTCON_REQUEST_DELETE;
- req_ctx->payload = NULL;
- break;
- default:
- free(req_ctx->bus_name);
- free(req_ctx);
- return OC_EH_ERROR;
- }
- }
-
- if (OC_OBSERVE_FLAG & flag) {
- /* observation info*/
- req_ctx->observe_id = request->obsInfo.obsId;
- req_ctx->observe_type = _ioty_oic_action_to_ioty_action(request->obsInfo.action);
- } else {
- req_ctx->observe_type = IOTCON_OBSERVE_NO_TYPE;
- }
-
- /* header options */
- req_ctx->options = _ocprocess_parse_header_options(
- request->rcvdVendorSpecificHeaderOptions,
- request->numRcvdVendorSpecificHeaderOptions);
-
- /* query */
- req_ctx->query = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
- query_str = request->query;
- while ((token = strtok_r(query_str, "&;", &save_ptr1))) {
- while ((query_key = strtok_r(token, "=", &save_ptr2))) {
- token = NULL;
- query_value = strtok_r(token, "=", &save_ptr2);
- if (NULL == query_value)
- break;
-
- g_variant_builder_add(req_ctx->query, "(ss)", query_key, query_value);
- }
- query_str = NULL;
- }
-
- ret = _ocprocess_worker_start(_worker_req_handler, req_ctx, _icd_req_context_free);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- _icd_req_context_free(req_ctx);
- return OC_EH_ERROR;
- }
-
- /* DO NOT FREE req_ctx. It MUST be freed in the _worker_req_handler func */
-
- return OC_EH_OK;
-}
-
-
-gpointer icd_ioty_ocprocess_thread(gpointer data)
-{
- FN_CALL;
- OCStackResult result;
- const struct timespec delay = {0, 10 * 1000 * 1000}; /* 10 ms */
-
- icd_ioty_alive = 1;
- while (icd_ioty_alive) {
- icd_ioty_csdk_lock();
- result = OCProcess();
- icd_ioty_csdk_unlock();
- if (OC_STACK_OK != result) {
- ERR("OCProcess() Fail(%d)", result);
- break;
- }
-
- /* TODO : Current '10ms' is not proven sleep time. Revise the time after test.
- * Or recommend changes to event driven architecture */
- nanosleep(&delay, NULL);
- }
-
- return NULL;
-}
-
-
-static void _icd_find_context_free(void *ctx)
-{
- struct icd_find_context *find_ctx = ctx;
-
- free(find_ctx->bus_name);
- free(find_ctx);
-}
-
-
-static int _worker_find_cb(void *context)
-{
- GVariant *value;
- int i, ret;
- struct icd_find_context *ctx = context;
-
- RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == ctx->payload, IOTCON_ERROR_INVALID_PARAMETER);
-
- for (i = 0; ctx->payload[i]; i++) {
- value = g_variant_new("(vi)", ctx->payload[i], ctx->conn_type);
- /* TODO : If one device has multi resources, it comes as bulk data.
- * To reduce the number of emit_signal, let's send signal only one time for one device.
- * for ex, client list. */
- ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_FOUND_RESOURCE,
- ctx->signal_number, value);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
- g_variant_unref(value);
- return ret;
- }
- }
-
- return ret;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- int ret;
- struct icd_find_context *find_ctx;
- icd_sig_ctx_s *sig_context = ctx;
-
- RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
- RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
- if (NULL == resp->payload)
- /* normal case : payload COULD be NULL */
- return OC_STACK_KEEP_TRANSACTION;
- RETVM_IF(PAYLOAD_TYPE_DISCOVERY != resp->payload->type,
- OC_STACK_KEEP_TRANSACTION, "Invalid payload type(%d)", resp->payload->type);
-
- find_ctx = calloc(1, sizeof(struct icd_find_context));
- if (NULL == find_ctx) {
- ERR("calloc() Fail(%d)", errno);
- return OC_STACK_KEEP_TRANSACTION;
- }
-
- find_ctx->signal_number = sig_context->signal_number;
- find_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
- find_ctx->payload = icd_payload_res_to_gvariant(resp->payload, &resp->devAddr);
- find_ctx->conn_type = icd_ioty_transport_flag_to_conn_type(resp->devAddr.adapter,
- resp->devAddr.flags);
-
- ret = _ocprocess_worker_start(_worker_find_cb, find_ctx, _icd_find_context_free);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- ic_utils_gvariant_array_free(find_ctx->payload);
- _icd_find_context_free(find_ctx);
- return OC_STACK_KEEP_TRANSACTION;
- }
-
- /* DO NOT FREE sig_context. It MUST be freed in the ocstack */
- /* DO NOT FREE find_ctx. It MUST be freed in the _worker_find_cb func */
-
- return OC_STACK_KEEP_TRANSACTION;
-}
-
-
-static void _icd_crud_context_free(void *ctx)
-{
- struct icd_crud_context *crud_ctx = ctx;
-
- g_variant_builder_unref(crud_ctx->options);
- free(crud_ctx);
-}
-
-
-static int _worker_crud_cb(void *context)
-{
- GVariant *value;
- struct icd_crud_context *ctx = context;
-
- RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (ICD_CRUD_DELETE == ctx->crud_type)
- value = g_variant_new("(a(qs)i)", ctx->options, ctx->res);
- else
- value = g_variant_new("(a(qs)vi)", ctx->options, ctx->payload, ctx->res);
- icd_ioty_complete(ctx->crud_type, ctx->invocation, value);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _ocprocess_worker(_ocprocess_cb cb, int type, OCPayload *payload, int res,
- GVariantBuilder *options, void *ctx)
-{
- int ret;
- struct icd_crud_context *crud_ctx;
-
- crud_ctx = calloc(1, sizeof(struct icd_crud_context));
- if (NULL == crud_ctx) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- crud_ctx->crud_type = type;
- crud_ctx->payload = icd_payload_to_gvariant(payload);
- crud_ctx->res = res;
- crud_ctx->options = options;
- crud_ctx->invocation = ctx;
-
- ret = _ocprocess_worker_start(cb, crud_ctx, _icd_crud_context_free);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- if (crud_ctx->payload)
- g_variant_unref(crud_ctx->payload);
- g_variant_builder_unref(crud_ctx->options);
- free(crud_ctx);
- }
-
- /* DO NOT FREE crud_ctx. It MUST be freed in the _worker_crud_cb func */
-
- return ret;
-}
-
-static int _ocprocess_parse_oic_result(OCStackResult result)
-{
- int res;
-
- switch (result) {
- case OC_STACK_OK:
- res = IOTCON_RESPONSE_OK;
- break;
- case OC_STACK_RESOURCE_CREATED:
- res = IOTCON_RESPONSE_RESOURCE_CREATED;
- break;
- case OC_STACK_RESOURCE_DELETED:
- res = IOTCON_RESPONSE_RESOURCE_DELETED;
- break;
- case OC_STACK_UNAUTHORIZED_REQ:
- res = IOTCON_RESPONSE_FORBIDDEN;
- break;
- default:
- WARN("response error(%d)", result);
- res = IOTCON_RESPONSE_ERROR;
- break;
- }
-
- return res;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- FN_CALL;
- int ret, res;
- GVariantBuilder *options;
-
- RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
-
- if (NULL == resp->payload) {
- ERR("payload is empty");
- icd_ioty_complete_error(ICD_CRUD_GET, ctx, IOTCON_ERROR_IOTIVITY);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- res = _ocprocess_parse_oic_result(resp->result);
-
- options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
- resp->numRcvdVendorSpecificHeaderOptions);
-
- ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_GET, resp->payload, res,
- options, ctx);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker() Fail(%d)", ret);
- icd_ioty_complete_error(ICD_CRUD_GET, ctx, ret);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- return OC_STACK_DELETE_TRANSACTION;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_put_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- FN_CALL;
- int ret, res;
- GVariantBuilder *options;
-
- RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
-
- if (NULL == resp->payload) {
- ERR("payload is empty");
- icd_ioty_complete_error(ICD_CRUD_PUT, ctx, IOTCON_ERROR_IOTIVITY);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- res = _ocprocess_parse_oic_result(resp->result);
-
- options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
- resp->numRcvdVendorSpecificHeaderOptions);
-
- ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_PUT, resp->payload, res,
- options, ctx);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker() Fail(%d)", ret);
- icd_ioty_complete_error(ICD_CRUD_PUT, ctx, ret);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- return OC_STACK_DELETE_TRANSACTION;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_post_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- FN_CALL;
- int ret, res;
- GVariantBuilder *options;
-
- RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
-
- if (NULL == resp->payload) {
- ERR("payload is empty");
- icd_ioty_complete_error(ICD_CRUD_POST, ctx, IOTCON_ERROR_IOTIVITY);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- res = _ocprocess_parse_oic_result(resp->result);
-
- options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
- resp->numRcvdVendorSpecificHeaderOptions);
-
- ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_POST, resp->payload, res,
- options, ctx);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker() Fail(%d)", ret);
- icd_ioty_complete_error(ICD_CRUD_POST, ctx, ret);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- return OC_STACK_DELETE_TRANSACTION;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_delete_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- FN_CALL;
- int ret, res;
- GVariantBuilder *options;
-
- RETV_IF(NULL == ctx, OC_STACK_DELETE_TRANSACTION);
-
- if (NULL == resp->payload) {
- ERR("payload is empty");
- icd_ioty_complete_error(ICD_CRUD_DELETE, ctx, IOTCON_ERROR_IOTIVITY);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- res = _ocprocess_parse_oic_result(resp->result);
-
- options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
- resp->numRcvdVendorSpecificHeaderOptions);
-
- ret = _ocprocess_worker(_worker_crud_cb, ICD_CRUD_DELETE, NULL, res, options, ctx);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker() Fail(%d)", ret);
- icd_ioty_complete_error(ICD_CRUD_DELETE, ctx, ret);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- return OC_STACK_DELETE_TRANSACTION;
-}
-
-
-static void _icd_observe_context_free(void *ctx)
-{
- struct icd_observe_context *observe_ctx = ctx;
-
- g_variant_builder_unref(observe_ctx->options);
- free(observe_ctx->bus_name);
- free(observe_ctx);
-}
-
-
-static int _worker_observe_cb(void *context)
-{
- int ret;
- GVariant *value;
- struct icd_observe_context *ctx = context;
-
- RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_variant_new("(a(qs)vii)", ctx->options, ctx->payload, ctx->res,
- ctx->seqnum);
-
- ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_OBSERVE,
- ctx->signal_number, value);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
-
- return ret;
-}
-
-
-static void _observe_cb_response_error(const char *dest,
- int64_t signal_number, int ret_val)
-{
- int ret;
- GVariant *value;
- GVariant *payload;
- GVariantBuilder options;
-
- g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
- payload = icd_payload_representation_empty_gvariant();
-
- value = g_variant_new("(a(qs)vii)", &options, payload, ret_val, 0);
-
- ret = _ocprocess_response_signal(dest, IC_DBUS_SIGNAL_OBSERVE, signal_number, value);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx,
- OCDoHandle handle, OCClientResponse *resp)
-{
- int ret, res;
- GVariantBuilder *options;
- struct icd_observe_context *observe_ctx;
- icd_sig_ctx_s *sig_context = ctx;
- OCStackApplicationResult cb_result;
-
- RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
- RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
-
- cb_result = (OC_OBSERVE_DEREGISTER == resp->sequenceNumber) ?
- OC_STACK_DELETE_TRANSACTION : OC_STACK_KEEP_TRANSACTION;
-
- if (NULL == resp->payload) {
- ERR("payload is empty");
- _observe_cb_response_error(sig_context->bus_name, sig_context->signal_number,
- IOTCON_ERROR_IOTIVITY);
- return cb_result;
- }
-
- observe_ctx = calloc(1, sizeof(struct icd_observe_context));
- if (NULL == observe_ctx) {
- ERR("calloc() Fail(%d)", errno);
- _observe_cb_response_error(sig_context->bus_name, sig_context->signal_number,
- IOTCON_ERROR_OUT_OF_MEMORY);
- return cb_result;
- }
-
- res = _ocprocess_parse_oic_result(resp->result);
-
- options = _ocprocess_parse_header_options(resp->rcvdVendorSpecificHeaderOptions,
- resp->numRcvdVendorSpecificHeaderOptions);
-
- observe_ctx->payload = icd_payload_to_gvariant(resp->payload);
- observe_ctx->signal_number = sig_context->signal_number;
- observe_ctx->res = res;
- observe_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
- observe_ctx->options = options;
- observe_ctx->seqnum = resp->sequenceNumber;
-
- ret = _ocprocess_worker_start(_worker_observe_cb, observe_ctx,
- _icd_observe_context_free);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- _observe_cb_response_error(sig_context->bus_name, sig_context->signal_number, ret);
- free(observe_ctx->bus_name);
- if (observe_ctx->payload)
- g_variant_unref(observe_ctx->payload);
- g_variant_builder_unref(observe_ctx->options);
- free(observe_ctx);
- return cb_result;
- }
-
- /* DO NOT FREE sig_context. It MUST be freed in the ocstack */
- /* DO NOT FREE observe_ctx. It MUST be freed in the _worker_observe_cb func */
-
- return cb_result;
-}
-
-
-static void _icd_presence_context_free(void *ctx)
-{
- struct icd_presence_context *presence_ctx = ctx;
-
- free(presence_ctx->resource_type);
- free(presence_ctx);
-}
-
-
-static int _worker_presence_cb(void *context)
-{
- int conn_type;
- OCDoHandle handle;
- char *host_address;
- GVariant *value, *value2;
- int ret = IOTCON_ERROR_NONE;
- struct icd_presence_context *ctx = context;
-
- RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = icd_ioty_get_host_address(&ctx->dev_addr, &host_address, &conn_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_get_host_address() Fail(%d)", ret);
- return ret;
- }
-
- value = g_variant_new("(iusiis)", ctx->result, ctx->nonce, host_address, conn_type,
- ctx->trigger, ic_utils_dbus_encode_str(ctx->resource_type));
- value2 = g_variant_ref(value);
-
- free(host_address);
-
- ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
- ICD_POINTER_TO_INT64(ctx->handle), value);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
-
- handle = icd_ioty_presence_table_get_handle(ICD_MULTICAST_ADDRESS);
- if (handle && (handle != ctx->handle)) {
- ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
- ICD_POINTER_TO_INT64(handle), value2);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
- } else {
- g_variant_unref(value2);
- }
-
- return ret;
-}
-
-
-static void _presence_cb_response_error(OCDoHandle handle, int ret_val)
-{
- FN_CALL;
- int ret;
- OCDoHandle handle2;
- GVariant *value, *value2;
-
- value = g_variant_new("(iusiis)", ret_val, 0, IC_STR_NULL, IOTCON_CONNECTIVITY_ALL,
- IOTCON_PRESENCE_RESOURCE_CREATED, IC_STR_NULL);
- value2 = g_variant_ref(value);
-
- ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
- ICD_POINTER_TO_INT64(handle), value);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
-
- handle2 = icd_ioty_presence_table_get_handle(ICD_MULTICAST_ADDRESS);
- if (handle2 && (handle2 != handle)) {
- ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_PRESENCE,
- ICD_POINTER_TO_INT64(handle), value2);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
- } else {
- g_variant_unref(value2);
- }
-}
-
-
-static int _presence_trigger_to_ioty_trigger(OCPresenceTrigger src,
- iotcon_presence_trigger_e *dest)
-{
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- switch (src) {
- case OC_PRESENCE_TRIGGER_CREATE:
- *dest = IOTCON_PRESENCE_RESOURCE_CREATED;
- break;
- case OC_PRESENCE_TRIGGER_CHANGE:
- *dest = IOTCON_PRESENCE_RESOURCE_UPDATED;
- break;
- case OC_PRESENCE_TRIGGER_DELETE:
- *dest = IOTCON_PRESENCE_RESOURCE_DESTROYED;
- break;
- default:
- ERR("Invalid trigger(%d)", src);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- FN_CALL;
- int ret;
- OCPresencePayload *payload;
- struct icd_presence_context *presence_ctx;
-
- RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
-
- presence_ctx = calloc(1, sizeof(struct icd_presence_context));
- if (NULL == presence_ctx) {
- ERR("calloc() Fail(%d)", errno);
- _presence_cb_response_error(handle, IOTCON_ERROR_OUT_OF_MEMORY);
- return OC_STACK_KEEP_TRANSACTION;
- }
-
- memcpy(&presence_ctx->dev_addr, &resp->devAddr, sizeof(OCDevAddr));
-
- payload = (OCPresencePayload*)resp->payload;
-
- switch (resp->result) {
- case OC_STACK_OK:
- presence_ctx->result = IOTCON_PRESENCE_OK;
- ret = _presence_trigger_to_ioty_trigger(payload->trigger, &presence_ctx->trigger);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_presence_trigger_to_ioty_trigger() Fail(%d)", ret);
- _presence_cb_response_error(handle, ret);
- free(presence_ctx);
- return OC_STACK_KEEP_TRANSACTION;
- }
- break;
- case OC_STACK_PRESENCE_STOPPED:
- presence_ctx->result = IOTCON_PRESENCE_STOPPED;
- break;
- case OC_STACK_PRESENCE_TIMEOUT:
- presence_ctx->result = IOTCON_PRESENCE_TIMEOUT;
- break;
- case OC_STACK_ERROR:
- default:
- DBG("Presence error(%d)", resp->result);
- presence_ctx->result = IOTCON_ERROR_IOTIVITY;
- }
-
- presence_ctx->handle = handle;
- presence_ctx->nonce = resp->sequenceNumber;
-
- if (payload->resourceType)
- presence_ctx->resource_type = strdup(payload->resourceType);
-
- ret = _ocprocess_worker_start(_worker_presence_cb, presence_ctx,
- _icd_presence_context_free);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- _presence_cb_response_error(handle, ret);
- _icd_presence_context_free(presence_ctx);
- return OC_STACK_KEEP_TRANSACTION;
- }
-
- /* DO NOT FREE presence_ctx. It MUST be freed in the _worker_presence_cb func */
-
- return OC_STACK_KEEP_TRANSACTION;
-}
-
-
-static void _icd_info_context_free(void *ctx)
-{
- struct icd_info_context *info_ctx = ctx;
-
- free(info_ctx->bus_name);
- free(info_ctx);
-}
-
-
-static int _worker_info_cb(void *context)
-{
- int ret;
- const char *signal_prefix = NULL;
- struct icd_info_context *ctx = context;
-
- RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (ICD_DEVICE_INFO == ctx->info_type)
- signal_prefix = IC_DBUS_SIGNAL_DEVICE;
- else if (ICD_PLATFORM_INFO == ctx->info_type)
- signal_prefix = IC_DBUS_SIGNAL_PLATFORM;
-
- ret = _ocprocess_response_signal(ctx->bus_name, signal_prefix, ctx->signal_number,
- ctx->payload);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
-
- return ret;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_info_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- int ret;
- int info_type;
- struct icd_info_context *info_ctx;
- icd_sig_ctx_s *sig_context = ctx;
-
- RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
- RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
- RETV_IF(NULL == resp->payload, OC_STACK_KEEP_TRANSACTION);
-
- if (PAYLOAD_TYPE_DEVICE == resp->payload->type)
- info_type = ICD_DEVICE_INFO;
- else if (PAYLOAD_TYPE_PLATFORM == resp->payload->type)
- info_type = ICD_PLATFORM_INFO;
- else
- return OC_STACK_KEEP_TRANSACTION;
-
- info_ctx = calloc(1, sizeof(struct icd_info_context));
- if (NULL == info_ctx) {
- ERR("calloc() Fail(%d)", errno);
- return OC_STACK_KEEP_TRANSACTION;
- }
-
- info_ctx->info_type = info_type;
- info_ctx->payload = icd_payload_to_gvariant(resp->payload);
- info_ctx->signal_number = sig_context->signal_number;
- info_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
-
- ret = _ocprocess_worker_start(_worker_info_cb, info_ctx, _icd_info_context_free);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- if (info_ctx->payload)
- g_variant_unref(info_ctx->payload);
- _icd_info_context_free(info_ctx);
- return OC_STACK_KEEP_TRANSACTION;
- }
-
- /* DO NOT FREE sig_context. It MUST be freed in the ocstack */
- /* DO NOT FREE info_ctx. It MUST be freed in the _worker_info_cb func */
-
- return OC_STACK_KEEP_TRANSACTION;
-}
-
-
-static void _icd_encap_get_context_free(void *ctx)
-{
- struct icd_encap_get_context *encap_ctx = ctx;
-
- free(encap_ctx->uri_path);
- free(encap_ctx);
-}
-
-
-static int _worker_encap_get_cb(void *context)
-{
- int ret, conn_type;
- char *host_address;
- icd_encap_info_s *encap_info;
- GVariant *monitoring_value, *caching_value;
- iotcon_remote_resource_state_e resource_state;
- struct icd_encap_get_context *encap_get_ctx = context;
-
- /* GET ENCAP INFO */
- ret = icd_ioty_get_host_address(&encap_get_ctx->dev_addr, &host_address, &conn_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_get_host_address() Fail");
- return ret;
- }
-
- encap_info = _icd_ioty_encap_table_get_info(encap_get_ctx->uri_path, host_address);
- if (NULL == encap_info) {
- ERR("_icd_ioty_encap_table_get_info() Fail");
- free(host_address);
- return IOTCON_ERROR_NO_DATA;
- }
- free(host_address);
-
- /* MONITORING */
- if (0 < encap_info->monitoring_count) {
- switch (encap_get_ctx->ret) {
- case OC_STACK_OK:
- resource_state = IOTCON_REMOTE_RESOURCE_ALIVE;
- break;
- case OC_STACK_ERROR:
- default:
- resource_state = IOTCON_REMOTE_RESOURCE_LOST_SIGNAL;
- }
- if (resource_state != encap_info->resource_state) {
- encap_info->resource_state = resource_state;
- monitoring_value = g_variant_new("(i)", resource_state);
- ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_MONITORING,
- encap_info->signal_number, monitoring_value);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
- OCRepPayloadDestroy(encap_get_ctx->oic_payload);
- return ret;
- }
- }
- }
-
- /* CACHING */
- if (0 < encap_info->caching_count) {
- if (OC_STACK_OK != encap_get_ctx->ret) {
- OCRepPayloadDestroy(encap_get_ctx->oic_payload);
- return IOTCON_ERROR_NONE;
- }
-
- ret = icd_payload_representation_compare(encap_info->oic_payload,
- encap_get_ctx->oic_payload);
- if (IC_EQUAL == ret) {
- OCRepPayloadDestroy(encap_get_ctx->oic_payload);
- return IOTCON_ERROR_NONE;
- }
-
- encap_info->oic_payload = encap_get_ctx->oic_payload;
- caching_value = icd_payload_to_gvariant((OCPayload*)encap_get_ctx->oic_payload);
-
- ret = _ocprocess_response_signal(NULL, IC_DBUS_SIGNAL_CACHING,
- encap_info->signal_number, caching_value);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_response_signal() Fail(%d)", ret);
- return ret;
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_encap_get_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- int ret;
- struct icd_encap_get_context *encap_get_ctx;
-
- RETV_IF(NULL == resp, OC_STACK_DELETE_TRANSACTION);
-
- encap_get_ctx = calloc(1, sizeof(struct icd_encap_get_context));
- if (NULL == encap_get_ctx) {
- ERR("calloc() Fail(%d)", errno);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- encap_get_ctx->ret = resp->result;
- encap_get_ctx->oic_payload = OCRepPayloadClone((OCRepPayload*)resp->payload);
- encap_get_ctx->uri_path = ic_utils_strdup(resp->resourceUri);
- memcpy(&encap_get_ctx->dev_addr, &resp->devAddr, sizeof(OCDevAddr));
-
- ret = _ocprocess_worker_start(_worker_encap_get_cb, encap_get_ctx,
- _icd_encap_get_context_free);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- OCRepPayloadDestroy((OCRepPayload*)encap_get_ctx->oic_payload);
- _icd_encap_get_context_free(encap_get_ctx);
- return OC_STACK_DELETE_TRANSACTION;
- }
-
- return OC_STACK_DELETE_TRANSACTION;
-}
-
-
-static int _worker_encap_get(void *context)
-{
- int ret, conn_type;
- char *host_address;
- icd_encap_info_s *encap_info;
- icd_encap_worker_ctx_s *encap_ctx = context;
-
- if (false == encap_ctx->is_valid)
- return IOTCON_ERROR_NONE;
-
- ret = icd_ioty_get_host_address(&encap_ctx->dev_addr, &host_address, &conn_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_get_host_address() Fail");
- return ret;
- }
-
- encap_info = _icd_ioty_encap_table_get_info(encap_ctx->uri_path, host_address);
- if (NULL == encap_info) {
- ERR("_icd_ioty_encap_table_get_info() Fail");
- free(host_address);
- return IOTCON_ERROR_NO_DATA;
- }
- free(host_address);
-
- g_source_remove(encap_info->get_timer_id);
- icd_ioty_encap_get(encap_info);
- encap_info->get_timer_id = g_timeout_add_seconds(icd_ioty_encap_get_time_interval(),
- icd_ioty_encap_get, encap_info);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_encap_observe_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp)
-{
- FN_CALL;
- int ret;
- icd_encap_worker_ctx_s *encap_ctx = ctx;
-
- RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
-
- if (OC_OBSERVE_DEREGISTER == resp->sequenceNumber)
- return OC_STACK_DELETE_TRANSACTION;
-
- if (OC_STACK_OK != resp->result)
- return OC_STACK_KEEP_TRANSACTION;
-
- memcpy(&encap_ctx->dev_addr, &resp->devAddr, sizeof(OCDevAddr));
-
- ret = _ocprocess_worker_start(_worker_encap_get, encap_ctx, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- return OC_STACK_KEEP_TRANSACTION;
- }
-
- return OC_STACK_KEEP_TRANSACTION;
-}
-
-
-OCStackApplicationResult icd_ioty_ocprocess_encap_presence_cb(void *ctx,
- OCDoHandle handle, OCClientResponse *resp)
-{
- FN_CALL;
- int ret;
- icd_encap_worker_ctx_s *encap_ctx = ctx;
- OCPresencePayload *payload = (OCPresencePayload*)resp->payload;
-
- RETV_IF(NULL == resp, OC_STACK_KEEP_TRANSACTION);
-
- if ((OC_STACK_OK == resp->result) && (OC_PRESENCE_TRIGGER_DELETE != payload->trigger))
- return OC_STACK_KEEP_TRANSACTION;
-
- memcpy(&encap_ctx->dev_addr, &resp->devAddr, sizeof(OCDevAddr));
-
- ret = _ocprocess_worker_start(_worker_encap_get, encap_ctx, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ocprocess_worker_start() Fail(%d)", ret);
- return OC_STACK_KEEP_TRANSACTION;
- }
-
- return OC_STACK_KEEP_TRANSACTION;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_OCPROCESS_H__
-#define __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_OCPROCESS_H__
-
-#include <glib.h>
-#include <octypes.h>
-
-void icd_ioty_ocprocess_stop();
-
-gpointer icd_ioty_ocprocess_thread(gpointer data);
-
-OCEntityHandlerResult icd_ioty_ocprocess_req_handler(OCEntityHandlerFlag flag,
- OCEntityHandlerRequest *request, void *user_data);
-
-OCStackApplicationResult icd_ioty_ocprocess_find_cb(void *ctx, OCDoHandle handle,
- OCClientResponse* resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_get_cb(void *ctx, OCDoHandle handle,
- OCClientResponse* resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_put_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_post_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_delete_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_observe_cb(void *ctx, OCDoHandle handle,
- OCClientResponse* resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle handle,
- OCClientResponse* resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_info_cb(void *ctx, OCDoHandle handle,
- OCClientResponse *resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_encap_get_cb(void *ctx, OCDoHandle handle,
- OCClientResponse* resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_encap_observe_cb(void *ctx, OCDoHandle handle,
- OCClientResponse* resp);
-
-OCStackApplicationResult icd_ioty_ocprocess_encap_presence_cb(void *ctx,
- OCDoHandle handle, OCClientResponse* resp);
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_OCPROCESS_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <limits.h>
-
-#include <octypes.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icd.h"
-#include "icd-ioty-type.h"
-
-OCConnectivityType icd_ioty_conn_type_to_oic_conn_type(int conn_type)
-{
- OCConnectivityType oic_conn_type = CT_DEFAULT;
-
- switch (conn_type) {
- case IOTCON_CONNECTIVITY_IPV4:
- oic_conn_type = CT_ADAPTER_IP | CT_IP_USE_V4;
- break;
- case IOTCON_CONNECTIVITY_IPV6:
- oic_conn_type = CT_ADAPTER_IP | CT_IP_USE_V6;
- break;
- case IOTCON_CONNECTIVITY_BT_EDR:
- oic_conn_type = CT_ADAPTER_RFCOMM_BTEDR;
- break;
- case IOTCON_CONNECTIVITY_BT_LE:
- oic_conn_type = CT_ADAPTER_GATT_BTLE;
- break;
- case IOTCON_CONNECTIVITY_ALL:
- default:
- oic_conn_type = CT_DEFAULT;
- }
-
- return oic_conn_type;
-}
-
-
-int icd_ioty_transport_flag_to_conn_type(OCTransportAdapter adapter,
- OCTransportFlags flag)
-{
- int conn_type = IOTCON_CONNECTIVITY_ALL;
-
- /* Need to consider to allow various connectivity types */
- switch (adapter) {
- case OC_ADAPTER_IP:
- if (OC_IP_USE_V4 & flag)
- conn_type = IOTCON_CONNECTIVITY_IPV4;
- else if (OC_IP_USE_V6 & flag)
- conn_type = IOTCON_CONNECTIVITY_IPV6;
- break;
- case OC_ADAPTER_RFCOMM_BTEDR:
- conn_type = IOTCON_CONNECTIVITY_BT_EDR;
- break;
- case OC_ADAPTER_GATT_BTLE:
- conn_type = IOTCON_CONNECTIVITY_BT_LE;
- break;
- default:
- ERR("Invalid Adpater");
- }
-
- return conn_type;
-}
-
-
-static void _icd_ioty_conn_type_to_oic_transport_type(int conn_type,
- OCTransportAdapter *adapter, OCTransportFlags *flag)
-{
- switch (conn_type) {
- case IOTCON_CONNECTIVITY_IPV4:
- *adapter = OC_ADAPTER_IP;
- *flag = OC_IP_USE_V4;
- break;
- case IOTCON_CONNECTIVITY_IPV6:
- *adapter = OC_ADAPTER_IP;
- *flag = OC_IP_USE_V6;
- break;
- case IOTCON_CONNECTIVITY_BT_EDR:
- *adapter = OC_ADAPTER_RFCOMM_BTEDR;
- *flag = OC_DEFAULT_FLAGS;
- break;
- case IOTCON_CONNECTIVITY_BT_LE:
- *adapter = OC_ADAPTER_GATT_BTLE;
- *flag = OC_DEFAULT_FLAGS;
- break;
- case IOTCON_CONNECTIVITY_ALL:
- default:
- *adapter = OC_DEFAULT_ADAPTER;
- *flag = OC_DEFAULT_FLAGS;
- }
-}
-
-
-int icd_ioty_get_dev_addr(const char *host_address, int conn_type, OCDevAddr *dev_addr)
-{
- char host[PATH_MAX] = {0};
- char *dev_host, *ptr = NULL;
-
- snprintf(host, sizeof(host), "%s", host_address);
-
- switch (conn_type) {
- case IOTCON_CONNECTIVITY_IPV4:
- dev_host = strtok_r(host, ":", &ptr);
- snprintf(dev_addr->addr, sizeof(dev_addr->addr), "%s", dev_host);
- dev_addr->port = atoi(strtok_r(NULL, ":", &ptr));
- break;
- case IOTCON_CONNECTIVITY_IPV6:
- dev_host = strtok_r(host, "]", &ptr);
- snprintf(dev_addr->addr, sizeof(dev_addr->addr), "%s", dev_host);
- dev_addr->port = atoi(strtok_r(NULL, "]", &ptr));
- break;
- case IOTCON_CONNECTIVITY_BT_EDR:
- snprintf(dev_addr->addr, sizeof(dev_addr->addr), "%s", host);
- break;
- case IOTCON_CONNECTIVITY_BT_LE:
- default:
- ERR("Invalid Connectivity Type(%d)", conn_type);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- _icd_ioty_conn_type_to_oic_transport_type(conn_type, &(dev_addr->adapter),
- &(dev_addr->flags));
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_get_host_address(OCDevAddr *dev_addr, char **host_address, int *conn_type)
-{
- int connectivity_type;
- char host_addr[PATH_MAX] = {0};
-
- connectivity_type = icd_ioty_transport_flag_to_conn_type(dev_addr->adapter,
- dev_addr->flags);
-
- switch (connectivity_type) {
- case IOTCON_CONNECTIVITY_IPV6:
- snprintf(host_addr, sizeof(host_addr), "[%s]:%d", dev_addr->addr,
- dev_addr->port);
- break;
- case IOTCON_CONNECTIVITY_IPV4:
- snprintf(host_addr, sizeof(host_addr), "%s:%d", dev_addr->addr,
- dev_addr->port);
- break;
- case IOTCON_CONNECTIVITY_BT_EDR:
- snprintf(host_addr, sizeof(host_addr), "%s", dev_addr->addr);
- break;
- case IOTCON_CONNECTIVITY_BT_LE:
- default:
- ERR("Invalid Connectivity Type(%d)", connectivity_type);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- *host_address = strdup(host_addr);
-
- *conn_type = connectivity_type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_oic_properties_to_properties(int oic_properties)
-{
- int prop = IOTCON_RESOURCE_NO_PROPERTY;
-
- if (OC_DISCOVERABLE & oic_properties)
- prop |= IOTCON_RESOURCE_DISCOVERABLE;
-
- if (OC_OBSERVABLE & oic_properties)
- prop |= IOTCON_RESOURCE_OBSERVABLE;
-
- if (OC_ACTIVE & oic_properties)
- prop |= IOTCON_RESOURCE_ACTIVE;
-
- if (OC_SLOW & oic_properties)
- prop |= IOTCON_RESOURCE_SLOW;
-
- if (OC_SECURE & oic_properties)
- prop |= IOTCON_RESOURCE_SECURE;
-
- if (OC_EXPLICIT_DISCOVERABLE & oic_properties)
- prop |= IOTCON_RESOURCE_EXPLICIT_DISCOVERABLE;
-
- return prop;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_TYPE_H__
-#define __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_TYPE_H__
-
-#include <octypes.h>
-
-OCConnectivityType icd_ioty_conn_type_to_oic_conn_type(int conn_type);
-
-int icd_ioty_transport_flag_to_conn_type(OCTransportAdapter adapter,
- OCTransportFlags flag);
-
-int icd_ioty_get_dev_addr(const char *host_address, int conn_type, OCDevAddr *dev_addr);
-
-int icd_ioty_get_host_address(OCDevAddr *dev_addr, char **host_address, int *conn_type);
-
-int icd_ioty_oic_properties_to_properties(int oic_properties);
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_TYPE_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdlib.h>
-#include <stdint.h> /* for uint8_t etc */
-#include <errno.h>
-#include <glib.h>
-#include <tizen_type.h>
-#include <system_info.h>
-#include <system_settings.h>
-
-#include <octypes.h>
-#include <ocstack.h>
-
-#include "iotcon.h"
-#include "ic-dbus.h"
-#include "ic-utils.h"
-#include "icd.h"
-#include "icd-cynara.h"
-#include "icd-payload.h"
-#include "icd-dbus.h"
-#include "icd-ioty.h"
-#include "icd-ioty-type.h"
-#include "icd-ioty-ocprocess.h"
-
-#define ICD_UUID_LENGTH 37
-#define ICD_REMOTE_RESOURCE_DEFAULT_TIME_INTERVAL 10 /* 10 sec */
-
-static int icd_remote_resource_time_interval = ICD_REMOTE_RESOURCE_DEFAULT_TIME_INTERVAL;
-
-static const char *ICD_SYSTEM_INFO_PLATFORM_NAME = "http://tizen.org/system/platform.name";
-static const char *ICD_SYSTEM_INFO_PLATFORM_VERSION = "http://tizen.org/feature/platform.version";
-static const char *ICD_SYSTEM_INFO_MANUF_NAME = "http://tizen.org/system/manufacturer";
-static const char *ICD_SYSTEM_INFO_MODEL_NAME = "http://tizen.org/system/model_name";
-static const char *ICD_SYSTEM_INFO_BUILD_STRING = "http://tizen.org/system/build.string";
-
-static GHashTable *icd_ioty_encap_table;
-static GHashTable *icd_ioty_presence_table;
-
-static GMutex icd_csdk_mutex;
-
-void icd_ioty_csdk_lock()
-{
- g_mutex_lock(&icd_csdk_mutex);
-}
-
-
-void icd_ioty_csdk_unlock()
-{
- g_mutex_unlock(&icd_csdk_mutex);
-}
-
-
-GThread* icd_ioty_init(const char *addr, unsigned short port)
-{
- FN_CALL;
- GError *error;
- GThread *thread;
-
- OCStackResult result = OCInit(addr, port, OC_CLIENT_SERVER);
- if (OC_STACK_OK != result) {
- ERR("OCInit() Fail(%d)", result);
- return NULL;
- }
-
- DBG("OCInit() Success");
-
- thread = g_thread_try_new("packet_receive_thread", icd_ioty_ocprocess_thread,
- NULL, &error);
- if (NULL == thread) {
- ERR("g_thread_try_new() Fail(%s)", error->message);
- g_error_free(error);
- return NULL;
- }
-
- return thread;
-}
-
-
-void icd_ioty_deinit(GThread *thread)
-{
- OCStackResult result;
-
- icd_ioty_ocprocess_stop();
- g_thread_join(thread);
-
- result = OCStop();
- if (OC_STACK_OK != result)
- ERR("OCStop() Fail(%d)", result);
-}
-
-static int _ioty_properties_to_oic_properties(int properties)
-{
- int prop = OC_RES_PROP_NONE;
-
- if (IOTCON_RESOURCE_DISCOVERABLE & properties)
- prop |= OC_DISCOVERABLE;
-
- if (IOTCON_RESOURCE_OBSERVABLE & properties)
- prop |= OC_OBSERVABLE;
-
- if (IOTCON_RESOURCE_ACTIVE & properties)
- prop |= OC_ACTIVE;
-
- if (IOTCON_RESOURCE_SLOW & properties)
- prop |= OC_SLOW;
-
- if (IOTCON_RESOURCE_SECURE & properties)
- prop |= OC_SECURE;
-
- if (IOTCON_RESOURCE_EXPLICIT_DISCOVERABLE & properties)
- prop |= OC_EXPLICIT_DISCOVERABLE;
-
- /* TODO: Secure option is not supported yet. */
- properties = (properties & OC_SECURE) ? (properties ^ OC_SECURE) : properties;
-
- return prop;
-}
-
-OCResourceHandle icd_ioty_register_resource(const char *uri_path,
- const char* const *res_types, const char* const *res_ifaces, int properties)
-{
- FN_CALL;
- int i;
- OCStackResult ret;
- OCResourceHandle handle;
-
- properties = _ioty_properties_to_oic_properties(properties);
-
- icd_ioty_csdk_lock();
- ret = OCCreateResource(&handle, res_types[0], res_ifaces[0], uri_path,
- icd_ioty_ocprocess_req_handler, NULL, properties);
- icd_ioty_csdk_unlock();
- if (OC_STACK_OK != ret) {
- ERR("OCCreateResource() Fail(%d)", ret);
- return NULL;
- }
-
- for (i = 1; res_types[i]; i++)
- icd_ioty_bind_type(handle, res_types[i]);
-
- for (i = 1; res_ifaces[i]; i++)
- icd_ioty_bind_interface(handle, res_ifaces[i]);
-
- return handle;
-}
-
-
-int icd_ioty_unregister_resource(OCResourceHandle handle)
-{
- OCStackResult ret;
-
- icd_ioty_csdk_lock();
- ret = OCDeleteResource(handle);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != ret) {
- ERR("OCDeleteResource() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_bind_interface(OCResourceHandle handle, const char *resource_interface)
-{
- OCStackResult ret;
-
- icd_ioty_csdk_lock();
- ret = OCBindResourceInterfaceToResource(handle, resource_interface);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != ret) {
- ERR("OCBindResourceInterfaceToResource() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_bind_type(OCResourceHandle handle, const char *resource_type)
-{
- OCStackResult ret;
-
- icd_ioty_csdk_lock();
- ret = OCBindResourceTypeToResource(handle, resource_type);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != ret) {
- ERR("OCBindResourceTypeToResource() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_bind_resource(OCResourceHandle parent, OCResourceHandle child)
-{
- OCStackResult ret;
-
- icd_ioty_csdk_lock();
- ret = OCBindResource(parent, child);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != ret) {
- ERR("OCBindResource() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_unbind_resource(OCResourceHandle parent, OCResourceHandle child)
-{
- OCStackResult ret;
-
- icd_ioty_csdk_lock();
- ret = OCUnBindResource(parent, child);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != ret) {
- ERR("OCUnBindResource() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-static OCQualityOfService _icd_ioty_convert_qos(gint qos)
-{
- switch (qos) {
- case IOTCON_QOS_HIGH:
- return OC_HIGH_QOS;
- case IOTCON_QOS_LOW:
- return OC_LOW_QOS;
- default:
- ERR("Invalid value(%d)", qos);
- return OC_NA_QOS;
- }
-}
-
-
-int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers, gint qos)
-{
- int i, obs_length, msg_length;
- GVariant *repr_gvar;
- GVariantIter obs_iter, msg_iter;
- OCStackResult ret;
- OCRepPayload *payload = NULL;
- OCQualityOfService oc_qos;
-
- g_variant_iter_init(&obs_iter, observers);
- obs_length = g_variant_iter_n_children(&obs_iter);
-
- /* Variable-length Array */
- OCObservationId obs_ids[obs_length];
-
- for (i = 0; i < obs_length; i++)
- g_variant_iter_loop(&obs_iter, "i", &obs_ids[i]);
-
- g_variant_iter_init(&msg_iter, msg);
- msg_length = g_variant_iter_n_children(&msg_iter);
- if (msg_length) {
- g_variant_iter_loop(&msg_iter, "v", &repr_gvar);
- /* TODO : How to use error_code. */
- payload = icd_payload_representation_from_gvariant(repr_gvar);
- }
-
- oc_qos = _icd_ioty_convert_qos(qos);
-
- icd_ioty_csdk_lock();
- /* TODO : QoS is come from lib. */
- if (msg_length)
- ret = OCNotifyListOfObservers(handle, obs_ids, obs_length, payload, oc_qos);
- else
- ret = OCNotifyAllObservers(handle, oc_qos);
-
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_NO_OBSERVERS == ret) {
- WARN("No Observers. Stop Notifying");
- return IOTCON_ERROR_NONE;
- } else if (OC_STACK_OK != ret) {
- ERR("OCNotifyListOfObservers() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _ioty_get_header_options(GVariantIter *src, int src_size,
- OCHeaderOption dest[], int dest_size)
-{
- int i = 0;
- char *option_data;
- unsigned short option_id;
-
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (dest_size < src_size) {
- ERR("Exceed Size(%d)", src_size);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- while (g_variant_iter_loop(src, "(q&s)", &option_id, &option_data)) {
- dest[i].protocolID = OC_COAP_ID;
- dest[i].optionID = option_id;
- dest[i].optionLength = strlen(option_data) + 1;
- memcpy(dest[i].optionData, option_data, dest[i].optionLength);
- i++;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_send_response(GVariant *resp)
-{
- GVariant *repr_gvar;
- GVariantIter *options;
- OCStackResult ret;
- OCEntityHandlerResponse response = {0};
- int result, options_size;
- int64_t request_handle, resource_handle;
-
- g_variant_get(resp, "(a(qs)ivxx)",
- &options,
- &result,
- &repr_gvar,
- &request_handle,
- &resource_handle);
-
- response.requestHandle = ICD_INT64_TO_POINTER(request_handle);
- response.resourceHandle = ICD_INT64_TO_POINTER(resource_handle);
- response.ehResult = (OCEntityHandlerResult)result;
-
- options_size = g_variant_iter_n_children(options);
- response.numSendVendorSpecificHeaderOptions = options_size;
-
- if (0 != options_size) {
- int ret = _ioty_get_header_options(options,
- response.numSendVendorSpecificHeaderOptions,
- response.sendVendorSpecificHeaderOptions,
- sizeof(response.sendVendorSpecificHeaderOptions)
- / sizeof(response.sendVendorSpecificHeaderOptions[0]));
-
- if (IOTCON_ERROR_NONE != ret)
- ERR("_ioty_get_header_options() Fail(%d)", ret);
- }
- g_variant_iter_free(options);
-
- response.payload = (OCPayload*)icd_payload_representation_from_gvariant(repr_gvar);
-
- /* related to block transfer */
- response.persistentBufferFlag = 0;
-
- icd_ioty_csdk_lock();
- ret = OCDoResponse(&response);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != ret) {
- ERR("OCDoResponse() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _ioty_free_signal_context(void *data)
-{
- icd_sig_ctx_s *context = data;
- free(context->bus_name);
- free(context);
-}
-
-
-static gboolean _icd_ioty_discovery_timeout(gpointer user_data)
-{
- int ret;
- OCDoHandle handle = user_data;
-
- icd_ioty_csdk_lock();
- ret = OCCancel(handle, OC_LOW_QOS, NULL, 0);
- icd_ioty_csdk_unlock();
- if (OC_STACK_OK != ret) {
- ERR("OCCancel() Fail(%d)", ret);
- return G_SOURCE_REMOVE;
- }
-
- return G_SOURCE_REMOVE;
-}
-
-
-int icd_ioty_find_resource(const char *host_address,
- int conn_type,
- const char *resource_type,
- bool is_secure,
- int timeout,
- int64_t signal_number,
- const char *bus_name)
-{
- int len;
- char *coap_str;
- OCDoHandle handle;
- OCStackResult result;
- icd_sig_ctx_s *context;
- char uri[PATH_MAX] = {0};
- OCCallbackData cbdata = {0};
- OCConnectivityType oic_conn_type;
-
- coap_str = is_secure ? ICD_IOTY_COAPS : ICD_IOTY_COAP;
-
- if (IC_STR_EQUAL == strcmp(IC_STR_NULL, host_address)) {
- len = snprintf(uri, sizeof(uri), "%s", OC_RSRVD_WELL_KNOWN_URI);
- } else {
- len = snprintf(uri, sizeof(uri), "%s%s%s", coap_str, host_address,
- OC_RSRVD_WELL_KNOWN_URI);
- }
- if (len <= 0 || sizeof(uri) <= len) {
- ERR("snprintf() Fail(%d)", len);
- return IOTCON_ERROR_IO_ERROR;
- }
-
- if (IC_STR_EQUAL != strcmp(IC_STR_NULL, resource_type))
- snprintf(uri + len, sizeof(uri) - len, "?rt=%s", resource_type);
-
- context = calloc(1, sizeof(icd_sig_ctx_s));
- if (NULL == context) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- context->bus_name = ic_utils_strdup(bus_name);
- context->signal_number = signal_number;
-
- cbdata.context = context;
- cbdata.cb = icd_ioty_ocprocess_find_cb;
- cbdata.cd = _ioty_free_signal_context;
-
- oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
-
- icd_ioty_csdk_lock();
- /* TODO : QoS is come from lib. */
- result = OCDoResource(&handle, OC_REST_DISCOVER, uri, NULL, NULL, oic_conn_type,
- OC_LOW_QOS, &cbdata, NULL, 0);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != result) {
- ERR("OCDoResource() Fail(%d)", result);
- free(context->bus_name);
- free(context);
- return icd_ioty_convert_error(result);
- }
-
- g_timeout_add_seconds(timeout, _icd_ioty_discovery_timeout, handle);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/*
- * returned string SHOULD be released by you
- */
-static char* _icd_ioty_resource_generate_uri(char *uri_path, GVariant *query)
-{
- int len;
- bool loop_first = true;
- char *key, *value;
- GVariantIter query_iter;
- char uri_buf[PATH_MAX] = {0};
-
- len = snprintf(uri_buf, sizeof(uri_buf), "%s", uri_path);
-
- /* remove suffix '/' */
- if ('/' == uri_buf[strlen(uri_buf) - 1]) {
- uri_buf[strlen(uri_buf) - 1] = '\0';
- len--;
- }
-
- g_variant_iter_init(&query_iter, query);
-
- while (g_variant_iter_loop(&query_iter, "(&s&s)", &key, &value)) {
- int query_len;
-
- DBG("query exist. key(%s), value(%s)", key, value);
-
- if (true == loop_first) {
- query_len = snprintf(uri_buf + len, sizeof(uri_buf) - len, "?%s=%s", key, value);
- loop_first = false;
- } else {
- query_len = snprintf(uri_buf + len, sizeof(uri_buf) - len, ";%s=%s", key, value);
- }
-
- len += query_len;
- }
-
- return strdup(uri_buf);
-}
-
-
-void icd_ioty_complete(int type, GDBusMethodInvocation *invocation, GVariant *value)
-{
- switch (type) {
- case ICD_CRUD_GET:
- ic_dbus_complete_get(icd_dbus_get_object(), invocation, value);
- break;
- case ICD_CRUD_PUT:
- ic_dbus_complete_put(icd_dbus_get_object(), invocation, value);
- break;
- case ICD_CRUD_POST:
- ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
- break;
- case ICD_CRUD_DELETE:
- ic_dbus_complete_delete(icd_dbus_get_object(), invocation, value);
- break;
- default:
- INFO("Invalid Type(%d)", type);
- }
-}
-
-
-void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int ret_val)
-{
- GVariant *value;
- GVariant *payload;
- GVariantBuilder options;
-
- switch (type) {
- case ICD_CRUD_GET:
- g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
- payload = icd_payload_representation_empty_gvariant();
- value = g_variant_new("(a(qs)vi)", &options, payload, ret_val);
- ic_dbus_complete_get(icd_dbus_get_object(), invocation, value);
- break;
- case ICD_CRUD_PUT:
- g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
- payload = icd_payload_representation_empty_gvariant();
- value = g_variant_new("(a(qs)vi)", &options, payload, ret_val);
- ic_dbus_complete_put(icd_dbus_get_object(), invocation, value);
- break;
- case ICD_CRUD_POST:
- g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
- payload = icd_payload_representation_empty_gvariant();
- value = g_variant_new("(a(qs)vi)", &options, payload, ret_val);
- ic_dbus_complete_post(icd_dbus_get_object(), invocation, value);
- break;
- case ICD_CRUD_DELETE:
- g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
- value = g_variant_new("(a(qs)i)", &options, ret_val);
- ic_dbus_complete_delete(icd_dbus_get_object(), invocation, value);
- break;
- default:
- INFO("Invalid Type(%d)", type);
- }
-
-}
-
-
-static gboolean _icd_ioty_crud(int type,
- icDbus *object,
- GDBusMethodInvocation *invocation,
- GVariant *resource,
- GVariant *query,
- GVariant *repr)
-{
- bool is_secure;
- OCMethod rest_type;
- OCStackResult result;
- GVariantIter *options;
- OCCallbackData cbdata = {0};
- int ret, conn_type, options_size;
- char *uri_path, *uri, *host;
- OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
- OCHeaderOption *oic_options_ptr = NULL;
- OCPayload *payload = NULL;
- OCConnectivityType oic_conn_type;
- OCDevAddr dev_addr = {0};
-
- ret = icd_cynara_check_network(invocation);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_check_network() Fail(%d)", ret);
- icd_ioty_complete_error(type, invocation, ret);
- return TRUE;
- }
-
- switch (type) {
- case ICD_CRUD_GET:
- cbdata.cb = icd_ioty_ocprocess_get_cb;
- rest_type = OC_REST_GET;
- break;
- case ICD_CRUD_PUT:
- cbdata.cb = icd_ioty_ocprocess_put_cb;
- rest_type = OC_REST_PUT;
- break;
- case ICD_CRUD_POST:
- cbdata.cb = icd_ioty_ocprocess_post_cb;
- rest_type = OC_REST_POST;
- break;
- case ICD_CRUD_DELETE:
- cbdata.cb = icd_ioty_ocprocess_delete_cb;
- rest_type = OC_REST_DELETE;
- break;
- default:
- ERR("Invalid CRUD Type(%d)", type);
- return TRUE;
- }
-
- g_variant_get(resource, "(&s&sba(qs)i)", &uri_path, &host, &is_secure, &options,
- &conn_type);
-
- switch (type) {
- case ICD_CRUD_GET:
- case ICD_CRUD_PUT:
- case ICD_CRUD_POST:
- uri = _icd_ioty_resource_generate_uri(uri_path, query);
- if (NULL == uri) {
- ERR("_icd_ioty_resource_generate_uri() Fail");
- g_variant_iter_free(options);
- icd_ioty_complete_error(type, invocation, IOTCON_ERROR_INVALID_PARAMETER);
- return TRUE;
- }
- break;
- case ICD_CRUD_DELETE:
- uri = strdup(uri_path);
- break;
- }
-
- cbdata.context = invocation;
-
- options_size = g_variant_iter_n_children(options);
- if (0 != options_size) {
- int ret = _ioty_get_header_options(options, options_size, oic_options,
- sizeof(oic_options) / sizeof(oic_options[0]));
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ioty_get_header_options() Fail(%d)", ret);
- free(uri);
- g_variant_iter_free(options);
- icd_ioty_complete_error(type, invocation, ret);
- return TRUE;
- }
- oic_options_ptr = oic_options;
- }
- g_variant_iter_free(options);
-
- if (repr)
- payload = (OCPayload*)icd_payload_representation_from_gvariant(repr);
-
- oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
-
- ret = icd_ioty_get_dev_addr(host, conn_type, &dev_addr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_get_dev_addr() Fail(%d)", ret);
- icd_ioty_complete_error(type, invocation, IOTCON_ERROR_IOTIVITY);
- free(uri);
- return TRUE;
- }
-
- icd_ioty_csdk_lock();
- /* TODO : QoS is come from lib. And user can set QoS to client structure. */
- result = OCDoResource(NULL, rest_type, uri, &dev_addr, payload, oic_conn_type,
- OC_HIGH_QOS, &cbdata, oic_options_ptr, options_size);
- icd_ioty_csdk_unlock();
-
- free(uri);
-
- if (OC_STACK_OK != result) {
- ERR("OCDoResource() Fail(%d)", result);
- icd_ioty_complete_error(type, invocation, icd_ioty_convert_error(result));
- return TRUE;
- }
-
- return TRUE;
-}
-
-gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *resource, GVariant *query)
-{
- return _icd_ioty_crud(ICD_CRUD_GET, object, invocation, resource, query, NULL);
-}
-
-
-gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *resource, GVariant *repr, GVariant *query)
-{
- return _icd_ioty_crud(ICD_CRUD_PUT, object, invocation, resource, query, repr);
-}
-
-
-gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *resource, GVariant *repr, GVariant *query)
-{
- return _icd_ioty_crud(ICD_CRUD_POST, object, invocation, resource, query, repr);
-}
-
-
-gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *resource)
-{
- return _icd_ioty_crud(ICD_CRUD_DELETE, object, invocation, resource, NULL, NULL);
-}
-
-
-static OCDoHandle _icd_ioty_observe_register(const char *uri_path,
- OCDevAddr *dev_addr,
- GVariantIter *options,
- OCMethod method,
- OCConnectivityType oic_conn_type,
- OCCallbackData *cbdata)
-{
- OCDoHandle handle;
- int options_size = 0;
- OCStackResult result;
- OCHeaderOption *oic_options_ptr = NULL;
- OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
-
- if (options) {
- options_size = g_variant_iter_n_children(options);
- if (0 != options_size) {
- int ret = _ioty_get_header_options(options, options_size, oic_options,
- sizeof(oic_options) / sizeof(oic_options[0]));
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ioty_get_header_options() Fail(%d)", ret);
- if (cbdata->cd)
- cbdata->cd(cbdata->context);
- return NULL;
- }
- oic_options_ptr = oic_options;
- }
- }
-
- icd_ioty_csdk_lock();
- /* TODO : QoS is come from lib. And user can set QoS to client structure. */
- result = OCDoResource(&handle, method, uri_path, dev_addr, NULL, oic_conn_type,
- OC_HIGH_QOS, cbdata, oic_options_ptr, options_size);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != result) {
- ERR("OCDoResource() Fail(%d)", result);
- if (cbdata->cd)
- cbdata->cd(cbdata->context);
- return NULL;
- }
-
- return handle;
-}
-
-
-OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_policy,
- GVariant *query, int64_t signal_number, const char *bus_name)
-{
- bool is_secure;
- OCMethod method;
- OCDoHandle handle;
- GVariantIter *options;
- int ret, conn_type;
- icd_sig_ctx_s *context;
- char *uri_path, *host, *uri;
- OCDevAddr dev_addr = {0};
- OCCallbackData cbdata = {0};
- OCConnectivityType oic_conn_type;
-
- g_variant_get(resource, "(&s&sba(qs)i)", &uri_path, &host, &is_secure, &options,
- &conn_type);
-
- uri = _icd_ioty_resource_generate_uri(uri_path, query);
- if (NULL == uri) {
- ERR("_icd_ioty_resource_generate_uri() Fail");
- g_variant_iter_free(options);
- return NULL;
- }
-
- switch (observe_policy) {
- case IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER:
- method = OC_REST_OBSERVE;
- break;
- case IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER:
- default:
- method = OC_REST_OBSERVE_ALL;
- }
-
- oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
-
- ret = icd_ioty_get_dev_addr(host, conn_type, &dev_addr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_get_dev_addr() Fail(%d)", ret);
- free(uri);
- g_variant_iter_free(options);
- return NULL;
- }
-
- context = calloc(1, sizeof(icd_sig_ctx_s));
- if (NULL == context) {
- ERR("calloc() Fail(%d)", errno);
- free(uri);
- g_variant_iter_free(options);
- return NULL;
- }
-
- context->signal_number = signal_number;
- context->bus_name = ic_utils_strdup(bus_name);
-
- cbdata.context = context;
- cbdata.cb = icd_ioty_ocprocess_observe_cb;
- cbdata.cd = _ioty_free_signal_context;
-
- handle = _icd_ioty_observe_register(uri, &dev_addr, options, method, oic_conn_type,
- &cbdata);
- if (NULL == handle)
- ERR("_icd_ioty_observe_register() Fail");
-
- free(uri);
- g_variant_iter_free(options);
-
- return handle;
-}
-
-
-int icd_ioty_observer_stop(OCDoHandle handle, GVariant *options)
-{
- OCStackResult ret;
- int options_size = 0;
- GVariantIter options_iter;
- OCHeaderOption oic_options[MAX_HEADER_OPTIONS];
- OCHeaderOption *oic_options_ptr = NULL;
-
- if (options) {
- g_variant_iter_init(&options_iter, options);
-
- options_size = g_variant_iter_n_children(&options_iter);
- if (0 != options_size) {
- int ret = _ioty_get_header_options(&options_iter, options_size, oic_options,
- sizeof(oic_options) / sizeof(oic_options[0]));
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ioty_get_header_options() Fail(%d)", ret);
- return ret;
- }
- oic_options_ptr = oic_options;
- }
- }
-
- icd_ioty_csdk_lock();
- ret = OCCancel(handle, OC_HIGH_QOS, oic_options_ptr, options_size);
- icd_ioty_csdk_unlock();
- if (OC_STACK_OK != ret) {
- ERR("OCCancel() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-int icd_ioty_get_info(int type, const char *host_address, int conn_type, int timeout,
- int64_t signal_number, const char *bus_name)
-{
- OCDoHandle handle;
- OCStackResult result;
- icd_sig_ctx_s *context;
- OCCallbackData cbdata = {0};
- char uri[PATH_MAX] = {0};
- char *uri_path = NULL;
- OCConnectivityType oic_conn_type;
-
- if (ICD_DEVICE_INFO == type)
- uri_path = OC_RSRVD_DEVICE_URI;
- else if (ICD_PLATFORM_INFO == type)
- uri_path = OC_RSRVD_PLATFORM_URI;
- else
- return IOTCON_ERROR_INVALID_PARAMETER;
-
- if (IC_STR_EQUAL == strcmp(IC_STR_NULL, host_address))
- snprintf(uri, sizeof(uri), "%s", uri_path);
- else
- snprintf(uri, sizeof(uri), "%s%s", host_address, uri_path);
-
- context = calloc(1, sizeof(icd_sig_ctx_s));
- if (NULL == context) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- context->bus_name = ic_utils_strdup(bus_name);
- context->signal_number = signal_number;
-
- cbdata.context = context;
- cbdata.cb = icd_ioty_ocprocess_info_cb;
- cbdata.cd = _ioty_free_signal_context;
-
- oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
-
- icd_ioty_csdk_lock();
- /* TODO : QoS is come from lib. And user can set QoS to client structure. */
- result = OCDoResource(&handle, OC_REST_DISCOVER, uri, NULL, NULL, oic_conn_type,
- OC_LOW_QOS, &cbdata, NULL, 0);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != result) {
- ERR("OCDoResource() Fail(%d)", result);
- free(context->bus_name);
- free(context);
- return icd_ioty_convert_error(result);
- }
-
- g_timeout_add_seconds(timeout, _icd_ioty_discovery_timeout, handle);
-
- return IOTCON_ERROR_NONE;
-}
-
-static int _ioty_set_device_info()
-{
- int ret;
- char *device_name = NULL;
- OCDeviceInfo device_info = {0};
-
- ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
- if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
- ERR("system_settings_get_value_string() Fail(%d)", ret);
- return IOTCON_ERROR_SYSTEM;
- }
-
- device_info.deviceName = device_name;
-
- icd_ioty_csdk_lock();
- ret = OCSetDeviceInfo(device_info);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != ret) {
- ERR("OCSetDeviceInfo() Fail(%d)", ret);
- free(device_name);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-static void _icd_ioty_on_device_name_changed_cb(system_settings_key_e key,
- void *user_data)
-{
- FN_CALL;
- int ret;
-
- ret = _ioty_set_device_info();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ioty_set_device_info() Fail(%d)", ret);
- return;
- }
-}
-
-int icd_ioty_set_device_info()
-{
- int ret;
-
- ret = system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_DEVICE_NAME,
- _icd_ioty_on_device_name_changed_cb, NULL);
- if (SYSTEM_SETTINGS_ERROR_NONE != ret) {
- ERR("system_settings_set_changed_cb() Fail(%d)", ret);
- return IOTCON_ERROR_SYSTEM;
- }
-
- ret = _ioty_set_device_info();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_ioty_set_device_info() Fail(%d)", ret);
- return ret;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-static void _ioty_free_platform_info(OCPlatformInfo platform_info)
-{
- free(platform_info.manufacturerName);
- free(platform_info.manufacturerUrl);
- free(platform_info.modelNumber);
- free(platform_info.dateOfManufacture);
- free(platform_info.platformVersion);
- free(platform_info.operatingSystemVersion);
- free(platform_info.hardwareVersion);
- free(platform_info.firmwareVersion);
- free(platform_info.supportUrl);
- free(platform_info.systemTime);
-}
-
-int icd_ioty_set_platform_info()
-{
- int ret;
- OCPlatformInfo platform_info = {0};
-
- ret = system_info_get_platform_string(ICD_SYSTEM_INFO_PLATFORM_NAME,
- &platform_info.platformID);
- if (SYSTEM_INFO_ERROR_NONE != ret) {
- ERR("system_info_get_platform_string() Fail(%d)", ret);
- _ioty_free_platform_info(platform_info);
- return IOTCON_ERROR_SYSTEM;
- }
-
- ret = system_info_get_platform_string(ICD_SYSTEM_INFO_MANUF_NAME,
- &platform_info.manufacturerName);
- if (SYSTEM_INFO_ERROR_NONE != ret) {
- ERR("system_info_get_platform_string() Fail(%d)", ret);
- _ioty_free_platform_info(platform_info);
- return IOTCON_ERROR_SYSTEM;
- }
-
- ret = system_info_get_platform_string(ICD_SYSTEM_INFO_MODEL_NAME,
- &platform_info.modelNumber);
- if (SYSTEM_INFO_ERROR_NONE != ret) {
- ERR("system_info_get_platform_string() Fail(%d)", ret);
- _ioty_free_platform_info(platform_info);
- return IOTCON_ERROR_SYSTEM;
- }
-
- ret = system_info_get_platform_string(ICD_SYSTEM_INFO_PLATFORM_VERSION,
- &platform_info.platformVersion);
- if (SYSTEM_INFO_ERROR_NONE != ret) {
- ERR("system_info_get_platform_string() Fail(%d)", ret);
- _ioty_free_platform_info(platform_info);
- return IOTCON_ERROR_SYSTEM;
- }
-
- ret = system_info_get_platform_string(ICD_SYSTEM_INFO_BUILD_STRING,
- &platform_info.firmwareVersion);
- if (SYSTEM_INFO_ERROR_NONE != ret) {
- ERR("system_info_get_platform_string() Fail(%d)", ret);
- _ioty_free_platform_info(platform_info);
- return IOTCON_ERROR_SYSTEM;
- }
-
- /* platform_info.manufacturerUrl */
- /* platform_info.dateOfManufacture */
- /* platform_info.operatingSystemVersion */
- /* platform_info.hardwareVersion */
- /* platform_info.supportUrl */
- /* platform_info.systemTime */
-
- icd_ioty_csdk_lock();
- ret = OCSetPlatformInfo(platform_info);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != ret) {
- ERR("OCSetPlatformInfo() Fail(%d)", ret);
- _ioty_free_platform_info(platform_info);
- return icd_ioty_convert_error(ret);
- }
- _ioty_free_platform_info(platform_info);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_ioty_presence_table_create()
-{
- if (icd_ioty_presence_table)
- return;
-
- icd_ioty_presence_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
-}
-
-
-static icd_presence_handle_info_s* _icd_ioty_presence_table_add(const char *host_address)
-{
- icd_presence_handle_info_s *handle_info;
-
- handle_info = calloc(1, sizeof(icd_presence_handle_info_s));
- if (NULL == handle_info) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
-
- handle_info->client_count = 1;
-
- g_hash_table_insert(icd_ioty_presence_table, ic_utils_strdup(host_address),
- handle_info);
-
- return handle_info;
-}
-
-
-static void _icd_ioty_presence_table_destroy()
-{
- g_hash_table_destroy(icd_ioty_presence_table);
- icd_ioty_presence_table = NULL;
-}
-
-
-static bool _icd_ioty_presence_table_remove(const char *host_address)
-{
- icd_presence_handle_info_s *handle_info;
-
- handle_info = g_hash_table_lookup(icd_ioty_presence_table, host_address);
- if (NULL == handle_info)
- return false;
-
- handle_info->client_count--;
- if (0 < handle_info->client_count)
- return false;
-
- g_hash_table_remove(icd_ioty_presence_table, host_address);
-
- if (0 == g_hash_table_size(icd_ioty_presence_table))
- _icd_ioty_presence_table_destroy();
-
- return true;
-}
-
-
-static icd_presence_handle_info_s* _icd_ioty_presence_table_get_handle_info(
- const char *host_address)
-{
- return g_hash_table_lookup(icd_ioty_presence_table, host_address);
-}
-
-
-OCDoHandle icd_ioty_presence_table_get_handle(const char *host_address)
-{
- icd_presence_handle_info_s *handle_info;
-
- handle_info = g_hash_table_lookup(icd_ioty_presence_table, host_address);
- if (NULL == handle_info)
- return NULL;
-
- return handle_info->handle;
-}
-
-
-static void _free_encap_worker_presence_ctx(void *data)
-{
- FN_CALL;
- icd_encap_worker_ctx_s *encap_ctx = data;
-
- encap_ctx->presence_flag = false;
- if (true == encap_ctx->observe_flag)
- return;
-
- free(encap_ctx->uri_path);
- free(encap_ctx);
-}
-
-
-static void _free_encap_worker_observe_ctx(void *data)
-{
- FN_CALL;
- icd_encap_worker_ctx_s *encap_ctx = data;
-
- encap_ctx->observe_flag = false;
- if (true == encap_ctx->presence_flag)
- return;
-
- free(encap_ctx->uri_path);
- free(encap_ctx);
-}
-
-
-OCDoHandle icd_ioty_subscribe_presence(int type, const char *host_address, int conn_type,
- const char *resource_type, void *context)
-{
- OCDoHandle handle;
- const char *address;
- OCStackResult result;
- char uri[PATH_MAX] = {0};
- OCCallbackData cbdata = {0};
- OCConnectivityType oic_conn_type;
- icd_presence_handle_info_s *handle_info;
-
- _icd_ioty_presence_table_create();
-
- if (IC_STR_EQUAL == strcmp(IC_STR_NULL, host_address) || '\0' == host_address[0])
- address = ICD_MULTICAST_ADDRESS;
- else
- address = host_address;
-
- handle_info = _icd_ioty_presence_table_get_handle_info(address);
- if (handle_info) {
- DBG("Already subscribe presence(%s)", address);
- handle_info->client_count++;
- return handle_info->handle;
- }
-
- handle_info = _icd_ioty_presence_table_add(address);
- if (NULL == handle_info) {
- ERR("_icd_ioty_presence_table_add() Fail");
- return NULL;
- }
-
- snprintf(uri, sizeof(uri), "%s%s", address, OC_RSRVD_PRESENCE_URI);
-
- switch (type) {
- case ICD_ENCAP_MONITORING:
- cbdata.context = context;
- cbdata.cb = icd_ioty_ocprocess_encap_presence_cb;
- cbdata.cd = _free_encap_worker_presence_ctx;
- break;
- case ICD_PRESENCE:
- default:
- cbdata.cb = icd_ioty_ocprocess_presence_cb;
- }
-
- oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
-
- icd_ioty_csdk_lock();
- result = OCDoResource(&handle, OC_REST_PRESENCE, uri, NULL, NULL, oic_conn_type,
- OC_LOW_QOS, &cbdata, NULL, 0);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != result) {
- ERR("OCDoResource() Fail(%d)", result);
- _icd_ioty_presence_table_remove(address);
- return NULL;
- }
-
- handle_info->handle = handle;
-
- return handle;
-}
-
-
-int icd_ioty_unsubscribe_presence(OCDoHandle handle, const char *host_address)
-{
- bool removed;
- OCStackResult ret;
- const char *address;
-
- if (IC_STR_EQUAL == strcmp(IC_STR_NULL, host_address) || '\0' == host_address[0])
- address = ICD_MULTICAST_ADDRESS;
- else
- address = host_address;
-
- removed = _icd_ioty_presence_table_remove(address);
- if (false == removed)
- return IOTCON_ERROR_NONE;
-
- icd_ioty_csdk_lock();
- ret = OCCancel(handle, OC_LOW_QOS, NULL, 0);
- icd_ioty_csdk_unlock();
- if (OC_STACK_OK != ret) {
- ERR("OCCancel() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_start_presence(unsigned int time_to_live)
-{
- OCStackResult ret;
-
- icd_ioty_csdk_lock();
- ret = OCStartPresence(time_to_live);
- icd_ioty_csdk_unlock();
- if (OC_STACK_OK != ret) {
- ERR("OCStartPresence() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_stop_presence()
-{
- OCStackResult ret;
-
- icd_ioty_csdk_lock();
- ret = OCStopPresence();
- icd_ioty_csdk_unlock();
- if (OC_STACK_OK != ret) {
- ERR("OCStopPresence() Fail(%d)", ret);
- return icd_ioty_convert_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icd_ioty_encap_get_time_interval()
-{
- return icd_remote_resource_time_interval;
-}
-
-
-static void _encap_set_time_interval(gpointer key, gpointer value, gpointer user_data)
-{
- icd_encap_info_s *encap_info = value;
-
- g_source_remove(encap_info->get_timer_id);
-
- encap_info->get_timer_id = g_timeout_add_seconds(icd_remote_resource_time_interval,
- icd_ioty_encap_get, encap_info);
-}
-
-
-void icd_ioty_encap_set_time_interval(int time_interval)
-{
- icd_remote_resource_time_interval = time_interval;
-
- g_hash_table_foreach(icd_ioty_encap_table, _encap_set_time_interval, NULL);
-}
-
-
-static void _free_encap_info(void *user_data)
-{
- icd_encap_info_s *encap_info = user_data;
-
- OCRepPayloadDestroy(encap_info->oic_payload);
- free(encap_info->uri_path);
- free(encap_info);
-}
-
-
-static icd_encap_info_s* _icd_ioty_encap_table_add(const char *uri_path,
- const char *host_address, int conn_type)
-{
- int ret;
- char key_str[PATH_MAX];
- icd_encap_info_s *encap_info;
-
- if (NULL == icd_ioty_encap_table) {
- icd_ioty_encap_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
- _free_encap_info);
- }
-
- encap_info = calloc(1, sizeof(icd_encap_info_s));
- if (NULL == encap_info) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
-
- ret = icd_ioty_get_dev_addr(host_address, conn_type, &encap_info->dev_addr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_get_dev_addr() Fail(%d)", ret);
- free(encap_info);
- return NULL;
- }
-
- /* encap_worker_ctx */
- encap_info->worker_ctx = calloc(1, sizeof(icd_encap_worker_ctx_s));
- if (NULL == encap_info->worker_ctx) {
- ERR("calloc() Fail(%d)", errno);
- free(encap_info);
- return NULL;
- }
- encap_info->worker_ctx->uri_path = ic_utils_strdup(uri_path);
- encap_info->worker_ctx->is_valid = true;
-
- encap_info->uri_path = ic_utils_strdup(uri_path);
- encap_info->oic_conn_type = icd_ioty_conn_type_to_oic_conn_type(conn_type);
- snprintf(key_str, sizeof(key_str), "%s%s", uri_path, host_address);
- encap_info->signal_number = icd_dbus_generate_signal_number();
-
- g_hash_table_insert(icd_ioty_encap_table, ic_utils_strdup(key_str),
- encap_info);
-
- return encap_info;
-}
-
-
-static void _icd_ioty_encap_table_remove(icd_encap_info_s *encap_info,
- const char *host_address)
-{
- char key_str[PATH_MAX];
-
- snprintf(key_str, sizeof(key_str), "%s%s", encap_info->uri_path, host_address);
-
- g_hash_table_remove(icd_ioty_encap_table, key_str);
-
- if (0 == g_hash_table_size(icd_ioty_encap_table)) {
- g_hash_table_destroy(icd_ioty_encap_table);
- icd_ioty_encap_table = NULL;
- }
-}
-
-
-icd_encap_info_s* _icd_ioty_encap_table_get_info(const char *uri_path,
- const char *host_address)
-{
- char key_str[PATH_MAX];
- icd_encap_info_s *encap_info;
-
- if (NULL == icd_ioty_encap_table)
- return NULL;
-
- snprintf(key_str, sizeof(key_str), "%s%s", uri_path, host_address);
-
- encap_info = g_hash_table_lookup(icd_ioty_encap_table, key_str);
- if (NULL == encap_info)
- return NULL;
-
- return encap_info;
-}
-
-
-gboolean icd_ioty_encap_get(gpointer user_data)
-{
- FN_CALL;
- OCStackResult result;
- OCCallbackData cbdata = {0};
- icd_encap_info_s *encap_info = user_data;
-
- cbdata.cb = icd_ioty_ocprocess_encap_get_cb;
-
- icd_ioty_csdk_lock();
- result = OCDoResource(NULL, OC_REST_GET, encap_info->uri_path, &encap_info->dev_addr,
- NULL, encap_info->oic_conn_type, OC_HIGH_QOS, &cbdata, NULL, 0);
- icd_ioty_csdk_unlock();
-
- if (OC_STACK_OK != result)
- ERR("OCDoResource() Fail(%d)", result);
-
- return G_SOURCE_CONTINUE;
-}
-
-
-int icd_ioty_start_encap(int type, const char *uri_path, const char *host_address,
- int conn_type, int64_t *signal_number)
-{
- OCCallbackData cbdata = {0};
- icd_encap_info_s *encap_info;
-
- encap_info = _icd_ioty_encap_table_get_info(uri_path, host_address);
- if (NULL == encap_info) {
- encap_info = _icd_ioty_encap_table_add(uri_path, host_address, conn_type);
- if (NULL == encap_info) {
- ERR("_icd_ioty_encap_table_add() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- }
-
- switch (type) {
- case ICD_ENCAP_MONITORING:
- if (0 != encap_info->monitoring_count) {
- *signal_number = encap_info->signal_number;
- encap_info->monitoring_count++;
- return IOTCON_ERROR_NONE;
- }
- /* DEVICE PRESENCE */
- encap_info->presence_handle = icd_ioty_subscribe_presence(ICD_ENCAP_MONITORING,
- host_address, conn_type, NULL, encap_info->worker_ctx);
- if (NULL == encap_info->presence_handle) {
- ERR("icd_ioty_subscribe_presence() Fail");
- if (0 == encap_info->monitoring_count + encap_info->caching_count)
- _icd_ioty_encap_table_remove(encap_info, host_address);
- return IOTCON_ERROR_IOTIVITY;
- }
- encap_info->worker_ctx->presence_flag = true;
- encap_info->monitoring_count++;
- break;
- case ICD_ENCAP_CACHING:
- if (0 != encap_info->caching_count) {
- *signal_number = encap_info->signal_number;
- encap_info->caching_count++;
- return IOTCON_ERROR_NONE;
- }
- /* OBSERVE METHOD */
- cbdata.context = encap_info->worker_ctx;
- cbdata.cb = icd_ioty_ocprocess_encap_observe_cb;
- cbdata.cd = _free_encap_worker_observe_ctx;
-
- encap_info->observe_handle = _icd_ioty_observe_register(uri_path,
- &encap_info->dev_addr,
- NULL,
- OC_REST_OBSERVE,
- encap_info->oic_conn_type,
- &cbdata);
- if (NULL == encap_info->observe_handle) {
- ERR("_icd_ioty_observe_register() Fail");
- if (0 == encap_info->monitoring_count + encap_info->caching_count)
- _icd_ioty_encap_table_remove(encap_info, host_address);
- return IOTCON_ERROR_IOTIVITY;
- }
- encap_info->worker_ctx->observe_flag = true;
- encap_info->caching_count++;
- break;
- default:
- ERR("Invalid Type(%d)", type);
- if (0 == encap_info->monitoring_count + encap_info->caching_count)
- _icd_ioty_encap_table_remove(encap_info, host_address);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- /* GET METHOD */
- if (1 == encap_info->monitoring_count + encap_info->caching_count) {
- icd_ioty_encap_get(encap_info);
- encap_info->get_timer_id = g_timeout_add_seconds(
- icd_remote_resource_time_interval, icd_ioty_encap_get, encap_info);
- }
-
- *signal_number = encap_info->signal_number;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_ioty_stop_encap_get(icd_encap_info_s *encap_info,
- const char *host_address)
-{
- icd_encap_worker_ctx_s *worker_ctx = encap_info->worker_ctx;
-
- if (0 != encap_info->monitoring_count + encap_info->caching_count)
- return;
-
- g_mutex_lock(&worker_ctx->icd_worker_mutex);
- g_source_remove(encap_info->get_timer_id);
- encap_info->get_timer_id = 0;
- encap_info->worker_ctx->is_valid = false;
- _icd_ioty_encap_table_remove(encap_info, host_address);
- g_mutex_unlock(&worker_ctx->icd_worker_mutex);
-
-}
-
-
-int icd_ioty_stop_encap(int type, const char *uri_path, const char *host_address)
-{
- int ret;
- OCDoHandle handle;
- icd_encap_info_s *encap_info;
-
- encap_info = _icd_ioty_encap_table_get_info(uri_path, host_address);
- if (NULL == encap_info) {
- ERR("_icd_ioty_encap_table_get_info() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- switch (type) {
- case ICD_ENCAP_MONITORING:
- if (0 == encap_info->monitoring_count) {
- ERR("Not Monitoring(%s%s)", host_address, uri_path);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- encap_info->monitoring_count--;
- if (0 != encap_info->monitoring_count)
- return IOTCON_ERROR_NONE;
-
- /* GET METHOD */
- handle = encap_info->presence_handle;
- _icd_ioty_stop_encap_get(encap_info, host_address);
-
- /* DEVICE PRESENCE */
- ret = icd_ioty_unsubscribe_presence(handle, host_address);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_unsubscribe_presence() Fail(%d)", ret);
- return ret;
- }
- break;
- case ICD_ENCAP_CACHING:
- if (0 == encap_info->caching_count) {
- ERR("Not Caching(%s%s)", host_address, uri_path);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- encap_info->caching_count--;
- if (0 != encap_info->caching_count)
- return IOTCON_ERROR_NONE;
-
- /* GET METHOD */
- handle = encap_info->observe_handle;
- _icd_ioty_stop_encap_get(encap_info, host_address);
-
- /* OBSERVE METHOD */
- ret = icd_ioty_observer_stop(handle, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_observer_stop() Fail(%d)", ret);
- return ret;
- }
- break;
- default:
- ERR("Invalid Type(%d)", type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_H__
-#define __IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_H__
-
-#include <stdio.h>
-#include <stdint.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#include <octypes.h>
-
-#include "iotcon.h"
-#include "ic-dbus.h"
-
-#define ICD_IOTY_COAP "coap://"
-#define ICD_IOTY_COAPS "coaps://"
-
-#define ICD_MULTICAST_ADDRESS "224.0.1.187:5683"
-
-typedef struct {
- int64_t signal_number;
- char *bus_name;
-} icd_sig_ctx_s;
-
-typedef struct {
- OCDoHandle handle;
- int client_count;
-} icd_presence_handle_info_s;
-
-typedef struct {
- GMutex icd_worker_mutex;
- OCDevAddr dev_addr;
- char *uri_path;
- bool presence_flag;
- bool observe_flag;
- bool is_valid;
-} icd_encap_worker_ctx_s;
-
-typedef struct {
- char *uri_path;
- OCDevAddr dev_addr;
- OCConnectivityType oic_conn_type;
- int64_t signal_number;
- int get_timer_id;
- int monitoring_count;
- int caching_count;
- OCDoHandle presence_handle;
- OCDoHandle observe_handle;
- iotcon_remote_resource_state_e resource_state;
- OCRepPayload *oic_payload;
- icd_encap_worker_ctx_s *worker_ctx;
-} icd_encap_info_s;
-
-enum {
- ICD_CRUD_GET,
- ICD_CRUD_PUT,
- ICD_CRUD_POST,
- ICD_CRUD_DELETE,
- ICD_DEVICE_INFO,
- ICD_PLATFORM_INFO,
- ICD_ENCAP_MONITORING,
- ICD_ENCAP_CACHING,
- ICD_PRESENCE,
-};
-
-void icd_ioty_csdk_lock();
-
-void icd_ioty_csdk_unlock();
-
-GThread* icd_ioty_init(const char *addr, unsigned short port);
-
-void icd_ioty_deinit(GThread *thread);
-
-OCResourceHandle icd_ioty_register_resource(const char *uri_path,
- const char* const *res_types, const char* const *res_ifaces, int properties);
-
-int icd_ioty_unregister_resource(OCResourceHandle handle);
-
-int icd_ioty_bind_interface(OCResourceHandle handle, const char *resource_interface);
-
-int icd_ioty_bind_type(OCResourceHandle handle, const char *resource_type);
-
-int icd_ioty_bind_resource(OCResourceHandle parent, OCResourceHandle child);
-
-int icd_ioty_unbind_resource(OCResourceHandle parent, OCResourceHandle child);
-
-int icd_ioty_notify(OCResourceHandle handle, GVariant *msg, GVariant *observers, gint qos);
-
-int icd_ioty_send_response(GVariant *resp);
-
-int icd_ioty_find_resource(const char *host_address,
- int conn_type,
- const char *resource_type,
- bool is_secure,
- int timeout,
- int64_t signal_number,
- const char *bus_name);
-
-void icd_ioty_complete(int type, GDBusMethodInvocation *invocation, GVariant *value);
-void icd_ioty_complete_error(int type, GDBusMethodInvocation *invocation, int ret_val);
-
-gboolean icd_ioty_get(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *resource, GVariant *query);
-
-gboolean icd_ioty_put(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *resource, GVariant *repr, GVariant *query);
-
-gboolean icd_ioty_post(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *resource, GVariant *repr, GVariant *query);
-
-gboolean icd_ioty_delete(icDbus *object, GDBusMethodInvocation *invocation,
- GVariant *resource);
-
-OCDoHandle icd_ioty_observer_start(GVariant *resource, int observe_type,
- GVariant *query, int64_t signal_number, const char *bus_name);
-
-int icd_ioty_observer_stop(OCDoHandle handle, GVariant *options);
-
-int icd_ioty_get_info(int type, const char *host_address, int conn_type, int timeout,
- int64_t signal_number, const char *bus_name);
-
-int icd_ioty_set_device_info();
-int icd_ioty_set_platform_info();
-
-OCDoHandle icd_ioty_presence_table_get_handle(const char *host_address);
-
-OCDoHandle icd_ioty_subscribe_presence(int type, const char *host_address, int conn_type,
- const char *resource_type, void *context);
-
-int icd_ioty_unsubscribe_presence(OCDoHandle handle, const char *host_address);
-
-int icd_ioty_start_presence(unsigned int time_to_live);
-
-int icd_ioty_stop_presence();
-
-int icd_ioty_encap_get_time_interval();
-
-void icd_ioty_encap_set_time_interval(int time_interval);
-
-icd_encap_info_s* _icd_ioty_encap_table_get_info(const char *uri_path,
- const char *host_address);
-
-gboolean icd_ioty_encap_get(gpointer user_data);
-
-int icd_ioty_start_encap(int type, const char *uri_path, const char *host_address,
- int conn_type, int64_t *signal_number);
-
-int icd_ioty_stop_encap(int type, const char *uri_path, const char *host_address);
-
-static inline int icd_ioty_convert_error(int ret)
-{
- switch (ret) {
- case OC_STACK_NO_MEMORY:
- return IOTCON_ERROR_OUT_OF_MEMORY;
- case OC_STACK_NO_RESOURCE:
- return IOTCON_ERROR_NO_DATA;
- default:
- break;
- }
- return IOTCON_ERROR_IOTIVITY;
-}
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdint.h>
-#include <stdlib.h>
-#include <glib.h>
-
-#include <ocstack.h>
-#include <octypes.h>
-#include <ocpayload.h>
-#include <ocrandom.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "icd.h"
-#include "icd-ioty.h"
-#include "icd-ioty-type.h"
-#include "icd-payload.h"
-
-union icd_state_value_u {
- int i;
- double d;
- bool b;
-};
-
-struct icd_state_list_s {
- OCRepPayloadPropType type;
- size_t dimensions[MAX_REP_ARRAY_DEPTH];
- GList *list;
-};
-
-static GVariant* _icd_payload_representation_to_gvariant(OCRepPayload *repr, gboolean is_parent);
-static int _icd_state_value_from_gvariant(OCRepPayload *repr, GVariantIter *iter);
-static GVariantBuilder* _icd_state_value_to_gvariant_builder(OCRepPayload *repr);
-
-GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr)
-{
- int port = 0;
- GVariant **value;
- OCStringLL *node;
- GVariantBuilder types;
- GVariantBuilder ifaces;
- OCRandomUuidResult random_res;
- OCDiscoveryPayload *discovered;
- struct OCResourcePayload *resource;
- int i, properties, res_count;
- char device_id[UUID_STRING_SIZE] = {0};
-
- discovered = (OCDiscoveryPayload*)payload;
- resource = discovered->resources;
-
- res_count = OCDiscoveryPayloadGetResourceCount(discovered);
-
- value = calloc(res_count + 1, sizeof(GVariant*));
- if (NULL == value) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
- for (i = 0; resource; i++, resource = resource->next) {
- /* uri path */
- if (NULL == resource->uri) {
- ERR("resource uri is NULL");
- continue;
- }
-
- /* device id */
- random_res = OCConvertUuidToString(discovered->sid, device_id);
- if (RAND_UUID_OK != random_res) {
- ERR("OCConvertUuidToString() Fail(%d)", random_res);
- continue;
- }
-
- /* Resource Types */
- g_variant_builder_init(&types, G_VARIANT_TYPE("as"));
- node = resource->types;
- if (NULL == node) {
- ERR("resource types is NULL");
- continue;
- }
- while (node) {
- g_variant_builder_add(&types, "s", node->value);
- node = node->next;
- }
-
- /* Resource Interfaces */
- g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
- node = resource->interfaces;
- if (NULL == node) {
- ERR("resource interfaces is NULL");
- g_variant_builder_clear(&types);
- continue;
- }
- while (node) {
- g_variant_builder_add(&ifaces, "s", node->value);
- node = node->next;
- }
-
- /* Resource Properties */
- properties = icd_ioty_oic_properties_to_properties(resource->bitmap);
-
- /* port */
- port = (resource->port) ? resource->port : dev_addr->port;
-
- /* TODO
- * Check "resource->secure" and "resource->bitmap" */
- value[i] = g_variant_new("(ssasasibsi)", resource->uri, device_id, &ifaces, &types,
- properties, resource->secure, dev_addr->addr, port);
- DBG("found resource[%d] : %s", i, g_variant_print(value[i], FALSE));
- }
-
- return value;
-}
-
-
-static GVariant* _icd_state_array_attr_to_gvariant(OCRepPayloadValueArray *arr, int len,
- int index)
-{
- int i;
- GVariant *var;
- GVariantBuilder builder;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
-
- switch (arr->type) {
- case OCREP_PROP_INT:
- for (i = 0; i < len; i++)
- g_variant_builder_add(&builder, "i", arr->iArray[index + i]);
- break;
- case OCREP_PROP_BOOL:
- for (i = 0; i < len; i++)
- g_variant_builder_add(&builder, "b", arr->bArray[index + i]);
- break;
- case OCREP_PROP_DOUBLE:
- for (i = 0; i < len; i++)
- g_variant_builder_add(&builder, "d", arr->dArray[index + i]);
- break;
- case OCREP_PROP_STRING:
- for (i = 0; i < len; i++)
- g_variant_builder_add(&builder, "s", arr->strArray[index + i]);
- break;
- case OCREP_PROP_BYTE_STRING:
- for (i = 0; i < len; i++) {
- var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"),
- arr->ocByteStrArray[index + i].bytes,
- arr->ocByteStrArray[index + i].len,
- sizeof(uint8_t));
- g_variant_builder_add(&builder, "v", var);
- }
- break;
- case OCREP_PROP_NULL:
- for (i = 0; i < len; i++)
- g_variant_builder_add(&builder, "s", IC_STR_NULL);
- break;
- case OCREP_PROP_OBJECT:
- for (i = 0; i < len; i++) {
- GVariantBuilder *state_var
- = _icd_state_value_to_gvariant_builder(arr->objArray[index + i]);
- var = g_variant_builder_end(state_var);
- g_variant_builder_add(&builder, "v", var);
- }
- break;
- case OCREP_PROP_ARRAY:
- default:
- break;
- }
-
- return g_variant_builder_end(&builder);
-}
-
-
-static GVariant* _icd_state_array_to_gvariant(OCRepPayloadValueArray *arr,
- int current_depth, int current_len, int index)
-{
- int i, next_len;
- GVariantBuilder builder;
- GVariant *arr_var = NULL;
-
- if ((MAX_REP_ARRAY_DEPTH - 1) == current_depth
- || 0 == arr->dimensions[current_depth + 1])
- return _icd_state_array_attr_to_gvariant(arr, current_len, index);
-
- i = current_len + index;
-
- next_len = current_len / arr->dimensions[current_depth];
- index -= next_len;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
-
- while ((index += next_len) < i) {
- arr_var = _icd_state_array_to_gvariant(arr, current_depth + 1, next_len, index);
- g_variant_builder_add(&builder, "v", arr_var);
- }
-
- return g_variant_builder_end(&builder);
-}
-
-static GVariant* _icd_state_value_to_gvariant(OCRepPayload *state)
-{
- GVariantBuilder *builder;
- GVariant *var;
-
- builder = _icd_state_value_to_gvariant_builder(state);
- var = g_variant_builder_end(builder);
-
- return var;
-}
-
-static GVariantBuilder* _icd_state_value_to_gvariant_builder(OCRepPayload *repr)
-{
- int total_len;
- GVariant *var = NULL;
- GVariantBuilder *builder;
- OCRepPayloadValue *val = repr->values;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-
- while (val) {
- switch (val->type) {
- case OCREP_PROP_INT:
- var = g_variant_new_int32(val->i);
- break;
- case OCREP_PROP_BOOL:
- var = g_variant_new_boolean(val->b);
- break;
- case OCREP_PROP_DOUBLE:
- var = g_variant_new_double(val->d);
- break;
- case OCREP_PROP_STRING:
- var = g_variant_new_string(val->str);
- break;
- case OCREP_PROP_BYTE_STRING:
- var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"), val->ocByteStr.bytes,
- val->ocByteStr.len, sizeof(uint8_t));
- break;
- case OCREP_PROP_NULL:
- var = g_variant_new_string(IC_STR_NULL);
- break;
- case OCREP_PROP_ARRAY:
- total_len = calcDimTotal(val->arr.dimensions);
- var = _icd_state_array_to_gvariant(&(val->arr), 0, total_len, 0);
- break;
- case OCREP_PROP_OBJECT:
- var = _icd_state_value_to_gvariant(val->obj);
- break;
- default:
- ERR("Invalid Type(%d)", val->type);
- }
- if (var) {
- g_variant_builder_add(builder, "{sv}", val->name, var);
- var = NULL;
- }
- val = val->next;
- }
-
- return builder;
-}
-
-
-static GVariant* _icd_payload_representation_to_gvariant(OCRepPayload *repr,
- gboolean is_parent)
-{
- OCStringLL *node;
- GVariant *child, *value;
- OCRepPayload *child_node;
- GVariantBuilder *repr_gvar;
- GVariantBuilder children, types_builder, ifaces_builder;
-
- RETV_IF(NULL == repr, NULL);
-
- /* Resource Types */
- g_variant_builder_init(&types_builder, G_VARIANT_TYPE("as"));
-
- node = repr->types;
- while (node) {
- g_variant_builder_add(&types_builder, "s", node->value);
- node = node->next;
- }
-
- /* Resource Interfaces */
- g_variant_builder_init(&ifaces_builder, G_VARIANT_TYPE("as"));
-
- node = repr->interfaces;
- while (node) {
- g_variant_builder_add(&ifaces_builder, "s", node->value);
- node = node->next;
- }
-
- /* Representation */
- repr_gvar = _icd_state_value_to_gvariant_builder(repr);
-
- /* Children */
- g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
-
- child_node = repr->next;
- while (is_parent && child_node) {
- /* generate recursively */
- child = _icd_payload_representation_to_gvariant(child_node, FALSE);
- g_variant_builder_add(&children, "v", child);
- child_node = child_node->next;
- }
-
- value = g_variant_new("(sasasa{sv}av)", ic_utils_dbus_encode_str(repr->uri),
- &ifaces_builder, &types_builder, repr_gvar, &children);
-
- return value;
-}
-
-
-GVariant* icd_payload_representation_empty_gvariant(void)
-{
- GVariant *value;
- GVariantBuilder ifaces, types, repr, children;
-
- g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
- g_variant_builder_init(&types, G_VARIANT_TYPE("as"));
- g_variant_builder_init(&repr, G_VARIANT_TYPE("a{sv}"));
- g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
-
- value = g_variant_new("(sasasa{sv}av)", IC_STR_NULL, &ifaces, &types, &repr, &children);
-
- return value;
-}
-
-
-static GVariant* _icd_payload_platform_to_gvariant(OCPlatformPayload *repr)
-{
- GVariant *value;
-
- value = g_variant_new("(sssssssssss)",
- repr->info.platformID,
- repr->info.manufacturerName,
- ic_utils_dbus_encode_str(repr->info.manufacturerUrl),
- ic_utils_dbus_encode_str(repr->info.modelNumber),
- ic_utils_dbus_encode_str(repr->info.dateOfManufacture),
- ic_utils_dbus_encode_str(repr->info.platformVersion),
- ic_utils_dbus_encode_str(repr->info.operatingSystemVersion),
- ic_utils_dbus_encode_str(repr->info.hardwareVersion),
- ic_utils_dbus_encode_str(repr->info.firmwareVersion),
- ic_utils_dbus_encode_str(repr->info.supportUrl),
- ic_utils_dbus_encode_str(repr->info.systemTime));
-
- return value;
-}
-
-
-static GVariant* _icd_payload_device_to_gvariant(OCDevicePayload *repr)
-{
- GVariant *value;
- OCRandomUuidResult random_res;
- char device_id[UUID_STRING_SIZE] = {0};
-
- random_res = OCConvertUuidToString(repr->sid, device_id);
- if (RAND_UUID_OK != random_res) {
- ERR("OCConvertUuidToString() Fail(%d)", random_res);
- return NULL;
- }
-
- value = g_variant_new("(ssss)", repr->deviceName, repr->specVersion,
- device_id, repr->dataModelVersion);
-
- return value;
-}
-
-
-GVariant* icd_payload_to_gvariant(OCPayload *repr)
-{
- GVariant *value = NULL;
-
- if (NULL == repr)
- return value;
-
- switch (repr->type) {
- case PAYLOAD_TYPE_REPRESENTATION:
- value = _icd_payload_representation_to_gvariant((OCRepPayload*)repr, TRUE);
- break;
- case PAYLOAD_TYPE_PLATFORM:
- value = _icd_payload_platform_to_gvariant((OCPlatformPayload*)repr);
- break;
- case PAYLOAD_TYPE_DEVICE:
- value = _icd_payload_device_to_gvariant((OCDevicePayload*)repr);
- break;
- case PAYLOAD_TYPE_PRESENCE:
- case PAYLOAD_TYPE_SECURITY:
- default:
- break;
- }
-
- return value;
-}
-
-
-static int _icd_state_list_from_gvariant(GVariant *var,
- struct icd_state_list_s *value_list, int depth)
-{
- int ret;
- GVariantIter iter;
- const GVariantType *type;
- union icd_state_value_u *value;
-
- type = g_variant_get_type(var);
-
- g_variant_iter_init(&iter, var);
-
- value_list->dimensions[depth] = g_variant_iter_n_children(&iter);
- DBG("[%d]list dim : %d", depth, value_list->dimensions[depth]);
-
- if (g_variant_type_equal(G_VARIANT_TYPE("ab"), type)) {
- bool b;
- value_list->type = OCREP_PROP_BOOL;
- while (g_variant_iter_loop(&iter, "b", &b)) {
- value = calloc(1, sizeof(union icd_state_value_u));
- if (NULL == value) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- value->b = b;
- value_list->list = g_list_append(value_list->list, value);
- }
- } else if (g_variant_type_equal(G_VARIANT_TYPE("ai"), type)) {
- int i;
- value_list->type = OCREP_PROP_INT;
- while (g_variant_iter_loop(&iter, "i", &i)) {
- value = calloc(1, sizeof(union icd_state_value_u));
- if (NULL == value) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- value->i = i;
- value_list->list = g_list_append(value_list->list, value);
- }
- } else if (g_variant_type_equal(G_VARIANT_TYPE("ad"), type)) {
- double d;
- value_list->type = OCREP_PROP_DOUBLE;
- while (g_variant_iter_loop(&iter, "d", &d)) {
- value = calloc(1, sizeof(union icd_state_value_u));
- if (NULL == value) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- value->d = d;
- value_list->list = g_list_append(value_list->list, value);
- }
- } else if (g_variant_type_equal(G_VARIANT_TYPE("as"), type)) {
- char *s;
- value_list->type = OCREP_PROP_STRING;
- while (g_variant_iter_next(&iter, "s", &s))
- value_list->list = g_list_append(value_list->list, s);
- } else if (g_variant_type_equal(G_VARIANT_TYPE("av"), type)) {
- GVariant *value;
- if (g_variant_iter_loop(&iter, "v", &value)) {
- if (g_variant_is_of_type(value, G_VARIANT_TYPE("a{sv}"))) {
- OCRepPayload *repr;
- GVariantIter state_iter;
- value_list->type = OCREP_PROP_OBJECT;
- do {
- repr = OCRepPayloadCreate();
- g_variant_iter_init(&state_iter, value);
- ret = _icd_state_value_from_gvariant(repr, &state_iter);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_state_value_from_gvariant() Fail(%d)", ret);
- OCRepPayloadDestroy(repr);
- return ret;
- }
- value_list->list = g_list_append(value_list->list, repr);
- } while (g_variant_iter_loop(&iter, "v", &value));
-
- } else if (g_variant_is_of_type(value, G_VARIANT_TYPE("ay"))) {
- OCByteString *byte_str;
- value_list->type = OCREP_PROP_BYTE_STRING;
- do {
- byte_str = calloc(1, sizeof(OCByteString));
- if (NULL == byte_str) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- byte_str->len = g_variant_get_size(value);
- byte_str->bytes = calloc(byte_str->len, sizeof(uint8_t));
- if (NULL == byte_str->bytes) {
- ERR("calloc() Fail(%d)", errno);
- free(byte_str);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- memcpy(byte_str->bytes, g_variant_get_data(value), byte_str->len);
-
- value_list->list = g_list_append(value_list->list, byte_str);
- } while (g_variant_iter_loop(&iter, "v", &value));
-
- } else if (g_variant_is_of_type(value, G_VARIANT_TYPE_ARRAY)) {
- do {
- ret = _icd_state_list_from_gvariant(value, value_list, depth + 1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_state_list_from_gvariant() Fail(%d)", ret);
- return ret;
- }
- } while (g_variant_iter_loop(&iter, "v", &value));
- }
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_payload_object_destroy(gpointer node)
-{
- OCRepPayloadDestroy(node);
-}
-
-
-static int _icd_state_array_from_list(OCRepPayload *repr,
- struct icd_state_list_s *value_list, const char *key)
-{
- int i, len;
- GList *node;
- bool *b_arr;
- double *d_arr;
- char **str_arr;
- int64_t *i_arr;
- OCByteString *byte_arr;
- union icd_state_value_u *value;
- struct OCRepPayload **state_arr;
-
- len = calcDimTotal(value_list->dimensions);
-
- switch (value_list->type) {
- case OCREP_PROP_INT:
- i_arr = calloc(len, sizeof(int64_t));
- if (NULL == i_arr) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- for (node = value_list->list, i = 0; node; node = node->next, i++) {
- value = node->data;
- i_arr[i] = value->i;
- }
- g_list_free_full(value_list->list, free);
- OCRepPayloadSetIntArrayAsOwner(repr, key, i_arr, value_list->dimensions);
- break;
- case OCREP_PROP_BOOL:
- b_arr = calloc(len, sizeof(bool));
- if (NULL == b_arr) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- for (node = value_list->list, i = 0; node; node = node->next, i++) {
- value = node->data;
- b_arr[i] = value->b;
- }
- g_list_free_full(value_list->list, free);
- OCRepPayloadSetBoolArrayAsOwner(repr, key, b_arr, value_list->dimensions);
- break;
- case OCREP_PROP_DOUBLE:
- d_arr = calloc(len, sizeof(double));
- if (NULL == d_arr) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- for (node = value_list->list, i = 0; node; node = node->next, i++) {
- value = node->data;
- d_arr[i] = value->d;
- }
- g_list_free_full(value_list->list, free);
- OCRepPayloadSetDoubleArrayAsOwner(repr, key, d_arr, value_list->dimensions);
- break;
- case OCREP_PROP_STRING:
- str_arr = calloc(len, sizeof(char *));
- if (NULL == str_arr) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- for (node = value_list->list, i = 0; node; node = node->next, i++)
- str_arr[i] = strdup(node->data);
- g_list_free_full(value_list->list, free);
- OCRepPayloadSetStringArrayAsOwner(repr, key, str_arr, value_list->dimensions);
- break;
- case OCREP_PROP_BYTE_STRING:
- byte_arr = calloc(len, sizeof(OCByteString));
- if (NULL == byte_arr) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- for (node = value_list->list, i = 0; node; node = node->next, i++) {
- OCByteString *byte_str = node->data;
- byte_arr[i].bytes = byte_str->bytes;
- byte_arr[i].len = byte_str->len;
- }
- g_list_free(value_list->list);
- OCRepPayloadSetByteStringArray(repr, key, byte_arr, value_list->dimensions);
-
- break;
- case OCREP_PROP_OBJECT:
- state_arr = calloc(len, sizeof(struct OCRepPayload *));
- if (NULL == state_arr) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- for (node = value_list->list, i = 0; node; node = node->next, i++)
- state_arr[i] = OCRepPayloadClone(node->data);
- g_list_free_full(value_list->list, _icd_payload_object_destroy);
- OCRepPayloadSetPropObjectArrayAsOwner(repr, key, state_arr,
- value_list->dimensions);
- break;
- case OCREP_PROP_ARRAY:
- case OCREP_PROP_NULL:
- default:
- ERR("Invalid Type(%d)", value_list->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icd_payload_state_list_destroy(struct icd_state_list_s *state_list)
-{
- switch (state_list->type) {
- case OCREP_PROP_BOOL:
- case OCREP_PROP_INT:
- case OCREP_PROP_DOUBLE:
- case OCREP_PROP_STRING:
- g_list_free_full(state_list->list, free);
- break;
- case OCREP_PROP_OBJECT:
- g_list_free_full(state_list->list, _icd_payload_object_destroy);
- break;
- case OCREP_PROP_ARRAY:
- case OCREP_PROP_NULL:
- default:
- ERR("Invalid Type(%d)", state_list->type);
- break;
- }
-
- return;
-}
-
-
-static int _icd_state_value_from_gvariant(OCRepPayload *repr, GVariantIter *iter)
-{
- int ret;
- char *key;
- GVariant *var;
- const char *str_value;
- OCRepPayload *repr_value;
- struct icd_state_list_s value_list = {0};
-
- while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
-
- if (g_variant_is_of_type(var, G_VARIANT_TYPE_BOOLEAN)) {
- OCRepPayloadSetPropBool(repr, key, g_variant_get_boolean(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_INT32)) {
- OCRepPayloadSetPropInt(repr, key, g_variant_get_int32(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_DOUBLE)) {
- OCRepPayloadSetPropDouble(repr, key, g_variant_get_double(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_STRING)) {
- str_value = g_variant_get_string(var, NULL);
- if (NULL == str_value) {
- ERR("g_variant_get_string() Fail");
- _icd_payload_state_list_destroy(&value_list);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- if (IC_STR_EQUAL == strcmp(IC_STR_NULL, str_value))
- OCRepPayloadSetNull(repr, key);
- else
- OCRepPayloadSetPropString(repr, key, str_value);
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("ay"))) {
- OCByteString byte_value;
- byte_value.bytes = (uint8_t*)g_variant_get_data(var);
- byte_value.len = g_variant_get_size(var);
- OCRepPayloadSetPropByteString(repr, key, byte_value);
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("a{sv}"))) {
- GVariantIter state_iter;
- repr_value = OCRepPayloadCreate();
- g_variant_iter_init(&state_iter, var);
-
- ret = _icd_state_value_from_gvariant(repr_value, &state_iter);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_state_value_from_gvariant() Fail(%d)", ret);
- _icd_payload_state_list_destroy(&value_list);
- OCRepPayloadDestroy(repr_value);
- return ret;
- }
- OCRepPayloadSetPropObjectAsOwner(repr, key, repr_value);
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_ARRAY)) {
- memset(&value_list, 0, sizeof(struct icd_state_list_s));
- ret = _icd_state_list_from_gvariant(var, &value_list, 0);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_state_list_from_gvariant() Fail(%d)", ret);
- _icd_payload_state_list_destroy(&value_list);
- return ret;
- }
- ret = _icd_state_array_from_list(repr, &value_list, key);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_state_array_from_list() Fail(%d)", ret);
- _icd_payload_state_list_destroy(&value_list);
- return ret;
- }
-
- } else {
- ERR("Invalid type(%s)", g_variant_get_type_string(var));
- return IOTCON_ERROR_INVALID_TYPE;
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-OCRepPayload* icd_payload_representation_from_gvariant(GVariant *var)
-{
- int ret;
- GVariant *child;
- OCRepPayload *repr, *cur;
- char *uri_path, *resource_iface, *resource_type;
- GVariantIter *resource_types, *resource_ifaces, *repr_gvar, *children;
-
- repr = OCRepPayloadCreate();
-
- g_variant_get(var, "(&sasasa{sv}av)", &uri_path, &resource_ifaces, &resource_types,
- &repr_gvar, &children);
-
- if (IC_STR_EQUAL != strcmp(IC_STR_NULL, uri_path))
- OCRepPayloadSetUri(repr, uri_path);
-
- while (g_variant_iter_loop(resource_ifaces, "s", &resource_iface))
- OCRepPayloadAddInterface(repr, resource_iface);
-
- while (g_variant_iter_loop(resource_types, "s", &resource_type))
- OCRepPayloadAddResourceType(repr, resource_type);
-
- ret = _icd_state_value_from_gvariant(repr, repr_gvar);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icd_state_value_from_gvariant() Fail(%d)", ret);
- OCRepPayloadDestroy(repr);
- return NULL;
- }
-
- cur = repr;
- while (g_variant_iter_loop(children, "v", &child)) {
- cur->next = icd_payload_representation_from_gvariant(child);
- if (NULL == cur->next) {
- ERR("icd_payload_representation_from_gvariant() Fail");
- OCRepPayloadDestroy(repr);
- return NULL;
- }
- cur = cur->next;
- }
- return repr;
-}
-
-
-static int _oic_string_list_length(OCStringLL *str_list)
-{
- int len = 0;
-
- while (str_list) {
- len++;
- str_list = str_list->next;
- }
-
- return len;
-}
-
-
-static bool _oic_string_list_contain(OCStringLL *str_list, char *str_value)
-{
- OCStringLL *c;
-
- for (c = str_list; c; c = c->next) {
- if (IC_STR_EQUAL == g_strcmp0(str_value, str_list->value))
- return true;
- }
-
- return false;
-}
-
-
-static int _representation_compare_string_list(OCStringLL *list1, OCStringLL *list2)
-{
- OCStringLL *c;
-
- if (NULL == list1 || NULL == list2)
- return !!(list1 - list2);
-
- if (_oic_string_list_length(list1) != _oic_string_list_length(list2))
- return 1;
-
- for (c = list1; c; c = c->next) {
- if (false == _oic_string_list_contain(list2, c->value))
- return 1;
- }
-
- return IC_EQUAL;
-}
-
-
-static int _representation_compare_array(OCRepPayloadValueArray arr1,
- OCRepPayloadValueArray arr2)
-{
- int i, len1, len2;
-
- len1 = calcDimTotal(arr1.dimensions);
- len2 = calcDimTotal(arr2.dimensions);
-
- if (len1 != len2)
- return 1;
-
- switch (arr1.type) {
- case OCREP_PROP_INT:
- for (i = 0; i < len1; i++) {
- if (arr1.iArray[i] != arr2.iArray[i])
- return 1;
- }
- break;
- case OCREP_PROP_BOOL:
- for (i = 0; i < len1; i++) {
- if (arr1.bArray[i] != arr2.bArray[i])
- return 1;
- }
- break;
- case OCREP_PROP_DOUBLE:
- for (i = 0; i < len1; i++) {
- if (arr1.dArray[i] != arr2.dArray[i])
- return 1;
- }
- break;
- case OCREP_PROP_STRING:
- for (i = 0; i < len1; i++) {
- if (IC_STR_EQUAL != g_strcmp0(arr1.strArray[i], arr2.strArray[i]))
- return 1;
- }
- break;
- case OCREP_PROP_BYTE_STRING:
- for (i = 0; i < len1; i++) {
- if (IC_EQUAL != memcmp(arr1.ocByteStrArray[i].bytes,
- arr2.ocByteStrArray[i].bytes, arr2.ocByteStrArray[i].len))
- return 1;
- }
- break;
- case OCREP_PROP_OBJECT:
- for (i = 0; i < len1; i++) {
- if (IC_EQUAL != icd_payload_representation_compare(arr1.objArray[i],
- arr2.objArray[i]))
- return 1;
- }
- break;
- default:
- ERR("Invalid Type (%d)", arr1.type);
- return 1;
- }
-
- return IC_EQUAL;
-}
-
-
-static int _representation_compare_value(OCRepPayloadValue *value1,
- OCRepPayloadValue *value2)
-{
- int ret = 1;
-
- if (NULL == value1 || NULL == value2)
- return !!(value1 - value2);
-
- /* compare key */
- if (IC_STR_EQUAL != g_strcmp0(value1->name, value2->name))
- return 1;
-
- /* compare value */
- if (value1->type != value2->type)
- return 1;
-
- switch (value1->type) {
- case OCREP_PROP_NULL:
- ret = IC_EQUAL;
- break;
- case OCREP_PROP_INT:
- ret = (value1->i == value2->i) ? IC_EQUAL : 1;
- break;
- case OCREP_PROP_DOUBLE:
- ret = (value1->d == value2->d) ? IC_EQUAL : 1;
- break;
- case OCREP_PROP_BOOL:
- ret = (value1->b == value2->b) ? IC_EQUAL : 1;
- break;
- case OCREP_PROP_STRING:
- ret = (IC_STR_EQUAL == g_strcmp0(value1->str, value2->str)) ? IC_EQUAL : 1;
- break;
- case OCREP_PROP_BYTE_STRING:
- ret = (IC_EQUAL == memcmp(value1->ocByteStr.bytes, value2->ocByteStr.bytes,
- value2->ocByteStr.len));
- break;
- case OCREP_PROP_OBJECT:
- ret = icd_payload_representation_compare(value1->obj, value2->obj);
- break;
- case OCREP_PROP_ARRAY:
- ret = _representation_compare_array(value1->arr, value2->arr);
- break;
- default:
- ERR("Invalid Type (%d)", value1->type);
- }
-
- return ret;
-}
-
-
-static int _representation_values_list_length(OCRepPayloadValue *value_list)
-{
- int len = 0;
-
- while (value_list) {
- len++;
- value_list = value_list->next;
- }
-
- return len;
-}
-
-
-static bool _representation_values_list_contain(OCRepPayloadValue *value_list,
- OCRepPayloadValue *value)
-{
- OCRepPayloadValue *c;
-
- for (c = value_list; c; c = c->next) {
- if (IC_EQUAL == _representation_compare_value(c, value))
- return true;
- }
-
- return false;
-}
-
-
-static int _representation_compare_values_list(OCRepPayloadValue *value1,
- OCRepPayloadValue *value2)
-{
- OCRepPayloadValue *c;
-
- if (NULL == value1 || NULL == value2)
- return !!(value1 - value2);
-
- if (_representation_values_list_length(value1)
- != _representation_values_list_length(value2))
- return 1;
-
- for (c = value1; c; c = c->next) {
- if (false == _representation_values_list_contain(value2, c))
- return 1;
- }
-
- return IC_EQUAL;
-}
-
-
-static int _representation_compare_without_children(OCRepPayload *repr1,
- OCRepPayload *repr2)
-{
- int ret;
-
- /* compare uri */
- if (IC_STR_EQUAL != g_strcmp0(repr1->uri, repr2->uri))
- return 1;
-
- /* compare resource types */
- ret = _representation_compare_string_list(repr1->types, repr2->types);
- if (IC_EQUAL != ret)
- return ret;
-
- /* compare resource interfaces */
- ret = _representation_compare_string_list(repr1->interfaces, repr2->interfaces);
- if (IC_EQUAL != ret)
- return ret;
-
- /* compare values */
- ret = _representation_compare_values_list(repr1->values, repr2->values);
- if (IC_EQUAL != ret)
- return ret;
-
- return IC_EQUAL;
-}
-
-
-static int _representation_list_length(OCRepPayload *repr_list)
-{
- int len = 0;
-
- while (repr_list) {
- len++;
- repr_list = repr_list->next;
- }
-
- return len;
-}
-
-
-static bool _representation_list_contain(OCRepPayload *repr_list, OCRepPayload *repr)
-{
- OCRepPayload *c;
-
- for (c = repr_list; c; c = c->next) {
- if (IC_EQUAL == _representation_compare_without_children(c, repr))
- return true;
- }
-
- return false;
-}
-
-
-static int _representation_compare_children(OCRepPayload *repr1, OCRepPayload *repr2)
-{
- OCRepPayload *c;
-
- if (NULL == repr1 || NULL == repr2)
- return !!(repr1 - repr2);
-
- if (_representation_list_length(repr1) != _representation_list_length(repr2))
- return 1;
-
- for (c = repr1; c; c = c->next) {
- if (false == _representation_list_contain(repr2, c))
- return 1;
- }
-
- return IC_EQUAL;
-}
-
-
-int icd_payload_representation_compare(OCRepPayload *repr1, OCRepPayload *repr2)
-{
- int ret;
-
- if (NULL == repr1 || NULL == repr2)
- return !!(repr1 - repr2);
-
- ret = _representation_compare_without_children(repr1, repr2);
- if (IC_EQUAL != ret)
- return ret;
-
- /* compare childrean */
- ret = _representation_compare_children(repr1->next, repr2->next);
- if (IC_EQUAL != ret)
- return ret;
-
- return IC_EQUAL;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_PAYLOAD_H__
-#define __IOT_CONNECTIVITY_MANAGER_DAEMON_PAYLOAD_H__
-
-#include <glib.h>
-
-#include <ocpayload.h>
-
-GVariant* icd_payload_representation_empty_gvariant(void);
-GVariant* icd_payload_to_gvariant(OCPayload *payload);
-GVariant** icd_payload_res_to_gvariant(OCPayload *payload, OCDevAddr *dev_addr);
-OCRepPayload* icd_payload_representation_from_gvariant(GVariant *var);
-int icd_payload_representation_compare(OCRepPayload *repr1, OCRepPayload *repr2);
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_PAYLOAD_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <gio/gio.h>
-
-#include "icd.h"
-#include "icd-dbus.h"
-#include "icd-ioty.h"
-#include "icd-cynara.h"
-#include "icd-ioty-ocprocess.h"
-
-#define ICD_ALL_INTERFACES "0.0.0.0"
-#define ICD_RANDOM_PORT 0
-
-int main(int argc, char **argv)
-{
- int ret;
- guint id;
- GThread *thread;
- GMainLoop *loop;
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
- g_type_init();
-#endif
-
- loop = g_main_loop_new(NULL, FALSE);
-
- id = icd_dbus_init();
- thread = icd_ioty_init(ICD_ALL_INTERFACES, ICD_RANDOM_PORT);
- if (NULL == thread) {
- ERR("icd_ioty_init() Fail");
- icd_dbus_deinit(id);
- return -1;
- }
-
- ret = icd_ioty_set_device_info();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_set_device_info() Fail(%d)", ret);
- icd_ioty_deinit(thread);
- icd_dbus_deinit(id);
- return -1;
- }
-
- ret = icd_ioty_set_platform_info();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_ioty_set_platform_info() Fail(%d)", ret);
- icd_ioty_deinit(thread);
- icd_dbus_deinit(id);
- return -1;
- }
-
- ret = icd_cynara_init();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icd_cynara_init() Fail(%d)", ret);
- icd_ioty_deinit(thread);
- icd_dbus_deinit(id);
- }
-
- g_main_loop_run(loop);
-
- icd_cynara_deinit();
- icd_ioty_deinit(thread);
- icd_dbus_deinit(id);
- g_main_loop_unref(loop);
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DAEMON_H__
-#define __IOT_CONNECTIVITY_MANAGER_DAEMON_H__
-
-#include "ic-common.h"
-
-#define IC_DAEMON
-#include "ic-log.h"
-
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-
-#ifndef __TIZEN_NETWORK_IOTCON_DOC_H__
-#define __TIZEN_NETWORK_IOTCON_DOC_H__
-
-/**
- * @ingroup CAPI_NETWORK_FRAMEWORK
- * @defgroup CAPI_IOT_CONNECTIVITY_MODULE Iotcon
- *
- * @brief The Iotcon API provides functions for IoT connectivity
- *
- * @section CAPI_IOT_CONNECTIVITY_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_MODULE_OVERVIEW Overview
- * The iotcon module provides various features based on Iotivity project.\n
- * The IoTivity project is sponsored by the Open Interconnect Consortium
- * a group of industry leaders who will be developing a standard specification and
- * certification program to address these challenges.\n
- * See http://iotivity.org and http://openinterconnect.org for more information.
- *
- * @subsection CAPI_IOT_CONNECTIVITY_MODULE_RESOURCE Resource
- * A Resource is a component in a server that can be viewed and conrolled by another client.\n
- * There are different resource types, for example a temperature sensor, a light controller etc.\n\n
- *
- * @subsection CAPI_IOT_CONNECTIVITY_MODULE_RESOURCE_REGISTRATION Resource registration
- * Registering a resource requires a URI and handler to process requests.\n
- * The URI path should be rooted. Iotcon will construct the fully qualified URI by adding
- * the URI authority to the provided URI path.\n
- * For example, given a service running on port 54321 in a device at IP address 192.168.1.1,
- * if the application registers a resource with a URI path "/light/1",\n
- * the resulting fully qualified URI is "oic://192.168.1.1:54321/light/1",
- * which uniquely identifies the resource's location.\n
- * Note : Only one resource can be registered at a given URI.
- *
- * Example :
- * @code
-#include <iotcon.h>
-...
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
-{
- int ret;
- iotcon_request_type_e type;
- iotcon_response_h response;
- iotcon_representation_h resp_repr;
-
- ret = iotcon_request_get_request_type(request, &type);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_REQUEST_GET == type) {
- ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_response_set_result(response, IOTCON_RESPONSE_OK);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_representation_create(&resp_repr);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_representation_set_uri_path(resp_repr, "/door/1");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(resp_repr);
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(resp_repr);
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_state_add_bool(resp_repr, "opened", true);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(resp_repr);
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT, resp_repr);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(resp_repr);
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(resp_repr);
- iotcon_response_destroy(response);
- return;
- }
-
- iotcon_state_destroy(state);
- iotcon_representation_destroy(resp_repr);
- iotcon_response_destroy(response);
- }
-}
-...
-{
- int ret;
- int properties = (IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE);
- const char *uri_path = "/door/1";
- const char *type = "org.tizen.door";
- iotcon_resource_types_h resource_types;
- iotcon_resource_interfaces_h resource_ifaces;
- iotcon_resource_h resource = NULL;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_resource_types_add(resource_types, type);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_interfaces_create(&resource_ifaces);
- if (IOTCON_ERROR_NONE != ret)
- iotcon_resource_types_destroy(resource_types);
- return;
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_create(uri_path, resource_types,
- resource_ifaces, properties, _request_handler, NULL, &resource);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
-}
- * @endcode
- *
- * @subsection CAPI_IOT_CONNECTIVITY_MODULE_FINDING_RESOURCE Finding a resource.
- * This operation returns all resources of given type on the network service.\n
- * This operation is sent via multicast to all services.\n
- * If you specify filter resource type in the query, only exact matches will be responded.
- *
- * Example :
- * @code
-#include <iotcon.h>
-static void _on_response_get(iotcon_remote_resource_h resource, iotcon_error_e err,
- iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
-{
- // handle get from response
-}
-...
-static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
- void *user_data)
-{
- int ret;
- char *resource_uri_path;
- char *resource_host;
- char *device_id;
- iotcon_query_h query;
- iotcon_resource_types_h resource_types;
- iotcon_resource_interfaces_h resource_interfaces;
- iotcon_remote_resource_h resource_clone = NULL;
-
- if (IOTCON_ERROR_NONE != result)
- return;
-
- ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_remote_resource_get_device_id(resource, &device_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_remote_resource_get_host_address(resource, &resource_host);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_remote_resource_get_types(resource, &resource_types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_query_create(&query);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_query_add(query, "key", "value");
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_remote_resource_clone(resource, &resource_clone);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_query_destroy(query);
- return;
- }
-
- ret = iotcon_remote_resource_get(resource_clone, query, _on_response_get, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_query_destroy(query);
- return;
- }
-
- iotcon_query_destroy(query);
-}
-...
-{
- int ret;
- const char *type = "org.tizen.door";
-
- ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4, type,
- false, _found_resource, NULL);
- if (IOTCON_ERROR_NONE != ret)
- return;
-}
- * @endcode
- *
- * @subsection CAPI_IOT_CONNECTIVITY_MODULE_OBSERVING_RESOURCE Observing resource
- * This operation fetches and registers as an observer for the value of simple specific resource.\n
- * An observable resource can handle any number of observers.\n
- * If the server responds with a success code, the registration is considered successful.\n
- * Notifications from the server to the client may be confirmable or non-confirmable.\n
- * If the client returns a RST message, the observation registration should be dropped immediately.\n
- * If the client fails to acknowledge a number of confirmable requests,
- * the server should assume that the client has abandoned the observation and drop the registration.\n
- * If the observed resource is removed, the server sends a NOTFOUND status to all observers.\n
- * If an observed resource fails to notify a client before the max-age of a resource value update,
- * the client should attempt to re-register the observation.\n
- *
- * Example (Server side) :
- * @code
-#include <iotcon.h>
-...
-static iotcon_resource_h _door_handle;
-static iotcon_observers_h _observers;
-...
-static void _request_handler(iotcon_request_h request, void *user_data)
-{
- int ret;
- int observe_id;
- iotcon_observe_type_e observe_type;
-
- ret = iotcon_request_get_observe_type(request, &observe_type);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_OBSERVE_REGISTER == observe_type) {
- int observe_id;
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (NULL == _observers) {
- ret = iotcon_observers_create(&_observers);
- if (IOTCON_ERROR_NONE != ret)
- return;
- }
- ret = iotcon_observers_add(_observers, observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
- } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
- int observe_id;
-
- if (NULL == _observers)
- return;
-
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_observers_remove(_observers, observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
- }
-}
-...
-{
- int ret;
- int properties = (IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE);
- const char *uri_path = "/door/1";
- const char *type = "org.tizen.door";
- iotcon_resource_types_h resource_types;
- iotcon_resource_interfaces_h resource_ifaces;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_resource_types_add(resource_types, type);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_interfaces_create(&resource_ifaces);
- if (IOTCON_ERROR_NONE != ret)
- iotcon_resource_types_destroy(resource_types);
- return;
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_create(uri_path, resource_types,
- resource_ifaces, properties, _request_handler, NULL, &_door_handle);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
-}
-...
-{
- int ret;
- iotcon_representation_h repr;
-
- ret = iotcon_representation_create(&resp_repr);
- if (IOTCON_ERROR_NONE != ret) {
- return;
- }
-
- ret = iotcon_resource_notify(_door_handle, resp_repr, _observers, IOTCON_QOS_HIGH);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- iotcon_representation_destroy(resp_repr);
-}
- * @endcode
- *
- * Example (Client side) :
- * @code
-#include <iotcon.h>
-...
-static iotcon_remote_resource_h _door_resource;
-...
-static void _on_response_observe(iotcon_remote_resource_h resource, iotcon_error_e err,
- iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
-{
-}
-...
-{
- int ret;
- ret = iotcon_remote_resource_observe_register(door_resource, IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER, NULL,
- _on_resopnse_observe, NULL);
- if (IOTCON_ERROR_NONE != ret)
- return;
-}
- * @endcode
- *
- */
-
-#endif /* __TIZEN_NETWORK_IOTCON_DOC_H__ */
+++ /dev/null
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/)
-INCLUDE_DIRECTORIES(include)
-
-FILE(GLOB CLIENT_SRCS *.c ${CMAKE_SOURCE_DIR}/common/*.c)
-SET(CLIENT_SRCS ${CLIENT_SRCS} ${CMAKE_SOURCE_DIR}/common/ic-dbus.c)
-
-SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/ic-dbus.c
- PROPERTIES GENERATED TRUE)
-
-pkg_check_modules(client_pkgs REQUIRED glib-2.0 dlog capi-base-common gio-2.0 capi-system-info
- gio-unix-2.0)
-INCLUDE_DIRECTORIES(${client_pkgs_INCLUDE_DIRS})
-LINK_DIRECTORIES(${client_pkgs_LIBRARY_DIRS})
-
-ADD_DEFINITIONS("-DIOTCON_DBUS_INTERFACE=\"${DBUS_INTERFACE}\"")
-
-ADD_LIBRARY(${CLIENT} SHARED ${CLIENT_SRCS})
-ADD_DEPENDENCIES(${CLIENT} GENERATED_DBUS_CODE)
-TARGET_LINK_LIBRARIES(${CLIENT} ${client_pkgs_LIBRARIES})
-SET_TARGET_PROPERTIES(${CLIENT} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER})
-INSTALL(TARGETS ${CLIENT} DESTINATION ${LIB_INSTALL_DIR})
-
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-CONFIGURE_FILE(${CLIENT}.pc.in ${CLIENT}.pc @ONLY)
-INSTALL(FILES ${CLIENT}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
-FILE(GLOB CLIENT_HEADER include/*.h)
-INSTALL(FILES ${CLIENT_HEADER} DESTINATION ${INCLUDE_INSTALL_DIR}/${CLIENT})
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-resource.h"
-#include "icl-resource-types.h"
-#include "icl-resource-interfaces.h"
-#include "icl-options.h"
-#include "icl-query.h"
-#include "icl-request.h"
-#include "icl-response.h"
-#include "icl-remote-resource.h"
-#include "icl-representation.h"
-#include "icl-device.h"
-#include "icl-payload.h"
-#include "icl-observation.h"
-#include "icl-dbus-type.h"
-
-const char** icl_dbus_resource_interfaces_to_array(iotcon_resource_interfaces_h ifaces)
-{
- int i = 0;
- GList *node = ifaces->iface_list;
- int len = g_list_length(node);
-
- if (0 == len) {
- ERR("Empty Resource Interface List");
- return NULL;
- }
-
- const char **array = calloc(len + 1, sizeof(char*));
- if (NULL == array) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
-
- for (node = ifaces->iface_list; node; node = node->next, i++)
- array[i] = node->data;
- array[i] = NULL;
-
- return array;
-}
-
-
-const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types)
-{
- int i = 0;
- GList *node = types->type_list;
- int len = g_list_length(node);
-
- if (0 == len) {
- ERR("Empty Resource Type List");
- return NULL;
- }
-
- const char **array = calloc(len + 1, sizeof(char*));
- if (NULL == array) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
-
- for (node = types->type_list; node; node = node->next, i++)
- array[i] = node->data;
- array[i] = NULL;
-
- return array;
-}
-
-
-GVariant* icl_dbus_representation_to_gvariant(struct icl_representation_s *repr)
-{
- GVariantBuilder builder;
- GVariant *repr_gvar;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE("av"));
-
- if (repr) {
- repr_gvar = icl_representation_to_gvariant(repr);
- if (NULL == repr_gvar) {
- ERR("icl_representation_to_gvariant() Fail");
- g_variant_builder_clear(&builder);
- return NULL;
- }
- g_variant_builder_add(&builder, "v", repr_gvar);
- }
-
- return g_variant_builder_end(&builder);
-}
-
-
-GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response)
-{
- FN_CALL;
- GVariant *value;
- GVariant *repr_gvar;
- GHashTableIter iter;
- GVariantBuilder options;
- gpointer option_id, option_data;
-
- g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
- if (response->header_options) {
- g_hash_table_iter_init(&iter, response->header_options->hash);
- while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
- g_variant_builder_add(&options, "(qs)", GPOINTER_TO_INT(option_id),
- option_data);
- }
- }
-
- repr_gvar = icl_representation_to_gvariant(response->repr);
- if (NULL == repr_gvar) {
- ERR("icl_representation_to_gvariant() Fail");
- g_variant_builder_clear(&options);
- return NULL;
- }
-
- value = g_variant_new("(a(qs)ivxx)",
- &options,
- response->result,
- repr_gvar,
- response->oic_request_h,
- response->oic_resource_h);
-
- return value;
-}
-
-
-GVariant* icl_dbus_remote_resource_to_gvariant(struct icl_remote_resource *resource)
-{
- FN_CALL;
- bool is_secure;
- GVariant *value;
- GHashTableIter iter;
- GVariantBuilder options;
- gpointer option_id, option_data;
-
- g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
- if (resource->header_options) {
- g_hash_table_iter_init(&iter, resource->header_options->hash);
- while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
- g_variant_builder_add(&options, "(qs)", GPOINTER_TO_INT(option_id),
- option_data);
- }
- }
-
- is_secure = resource->properties & IOTCON_RESOURCE_SECURE;
- value = g_variant_new("(ssba(qs)i)", resource->uri_path, resource->host_address,
- is_secure, &options, resource->connectivity_type);
-
- return value;
-}
-
-
-GVariant* icl_dbus_query_to_gvariant(iotcon_query_h query)
-{
- FN_CALL;
- gpointer key, value;
- GHashTableIter iter;
- GVariantBuilder builder;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)"));
- if (query) {
- g_hash_table_iter_init(&iter, query->hash);
- while (g_hash_table_iter_next(&iter, &key, &value))
- g_variant_builder_add(&builder, "(ss)", key, value);
- }
-
- return g_variant_builder_end(&builder);
-}
-
-
-GVariant* icl_dbus_options_to_gvariant(iotcon_options_h options)
-{
- GHashTableIter iter;
- GVariantBuilder builder;
- gpointer option_id, option_data;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE("a(qs)"));
- if (options) {
- g_hash_table_iter_init(&iter, options->hash);
- while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
- g_variant_builder_add(&builder, "(qs)", GPOINTER_TO_INT(option_id),
- option_data);
- }
- }
-
- return g_variant_builder_end(&builder);
-}
-
-
-GVariant* icl_dbus_observers_to_gvariant(iotcon_observers_h observers)
-{
- GList *node;
- GVariantBuilder builder;
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE("ai"));
- if (observers) {
- for (node = observers->observers_list; node; node = node->next)
- g_variant_builder_add(&builder, "i", GPOINTER_TO_INT(node->data));
- }
-
- return g_variant_builder_end(&builder);
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_DBUS_TYPE_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_DBUS_TYPE_H__
-
-#include <glib.h>
-
-#include "icl-device.h"
-#include "icl-resource-types.h"
-
-const char** icl_dbus_resource_interfaces_to_array(iotcon_resource_interfaces_h types);
-const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types);
-GVariant* icl_dbus_representation_to_gvariant(struct icl_representation_s *repr);
-GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response);
-GVariant* icl_dbus_remote_resource_to_gvariant(struct icl_remote_resource *resource);
-GVariant* icl_dbus_query_to_gvariant(iotcon_query_h query);
-GVariant* icl_dbus_options_to_gvariant(iotcon_options_h options);
-GVariant* icl_dbus_observers_to_gvariant(iotcon_observers_h observers);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_DBUS_TYPE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <gio/gio.h>
-#include <tizen_type.h>
-
-#include "iotcon.h"
-#include "ic-common.h"
-#include "ic-utils.h"
-#include "ic-dbus.h"
-#include "icl.h"
-#include "icl-dbus.h"
-
-static unsigned int icl_dbus_count;
-static icDbus *icl_dbus_object;
-static GList *icl_dbus_sub_ids;
-static GList *icl_dbus_conn_changed_cbs;
-
-typedef struct {
- void *cb;
- void *user_data;
- unsigned int id;
-} icl_cb_container_s;
-
-
-icDbus* icl_dbus_get_object()
-{
- return icl_dbus_object;
-}
-
-
-unsigned int icl_dbus_subscribe_signal(char *signal_name, void *cb_container,
- void *cb_free, GDBusSignalCallback sig_handler)
-{
- unsigned int id;
- GDBusConnection *conn = g_dbus_proxy_get_connection(G_DBUS_PROXY(icl_dbus_object));
-
- id = g_dbus_connection_signal_subscribe(conn,
- NULL,
- IOTCON_DBUS_INTERFACE,
- signal_name,
- IOTCON_DBUS_OBJPATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- sig_handler,
- cb_container,
- cb_free);
- if (0 == id) {
- ERR("g_dbus_connection_signal_subscribe() Fail");
- return id;
- }
-
- icl_dbus_sub_ids = g_list_append(icl_dbus_sub_ids, GUINT_TO_POINTER(id));
-
- return id;
-}
-
-
-void icl_dbus_unsubscribe_signal(unsigned int id)
-{
- GDBusConnection *conn = g_dbus_proxy_get_connection(G_DBUS_PROXY(icl_dbus_object));
-
- g_dbus_connection_signal_unsubscribe(conn, id);
-
- icl_dbus_sub_ids = g_list_remove(icl_dbus_sub_ids, GUINT_TO_POINTER(id));
-}
-
-
-static void _icl_dbus_connection_changed_cb(GObject *object, GParamSpec *pspec,
- gpointer user_data)
-{
- bool is_connected = false;
- GDBusProxy *proxy = G_DBUS_PROXY(object);
- gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
- icl_cb_container_s *cb_container = user_data;
- iotcon_connection_changed_cb cb = cb_container->cb;
-
- if (name_owner)
- is_connected = true;
-
- if (cb)
- cb(is_connected, cb_container->user_data);
-}
-
-
-static icl_cb_container_s* _dbus_find_conn_changed_cb(iotcon_connection_changed_cb cb,
- void *user_data)
-{
- GList *node;
-
- for (node = icl_dbus_conn_changed_cbs; node; node = node->next) {
- icl_cb_container_s *cb_container = node->data;
- if ((cb == cb_container->cb) && (user_data == cb_container->user_data))
- return cb_container;
- }
-
- return NULL;
-}
-
-
-API int iotcon_add_connection_changed_cb(iotcon_connection_changed_cb cb, void *user_data)
-{
- unsigned int id;
- icl_cb_container_s *cb_container;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (_dbus_find_conn_changed_cb(cb, user_data)) {
- ERR("This callback is already registered.");
- return IOTCON_ERROR_ALREADY;
- }
-
- cb_container = calloc(1, sizeof(icl_cb_container_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- id = g_signal_connect_after(icl_dbus_object, "notify::g-name-owner",
- G_CALLBACK(_icl_dbus_connection_changed_cb), cb_container);
- if (0 == id) {
- ERR("g_signal_connect_after() Fail");
- free(cb_container);
- return IOTCON_ERROR_DBUS;
- }
-
- cb_container->id = id;
-
- icl_dbus_conn_changed_cbs = g_list_append(icl_dbus_conn_changed_cbs, cb_container);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remove_connection_changed_cb(iotcon_connection_changed_cb cb,
- void *user_data)
-{
- icl_cb_container_s *cb_container;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cb_container = _dbus_find_conn_changed_cb(cb, user_data);
- if (NULL == cb_container) {
- ERR("This callback is not registered");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- icl_dbus_conn_changed_cbs = g_list_remove(icl_dbus_conn_changed_cbs, cb_container);
-
- g_signal_handler_disconnect(icl_dbus_object, cb_container->id);
- free(cb_container);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icl_dbus_sub_id_list_free(gpointer data)
-{
- GDBusConnection *conn = g_dbus_proxy_get_connection(G_DBUS_PROXY(icl_dbus_object));
-
- g_dbus_connection_signal_unsubscribe(conn, GPOINTER_TO_UINT(data));
-}
-
-
-/* Unsubscribe all signals */
-static void _icl_dbus_cleanup()
-{
- g_list_free_full(icl_dbus_sub_ids, _icl_dbus_sub_id_list_free);
- icl_dbus_sub_ids = NULL;
-}
-
-
-static void _icl_dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
- gpointer user_data)
-{
- GDBusProxy *proxy = G_DBUS_PROXY(object);
- gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
-
- if (name_owner)
- return;
-
- _icl_dbus_cleanup();
-}
-
-
-inline int icl_dbus_convert_daemon_error(int error)
-{
- int ret;
-
- if (IOTCON_ERROR_INVALID_PARAMETER == error)
- ret = IOTCON_ERROR_SYSTEM;
- else
- ret = error;
-
- return ret;
-}
-
-
-inline int icl_dbus_convert_dbus_error(int error)
-{
- int ret;
-
- if (G_DBUS_ERROR_ACCESS_DENIED == error)
- ret = IOTCON_ERROR_PERMISSION_DENIED;
- else if (G_DBUS_ERROR_TIMEOUT == error)
- ret = IOTCON_ERROR_TIMEOUT;
- else
- ret = IOTCON_ERROR_DBUS;
-
- return ret;
-}
-
-int icl_dbus_set_timeout(int timeout_seconds)
-{
- RETV_IF(NULL == icl_dbus_object, IOTCON_ERROR_DBUS);
-
- g_dbus_proxy_set_default_timeout(G_DBUS_PROXY(icl_dbus_object), timeout_seconds * 1000);
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_dbus_get_timeout()
-{
- gint timeout;
-
- RETV_IF(NULL == icl_dbus_object, ICL_DBUS_TIMEOUT_DEFAULT);
-
- timeout = g_dbus_proxy_get_default_timeout(G_DBUS_PROXY(icl_dbus_object));
- if (timeout <= 0) {
- ERR("Invalid timeout (%d)", timeout);
- return ICL_DBUS_TIMEOUT_DEFAULT;
- }
- return timeout/1000;
-}
-
-int icl_dbus_start()
-{
- unsigned int id;
- GError *error = NULL;
-
- if (icl_dbus_object) {
- icl_dbus_count++;
- return IOTCON_ERROR_NONE;
- }
-
- icl_dbus_object = ic_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- IOTCON_DBUS_INTERFACE,
- IOTCON_DBUS_OBJPATH,
- NULL,
- &error);
- if (NULL == icl_dbus_object) {
- ERR("ic_dbus_proxy_new_for_bus_sync() Fail(%s)", error->message);
- g_error_free(error);
- return IOTCON_ERROR_DBUS;
- }
-
- id = g_signal_connect(icl_dbus_object, "notify::g-name-owner",
- G_CALLBACK(_icl_dbus_name_owner_notify), NULL);
- if (0 == id) {
- ERR("g_signal_connect() Fail");
- return IOTCON_ERROR_DBUS;
- }
-
- g_dbus_proxy_set_default_timeout(G_DBUS_PROXY(icl_dbus_object),
- ICL_DBUS_TIMEOUT_DEFAULT * 1000);
-
- icl_dbus_count++;
- return IOTCON_ERROR_NONE;
-}
-
-
-void icl_dbus_stop()
-{
- if (0 == icl_dbus_count) {
- WARN("dbus not initialized");
- return;
- }
-
- icl_dbus_count--;
-
- if (0 < icl_dbus_count)
- return;
-
- DBG("All connection is closed");
-
- _icl_dbus_cleanup();
-
- g_list_free_full(icl_dbus_conn_changed_cbs, free);
- icl_dbus_conn_changed_cbs = NULL;
-
- g_object_unref(icl_dbus_object);
- icl_dbus_object = NULL;
-
- return;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_DBUS_H__
-#define __IOT_CONNECTIVITY_MANAGER_DBUS_H__
-
-#include <stdint.h>
-
-#include "ic-dbus.h"
-
-#define ICL_DBUS_TIMEOUT_DEFAULT 30 /* 30 sec */
-#define ICL_DBUS_TIMEOUT_MAX 60*60 /* 60 min */
-
-
-icDbus* icl_dbus_get_object();
-
-unsigned int icl_dbus_subscribe_signal(char *signal_name, void *cb_container,
- void *cb_free, GDBusSignalCallback sig_handler);
-void icl_dbus_unsubscribe_signal(unsigned int id);
-
-int icl_dbus_add_connection_changed_cb(iotcon_connection_changed_cb cb,
- void *user_data);
-int icl_dbus_remove_connection_changed_cb(iotcon_connection_changed_cb cb,
- void *user_data);
-
-int icl_dbus_convert_daemon_error(int error);
-int icl_dbus_convert_dbus_error(int error);
-
-int icl_dbus_set_timeout(int timeout_seconds);
-int icl_dbus_get_timeout();
-
-int icl_dbus_start();
-void icl_dbus_stop();
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_DBUS_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-representation.h"
-#include "icl-dbus.h"
-#include "icl-dbus-type.h"
-#include "icl-device.h"
-
-/**
- * @brief The maximum length which can be held in a manufacturer name.
- *
- * @since_tizen 3.0
- */
-#define ICL_MANUFACTURER_NAME_LENGTH_MAX 15
-
-/**
- * @brief The maximum length which can be held in a manufacturer url.
- *
- * @since_tizen 3.0
- */
-#define ICL_MANUFACTURER_URL_LENGTH_MAX 32
-
-
-typedef struct {
- bool found;
- iotcon_device_info_cb cb;
- void *user_data;
- unsigned int id;
- int timeout_id;
-} icl_device_info_s;
-
-typedef struct {
- bool found;
- iotcon_platform_info_cb cb;
- void *user_data;
- unsigned int id;
- int timeout_id;
-} icl_platform_info_s;
-
-
-API int iotcon_device_info_get_property(iotcon_device_info_h device_info,
- iotcon_device_info_e property, char **value)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == device_info, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
-
- switch (property) {
- case IOTCON_DEVICE_INFO_NAME:
- *value = device_info->device_name;
- break;
- case IOTCON_DEVICE_INFO_SPEC_VER:
- *value = device_info->spec_ver;
- break;
- case IOTCON_DEVICE_INFO_ID:
- *value = device_info->device_id;
- break;
- case IOTCON_DEVICE_INFO_DATA_MODEL_VER:
- *value = device_info->data_model_ver;
- break;
- default:
- ERR("Invalid property(%d)", property);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-static void _icl_device_info_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- struct icl_device_info info = {0};
- icl_device_info_s *cb_container = user_data;
- iotcon_device_info_cb cb = cb_container->cb;
-
- cb_container->found = true;
-
- g_variant_get(parameters, "(&s&s&s&s)", &info.device_name,
- &info.spec_ver, &info.device_id, &info.data_model_ver);
-
- if (cb)
- cb(&info, IOTCON_ERROR_NONE, cb_container->user_data);
-}
-
-static gboolean _icl_timeout_get_device_info(gpointer p)
-{
- FN_CALL;
- icl_device_info_s *cb_container = p;
- struct icl_device_info info = {0};
-
- if (NULL == cb_container) {
- ERR("cb_container is NULL");
- return G_SOURCE_REMOVE;
- }
-
- if (false == cb_container->found && cb_container->cb)
- cb_container->cb(&info, IOTCON_ERROR_TIMEOUT, cb_container->user_data);
- cb_container->timeout_id = 0;
-
- icl_dbus_unsubscribe_signal(cb_container->id);
- cb_container->id = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-static void _icl_device_info_conn_cleanup(icl_device_info_s *cb_container)
-{
- RET_IF(NULL == cb_container);
- if (cb_container->timeout_id)
- g_source_remove(cb_container->timeout_id);
- free(cb_container);
-}
-
-API int iotcon_get_device_info(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- iotcon_device_info_cb cb,
- void *user_data)
-{
- int ret, timeout;
- unsigned int sub_id;
- GError *error = NULL;
- icl_device_info_s *cb_container;
- int64_t signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- timeout = icl_dbus_get_timeout();
-
- ic_dbus_call_get_device_info_sync(icl_dbus_get_object(),
- ic_utils_dbus_encode_str(host_address),
- connectivity_type,
- timeout,
- &signal_number,
- &ret,
- NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_get_device_info_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_DEVICE,
- signal_number);
-
- cb_container = calloc(1, sizeof(icl_device_info_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container,
- _icl_device_info_conn_cleanup, _icl_device_info_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- free(cb_container);
- return IOTCON_ERROR_DBUS;
- }
-
- cb_container->id = sub_id;
-
- cb_container->timeout_id = g_timeout_add_seconds(timeout,
- _icl_timeout_get_device_info, cb_container);
-
- return ret;
-}
-
-API int iotcon_platform_info_get_property(iotcon_platform_info_h platform_info,
- iotcon_platform_info_e property, char **value)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == platform_info, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
-
- switch (property) {
- case IOTCON_PLATFORM_INFO_ID:
- *value = platform_info->platform_id;
- break;
- case IOTCON_PLATFORM_INFO_MANUF_NAME:
- *value = platform_info->manuf_name;
- break;
- case IOTCON_PLATFORM_INFO_MANUF_URL:
- *value = platform_info->manuf_url;
- break;
- case IOTCON_PLATFORM_INFO_MODEL_NUMBER:
- *value = platform_info->model_number;
- break;
- case IOTCON_PLATFORM_INFO_DATE_OF_MANUF:
- *value = platform_info->date_of_manuf;
- break;
- case IOTCON_PLATFORM_INFO_PLATFORM_VER:
- *value = platform_info->platform_ver;
- break;
- case IOTCON_PLATFORM_INFO_OS_VER:
- *value = platform_info->os_ver;
- break;
- case IOTCON_PLATFORM_INFO_HARDWARE_VER:
- *value = platform_info->hardware_ver;
- break;
- case IOTCON_PLATFORM_INFO_FIRMWARE_VER:
- *value = platform_info->firmware_ver;
- break;
- case IOTCON_PLATFORM_INFO_SUPPORT_URL:
- *value = platform_info->support_url;
- break;
- case IOTCON_PLATFORM_INFO_SYSTEM_TIME:
- *value = platform_info->system_time;
- break;
- default:
- ERR("Invalid property(%d)", property);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icl_platform_info_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- struct icl_platform_info info = {0};
- icl_platform_info_s *cb_container = user_data;
- iotcon_platform_info_cb cb = cb_container->cb;
-
- cb_container->found = true;
-
- g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s)",
- &info.platform_id,
- &info.manuf_name,
- &info.manuf_url,
- &info.model_number,
- &info.date_of_manuf,
- &info.platform_ver,
- &info.os_ver,
- &info.hardware_ver,
- &info.firmware_ver,
- &info.support_url,
- &info.system_time);
-
- info.manuf_url = ic_utils_dbus_decode_str(info.manuf_url);
- info.model_number = ic_utils_dbus_decode_str(info.model_number);
- info.date_of_manuf = ic_utils_dbus_decode_str(info.date_of_manuf);
- info.platform_ver = ic_utils_dbus_decode_str(info.platform_ver);
- info.os_ver = ic_utils_dbus_decode_str(info.os_ver);
- info.hardware_ver = ic_utils_dbus_decode_str(info.hardware_ver);
- info.firmware_ver = ic_utils_dbus_decode_str(info.firmware_ver);
- info.support_url = ic_utils_dbus_decode_str(info.support_url);
- info.system_time = ic_utils_dbus_decode_str(info.system_time);
-
- if (cb)
- cb(&info, IOTCON_ERROR_NONE, cb_container->user_data);
-}
-
-static gboolean _icl_timeout_get_platform_info(gpointer p)
-{
- FN_CALL;
- icl_platform_info_s *cb_container = p;
- struct icl_platform_info info = {0};
-
- if (NULL == cb_container) {
- ERR("cb_container is NULL");
- return G_SOURCE_REMOVE;
- }
-
- if (false == cb_container->found && cb_container->cb)
- cb_container->cb(&info, IOTCON_ERROR_TIMEOUT, cb_container->user_data);
- cb_container->timeout_id = 0;
-
- icl_dbus_unsubscribe_signal(cb_container->id);
- cb_container->id = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-static void _icl_platform_info_conn_cleanup(icl_platform_info_s *cb_container)
-{
- RET_IF(NULL == cb_container);
-
- if (cb_container->timeout_id)
- g_source_remove(cb_container->timeout_id);
-
- free(cb_container);
-}
-
-API int iotcon_get_platform_info(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- iotcon_platform_info_cb cb,
- void *user_data)
-{
- int ret, timeout;
- unsigned int sub_id;
- GError *error = NULL;
- icl_platform_info_s *cb_container;
- int64_t signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- timeout = icl_dbus_get_timeout();
-
- ic_dbus_call_get_platform_info_sync(icl_dbus_get_object(),
- ic_utils_dbus_encode_str(host_address),
- connectivity_type,
- timeout,
- &signal_number,
- &ret,
- NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_get_platform_info_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_PLATFORM,
- signal_number);
-
- cb_container = calloc(1, sizeof(icl_platform_info_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container,
- _icl_platform_info_conn_cleanup, _icl_platform_info_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- free(cb_container);
- return IOTCON_ERROR_DBUS;
- }
-
- cb_container->id = sub_id;
- cb_container->timeout_id = g_timeout_add_seconds(timeout,
- _icl_timeout_get_platform_info, cb_container);
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_DEVICE_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_DEVICE_H__
-
-#include "iotcon-types.h"
-
-struct icl_device_info {
- char *device_name;
- char *spec_ver;
- char *device_id;
- char *data_model_ver;
-};
-
-struct icl_platform_info {
- char *platform_id;
- char *manuf_name;
- char *manuf_url;
- char *model_number;
- char *date_of_manuf;
- char *platform_ver;
- char *os_ver;
- char *hardware_ver;
- char *firmware_ver;
- char *support_url;
- char *system_time;
-};
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_DEVICE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <errno.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-state.h"
-#include "icl-representation.h"
-#include "icl-value.h"
-#include "icl-list.h"
-
-iotcon_list_h icl_list_ref(iotcon_list_h list)
-{
- RETV_IF(NULL == list, NULL);
- RETV_IF(list->ref_count <= 0, NULL);
-
- list->ref_count++;
-
- return list;
-}
-
-
-API int iotcon_list_create(iotcon_type_e type, iotcon_list_h *ret_list)
-{
- iotcon_list_h list;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_list, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (type < IOTCON_TYPE_INT || IOTCON_TYPE_STATE < type) {
- ERR("Invalid Type(%d)", type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- list = calloc(1, sizeof(struct icl_list_s));
- if (NULL == list) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- list->ref_count = 1;
- list->type = type;
-
- *ret_list = list;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_add_int(iotcon_list_h list, int val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
- list->type);
-
- value = icl_value_create_int(val);
- if (NULL == value) {
- ERR("icl_value_create_int(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_bool(iotcon_list_h list, bool val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_bool(val);
- if (NULL == value) {
- ERR("icl_value_create_bool(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_double(iotcon_list_h list, double val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_double(val);
- if (NULL == value) {
- ERR("icl_value_create_double(%f) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_str(iotcon_list_h list, char *val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_str(val);
- if (NULL == value) {
- ERR("icl_value_create_str(%s) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_byte_str(iotcon_list_h list, unsigned char *val, int len, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BYTE_STR != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_byte_str(val, len);
- if (NULL == value) {
- ERR("icl_value_create_str() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_list(iotcon_list_h list, iotcon_list_h val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_list(val);
- if (NULL == value) {
- ERR("icl_value_create_list(%p) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_add_state(iotcon_list_h list, iotcon_state_h val, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STATE != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
-
- value = icl_value_create_state(val);
- if (NULL == value) {
- ERR("icl_value_create_state(%p) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return icl_list_insert(list, value, pos);
-}
-
-
-API int iotcon_list_get_nth_int(iotcon_list_h list, int pos, int *val)
-{
- int ival, ret;
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_int(value, &ival);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_int() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = ival;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_bool(iotcon_list_h list, int pos, bool *val)
-{
- int ret;
- bool bval;
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_bool(value, &bval);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_bool() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = bval;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_double(iotcon_list_h list, int pos, double *val)
-{
- int ret;
- double dbval;
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_double(value, &dbval);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_double() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = dbval;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_str(iotcon_list_h list, int pos, char **val)
-{
- int ret;
- char *strval;
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_str(value, &strval);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_str() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = strval;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_byte_str(iotcon_list_h list, int pos, unsigned char **val,
- int *len)
-{
- unsigned char *byte_val;
- int ret, byte_len;
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == len, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_byte_str(value, &byte_val, &byte_len);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_byte_str() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *val = byte_val;
- *len = byte_len;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_list(iotcon_list_h src, int pos, iotcon_list_h *dest)
-{
- int ret;
- iotcon_value_h value;
- iotcon_list_h list_val;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == src->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(src->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_list(value, &list_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_list() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *dest = list_val;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *state)
-{
- int ret;
- iotcon_value_h value;
- iotcon_state_h state_val;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = icl_value_get_state(value, &state_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_state() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- *state = state_val;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_remove_nth(iotcon_list_h list, int pos)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list->list, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_list_nth_data(list->list, pos);
- if (NULL == value) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- list->list = g_list_remove(list->list, value);
-
- icl_value_destroy(value);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_type(iotcon_list_h list, iotcon_type_e *type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *type = list->type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_list_get_length(iotcon_list_h list, unsigned int *length)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == length, IOTCON_ERROR_INVALID_PARAMETER);
- if (NULL == list->list)
- *length = 0;
- else
- *length = g_list_length(list->list);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icl_list_insert(iotcon_list_h list, iotcon_value_h value, int pos)
-{
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
- list->list = g_list_insert(list->list, value, pos);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_basic_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_INT != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
- list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->val.i, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_basic_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BOOL != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->val.b, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_basic_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_DOUBLE != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->val.d, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_basic_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STR != list->type, IOTCON_ERROR_INVALID_TYPE, "Invalid Type(%d)",
- list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->val.s, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_byte_str(iotcon_list_h list, iotcon_list_byte_str_cb cb,
- void *user_data)
-{
- GList *cur;
- int index = 0;
- icl_val_byte_str_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BYTE_STR != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->s, real->len, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb,
- void *user_data)
-{
- int index = 0;
- GList *cur = NULL;
- icl_val_list_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_LIST != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->list, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_list_foreach_state(iotcon_list_h list, iotcon_list_state_cb cb,
- void *user_data)
-{
- int index = 0;
- GList *cur = NULL;
- icl_val_state_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STATE != list->type, IOTCON_ERROR_INVALID_TYPE,
- "Invalid Type(%d)", list->type);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);;
-
- cur = list->list;
- while (cur) {
- GList *next = cur->next;
- real = cur->data;
- if (IOTCON_FUNC_STOP == cb(index, real->state, user_data))
- break;
- index++;
- cur = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static iotcon_value_h _icl_list_get_nth_value(iotcon_list_h list, int pos)
-{
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == list->list, NULL);
-
- return g_list_nth_data(list->list, pos);
-}
-
-
-API void iotcon_list_destroy(iotcon_list_h list)
-{
- GList *cur = NULL;
-
- RET_IF(NULL == list);
-
- list->ref_count--;
-
- if (0 != list->ref_count)
- return;
-
- cur = list->list;
- while (cur) {
- icl_value_destroy(cur->data);
- cur = cur->next;
- }
- free(list);
-}
-
-static int _icl_list_clone_value(iotcon_list_h list, iotcon_list_h ret_list)
-{
- int i, ret, count;
- iotcon_value_h value, copied_value;
-
- count = g_list_length(list->list);
- for (i = 0; i < count; i++) {
- value = _icl_list_get_nth_value(list, i);
- if (NULL == value) {
- ERR("_icl_list_get_nth_value() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- if (list->type != value->type) {
- ERR("Type Mismatching(list:%d, value:%d)", list->type, value->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- copied_value = icl_value_clone(value);
- if (NULL == copied_value) {
- ERR("icl_value_clone() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- ret = icl_list_insert(ret_list, copied_value, -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_list_insert() Fail");
- icl_value_destroy(copied_value);
- return IOTCON_ERROR_REPRESENTATION;
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _icl_list_clone_list(iotcon_list_h list, iotcon_list_h ret_list)
-{
- int i, ret, count;
-
- iotcon_value_h value;
- iotcon_list_h list_val, copied_list;
-
- count = g_list_length(list->list);
- for (i = 0; i < count; i++) {
- ret = iotcon_list_get_nth_list(list, i, &list_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_get_nth_list() Fail(%d)", ret);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- copied_list = icl_list_clone(list_val);
- if (NULL == copied_list) {
- ERR("icl_list_clone() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- value = icl_value_create_list(copied_list);
- if (NULL == value) {
- ERR("icl_value_create_list(%p) Fail", copied_list);
- iotcon_list_destroy(copied_list);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- ret = icl_list_insert(ret_list, value, -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_list_insert(%d) Fail", ret);
- icl_value_destroy(value);
- return IOTCON_ERROR_REPRESENTATION;
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _icl_list_clone_state(iotcon_list_h list, iotcon_list_h ret_list)
-{
- int i, ret, count;
- iotcon_value_h value;
- iotcon_state_h state_val;
- iotcon_state_h copied_state = NULL;
-
- count = g_list_length(list->list);
- for (i = 0; i < count; i++) {
- ret = iotcon_list_get_nth_state(list, i, &state_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_get_nth_state() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
-
- if (state_val->hash_table) {
- g_hash_table_foreach(state_val->hash_table, (GHFunc)icl_state_clone_foreach,
- copied_state);
- }
-
- value = icl_value_create_state(copied_state);
- if (NULL == value) {
- ERR("icl_value_create_state(%p) Fail", copied_state);
- iotcon_state_destroy(copied_state);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- ret = icl_list_insert(ret_list, value, -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_list_insert(%d) Fail", ret);
- icl_value_destroy(value);
- return IOTCON_ERROR_REPRESENTATION;
- }
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-iotcon_list_h icl_list_clone(iotcon_list_h list)
-{
- int ret;
- iotcon_list_h ret_list = NULL;
-
- RETV_IF(NULL == list, NULL);
- RETV_IF(NULL == list->list, NULL);
-
- ret = iotcon_list_create(list->type, &ret_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create(%d) Fail(%d)", list->type, ret);
- return NULL;
- }
-
- switch (list->type) {
- case IOTCON_TYPE_INT:
- case IOTCON_TYPE_BOOL:
- case IOTCON_TYPE_DOUBLE:
- case IOTCON_TYPE_STR:
- case IOTCON_TYPE_NULL:
- case IOTCON_TYPE_BYTE_STR:
- ret = _icl_list_clone_value(list, ret_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_clone_value() Fail(%d)", ret);
- iotcon_list_destroy(ret_list);
- return NULL;
- }
- break;
- case IOTCON_TYPE_LIST:
- ret = _icl_list_clone_list(list, ret_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_clone_list() Fail(%d)", ret);
- iotcon_list_destroy(ret_list);
- return NULL;
- }
- break;
- case IOTCON_TYPE_STATE:
- ret = _icl_list_clone_state(list, ret_list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_list_clone_state() Fail(%d)", ret);
- iotcon_list_destroy(ret_list);
- return NULL;
- }
- break;
- default:
- ERR("Invalid type(%d)", list->type);
- iotcon_list_destroy(ret_list);
- return NULL;
- }
-
- return ret_list;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_LIST_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_LIST_H__
-
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "icl-value.h"
-
-struct icl_list_s {
- int type;
- int ref_count;
- GList *list;
-};
-
-int icl_list_remove(iotcon_list_h list, iotcon_value_h val);
-int icl_list_insert(iotcon_list_h list, iotcon_value_h value, int pos);
-
-iotcon_list_h icl_list_clone(iotcon_list_h list);
-
-iotcon_list_h icl_list_ref(iotcon_list_h list);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_LIST_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-dbus.h"
-#include "icl-representation.h"
-#include "icl-state.h"
-#include "icl-value.h"
-#include "icl-list.h"
-#include "icl-dbus-type.h"
-#include "icl-payload.h"
-#include "icl-resource.h"
-#include "icl-response.h"
-
-struct icl_lite_resource {
- char *uri_path;
- iotcon_state_h state;
- int64_t handle;
- unsigned int sub_id;
- int properties;
- iotcon_lite_resource_post_request_cb cb;
- void *cb_data;
-};
-
-
-static inline int _icl_lite_resource_set_state(iotcon_state_h state,
- iotcon_state_h res_state)
-{
- GHashTableIter iter;
- gpointer key, value;
- iotcon_value_h res_value, src_value;
-
- if (NULL == res_state) {
- DBG("resource_state is NULL");
- return IOTCON_ERROR_NONE;
- }
-
- g_hash_table_iter_init(&iter, state->hash_table);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- res_value = g_hash_table_lookup(res_state->hash_table, key);
- if (NULL == res_value) {
- WARN("Invalid Key(%s)", key);
- continue;
- }
-
- src_value = icl_value_clone(value);
- if (NULL == src_value) {
- ERR("icl_value_clone() Fail");
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- if (src_value->type != res_value->type) {
- WARN("Different Type(%d)", (src_value->type));
- icl_value_destroy(src_value);
- continue;
- }
-
- g_hash_table_replace(res_state->hash_table, ic_utils_strdup(key), src_value);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _icl_lite_resource_response_send(iotcon_representation_h repr,
- int64_t oic_request_h, int64_t oic_resource_h, int response_result)
-{
- int ret;
- iotcon_response_h response;
-
- response = calloc(1, sizeof(struct icl_resource_response));
- if (NULL == response) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- response->iface = strdup(IOTCON_INTERFACE_DEFAULT);
- response->result = response_result;
- response->oic_request_h = oic_request_h;
- response->oic_resource_h = oic_resource_h;
- if (repr)
- response->repr = icl_representation_ref(repr);
-
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_send() Fail(%d)", ret);
- iotcon_response_destroy(response);
- return ret;
- }
-
- iotcon_response_destroy(response);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static int _icl_lite_resource_notify(iotcon_lite_resource_h lite_resource)
-{
- int ret;
- struct icl_resource resource = {0};
-
- RETV_IF(NULL == lite_resource, IOTCON_ERROR_INVALID_PARAMETER);
- if (false == (IOTCON_RESOURCE_OBSERVABLE & lite_resource->properties))
- return IOTCON_ERROR_NONE;
-
- resource.handle = lite_resource->handle;
- resource.sub_id = lite_resource->sub_id;
-
- ret = iotcon_resource_notify(&resource, NULL, NULL, IOTCON_QOS_HIGH);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_notify() Fail(%d)", ret);
- return ret;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icl_lite_resource_request_handler(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- GVariant *repr_gvar;
- int ret, request_type;
- int64_t oic_request_h = 0;
- int64_t oic_resource_h = 0;
- iotcon_representation_h repr;
- iotcon_state_h recv_state = NULL;
- GVariantIter *repr_iter, *state_iter;
- iotcon_lite_resource_h resource = user_data;
-
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- _icl_lite_resource_response_send(NULL, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_ERROR);
- return;
- }
-
- ret = iotcon_representation_set_uri_path(repr, resource->uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
- _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_ERROR);
- iotcon_representation_destroy(repr);
- return;
- }
-
- g_variant_get(parameters, "(siia(qs)a(ss)iiavxx)",
- NULL, /* host address */
- NULL, /* connectivity type */
- &request_type,
- NULL, /* header options */
- NULL, /* query */
- NULL, /* observe action */
- NULL, /* observe_id */
- &repr_iter,
- &oic_request_h,
- &oic_resource_h);
-
- switch (request_type) {
- case IOTCON_REQUEST_GET:
- break;
- case IOTCON_REQUEST_POST:
- if (FALSE == g_variant_iter_loop(repr_iter, "v", &repr_gvar)) {
- ERR("Received representation is empty.");
- _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_ERROR);
- iotcon_representation_destroy(repr);
- return;
- }
-
- g_variant_get(repr_gvar, "(sasasa{sv}av)", NULL, NULL, NULL, &state_iter,
- NULL);
-
- ret = iotcon_state_create(&recv_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_ERROR);
- iotcon_representation_destroy(repr);
- return;
- }
-
- icl_state_from_gvariant(recv_state, state_iter);
-
- if (resource->cb) {
- if (false == resource->cb(resource, recv_state, resource->cb_data)) {
- _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_ERROR);
- iotcon_state_destroy(recv_state);
- iotcon_representation_destroy(repr);
- return;
- }
- }
-
- ret = _icl_lite_resource_set_state(recv_state, resource->state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_lite_resource_set_state() Fail(%d)", ret);
- _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_ERROR);
- iotcon_state_destroy(recv_state);
- iotcon_representation_destroy(repr);
- return;
- }
-
- iotcon_state_destroy(recv_state);
- break;
- case IOTCON_REQUEST_PUT:
- case IOTCON_REQUEST_DELETE:
- default:
- WARN("Not supported request (only GET / POST / OBSERVE)");
- ret = _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_FORBIDDEN);
- if (IOTCON_ERROR_NONE != ret)
- ERR("_icl_lite_resource_response_send() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return;
- }
-
- ret = iotcon_representation_set_state(repr, resource->state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_ERROR);
- iotcon_representation_destroy(repr);
- return;
- }
-
- ret = _icl_lite_resource_response_send(repr, oic_request_h, oic_resource_h,
- IOTCON_RESPONSE_OK);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_lite_resource_response_send() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return;
- }
-
- if (IOTCON_REQUEST_POST == request_type) {
- ret = _icl_lite_resource_notify(resource);
- if (IOTCON_ERROR_NONE != ret)
- WARN("_icl_lite_resource_notify() Fail(%d)", ret);
- }
- iotcon_representation_destroy(repr);
-}
-
-
-static void _icl_lite_resource_conn_cleanup(iotcon_lite_resource_h resource)
-{
- resource->sub_id = 0;
-
- if (resource->handle) {
- resource->handle = 0;
- return;
- }
-
- if (resource->state)
- iotcon_state_destroy(resource->state);
- free(resource->uri_path);
- free(resource);
-}
-
-
-/* The length of uri_path should be less than or equal to 36. */
-API int iotcon_lite_resource_create(const char *uri_path,
- iotcon_resource_types_h res_types,
- int properties,
- iotcon_state_h state,
- iotcon_lite_resource_post_request_cb cb,
- void *user_data,
- iotcon_lite_resource_h *resource_handle)
-{
- int ret;
- unsigned int sub_id;
- const gchar **types, **ifaces;
- GError *error = NULL;
- iotcon_lite_resource_h resource;
- int64_t signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH];
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(ICL_URI_PATH_LENGTH_MAX < strlen(uri_path),
- IOTCON_ERROR_INVALID_PARAMETER, "Invalid uri_path(%s)", uri_path);
- RETV_IF(NULL == res_types, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
-
- resource = calloc(1, sizeof(struct icl_lite_resource));
- if (NULL == resource) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- ifaces = calloc(2, sizeof(char*));
- if (NULL == ifaces) {
- ERR("calloc() Fail(%d)", errno);
- free(resource);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- ifaces[0] = IOTCON_INTERFACE_DEFAULT;
- ifaces[1] = NULL;
-
- types = icl_dbus_resource_types_to_array(res_types);
- if (NULL == types) {
- ERR("icl_dbus_resource_types_to_array() Fail");
- free(ifaces);
- free(resource);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, types, ifaces,
- properties, true, &signal_number, &(resource->handle), NULL, &error);
- if (error) {
- ERR("ic_dbus_call_register_resource_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- free(types);
- free(ifaces);
- free(resource);
- return ret;
- }
- free(types);
- free(ifaces);
-
- if (0 == resource->handle) {
- ERR("iotcon-daemon Fail");
- free(resource);
- return IOTCON_ERROR_IOTIVITY;
- }
-
- resource->properties = properties;
- resource->uri_path = ic_utils_strdup(uri_path);
- if (state)
- resource->state = icl_state_ref(state);
- resource->cb = cb;
- resource->cb_data = user_data;
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_REQUEST_HANDLER,
- signal_number);
-
- sub_id = icl_dbus_subscribe_signal(signal_name, resource,
- _icl_lite_resource_conn_cleanup, _icl_lite_resource_request_handler);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- if (resource->state)
- iotcon_state_destroy(resource->state);
- free(resource->uri_path);
- free(resource);
- return IOTCON_ERROR_DBUS;
- }
-
- resource->sub_id = sub_id;
-
- *resource_handle = resource;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_lite_resource_destroy(iotcon_lite_resource_h resource)
-{
- int ret;
- GError *error = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 == resource->handle) { /* disconnected iotcon dbus */
- WARN("Invalid Resource handle");
- iotcon_state_destroy(resource->state);
- free(resource->uri_path);
- free(resource);
- return IOTCON_ERROR_NONE;
- }
-
- if (NULL == icl_dbus_get_object()) {
- ERR("icl_dbus_get_object() return NULL");
- return IOTCON_ERROR_DBUS;
- }
-
- ic_dbus_call_unregister_resource_sync(icl_dbus_get_object(), resource->handle, NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_unregister_resource_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- resource->handle = 0;
-
- icl_dbus_unsubscribe_signal(resource->sub_id);
- resource->sub_id = 0;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_lite_resource_update_state(iotcon_lite_resource_h resource,
- iotcon_state_h state)
-{
- int ret;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (state)
- state = icl_state_ref(state);
-
- if (resource->state)
- iotcon_state_destroy(resource->state);
-
- resource->state = state;
-
- ret = _icl_lite_resource_notify(resource);
- if (IOTCON_ERROR_NONE != ret)
- WARN("_icl_lite_resource_notify() Fail");
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_lite_resource_get_state(iotcon_lite_resource_h resource,
- iotcon_state_h *state)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
-
- *state = resource->state;
-
- return IOTCON_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-observation.h"
-
-API int iotcon_observers_create(iotcon_observers_h *ret_observers)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_observers, IOTCON_ERROR_INVALID_PARAMETER);
-
- iotcon_observers_h observers = calloc(1, sizeof(struct icl_observers));
- if (NULL == observers) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- *ret_observers = observers;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_observers_destroy(iotcon_observers_h observers)
-{
- RET_IF(NULL == observers);
-
- g_list_free(observers->observers_list);
- free(observers);
-}
-
-
-API int iotcon_observers_add(iotcon_observers_h observers, int obs_id)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == observers, IOTCON_ERROR_INVALID_PARAMETER);
-
- observers->observers_list = g_list_append(observers->observers_list,
- GUINT_TO_POINTER(obs_id));
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_observers_remove(iotcon_observers_h observers, int obs_id)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == observers, IOTCON_ERROR_INVALID_PARAMETER);
-
- observers->observers_list = g_list_remove(observers->observers_list,
- GUINT_TO_POINTER(obs_id));
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_OBSERVATION_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_OBSERVATION_H__
-
-#include <glib.h>
-#include "iotcon-types.h"
-
-struct icl_observers {
- GList *observers_list;
-};
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_OBSERVATION_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-options.h"
-
-/**
- * @brief HeaderOption range from 2048 to 3000
- * NOTE: HeaderOptionID is an unsigned integer value which MUST be within
- * range of 2048 to 3000 inclusive of lower and upper bound.
- * HeaderOptions instance creation fails if above condition is not satisfied.
- *
- * @since_tizen 3.0
- */
-#define ICL_OPTIONID_MIN 2048
-
-/**
- * @brief The maximum value of option id which can be held in a resource.
- *
- * @since_tizen 3.0
- */
-#define ICL_OPTIONID_MAX 3000
-
-/**
- * @brief The maximum number of option which can be held in a resource.
- *
- * @since_tizen 3.0
- */
-#define ICL_OPTIONS_MAX 2
-
-/**
- * @brief The maximum length of option data which can be held in a resource.
- *
- * @since_tizen 3.0
- */
-#define ICL_OPTION_DATA_LENGTH_MAX 16
-
-
-iotcon_options_h icl_options_ref(iotcon_options_h options)
-{
- RETV_IF(NULL == options, NULL);
- RETV_IF(options->ref_count <= 0, NULL);
-
- options->ref_count++;
-
- return options;
-}
-
-
-API int iotcon_options_create(iotcon_options_h *ret_options)
-{
- iotcon_options_h options;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_options, IOTCON_ERROR_INVALID_PARAMETER);
-
- options = calloc(1, sizeof(struct icl_options));
- if (NULL == options) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- options->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free);
- options->ref_count = 1;
-
- *ret_options = options;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_options_destroy(iotcon_options_h options)
-{
- RET_IF(NULL == options);
-
- options->ref_count--;
-
- if (0 == options->ref_count) {
- g_hash_table_unref(options->hash);
- free(options);
- }
-}
-
-
-/* iotcon_options_h can have up to 2 options.
- * option id is always situated between 2048 and 3000.
- * Length of option data is less than or equal to 15. */
-API int iotcon_options_add(iotcon_options_h options, unsigned short id,
- const char *data)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(1 < options->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
- "Don't modify it. It is already set.");
- RETVM_IF(ICL_OPTIONS_MAX <= g_hash_table_size(options->hash),
- IOTCON_ERROR_OUT_OF_MEMORY, "Options already have maximum elements.");
-
- RETVM_IF(((id < ICL_OPTIONID_MIN) || (ICL_OPTIONID_MAX < id)),
- IOTCON_ERROR_INVALID_PARAMETER, "Invalid id(%d)", id);
-
- RETV_IF(NULL == data, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(ICL_OPTION_DATA_LENGTH_MAX < strlen(data), IOTCON_ERROR_INVALID_PARAMETER,
- "The length of option data(%s) is invalid.", data);
-
- g_hash_table_insert(options->hash, GUINT_TO_POINTER(id), ic_utils_strdup(data));
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_options_remove(iotcon_options_h options, unsigned short id)
-{
- gboolean is_removed;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(1 < options->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
- "Don't modify it. It is already set.");
-
- is_removed = g_hash_table_remove(options->hash, GUINT_TO_POINTER(id));
- if (FALSE == is_removed) {
- ERR("g_hash_table_remove() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_options_lookup(iotcon_options_h options, unsigned short id, char **data)
-{
- char *value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == data, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(options->hash, GUINT_TO_POINTER(id));
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- *data = value;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb cb,
- void *user_data)
-{
- GHashTableIter iter;
- gpointer key, value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_hash_table_iter_init(&iter, options->hash);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- if (IOTCON_FUNC_STOP == cb(GPOINTER_TO_UINT(key), value, user_data))
- break;
- }
-
- return IOTCON_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_OPTIONS_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_OPTIONS_H__
-
-#include <glib.h>
-#include "iotcon-types.h"
-
-struct icl_options {
- int ref_count;
- GHashTable *hash;
-};
-
-iotcon_options_h icl_options_ref(iotcon_options_h options);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_OPTIONS_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-representation.h"
-#include "icl-state.h"
-#include "icl-list.h"
-#include "icl-value.h"
-#include "icl-resource-types.h"
-#include "icl-resource-interfaces.h"
-#include "icl-response.h"
-#include "icl-payload.h"
-
-static GVariant* _icl_state_value_to_gvariant(GHashTable *hash);
-static iotcon_list_h _icl_state_list_from_gvariant(GVariant *var);
-
-static GVariant* _icl_state_list_to_gvariant(iotcon_list_h list)
-{
- GList *node;
- GVariant *var = NULL;
- GVariantBuilder builder;
- iotcon_state_h state;
- struct icl_value_s *state_value = NULL;
-
- RETV_IF(NULL == list, NULL);
-
- g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY);
-
- switch (list->type) {
- case IOTCON_TYPE_INT:
- for (node = list->list; node; node = node->next) {
- state_value = node->data;
- g_variant_builder_add(&builder, "i", ((icl_basic_s*)state_value)->val.i);
- }
- break;
- case IOTCON_TYPE_BOOL:
- for (node = list->list; node; node = node->next) {
- state_value = node->data;
- g_variant_builder_add(&builder, "b", ((icl_basic_s*)state_value)->val.b);
- }
- break;
- case IOTCON_TYPE_DOUBLE:
- for (node = list->list; node; node = node->next) {
- state_value = node->data;
- g_variant_builder_add(&builder, "d", ((icl_basic_s*)state_value)->val.d);
- }
- break;
- case IOTCON_TYPE_STR:
- for (node = list->list; node; node = node->next) {
- state_value = node->data;
- g_variant_builder_add(&builder, "s", ((icl_basic_s*)state_value)->val.s);
- }
- break;
- case IOTCON_TYPE_BYTE_STR:
- for (node = list->list; node; node = node->next) {
- state_value = node->data;
- var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"),
- ((icl_val_byte_str_s*)state_value)->s,
- ((icl_val_byte_str_s*)state_value)->len,
- sizeof(unsigned char));
- g_variant_builder_add(&builder, "v", var);
- }
- break;
- case IOTCON_TYPE_LIST:
- for (node = list->list; node; node = node->next) {
- state_value = node->data;
- var = _icl_state_list_to_gvariant(((icl_val_list_s*)state_value)->list);
- g_variant_builder_add(&builder, "v", var);
- }
- break;
- case IOTCON_TYPE_STATE:
- for (node = list->list; node; node = node->next) {
- state_value = node->data;
- state = ((icl_val_state_s*)state_value)->state;
- var = _icl_state_value_to_gvariant(state->hash_table);
- g_variant_builder_add(&builder, "v", var);
- }
- break;
- default:
- ERR("Invalid type(%d)", list->type);
- return NULL;
- }
-
- return g_variant_builder_end(&builder);
-
-}
-
-
-static GVariantBuilder* _icl_state_value_to_gvariant_builder(GHashTable *hash)
-{
- gpointer key, value;
- GHashTableIter iter;
- GVariant *var = NULL;
- iotcon_state_h state;
- GVariantBuilder *builder;
- struct icl_value_s *state_value = NULL;
-
- if (NULL == hash)
- return NULL;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-
- g_hash_table_iter_init(&iter, hash);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- state_value = value;
- switch (state_value->type) {
- case IOTCON_TYPE_INT:
- var = g_variant_new_int32(((icl_basic_s*)state_value)->val.i);
- break;
- case IOTCON_TYPE_BOOL:
- var = g_variant_new_boolean(((icl_basic_s*)state_value)->val.b);
- break;
- case IOTCON_TYPE_DOUBLE:
- var = g_variant_new_double(((icl_basic_s*)state_value)->val.d);
- break;
- case IOTCON_TYPE_STR:
- var = g_variant_new_string(((icl_basic_s*)state_value)->val.s);
- break;
- case IOTCON_TYPE_NULL:
- var = g_variant_new_string(IC_STR_NULL);
- break;
- case IOTCON_TYPE_BYTE_STR:
- var = g_variant_new_fixed_array(G_VARIANT_TYPE("y"),
- ((icl_val_byte_str_s*)state_value)->s,
- ((icl_val_byte_str_s*)state_value)->len,
- sizeof(unsigned char));
- break;
- case IOTCON_TYPE_LIST:
- var = _icl_state_list_to_gvariant(((icl_val_list_s*)state_value)->list);
- break;
- case IOTCON_TYPE_STATE:
- state = ((icl_val_state_s*)state_value)->state;
- var = _icl_state_value_to_gvariant(state->hash_table);
- break;
- case IOTCON_TYPE_NONE:
- default:
- ERR("Invalid Type(%d)", state_value->type);
- g_variant_builder_unref(builder);
- return NULL;
- }
-
- if (var)
- g_variant_builder_add(builder, "{sv}", key, var);
- }
-
- return builder;
-}
-
-
-static GVariant* _icl_state_value_to_gvariant(GHashTable *hash)
-{
- GVariantBuilder* builder;
-
- builder = _icl_state_value_to_gvariant_builder(hash);
-
- return g_variant_builder_end(builder);
-}
-
-
-static GVariant* _icl_representation_empty_gvariant(void)
-{
- GVariant *value;
- GVariantBuilder types, ifaces, repr, children;
-
- g_variant_builder_init(&ifaces, G_VARIANT_TYPE("as"));
- g_variant_builder_init(&types, G_VARIANT_TYPE("as"));
- g_variant_builder_init(&repr, G_VARIANT_TYPE("a{sv}"));
- g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
-
- value = g_variant_new("(sasasa{sv}av)", IC_STR_NULL, &ifaces, &types, &repr, &children);
-
- return value;
-}
-
-
-GVariant* icl_representation_to_gvariant(iotcon_representation_h repr)
-{
- GList *node;
- const char *uri_path;
- GVariant *value, *child;
- iotcon_state_h state;
- GVariantBuilder *repr_gvar = NULL;
- GVariantBuilder children, resource_types, resource_ifaces;
-
- if (NULL == repr)
- return _icl_representation_empty_gvariant();
-
- /* uri path */
- uri_path = ic_utils_dbus_encode_str(repr->uri_path);
-
- /* Resource Types & Interfaces */
- g_variant_builder_init(&resource_types, G_VARIANT_TYPE("as"));
- g_variant_builder_init(&resource_ifaces, G_VARIANT_TYPE("as"));
-
- if (ICL_VISIBILITY_PROP & repr->visibility) {
- if (repr->res_types) {
- for (node = repr->res_types->type_list; node; node = node->next)
- g_variant_builder_add(&resource_types, "s", node->data);
- }
-
- if (repr->interfaces) {
- for (node = repr->interfaces->iface_list; node; node = node->next)
- g_variant_builder_add(&resource_ifaces, "s", node->data);
- }
- }
-
- /* Representation */
- state = repr->state;
- if (state && (ICL_VISIBILITY_REPR & repr->visibility))
- repr_gvar = _icl_state_value_to_gvariant_builder(state->hash_table);
-
- /* Children */
- g_variant_builder_init(&children, G_VARIANT_TYPE("av"));
-
- for (node = repr->children; node; node = node->next) {
- /* generate recursively */
- child = icl_representation_to_gvariant(node->data);
- g_variant_builder_add(&children, "v", child);
- }
-
- value = g_variant_new("(sasasa{sv}av)", uri_path, &resource_ifaces, &resource_types,
- repr_gvar, &children);
-
- return value;
-}
-
-
-void icl_state_from_gvariant(iotcon_state_h state, GVariantIter *iter)
-{
- char *key;
- GVariant *var;
- const char *str_value;
- iotcon_list_h list_value;
- iotcon_value_h value = NULL;
- iotcon_state_h state_value = NULL;
-
- while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
- if (g_variant_is_of_type(var, G_VARIANT_TYPE_BOOLEAN)) {
- value = icl_value_create_bool(g_variant_get_boolean(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_INT32)) {
- value = icl_value_create_int(g_variant_get_int32(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_DOUBLE)) {
- value = icl_value_create_double(g_variant_get_double(var));
-
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_STRING)) {
- str_value = g_variant_get_string(var, NULL);
- if (IC_STR_EQUAL == strcmp(IC_STR_NULL, str_value))
- value = icl_value_create_null();
- else
- value = icl_value_create_str(str_value);
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("a{sv}"))) {
- GVariantIter state_iter;
- iotcon_state_create(&state_value);
- g_variant_iter_init(&state_iter, var);
- icl_state_from_gvariant(state_value, &state_iter);
- value = icl_value_create_state(state_value);
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE("ay"))) {
- value = icl_value_create_byte_str(g_variant_get_data(var),
- g_variant_get_size(var));
- } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_ARRAY)) {
- list_value = _icl_state_list_from_gvariant(var);
- value = icl_value_create_list(list_value);
- } else {
- ERR("Invalid type(%s)", g_variant_get_type_string(var));
- }
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
- }
-
- return;
-}
-
-
-static iotcon_list_h _icl_state_list_from_gvariant(GVariant *var)
-{
- int ret;
- GVariantIter iter;
- const GVariantType *type;
- iotcon_list_h list = NULL;
-
- type = g_variant_get_type(var);
-
- g_variant_iter_init(&iter, var);
-
- if (g_variant_type_equal(G_VARIANT_TYPE("ab"), type)) {
- bool b;
- ret = iotcon_list_create(IOTCON_TYPE_BOOL, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create() Fail(%d)", ret);
- return NULL;
- }
-
- while (g_variant_iter_loop(&iter, "b", &b))
- iotcon_list_add_bool(list, b, -1);
- } else if (g_variant_type_equal(G_VARIANT_TYPE("ai"), type)) {
- int i;
- ret = iotcon_list_create(IOTCON_TYPE_INT, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create() Fail(%d)", ret);
- return NULL;
- }
-
- while (g_variant_iter_loop(&iter, "i", &i))
- iotcon_list_add_int(list, i, -1);
- } else if (g_variant_type_equal(G_VARIANT_TYPE("ad"), type)) {
- double d;
- ret = iotcon_list_create(IOTCON_TYPE_DOUBLE, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create() Fail(%d)", ret);
- return NULL;
- }
-
- while (g_variant_iter_loop(&iter, "d", &d))
- iotcon_list_add_double(list, d, -1);
- } else if (g_variant_type_equal(G_VARIANT_TYPE("as"), type)) {
- char *s;
- ret = iotcon_list_create(IOTCON_TYPE_STR, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create() Fail(%d)", ret);
- return NULL;
- }
-
- while (g_variant_iter_loop(&iter, "s", &s))
- iotcon_list_add_str(list, s, -1);
- } else if (g_variant_type_equal(G_VARIANT_TYPE("av"), type)) {
- GVariant *variant;
- iotcon_list_h list_value;
- iotcon_state_h state_value = NULL;
-
- while (g_variant_iter_loop(&iter, "v", &variant)) {
- if (g_variant_is_of_type(variant, G_VARIANT_TYPE("a{sv}"))) {
- GVariantIter state_iter;
- if (NULL == list) {
- ret = iotcon_list_create(IOTCON_TYPE_STATE, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create() Fail(%d)", ret);
- return NULL;
- }
- }
- iotcon_state_create(&state_value);
- g_variant_iter_init(&state_iter, variant);
- icl_state_from_gvariant(state_value, &state_iter);
- iotcon_list_add_state(list, state_value, -1);
- } else if (g_variant_is_of_type(variant, G_VARIANT_TYPE("ay"))) {
- unsigned char *byte_str;
- if (NULL == list) {
- ret = iotcon_list_create(IOTCON_TYPE_BYTE_STR, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create() Fail(%d)", ret);
- return NULL;
- }
- }
- byte_str = (unsigned char*)g_variant_get_data(variant);
- iotcon_list_add_byte_str(list, byte_str, g_variant_get_size(variant), -1);
- } else if (g_variant_is_of_type(variant, G_VARIANT_TYPE_ARRAY)) {
- if (NULL == list) {
- ret = iotcon_list_create(IOTCON_TYPE_LIST, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create() Fail(%d)", ret);
- return NULL;
- }
- }
- list_value = _icl_state_list_from_gvariant(variant);
- iotcon_list_add_list(list, list_value, -1);
- } else {
- ERR("Invalid type(%s)", g_variant_get_type_string(variant));
- }
- }
- } else {
- ERR("Invalid type(%s)", g_variant_get_type_string(var));
- }
-
- return list;
-}
-
-
-iotcon_representation_h icl_representation_from_gvariant(GVariant *var)
-{
- int ret;
- GVariant *child;
- iotcon_representation_h repr;
- iotcon_state_h state;
- char *uri_path, *resource_type, *resource_iface;
- GVariantIter *children, *repr_gvar, *resource_types, *resource_ifaces;
-
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return NULL;
- }
-
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- g_variant_get(var, "(&sasasa{sv}av)", &uri_path, &resource_ifaces, &resource_types,
- &repr_gvar, &children);
-
- /* uri path */
- if (IC_STR_EQUAL != strcmp(IC_STR_NULL, uri_path))
- repr->uri_path = strdup(uri_path);
-
- /* resource types */
- if (g_variant_iter_n_children(resource_types)) {
- ret = iotcon_resource_types_create(&repr->res_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_create() Fail(%d)", ret);
- g_variant_iter_free(resource_ifaces);
- g_variant_iter_free(resource_types);
- g_variant_iter_free(children);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- while (g_variant_iter_loop(resource_types, "s", &resource_type))
- iotcon_resource_types_add(repr->res_types, resource_type);
- }
- g_variant_iter_free(resource_types);
-
- /* resource ifaces */
- if (g_variant_iter_n_children(resource_ifaces)) {
- ret = iotcon_resource_interfaces_create(&repr->interfaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
- g_variant_iter_free(resource_ifaces);
- g_variant_iter_free(children);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- while (g_variant_iter_loop(resource_ifaces, "s", &resource_iface))
- iotcon_resource_interfaces_add(repr->interfaces, resource_iface);
- }
- g_variant_iter_free(resource_ifaces);
-
- /* attribute */
- icl_state_from_gvariant(state, repr_gvar);
-
- ret = iotcon_representation_set_state(repr, state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
- iotcon_state_destroy(state);
-
- /* children */
- while (g_variant_iter_loop(children, "v", &child)) {
- repr->children = g_list_append(repr->children,
- icl_representation_from_gvariant(child));
- }
- g_variant_iter_free(children);
-
- return repr;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_PAYLOAD_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_PAYLOAD_H__
-
-#include <glib.h>
-
-void icl_state_from_gvariant(iotcon_state_h state, GVariantIter *iter);
-GVariant* icl_representation_to_gvariant(iotcon_representation_h repr);
-iotcon_representation_h icl_representation_from_gvariant(GVariant *var);
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_LIBRARY_PAYLOAD_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "iotcon-internal.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-resource-types.h"
-#include "icl-dbus.h"
-
-#define ICL_PRESENCE_TTL_SECONDS_MAX (60 * 60 * 24) /* 60 sec/min * 60 min/hr * 24 hr/day */
-
-typedef struct icl_presence {
- char *host_address;
- iotcon_connectivity_type_e connectivity_type;
- char *resource_type;
- iotcon_presence_cb cb;
- void *user_data;
- unsigned int sub_id;
- int64_t handle;
-} icl_presence_s;
-
-
-typedef struct icl_presence_response {
- char *host_address;
- iotcon_connectivity_type_e connectivity_type;
- char *resource_type;
- iotcon_presence_result_e result;
- iotcon_presence_trigger_e trigger;
-} icl_presence_response_s;
-
-
-API int iotcon_start_presence(unsigned int time_to_live)
-{
- FN_CALL;
- int ret;
- GError *error = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(ICL_PRESENCE_TTL_SECONDS_MAX < time_to_live, IOTCON_ERROR_INVALID_PARAMETER);
-
- ic_dbus_call_start_presence_sync(icl_dbus_get_object(), time_to_live, &ret, NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_start_presence_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_stop_presence(void)
-{
- FN_CALL;
- int ret;
- GError *error = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
-
- ic_dbus_call_stop_presence_sync(icl_dbus_get_object(), &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_stop_presence_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icl_presence_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- FN_CALL;
- unsigned int nonce;
- char *host_address, *resource_type;
- int res, connectivity_type, trigger;
- icl_presence_s *presence = user_data;
- iotcon_presence_cb cb = presence->cb;
- icl_presence_response_s response = {0};
-
- g_variant_get(parameters, "(iu&sii&s)", &res, &nonce, &host_address,
- &connectivity_type, &trigger, &resource_type);
-
- response.resource_type = ic_utils_dbus_decode_str(resource_type);
-
- if (response.resource_type && presence->resource_type) {
- if (IC_STR_EQUAL != strcmp(response.resource_type, presence->resource_type))
- return;
- }
-
- if (res < IOTCON_ERROR_NONE && cb)
- cb(presence, icl_dbus_convert_daemon_error(res), NULL, presence->user_data);
-
- DBG("presence nonce : %u", nonce);
-
- response.host_address = host_address;
- response.connectivity_type = connectivity_type;
- response.result = res;
- response.trigger = trigger;
-
- if (cb)
- cb(presence, IOTCON_ERROR_NONE, &response, presence->user_data);
-}
-
-
-static void _icl_presence_conn_cleanup(icl_presence_s *presence)
-{
- presence->sub_id = 0;
-
- if (presence->handle) {
- presence->handle = 0;
- return;
- }
-
- free(presence->resource_type);
- free(presence->host_address);
- free(presence);
-}
-
-
-/* The length of resource_type should be less than or equal to 61. */
-API int iotcon_add_presence_cb(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- const char *resource_type,
- iotcon_presence_cb cb,
- void *user_data,
- iotcon_presence_h *presence_handle)
-{
- FN_CALL;
- int ret;
- unsigned int sub_id;
- GError *error = NULL;
- icl_presence_s *presence;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == presence_handle, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (resource_type && (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
- ERR("The length of resource_type(%s) is invalid", resource_type);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- if ((IOTCON_MULTICAST_ADDRESS == host_address || '\0' == host_address[0])
- && (IOTCON_CONNECTIVITY_IPV4 != connectivity_type
- && IOTCON_CONNECTIVITY_ALL != connectivity_type)) {
- ERR("Multicast is available only if IPV4");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- presence = calloc(1, sizeof(icl_presence_s));
- if (NULL == presence) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- ic_dbus_call_subscribe_presence_sync(icl_dbus_get_object(),
- ic_utils_dbus_encode_str(host_address),
- connectivity_type,
- ic_utils_dbus_encode_str(resource_type),
- &(presence->handle),
- NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_subscribe_presence_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- free(presence);
- return ret;
- }
-
- if (0 == presence->handle) {
- ERR("iotcon-daemon Fail");
- free(presence);
- return IOTCON_ERROR_IOTIVITY;
- }
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_PRESENCE,
- presence->handle);
-
- presence->cb = cb;
- presence->user_data = user_data;
-
- if (host_address)
- presence->host_address = strdup(host_address);
- presence->connectivity_type = connectivity_type;
- if (resource_type)
- presence->resource_type = strdup(resource_type);
-
- sub_id = icl_dbus_subscribe_signal(signal_name, presence,
- _icl_presence_conn_cleanup, _icl_presence_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- free(presence->resource_type);
- free(presence->host_address);
- free(presence);
- return IOTCON_ERROR_DBUS;
- }
-
- presence->sub_id = sub_id;
-
- *presence_handle = presence;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remove_presence_cb(iotcon_presence_h presence)
-{
- FN_CALL;
- int ret;
- GError *error = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 == presence->sub_id) { /* disconnected iotcon dbus */
- WARN("Invalid Presence handle");
- free(presence->resource_type);
- free(presence->host_address);
- free(presence);
- return IOTCON_ERROR_NONE;
- }
-
- if (NULL == icl_dbus_get_object()) {
- ERR("icl_dbus_get_object() return NULL");
- return IOTCON_ERROR_DBUS;
- }
-
- ic_dbus_call_unsubscribe_presence_sync(icl_dbus_get_object(), presence->handle,
- presence->host_address, &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_unsubscribe_presence_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
- presence->handle = 0;
-
- icl_dbus_unsubscribe_signal(presence->sub_id);
- presence->sub_id = 0;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_presence_get_host_address(iotcon_presence_h presence, char **host_address)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
-
- *host_address = presence->host_address;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_presence_get_connectivity_type(iotcon_presence_h presence,
- iotcon_connectivity_type_e *connectivity_type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == connectivity_type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *connectivity_type = presence->connectivity_type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_presence_get_resource_type(iotcon_presence_h presence,
- char **resource_type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == presence, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *resource_type = presence->resource_type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_presence_response_get_host_address(iotcon_presence_response_h response,
- char **host_address)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
-
- *host_address = response->host_address;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_presence_response_get_connectivity_type(
- iotcon_presence_response_h response, iotcon_connectivity_type_e *connectivity_type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == connectivity_type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *connectivity_type = response->connectivity_type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_presence_response_get_resource_type(iotcon_presence_response_h response,
- char **resource_type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *resource_type = response->resource_type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_presence_response_get_result(iotcon_presence_response_h response,
- iotcon_presence_result_e *result)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == result, IOTCON_ERROR_INVALID_PARAMETER);
-
- *result = response->result;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_presence_response_get_trigger(iotcon_presence_response_h response,
- iotcon_presence_trigger_e *trigger)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == trigger, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (IOTCON_PRESENCE_OK != response->result) {
- ERR("trigger is valid if IOTCON_PRESENCE_OK");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- *trigger = response->trigger;
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-resource-types.h"
-#include "icl-query.h"
-
-API int iotcon_query_create(iotcon_query_h *ret_query)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_query, IOTCON_ERROR_INVALID_PARAMETER);
-
- iotcon_query_h query = calloc(1, sizeof(struct icl_query));
- if (NULL == query) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- query->hash = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
-
- *ret_query = query;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_query_destroy(iotcon_query_h query)
-{
- RET_IF(NULL == query);
-
- g_hash_table_unref(query->hash);
- free(query);
-}
-
-
-API int iotcon_query_get_resource_type(iotcon_query_h query,
- char **resource_type)
-{
- char *type;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_type, IOTCON_ERROR_INVALID_PARAMETER);
-
- iotcon_query_lookup(query, ICL_QUERY_KEY_RESOURCE_TYPE, &type);
- if (NULL == type) {
- ERR("resource_type is NULL");
- return IOTCON_ERROR_NO_DATA;
- }
-
- *resource_type = type;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_query_get_interface(iotcon_query_h query, char **resource_iface)
-{
- char *iface = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_iface, IOTCON_ERROR_INVALID_PARAMETER);
-
- iotcon_query_lookup(query, ICL_QUERY_KEY_INTERFACE, &iface);
- if (NULL == iface) {
- ERR("iface is NULL");
- return IOTCON_ERROR_NO_DATA;
- }
-
- *resource_iface = iface;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_query_set_resource_type(iotcon_query_h query, const char *resource_type)
-{
- int length_old = 0;
- int length_new = 0;
- char *value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(query->hash, ICL_QUERY_KEY_RESOURCE_TYPE);
- if (value)
- length_old = (sizeof(ICL_QUERY_KEY_RESOURCE_TYPE) - 1) + strlen(value) + 2;
-
- if (resource_type && *resource_type)
- length_new = (sizeof(ICL_QUERY_KEY_RESOURCE_TYPE) - 1) + strlen(resource_type) + 2;
-
- if (ICL_QUERY_LENGTH_MAX < query->len - length_old + length_new) {
- ERR("Length of query is invalid.");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- if (value)
- iotcon_query_remove(query, ICL_QUERY_KEY_RESOURCE_TYPE);
-
- if (resource_type)
- iotcon_query_add(query, ICL_QUERY_KEY_RESOURCE_TYPE, resource_type);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_query_set_interface(iotcon_query_h query, const char *resource_iface)
-{
- int length_old = 0;
- int length_new = 0;
- char *value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(query->hash, ICL_QUERY_KEY_INTERFACE);
- if (value)
- length_old = (sizeof(ICL_QUERY_KEY_INTERFACE) - 1) + strlen(value) + 2;
-
- if (resource_iface && *resource_iface)
- length_new = (sizeof(ICL_QUERY_KEY_INTERFACE) - 1) + strlen(resource_iface) + 2;
-
- if (ICL_QUERY_LENGTH_MAX < query->len - length_old + length_new) {
- ERR("Length of query is invalid.");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- if (value)
- iotcon_query_remove(query, ICL_QUERY_KEY_INTERFACE);
-
- iotcon_query_add(query, ICL_QUERY_KEY_INTERFACE, resource_iface);
-
- return IOTCON_ERROR_NONE;
-}
-
-/* The full length of query should be less than or equal to 64. */
-API int iotcon_query_add(iotcon_query_h query, const char *key, const char *value)
-{
- int query_len;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
-
- /* first query : ?key=value
- * Rest of query : ;key=value */
- query_len = strlen(key) + strlen(value) + 2;
- if (ICL_QUERY_LENGTH_MAX < (query->len + query_len)) {
- ERR("Length of query is invalid.");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_insert(query->hash, ic_utils_strdup(key), ic_utils_strdup(value));
- query->len += query_len;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_query_remove(iotcon_query_h query, const char *key)
-{
- gboolean is_removed;
- int query_len;
- char *value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(query->hash, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- query_len = strlen(key) + strlen(value) + 2;
-
- is_removed = g_hash_table_remove(query->hash, key);
- if (FALSE == is_removed) {
- ERR("g_hash_table_remove() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- query->len -= query_len;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_query_lookup(iotcon_query_h query, const char *key, char **data)
-{
- char *value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == data, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(query->hash, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- *data = value;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
- void *user_data)
-{
- GHashTableIter iter;
- gpointer key, value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_hash_table_iter_init(&iter, query->hash);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- if (IOTCON_FUNC_STOP == cb(key, value, user_data))
- break;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_QUERY_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_QUERY_H__
-
-#include <glib.h>
-#include "iotcon-types.h"
-
-/**
- * @brief The maximum length which can be held in a query.
- *
- * @since_tizen 3.0
- */
-#define ICL_QUERY_LENGTH_MAX 64
-
-#define ICL_QUERY_KEY_RESOURCE_TYPE "rt"
-#define ICL_QUERY_KEY_INTERFACE "if"
-
-struct icl_query {
- int len;
- GHashTable *hash;
-};
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_QUERY_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "iotcon-internal.h"
-#include "ic-dbus.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-dbus.h"
-#include "icl-dbus-type.h"
-#include "icl-representation.h"
-#include "icl-list.h"
-#include "icl-value.h"
-#include "icl-payload.h"
-#include "icl-remote-resource.h"
-
-typedef struct {
- iotcon_remote_resource_cached_representation_changed_cb cb;
- void *user_data;
- iotcon_remote_resource_h resource;
-} icl_caching_s;
-
-
-static void _icl_caching_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- FN_CALL;
- int ret;
- iotcon_representation_h repr, cached_repr;
- icl_caching_s *cb_container = user_data;
- iotcon_remote_resource_cached_representation_changed_cb cb = cb_container->cb;
-
- repr = icl_representation_from_gvariant(parameters);
-
- ret = iotcon_representation_clone(repr, &cached_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_clone() Fail(%d)", ret);
- return;
- }
-
- if (cb_container->resource->cached_repr)
- iotcon_representation_destroy(cb_container->resource->cached_repr);
- cb_container->resource->cached_repr = cached_repr;
-
- if (cb) {
- cb(cb_container->resource, cb_container->resource->cached_repr,
- cb_container->user_data);
- }
-}
-
-
-static void _icl_caching_conn_cleanup(icl_caching_s *cb_container)
-{
- if (cb_container->resource->cached_repr) {
- iotcon_representation_destroy(cb_container->resource->cached_repr);
- cb_container->resource->cached_repr = NULL;
- }
- cb_container->resource->caching_sub_id = 0;
- icl_remote_resource_unref(cb_container->resource);
- free(cb_container);
-}
-
-
-API int iotcon_remote_resource_start_caching(iotcon_remote_resource_h resource,
- iotcon_remote_resource_cached_representation_changed_cb cb, void *user_data)
-{
- int ret, sub_id;
- GError *error = NULL;
- int64_t signal_number;
- icl_caching_s *cb_container;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 != resource->caching_sub_id) {
- ERR("Already Start Caching");
- return IOTCON_ERROR_ALREADY;
- }
-
- INFO("Start Caching");
-
- ic_dbus_call_start_caching_sync(icl_dbus_get_object(),
- resource->uri_path,
- resource->host_address,
- resource->connectivity_type,
- &signal_number,
- &ret,
- NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_start_caching_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return IOTCON_ERROR_DBUS;
- }
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_CACHING,
- signal_number);
-
- cb_container = calloc(1, sizeof(icl_caching_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container,
- _icl_caching_conn_cleanup, _icl_caching_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- free(cb_container);
- return IOTCON_ERROR_DBUS;
- }
- resource->caching_sub_id = sub_id;
- cb_container->resource = resource;
- icl_remote_resource_ref(resource);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remote_resource_stop_caching(iotcon_remote_resource_h resource)
-{
- int ret;
- GError *error = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 == resource->caching_sub_id) {
- ERR("Not Cached");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- INFO("Stop Caching");
-
- ic_dbus_call_stop_caching_sync(icl_dbus_get_object(),
- resource->uri_path,
- resource->host_address,
- &ret,
- NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_stop_caching_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_dbus_error(ret);
- }
-
- icl_dbus_unsubscribe_signal(resource->caching_sub_id);
- resource->caching_sub_id = 0;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remote_resource_get_cached_representation(
- iotcon_remote_resource_h resource,
- iotcon_representation_h *representation)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == representation, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (NULL == resource->cached_repr) {
- ERR("No Caching Representation");
- return IOTCON_ERROR_NO_DATA;
- }
-
- *representation = resource->cached_repr;
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "ic-dbus.h"
-#include "icl.h"
-#include "icl-options.h"
-#include "icl-dbus.h"
-#include "icl-dbus-type.h"
-#include "icl-representation.h"
-#include "icl-response.h"
-#include "icl-remote-resource.h"
-#include "icl-payload.h"
-
-typedef struct {
- iotcon_remote_resource_response_cb cb;
- void *user_data;
- iotcon_remote_resource_h resource;
-} icl_on_response_s;
-
-typedef struct {
- iotcon_remote_resource_observe_cb cb;
- void *user_data;
- iotcon_remote_resource_h resource;
-} icl_on_observe_s;
-
-static GList *icl_crud_cb_list = NULL;
-
-void icl_remote_resource_crud_stop(iotcon_remote_resource_h resource)
-{
- GList *c;
- for (c = icl_crud_cb_list; c; c = c->next) {
- icl_on_response_s *cb_container = c->data;
- if (NULL == cb_container) {
- ERR("cb_container is NULL");
- continue;
- }
- if (cb_container->resource == resource)
- cb_container->cb = NULL;
- }
-}
-
-static iotcon_options_h _icl_parse_options_iter(GVariantIter *iter)
-{
- int ret;
- iotcon_options_h options = NULL;
-
- if (NULL == iter)
- return NULL;
-
- if (g_variant_iter_n_children(iter)) {
- unsigned short option_id;
- char *option_data;
-
- ret = iotcon_options_create(&options);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_options_create() Fail(%d)", ret);
- return NULL;
- }
- while (g_variant_iter_loop(iter, "(q&s)", &option_id, &option_data))
- iotcon_options_add(options, option_id, option_data);
- }
- return options;
-}
-
-static int _icl_parse_crud_gvariant(iotcon_request_type_e request_type,
- GVariant *gvar, iotcon_response_h *response)
-{
- int res;
- GVariantIter *options_iter = NULL;
- GVariant *repr_gvar = NULL;
- iotcon_response_h resp = NULL;
- iotcon_options_h options = NULL;
- iotcon_representation_h repr = NULL;
-
- if (IOTCON_REQUEST_DELETE == request_type)
- g_variant_get(gvar, "(a(qs)i)", &options_iter, &res);
- else
- g_variant_get(gvar, "(a(qs)vi)", &options_iter, &repr_gvar, &res);
-
- if (options_iter) {
- options = _icl_parse_options_iter(options_iter);
- g_variant_iter_free(options_iter);
- }
-
- if (repr_gvar) {
- repr = icl_representation_from_gvariant(repr_gvar);
- if (NULL == repr) {
- ERR("icl_representation_from_gvariant() Fail");
- if (options)
- iotcon_options_destroy(options);
- return IOTCON_ERROR_SYSTEM;
- }
- }
-
- res = icl_dbus_convert_daemon_error(res);
-
- resp = calloc(1, sizeof(struct icl_resource_response));
- if (NULL == resp) {
- ERR("calloc() Fail(%d)", errno);
- if (repr)
- iotcon_representation_destroy(repr);
- if (options)
- iotcon_options_destroy(options);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- resp->result = res;
- resp->repr = repr;
- resp->header_options = options;
-
- *response = resp;
-
- return IOTCON_ERROR_NONE;
-}
-
-static void _icl_on_crud_cb(iotcon_request_type_e request_type,
- GObject *object, GAsyncResult *g_async_res, icl_on_response_s *cb_container)
-{
- int ret;
- iotcon_response_h response = NULL;
- GVariant *result;
- GError *error = NULL;
-
- RET_IF(NULL == cb_container);
-
- icl_crud_cb_list = g_list_remove(icl_crud_cb_list, cb_container);
-
- switch (request_type) {
- case IOTCON_REQUEST_GET:
- ic_dbus_call_get_finish(IC_DBUS(object), &result, g_async_res, &error);
- break;
- case IOTCON_REQUEST_PUT:
- ic_dbus_call_put_finish(IC_DBUS(object), &result, g_async_res, &error);
- break;
- case IOTCON_REQUEST_POST:
- ic_dbus_call_post_finish(IC_DBUS(object), &result, g_async_res, &error);
- break;
- case IOTCON_REQUEST_DELETE:
- ic_dbus_call_delete_finish(IC_DBUS(object), &result, g_async_res, &error);
- break;
- default:
- ERR("Invalid type(%d)", request_type);
- return;
- }
-
- if (error) {
- ERR("ic_dbus_call_finish() Fail(%d, %s)", request_type, error->message);
- if (cb_container->cb) {
- int ret = icl_dbus_convert_dbus_error(error->code);
- cb_container->cb(cb_container->resource, ret, request_type, NULL,
- cb_container->user_data);
- }
- g_error_free(error);
- free(cb_container);
- return;
- }
-
- ret = _icl_parse_crud_gvariant(request_type, result, &response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_parse_crud_gvariant() Fail(%s)", ret);
- if (cb_container->cb) {
- cb_container->cb(cb_container->resource, ret, request_type, NULL,
- cb_container->user_data);
- }
- free(cb_container);
- return;
- }
- if (cb_container->cb)
- cb_container->cb(cb_container->resource, IOTCON_ERROR_NONE, request_type,
- response, cb_container->user_data);
-
- if (response)
- iotcon_response_destroy(response);
-
- free(cb_container);
-}
-
-
-static void _icl_on_get_cb(GObject *object, GAsyncResult *g_async_res,
- gpointer user_data)
-{
- _icl_on_crud_cb(IOTCON_REQUEST_GET, object, g_async_res, user_data);
-}
-
-
-static void _icl_on_put_cb(GObject *object, GAsyncResult *g_async_res,
- gpointer user_data)
-{
- _icl_on_crud_cb(IOTCON_REQUEST_PUT, object, g_async_res, user_data);
-}
-
-
-static void _icl_on_post_cb(GObject *object, GAsyncResult *g_async_res,
- gpointer user_data)
-{
- _icl_on_crud_cb(IOTCON_REQUEST_POST, object, g_async_res, user_data);
-}
-
-
-API int iotcon_remote_resource_get(iotcon_remote_resource_h resource,
- iotcon_query_h query, iotcon_remote_resource_response_cb cb, void *user_data)
-{
- GVariant *arg_query;
- GVariant *arg_remote_resource;
- icl_on_response_s *cb_container;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cb_container = calloc(1, sizeof(icl_on_response_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->resource = resource;
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
- arg_query = icl_dbus_query_to_gvariant(query);
-
- ic_dbus_call_get(icl_dbus_get_object(), arg_remote_resource, arg_query, NULL,
- _icl_on_get_cb, cb_container);
-
- icl_crud_cb_list = g_list_append(icl_crud_cb_list, cb_container);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remote_resource_put(iotcon_remote_resource_h resource,
- iotcon_representation_h repr,
- iotcon_query_h query,
- iotcon_remote_resource_response_cb cb,
- void *user_data)
-{
- GVariant *arg_repr;
- GVariant *arg_remote_resource;
- GVariant *arg_query;
- icl_on_response_s *cb_container;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cb_container = calloc(1, sizeof(icl_on_response_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->resource = resource;
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- arg_repr = icl_representation_to_gvariant(repr);
- if (NULL == arg_repr) {
- ERR("icl_representation_to_gvariant() Fail");
- free(cb_container);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
- arg_query = icl_dbus_query_to_gvariant(query);
-
- ic_dbus_call_put(icl_dbus_get_object(), arg_remote_resource, arg_repr, arg_query,
- NULL, _icl_on_put_cb, cb_container);
-
- icl_crud_cb_list = g_list_append(icl_crud_cb_list, cb_container);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remote_resource_post(iotcon_remote_resource_h resource,
- iotcon_representation_h repr,
- iotcon_query_h query,
- iotcon_remote_resource_response_cb cb,
- void *user_data)
-{
- GVariant *arg_repr;
- GVariant *arg_query;
- GVariant *arg_remote_resource;
- icl_on_response_s *cb_container;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cb_container = calloc(1, sizeof(icl_on_response_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->resource = resource;
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- arg_repr = icl_representation_to_gvariant(repr);
- if (NULL == arg_repr) {
- ERR("icl_representation_to_gvariant() Fail");
- free(cb_container);
- return IOTCON_ERROR_REPRESENTATION;
- }
-
- arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
- arg_query = icl_dbus_query_to_gvariant(query);
-
- ic_dbus_call_post(icl_dbus_get_object(), arg_remote_resource, arg_repr, arg_query,
- NULL, _icl_on_post_cb, cb_container);
-
- icl_crud_cb_list = g_list_append(icl_crud_cb_list, cb_container);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static void _icl_on_delete_cb(GObject *object, GAsyncResult *g_async_res,
- gpointer user_data)
-{
- _icl_on_crud_cb(IOTCON_REQUEST_DELETE, object, g_async_res, user_data);
-}
-
-
-API int iotcon_remote_resource_delete(iotcon_remote_resource_h resource,
- iotcon_remote_resource_response_cb cb, void *user_data)
-{
- GVariant *arg_remote_resource;
- icl_on_response_s *cb_container;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- cb_container = calloc(1, sizeof(icl_on_response_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->resource = resource;
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
-
- ic_dbus_call_delete(icl_dbus_get_object(), arg_remote_resource, NULL,
- _icl_on_delete_cb, cb_container);
-
- icl_crud_cb_list = g_list_append(icl_crud_cb_list, cb_container);
-
- return IOTCON_ERROR_NONE;
-}
-
-static void _icl_on_observe_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- int res;
- int seq_number = -1;
- GVariantIter *options_iter = NULL;
- GVariant *repr_gvar = NULL;
- iotcon_response_h response = NULL;
- icl_on_observe_s *cb_container = user_data;
- iotcon_options_h options = NULL;
- iotcon_representation_h repr = NULL;
-
- RET_IF(NULL == cb_container);
-
- g_variant_get(parameters, "(a(qs)vii)", &options_iter, &repr_gvar, &res, &seq_number);
-
- if (options_iter) {
- options = _icl_parse_options_iter(options_iter);
- g_variant_iter_free(options_iter);
- }
-
- if (repr_gvar) {
- repr = icl_representation_from_gvariant(repr_gvar);
- if (NULL == repr) {
- ERR("icl_representation_from_gvariant() Fail");
- if (options)
- iotcon_options_destroy(options);
-
- if (cb_container->cb)
- cb_container->cb(cb_container->resource, IOTCON_ERROR_SYSTEM, -1,
- NULL, cb_container->user_data);
- return;
- }
- }
-
- res = icl_dbus_convert_daemon_error(res);
-
- response = calloc(1, sizeof(struct icl_resource_response));
- if (NULL == response) {
- ERR("calloc() Fail(%d)", errno);
- if (repr)
- iotcon_representation_destroy(repr);
- if (options)
- iotcon_options_destroy(options);
-
- if (cb_container->cb)
- cb_container->cb(cb_container->resource, IOTCON_ERROR_OUT_OF_MEMORY, -1,
- NULL, cb_container->user_data);
- return;
- }
- response->result = res;
- response->repr = repr;
- response->header_options = options;
-
- if (cb_container->cb)
- cb_container->cb(cb_container->resource, IOTCON_ERROR_NONE, seq_number,
- response, cb_container->user_data);
-
- if (response)
- iotcon_response_destroy(response);
-}
-
-
-static void _icl_observe_conn_cleanup(icl_on_observe_s *cb_container)
-{
- cb_container->resource->observe_handle = 0;
- cb_container->resource->observe_sub_id = 0;
- icl_remote_resource_unref(cb_container->resource);
- free(cb_container);
-}
-
-
-API int iotcon_remote_resource_observe_register(iotcon_remote_resource_h resource,
- iotcon_observe_policy_e observe_policy,
- iotcon_query_h query,
- iotcon_remote_resource_observe_cb cb,
- void *user_data)
-{
- int ret;
- unsigned int sub_id;
- GError *error = NULL;
- int64_t signal_number;
- int64_t observe_handle;
- icl_on_observe_s *cb_container;
- GVariant *arg_query, *arg_remote_resource;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(resource->observe_handle || resource->observe_sub_id, IOTCON_ERROR_ALREADY);
-
- arg_remote_resource = icl_dbus_remote_resource_to_gvariant(resource);
- arg_query = icl_dbus_query_to_gvariant(query);
-
- cb_container = calloc(1, sizeof(icl_on_observe_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- g_variant_unref(arg_query);
- g_variant_unref(arg_remote_resource);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->resource = resource;
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- ic_dbus_call_observer_start_sync(icl_dbus_get_object(), arg_remote_resource,
- observe_policy, arg_query, &signal_number, &observe_handle, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_observer_start_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- g_variant_unref(arg_query);
- g_variant_unref(arg_remote_resource);
- free(cb_container);
- return ret;
- }
- if (0 == observe_handle) {
- ERR("iotcon-daemon Fail");
- free(cb_container);
- return IOTCON_ERROR_IOTIVITY;
- }
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_OBSERVE,
- signal_number);
-
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container,
- _icl_observe_conn_cleanup, _icl_on_observe_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- free(cb_container);
- return IOTCON_ERROR_DBUS;
- }
-
- resource->observe_sub_id = sub_id;
- resource->observe_handle = observe_handle;
- icl_remote_resource_ref(resource);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remote_resource_observe_deregister(iotcon_remote_resource_h resource)
-{
- int ret;
- GError *error = NULL;
- GVariant *arg_options;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- if (0 == resource->observe_handle) {
- ERR("It doesn't have a observe_handle");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- arg_options = icl_dbus_options_to_gvariant(resource->header_options);
-
- ic_dbus_call_observer_stop_sync(icl_dbus_get_object(), resource->observe_handle,
- arg_options, &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_observer_stop_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
- resource->observe_handle = 0;
-
- icl_dbus_unsubscribe_signal(resource->observe_sub_id);
- resource->observe_sub_id = 0;
-
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "iotcon-internal.h"
-#include "icl.h"
-#include "icl-dbus.h"
-#include "ic-utils.h"
-#include "icl-remote-resource.h"
-
-typedef struct {
- iotcon_remote_resource_state_changed_cb cb;
- void *user_data;
- iotcon_remote_resource_h resource;
-} icl_monitoring_s;
-
-static void _icl_monitoring_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- FN_CALL;
- icl_monitoring_s *cb_container = user_data;
- iotcon_remote_resource_state_e resource_state;
- iotcon_remote_resource_state_changed_cb cb = cb_container->cb;
-
- g_variant_get(parameters, "(i)", &resource_state);
-
- if (cb)
- cb(cb_container->resource, resource_state, cb_container->user_data);
-
-}
-
-
-static void _icl_monitoring_conn_cleanup(icl_monitoring_s *cb_container)
-{
- cb_container->resource->monitoring_sub_id = 0;
- icl_remote_resource_unref(cb_container->resource);
- free(cb_container);
-}
-
-
-API int iotcon_remote_resource_start_monitoring(iotcon_remote_resource_h resource,
- iotcon_remote_resource_state_changed_cb cb, void *user_data)
-{
- int ret, sub_id;
- GError *error = NULL;
- int64_t signal_number;
- icl_monitoring_s *cb_container;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 != resource->monitoring_sub_id) {
- ERR("Already Start Monitoring");
- return IOTCON_ERROR_ALREADY;
- }
-
- INFO("Start Monitoring");
-
- ic_dbus_call_start_monitoring_sync(icl_dbus_get_object(),
- resource->uri_path,
- resource->host_address,
- resource->connectivity_type,
- &signal_number,
- &ret,
- NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_start_monitoring_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return IOTCON_ERROR_DBUS;
- }
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_MONITORING,
- signal_number);
-
- cb_container = calloc(1, sizeof(icl_monitoring_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container,
- _icl_monitoring_conn_cleanup, _icl_monitoring_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- free(cb_container);
- return IOTCON_ERROR_DBUS;
- }
- resource->monitoring_sub_id = sub_id;
- cb_container->resource = resource;
- icl_remote_resource_ref(resource);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remote_resource_stop_monitoring(iotcon_remote_resource_h resource)
-{
- int ret;
- GError *error = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 == resource->monitoring_sub_id) {
- ERR("Not Monitoring");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- INFO("Stop Monitoring");
-
- ic_dbus_call_stop_monitoring_sync(icl_dbus_get_object(),
- resource->uri_path,
- resource->host_address,
- &ret,
- NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_stop_monitoring_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- icl_dbus_unsubscribe_signal(resource->monitoring_sub_id);
- resource->monitoring_sub_id = 0;
-
- return IOTCON_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-options.h"
-#include "icl-dbus.h"
-#include "icl-representation.h"
-#include "icl-remote-resource.h"
-#include "icl-resource-types.h"
-#include "icl-resource-interfaces.h"
-#include "icl-payload.h"
-
-#define ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL 3600 /* 60 min */
-
-typedef struct {
- bool found;
- iotcon_found_resource_cb cb;
- void *user_data;
- unsigned int id;
- int timeout_id;
-} icl_found_resource_s;
-
-static iotcon_remote_resource_h _icl_remote_resource_from_gvariant(GVariant *payload,
- iotcon_connectivity_type_e connectivity_type);
-
-static void _icl_found_resource_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- FN_CALL;
- int connectivity_type;
- iotcon_remote_resource_h resource;
-
- GVariant *payload;
- icl_found_resource_s *cb_container = user_data;
- iotcon_found_resource_cb cb = cb_container->cb;
-
- cb_container->found = true;
-
- g_variant_get(parameters, "(vi)", &payload, &connectivity_type);
-
- resource = _icl_remote_resource_from_gvariant(payload, connectivity_type);
- if (NULL == resource) {
- ERR("icl_remote_resource_from_gvariant() Fail");
- return;
- }
-
- if (cb)
- cb(resource, IOTCON_ERROR_NONE, cb_container->user_data);
-
- iotcon_remote_resource_destroy(resource);
-}
-
-static gboolean _icl_timeout_find_resource(gpointer p)
-{
- icl_found_resource_s *cb_container = p;
-
- if (NULL == cb_container) {
- ERR("cb_container is NULL");
- return G_SOURCE_REMOVE;
- }
-
- if (false == cb_container->found && cb_container->cb)
- cb_container->cb(NULL, IOTCON_ERROR_TIMEOUT, cb_container->user_data);
- cb_container->timeout_id = 0;
-
- icl_dbus_unsubscribe_signal(cb_container->id);
- cb_container->id = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-static void _icl_find_resource_conn_cleanup(icl_found_resource_s *cb_container)
-{
- RET_IF(NULL == cb_container);
- if (cb_container->timeout_id)
- g_source_remove(cb_container->timeout_id);
- free(cb_container);
-}
-
-
-/* The length of resource_type should be less than or equal to 61.
- * If resource_type is NULL, then All resources in host are discovered. */
-API int iotcon_find_resource(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- const char *resource_type,
- bool is_secure,
- iotcon_found_resource_cb cb,
- void *user_data)
-{
- int ret, timeout;
- unsigned int sub_id;
- GError *error = NULL;
- int64_t signal_number;
- icl_found_resource_s *cb_container;
- char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- if (resource_type && (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(resource_type))) {
- ERR("The length of resource_type(%s) is invalid", resource_type);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- timeout = icl_dbus_get_timeout();
-
- ic_dbus_call_find_resource_sync(icl_dbus_get_object(),
- ic_utils_dbus_encode_str(host_address),
- connectivity_type,
- ic_utils_dbus_encode_str(resource_type),
- is_secure,
- timeout,
- &signal_number,
- &ret,
- NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_find_resource_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_FOUND_RESOURCE,
- signal_number);
-
- cb_container = calloc(1, sizeof(icl_found_resource_s));
- if (NULL == cb_container) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- cb_container->cb = cb;
- cb_container->user_data = user_data;
-
- sub_id = icl_dbus_subscribe_signal(signal_name, cb_container,
- _icl_find_resource_conn_cleanup, _icl_found_resource_cb);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- return IOTCON_ERROR_DBUS;
- }
-
- cb_container->id = sub_id;
-
- cb_container->timeout_id = g_timeout_add_seconds(timeout, _icl_timeout_find_resource,
- cb_container);
-
- return ret;
-}
-
-/* If you know the information of resource, then you can make a proxy of the resource. */
-API int iotcon_remote_resource_create(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- const char *uri_path,
- int properties,
- iotcon_resource_types_h resource_types,
- iotcon_resource_interfaces_h resource_ifaces,
- iotcon_remote_resource_h *resource_handle)
-{
- FN_CALL;
- iotcon_remote_resource_h resource = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_types, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_ifaces, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
-
- resource = calloc(1, sizeof(struct icl_remote_resource));
- if (NULL == resource) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- resource->host_address = ic_utils_strdup(host_address);
- resource->connectivity_type = connectivity_type;
- resource->uri_path = ic_utils_strdup(uri_path);
- resource->properties = properties;
- resource->types = icl_resource_types_ref(resource_types);
- resource->ifaces = icl_resource_interfaces_ref(resource_ifaces);
- resource->ref_count = 1;
-
- *resource_handle = resource;
-
- return IOTCON_ERROR_NONE;
-}
-
-static void _icl_remote_resource_destroy(iotcon_remote_resource_h resource)
-{
- RET_IF(NULL == resource);
- if (resource->ref_count < 0)
- ERR("Invalid ref_count (%d)", resource->ref_count);
- free(resource->uri_path);
- free(resource->host_address);
- free(resource->device_id);
- iotcon_resource_interfaces_destroy(resource->ifaces);
- iotcon_resource_types_destroy(resource->types);
-
- /* null COULD be allowed */
- if (resource->header_options)
- iotcon_options_destroy(resource->header_options);
-
- free(resource);
-}
-
-void icl_remote_resource_ref(iotcon_remote_resource_h resource)
-{
- RET_IF(NULL == resource);
- resource->ref_count++;
-}
-
-void icl_remote_resource_unref(iotcon_remote_resource_h resource)
-{
- RET_IF(NULL == resource);
- resource->ref_count--;
- if (0 == resource->ref_count)
- _icl_remote_resource_destroy(resource);
-}
-
-
-API void iotcon_remote_resource_destroy(iotcon_remote_resource_h resource)
-{
- RET_IF(NULL == resource);
-
- if (resource->observe_handle)
- iotcon_remote_resource_observe_deregister(resource);
- icl_remote_resource_crud_stop(resource);
- if (0 != resource->caching_sub_id)
- iotcon_remote_resource_stop_caching(resource);
- if (0 != resource->monitoring_sub_id)
- iotcon_remote_resource_stop_monitoring(resource);
-
- icl_remote_resource_unref(resource);
-}
-
-static bool _icl_remote_resource_header_foreach_cb(unsigned short id,
- const char *data, void *user_data)
-{
- int ret;
- iotcon_remote_resource_h resource = user_data;
-
- RETV_IF(NULL == resource, IOTCON_FUNC_STOP);
-
- if (NULL == resource->header_options) {
- ret = iotcon_options_create(&resource->header_options);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("resource->header_options() Fail(%d)", ret);
- return IOTCON_FUNC_STOP;
- }
- }
-
- ret = iotcon_options_add(resource->header_options, id, data);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_options_add() Fail(%d)", ret);
- return IOTCON_FUNC_STOP;
- }
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-API int iotcon_remote_resource_clone(iotcon_remote_resource_h src,
- iotcon_remote_resource_h *dest)
-{
- int ret;
- iotcon_remote_resource_h resource = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- resource = calloc(1, sizeof(struct icl_remote_resource));
- if (NULL == resource) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- resource->uri_path = ic_utils_strdup(src->uri_path);
- resource->host_address = ic_utils_strdup(src->host_address);
- resource->connectivity_type = src->connectivity_type;
- resource->device_id = ic_utils_strdup(src->device_id);
- resource->properties = src->properties;
- resource->ref_count = 1;
-
- if (src->header_options) {
- ret = iotcon_options_foreach(src->header_options,
- _icl_remote_resource_header_foreach_cb, resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_options_foreach() Fail(%d)", ret);
- iotcon_remote_resource_destroy(resource);
- return ret;
- }
- }
-
- ret = iotcon_resource_types_clone(src->types, &resource->types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_clone() Fail(%d)", ret);
- iotcon_remote_resource_destroy(resource);
- return ret;
- }
-
- ret = iotcon_resource_interfaces_clone(src->ifaces, &resource->ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_clone() Fail(%d)", ret);
- iotcon_remote_resource_destroy(resource);
- return ret;
- }
-
- resource->connectivity_type = src->connectivity_type;
-
- *dest = resource;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_remote_resource_get_uri_path(iotcon_remote_resource_h resource,
- char **uri_path)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
-
- *uri_path = resource->uri_path;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_remote_resource_get_host_address(iotcon_remote_resource_h resource,
- char **host_address)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
-
- *host_address = resource->host_address;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_remote_resource_get_connectivity_type(iotcon_remote_resource_h resource,
- iotcon_connectivity_type_e *connectivity_type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == connectivity_type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *connectivity_type = resource->connectivity_type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_remote_resource_get_device_id(iotcon_remote_resource_h resource,
- char **device_id)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == device_id, IOTCON_ERROR_INVALID_PARAMETER);
-
- *device_id = resource->device_id;
-
- return IOTCON_ERROR_NONE;
-}
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource,
- iotcon_resource_types_h *types)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
-
- *types = resource->types;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource,
- iotcon_resource_interfaces_h *ifaces)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
-
- *ifaces = resource->ifaces;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remote_resource_get_properties(iotcon_remote_resource_h resource,
- int *properties)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == properties, IOTCON_ERROR_INVALID_PARAMETER);
-
- *properties = resource->properties;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_remote_resource_get_options(iotcon_remote_resource_h resource,
- iotcon_options_h *options)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
-
- *options = resource->header_options;
-
- return IOTCON_ERROR_NONE;
-}
-
-/* if header_options is NULL, then client's header_options is unset */
-API int iotcon_remote_resource_set_options(iotcon_remote_resource_h resource,
- iotcon_options_h options)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (options)
- options = icl_options_ref(options);
-
- if (resource->header_options)
- iotcon_options_destroy(resource->header_options);
-
- resource->header_options = options;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-static iotcon_remote_resource_h _icl_remote_resource_from_gvariant(GVariant *payload,
- iotcon_connectivity_type_e connectivity_type)
-{
- int ret;
- iotcon_remote_resource_h resource;
- GVariantIter *types_iter, *ifaces_iter;
- char host_addr[PATH_MAX] = {0};
- iotcon_resource_types_h res_types;
- iotcon_resource_interfaces_h ifaces;
- char *uri_path, *device_id, *res_type, *iface, *addr;
- int properties, is_secure, port;
-
- g_variant_get(payload, "(&s&sasasib&si)", &uri_path, &device_id, &ifaces_iter,
- &types_iter, &properties, &is_secure, &addr, &port);
-
- switch (connectivity_type) {
- case IOTCON_CONNECTIVITY_IPV6:
- snprintf(host_addr, sizeof(host_addr), "[%s]:%d", addr, port);
- break;
- case IOTCON_CONNECTIVITY_IPV4:
- snprintf(host_addr, sizeof(host_addr), "%s:%d", addr, port);
- break;
- case IOTCON_CONNECTIVITY_BT_EDR:
- default:
- snprintf(host_addr, sizeof(host_addr), "%s", addr);
- }
-
- ret = iotcon_resource_types_create(&res_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_create() Fail(%d)", ret);
- return NULL;
- }
-
- while (g_variant_iter_loop(types_iter, "s", &res_type))
- iotcon_resource_types_add(res_types, res_type);
-
- ret = iotcon_resource_interfaces_create(&ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
- iotcon_resource_types_destroy(res_types);
- return NULL;
- }
-
- while (g_variant_iter_loop(ifaces_iter, "s", &iface))
- iotcon_resource_interfaces_add(ifaces, iface);
-
- ret = iotcon_remote_resource_create(host_addr, connectivity_type, uri_path,
- properties, res_types, ifaces, &resource);
-
- iotcon_resource_interfaces_destroy(ifaces);
- iotcon_resource_types_destroy(res_types);
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_create() Fail");
- return NULL;
- }
-
- resource->device_id = strdup(device_id);
- if (NULL == resource->device_id) {
- ERR("strdup(device_id) Fail(%d)", errno);
- iotcon_remote_resource_destroy(resource);
- return NULL;
- }
- resource->connectivity_type = connectivity_type;
- resource->properties = properties;
-
- return resource;
-}
-
-
-API int iotcon_remote_resource_get_time_interval(int *time_interval)
-{
- GError *error = NULL;
- int ret, arg_time_interval;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == time_interval, IOTCON_ERROR_INVALID_PARAMETER);
-
- ic_dbus_call_encap_get_time_interval_sync(icl_dbus_get_object(), &arg_time_interval,
- NULL, &error);
- if (error) {
- ERR("ic_dbus_call_encap_get_time_interval_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- *time_interval = arg_time_interval;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_remote_resource_set_time_interval(int time_interval)
-{
- int ret;
- GError *error = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(ICL_REMOTE_RESOURCE_MAX_TIME_INTERVAL < time_interval || time_interval <= 0,
- IOTCON_ERROR_INVALID_PARAMETER);
-
- ic_dbus_call_encap_set_time_interval_sync(icl_dbus_get_object(), time_interval,
- NULL, &error);
- if (error) {
- ERR("ic_dbus_call_encap_set_time_interval_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__
-
-#include <stdint.h>
-#include <gio/gio.h>
-
-#include "iotcon-types.h"
-#include "iotcon-remote-resource.h"
-
-#include "icl-options.h"
-
-typedef enum {
- ICL_DEVICE_STATE_ALIVE,
- ICL_DEVICE_STATE_LOST_SIGNAL,
-} icl_remote_resource_device_state_e;
-
-struct icl_remote_resource {
- int ref_count;
- char *uri_path;
- char *host_address;
- char *device_id;
- int properties;
- iotcon_options_h header_options;
- iotcon_resource_types_h types;
- iotcon_resource_interfaces_h ifaces;
- iotcon_connectivity_type_e connectivity_type;
- int64_t observe_handle;
- unsigned int observe_sub_id;
- unsigned int monitoring_sub_id;
- unsigned int caching_sub_id;
- iotcon_representation_h cached_repr;
-};
-
-void icl_remote_resource_ref(iotcon_remote_resource_h resource);
-void icl_remote_resource_unref(iotcon_remote_resource_h resource);
-void icl_remote_resource_crud_stop(iotcon_remote_resource_h resource);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_CLIENT_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-resource.h"
-#include "icl-resource-types.h"
-#include "icl-resource-interfaces.h"
-#include "icl-response.h"
-#include "icl-list.h"
-#include "icl-value.h"
-#include "icl-state.h"
-#include "icl-representation.h"
-
-iotcon_representation_h icl_representation_ref(iotcon_representation_h repr)
-{
- RETV_IF(NULL == repr, NULL);
- RETV_IF(repr->ref_count <= 0, NULL);
-
- repr->ref_count++;
-
- return repr;
-}
-
-
-API int iotcon_representation_create(iotcon_representation_h *ret_repr)
-{
- errno = 0;
- iotcon_representation_h repr;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- repr = calloc(1, sizeof(struct icl_representation_s));
- if (NULL == repr) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- repr->visibility = (ICL_VISIBILITY_REPR | ICL_VISIBILITY_PROP);
- repr->ref_count = 1;
-
- *ret_repr = repr;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_representation_destroy(iotcon_representation_h repr)
-{
- RET_IF(NULL == repr);
-
- repr->ref_count--;
-
- if (0 != repr->ref_count)
- return;
-
- free(repr->uri_path);
-
- /* (GDestroyNotify) : iotcon_representation_h is proper type than gpointer */
- g_list_free_full(repr->children, (GDestroyNotify)iotcon_representation_destroy);
-
- /* null COULD be allowed */
- if (repr->interfaces)
- iotcon_resource_interfaces_destroy(repr->interfaces);
-
- /* null COULD be allowed */
- if (repr->res_types)
- iotcon_resource_types_destroy(repr->res_types);
-
- /* null COULD be allowed */
- if (repr->state)
- iotcon_state_destroy(repr->state);
-
- free(repr);
-}
-
-
-API int iotcon_representation_get_uri_path(iotcon_representation_h repr, char **uri_path)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
-
- *uri_path = repr->uri_path;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_set_uri_path(iotcon_representation_h repr,
- const char *uri_path)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
-
- free(repr->uri_path);
- repr->uri_path = strdup(uri_path);
- if (NULL == repr->uri_path) {
- ERR("strdup() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_get_resource_types(iotcon_representation_h repr,
- iotcon_resource_types_h *types)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
-
- *types = repr->res_types;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_set_resource_types(iotcon_representation_h repr,
- iotcon_resource_types_h types)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (types)
- types = icl_resource_types_ref(types);
-
- if (repr->res_types)
- iotcon_resource_types_destroy(repr->res_types);
-
- repr->res_types = types;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
- iotcon_resource_interfaces_h *ifaces)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
-
- *ifaces = repr->interfaces;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
- iotcon_resource_interfaces_h ifaces)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (ifaces)
- ifaces = icl_resource_interfaces_ref(ifaces);
-
- if (repr->interfaces)
- iotcon_resource_interfaces_destroy(repr->interfaces);
-
- repr->interfaces = ifaces;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_set_state(iotcon_representation_h repr,
- iotcon_state_h state)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (state)
- state = icl_state_ref(state);
-
- if (repr->state)
- iotcon_state_destroy(repr->state);
-
- repr->state = state;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_get_state(iotcon_representation_h repr,
- iotcon_state_h *state)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
-
- *state = repr->state;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_add_child(iotcon_representation_h parent,
- iotcon_representation_h child)
-{
- iotcon_representation_h repr;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
-
- repr = icl_representation_ref(child);
-
- parent->children = g_list_append(parent->children, repr);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_remove_child(iotcon_representation_h parent,
- iotcon_representation_h child)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
-
- parent->children = g_list_remove(parent->children, child);
-
- iotcon_representation_destroy(child);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_foreach_children(iotcon_representation_h parent,
- iotcon_children_cb cb, void *user_data)
-{
- GList *list, *next;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- list = parent->children;
- while (list) {
- next = list->next;
- if (IOTCON_FUNC_STOP == cb(list->data, user_data))
- break;
- list = next;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_get_children_count(iotcon_representation_h parent,
- unsigned int *count)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == count, IOTCON_ERROR_INVALID_PARAMETER);
- if (NULL == parent->children)
- *count = 0;
- else
- *count = g_list_length(parent->children);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_representation_get_nth_child(iotcon_representation_h parent, int pos,
- iotcon_representation_h *child)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == parent->children, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
-
- *child = g_list_nth_data(parent->children, pos);
- if (NULL == *child) {
- ERR("g_list_nth_data() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_representation_clone(const iotcon_representation_h src,
- iotcon_representation_h *dest)
-{
- FN_CALL;
- int ret;
- GList *node;
- iotcon_resource_types_h types;
- iotcon_resource_interfaces_h ifaces;
- iotcon_representation_h cloned_repr, copied_repr;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = iotcon_representation_create(&cloned_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return ret;
- }
-
- if (src->uri_path) {
- cloned_repr->uri_path = strdup(src->uri_path);
- if (NULL == cloned_repr->uri_path) {
- ERR("strdup() Fail");
- iotcon_representation_destroy(cloned_repr);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- }
-
- if (src->interfaces) {
- ret = iotcon_resource_interfaces_clone(src->interfaces, &ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_clone() Fail(%d)");
- iotcon_representation_destroy(cloned_repr);
- return ret;
- }
- cloned_repr->interfaces = ifaces;
- }
-
- if (src->res_types) {
- ret = iotcon_resource_types_clone(src->res_types, &types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_clone() Fail");
- iotcon_representation_destroy(cloned_repr);
- return ret;
- }
- cloned_repr->res_types = types;
- }
-
- if (src->children) {
- for (node = g_list_first(src->children); node; node = node->next) {
- ret = iotcon_representation_clone((iotcon_representation_h)node->data,
- &copied_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_clone(child) Fail(%d)", ret);
- iotcon_representation_destroy(cloned_repr);
- return ret;
- }
- cloned_repr->children = g_list_append(cloned_repr->children, copied_repr);
- }
- }
-
- if (src->state) {
- ret = iotcon_state_clone(src->state, &cloned_repr->state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_clone() Fail(%d)", ret);
- iotcon_representation_destroy(cloned_repr);
- return ret;
- }
- }
-
- *dest = cloned_repr;
-
- return IOTCON_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__
-
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "icl-value.h"
-
-struct icl_state_s {
- int ref_count;
- GHashTable *hash_table;
-};
-
-struct icl_representation_s {
- char *uri_path;
- int ref_count;
- int visibility;
- GList *children;
- iotcon_resource_types_h res_types;
- iotcon_resource_interfaces_h interfaces;
- struct icl_state_s *state;
-};
-
-iotcon_representation_h icl_representation_ref(iotcon_representation_h repr);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REPRESENTATION_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-request.h"
-
-API int iotcon_request_get_host_address(iotcon_request_h request,
- char **host_address)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
-
- *host_address = request->host_address;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_request_get_connectivity_type(iotcon_request_h request,
- iotcon_connectivity_type_e *connectivity_type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == connectivity_type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *connectivity_type = request->connectivity_type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the request should not be freed by user. */
-API int iotcon_request_get_representation(iotcon_request_h request,
- iotcon_representation_h *repr)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
-
- *repr = request->repr;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_request_get_request_type(iotcon_request_h request,
- iotcon_request_type_e *type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *type = request->type;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the request should not be freed by user. */
-API int iotcon_request_get_options(iotcon_request_h request, iotcon_options_h *options)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
-
- *options = request->header_options;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the request should not be freed by user. */
-API int iotcon_request_get_query(iotcon_request_h request, iotcon_query_h *query)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == query, IOTCON_ERROR_INVALID_PARAMETER);
-
- *query = request->query;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_request_get_observe_type(iotcon_request_h request,
- iotcon_observe_type_e *observe_type)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == observe_type, IOTCON_ERROR_INVALID_PARAMETER);
-
- *observe_type = request->observation_info.action;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_request_get_observe_id(iotcon_request_h request, int *observe_id)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == observe_id, IOTCON_ERROR_INVALID_PARAMETER);
-
- *observe_id = request->observation_info.observe_id;
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_REQUEST_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_REQUEST_H__
-
-#include <stdint.h>
-#include "iotcon-types.h"
-
-struct icl_observe_info {
- iotcon_observe_type_e action;
- int observe_id;
-};
-
-struct icl_resource_request {
- char *host_address;
- iotcon_connectivity_type_e connectivity_type;
- iotcon_request_type_e type;
- iotcon_options_h header_options;
- iotcon_query_h query;
- struct icl_observe_info observation_info;
- iotcon_representation_h repr;
- int64_t oic_request_h;
- int64_t oic_resource_h;
-};
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_REQUEST_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-resource-interfaces.h"
-
-iotcon_resource_interfaces_h icl_resource_interfaces_ref(
- iotcon_resource_interfaces_h ifaces)
-{
- RETV_IF(NULL == ifaces, NULL);
- RETV_IF(ifaces->ref_count <= 0, NULL);
-
- ifaces->ref_count++;
-
- return ifaces;
-}
-
-
-API int iotcon_resource_interfaces_create(iotcon_resource_interfaces_h *ret_ifaces)
-{
- iotcon_resource_interfaces_h ifaces;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_ifaces, IOTCON_ERROR_INVALID_PARAMETER);
-
- ifaces = calloc(1, sizeof(struct icl_resource_ifaces));
- if (NULL == ifaces) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- ifaces->ref_count = 1;
-
- *ret_ifaces = ifaces;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_resource_interfaces_destroy(iotcon_resource_interfaces_h ifaces)
-{
- RET_IF(NULL == ifaces);
-
- ifaces->ref_count--;
-
- if (0 == ifaces->ref_count) {
- g_list_free_full(ifaces->iface_list, free);
- free(ifaces);
- }
-}
-
-
-static int _icl_resource_interfaces_strcmp(const void *a, const void *b)
-{
- return strcmp(a, b);
-}
-
-
-static bool _icl_resource_interfaces_duplicate_check(iotcon_resource_interfaces_h ifaces,
- const char *iface)
-{
- GList *node = NULL;
-
- RETV_IF(NULL == ifaces, false);
- RETV_IF(NULL == iface, false);
-
- node = g_list_find_custom(ifaces->iface_list, iface, _icl_resource_interfaces_strcmp);
- if (NULL == node)
- return false;
-
- return true;
-}
-
-
-/* Duplicate strings are not allowed. */
-API int iotcon_resource_interfaces_add(iotcon_resource_interfaces_h ifaces,
- const char *iface)
-{
- char *resource_iface;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(1 < ifaces->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
- "Don't modify it. It is already set.");
-
- if (true == _icl_resource_interfaces_duplicate_check(ifaces, iface)) {
- ERR("%s is already contained.", iface);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- resource_iface = strdup(iface);
- if (NULL == resource_iface) {
- ERR("strdup() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- ifaces->iface_list = g_list_append(ifaces->iface_list, resource_iface);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_interfaces_remove(iotcon_resource_interfaces_h ifaces,
- const char *iface)
-{
- GList *node;
- char *node_data;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(1 < ifaces->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
- "Don't modify it. It is already set.");
-
- node = g_list_find_custom(ifaces->iface_list, iface, _icl_resource_interfaces_strcmp);
- if (NULL == node) {
- ERR("g_list_find_custom() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- node_data = node->data;
- ifaces->iface_list = g_list_delete_link(ifaces->iface_list, node);
- free(node_data);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_interfaces_foreach(iotcon_resource_interfaces_h ifaces,
- iotcon_resource_interfaces_foreach_cb cb, void *user_data)
-{
- GList *node;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- for (node = ifaces->iface_list; node; node = node->next) {
- if (IOTCON_FUNC_STOP == cb((const char*)node->data, user_data))
- break;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_interfaces_clone(iotcon_resource_interfaces_h src,
- iotcon_resource_interfaces_h *dest)
-{
- GList *node;
- char *resource_iface;
- iotcon_resource_interfaces_h resource_ifaces;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- resource_ifaces = calloc(1, sizeof(struct icl_resource_ifaces));
- if (NULL == resource_ifaces) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- for (node = src->iface_list; node; node = node->next) {
- resource_iface = ic_utils_strdup(node->data);
- if (NULL == resource_iface) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- ERR("ic_utils_strdup() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- resource_ifaces->iface_list = g_list_append(resource_ifaces->iface_list,
- resource_iface);
- }
-
- resource_ifaces->ref_count = 1;
-
- *dest = resource_ifaces;
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_INTERFACES_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_INTERFACES_H__
-
-#include <glib.h>
-#include "iotcon-types.h"
-
-struct icl_resource_ifaces {
- int ref_count;
- GList *iface_list;
-};
-
-iotcon_resource_interfaces_h icl_resource_interfaces_ref(
- iotcon_resource_interfaces_h res_ifaces);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_INTERFACES_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-resource-types.h"
-
-iotcon_resource_types_h icl_resource_types_ref(iotcon_resource_types_h types)
-{
- RETV_IF(NULL == types, NULL);
- RETV_IF(types->ref_count <= 0, NULL);
-
- types->ref_count++;
-
- return types;
-}
-
-
-API int iotcon_resource_types_create(iotcon_resource_types_h *ret_types)
-{
- iotcon_resource_types_h types;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_types, IOTCON_ERROR_INVALID_PARAMETER);
-
- types = calloc(1, sizeof(struct icl_resource_types));
- if (NULL == types) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- types->ref_count = 1;
-
- *ret_types = types;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_resource_types_destroy(iotcon_resource_types_h types)
-{
- RET_IF(NULL == types);
-
- types->ref_count--;
-
- if (0 == types->ref_count) {
- g_list_free_full(types->type_list, free);
- free(types);
- }
-}
-
-
-static int _icl_resource_types_strcmp(const void *a, const void *b)
-{
- return strcmp(a, b);
-}
-
-
-static bool _icl_resource_types_duplicate_check(iotcon_resource_types_h types,
- const char *type)
-{
- GList *found_node = NULL;
-
- RETV_IF(NULL == types, false);
- RETV_IF(NULL == type, false);
-
- found_node = g_list_find_custom(types->type_list, type, _icl_resource_types_strcmp);
- if (NULL == found_node)
- return false;
-
- return true;
-}
-
-
-/* The length of resource type should be less than or equal to 61.
- * Duplicate strings are not allowed. */
-API int iotcon_resource_types_add(iotcon_resource_types_h types, const char *type)
-{
- char *resource_type;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(1 < types->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
- "Don't modify it. It is already set.");
-
- if (ICL_RESOURCE_TYPE_LENGTH_MAX < strlen(type)) {
- ERR("The length of type(%s) should be less than or equal to %d.", type,
- ICL_RESOURCE_TYPE_LENGTH_MAX);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- if (true == _icl_resource_types_duplicate_check(types, type)) {
- ERR("%s is already contained.", type);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- resource_type = strdup(type);
- if (NULL == resource_type) {
- ERR("strdup() Fail");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- types->type_list = g_list_append(types->type_list, resource_type);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_types_remove(iotcon_resource_types_h types, const char *type)
-{
- GList *found_node;
- char *node_data;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(1 < types->ref_count, IOTCON_ERROR_INVALID_PARAMETER,
- "Don't modify it. It is already set.");
-
- found_node = g_list_find_custom(types->type_list, type, _icl_resource_types_strcmp);
- if (NULL == found_node) {
- ERR("g_list_find_custom() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- node_data = found_node->data;
- types->type_list = g_list_delete_link(types->type_list, found_node);
- free(node_data);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_types_foreach(iotcon_resource_types_h types,
- iotcon_resource_types_foreach_cb cb, void *user_data)
-{
- GList *node;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- for (node = types->type_list; node; node = node->next) {
- if (IOTCON_FUNC_STOP == cb((const char*)node->data, user_data))
- break;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_types_clone(iotcon_resource_types_h src,
- iotcon_resource_types_h *dest)
-{
- GList *node;
- char *resource_type;
- iotcon_resource_types_h resource_types;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- resource_types = calloc(1, sizeof(struct icl_resource_types));
- if (NULL == resource_types) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- for (node = src->type_list; node; node = node->next) {
- resource_type = ic_utils_strdup(node->data);
- if (NULL == resource_type) {
- iotcon_resource_types_destroy(resource_types);
- ERR("ic_utils_strdup() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
- resource_types->type_list = g_list_append(resource_types->type_list,
- resource_type);
- }
-
- resource_types->ref_count = 1;
-
- *dest = resource_types;
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_TYPES_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_TYPES_H__
-
-#include <glib.h>
-#include "iotcon-types.h"
-#include "icl-query.h"
-
-/**
- * @brief The maximum length which can be held in a resource type.
- *
- * @since_tizen 3.0
- */
-#define ICL_RESOURCE_TYPE_LENGTH_MAX (ICL_QUERY_LENGTH_MAX - 3)
-
-
-struct icl_resource_types {
- int ref_count;
- GList *type_list;
-};
-
-iotcon_resource_types_h icl_resource_types_ref(iotcon_resource_types_h res_types);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_TYPES_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <glib.h>
-#include <tizen_type.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-representation.h"
-#include "icl-dbus.h"
-#include "icl-request.h"
-#include "icl-dbus-type.h"
-#include "icl-resource-types.h"
-#include "icl-resource-interfaces.h"
-#include "icl-resource.h"
-#include "icl-payload.h"
-
-static void _icl_request_handler(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- FN_CALL;
- int ret;
- char *key = NULL;
- char *option_data;
- char *value = NULL;
- GVariant *repr_gvar;
- GVariantIter *query;
- GVariantIter *options;
- GVariantIter *repr_iter;
- unsigned short option_id;
- struct icl_resource_request request = {0};
- iotcon_resource_h resource = user_data;
- iotcon_request_handler_cb cb = resource->cb;
-
- g_variant_get(parameters, "(siia(qs)a(ss)iiavxx)",
- &request.host_address,
- &request.connectivity_type,
- &request.type,
- &options,
- &query,
- &request.observation_info.action,
- &request.observation_info.observe_id,
- &repr_iter,
- &request.oic_request_h,
- &request.oic_resource_h);
-
- if (g_variant_iter_n_children(options)) {
- ret = iotcon_options_create(&request.header_options);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_options_create() Fail(%d)", ret);
- g_variant_iter_free(options);
- g_variant_iter_free(query);
- g_variant_iter_free(repr_iter);
- return;
- }
-
- while (g_variant_iter_loop(options, "(q&s)", &option_id, &option_data))
- iotcon_options_add(request.header_options, option_id, option_data);
- }
- g_variant_iter_free(options);
-
- if (g_variant_iter_n_children(query)) {
- ret = iotcon_query_create(&request.query);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_query_create() Fail(%d)", ret);
- g_variant_iter_free(query);
- g_variant_iter_free(repr_iter);
- if (request.header_options)
- iotcon_options_destroy(request.header_options);
- return;
- }
-
- while (g_variant_iter_loop(query, "(&s&s)", &key, &value))
- iotcon_query_add(request.query, key, value);
- }
- g_variant_iter_free(query);
-
- if (g_variant_iter_loop(repr_iter, "v", &repr_gvar)) {
- request.repr = icl_representation_from_gvariant(repr_gvar);
- if (NULL == request.repr) {
- ERR("icl_representation_from_gvariant() Fail");
- if (request.query)
- iotcon_query_destroy(request.query);
- if (request.header_options)
- iotcon_options_destroy(request.header_options);
- return;
- }
- }
- g_variant_iter_free(repr_iter);
-
- /* for iotcon_resource_notify */
- if (IOTCON_OBSERVE_REGISTER == request.observation_info.action) {
- if (NULL == resource->observers)
- iotcon_observers_create(&resource->observers);
- iotcon_observers_add(resource->observers, request.observation_info.observe_id);
- } else if (IOTCON_OBSERVE_DEREGISTER == request.observation_info.action) {
- iotcon_observers_remove(resource->observers, request.observation_info.observe_id);
- }
-
- if (cb)
- cb(resource, &request, resource->user_data);
-
- /* To avoid unnecessary ERR log (representation could be NULL) */
- if (request.repr)
- iotcon_representation_destroy(request.repr);
- if (request.query)
- iotcon_query_destroy(request.query);
- if (request.header_options)
- iotcon_options_destroy(request.header_options);
-}
-
-
-static void _icl_resource_conn_cleanup(iotcon_resource_h resource)
-{
- resource->sub_id = 0;
-
- if (resource->handle) {
- resource->handle = 0;
- return;
- }
-
- iotcon_resource_interfaces_destroy(resource->ifaces);
- iotcon_resource_types_destroy(resource->types);
- if (resource->observers)
- iotcon_observers_destroy(resource->observers);
- free(resource->uri_path);
- free(resource);
-}
-
-
-/* The length of uri_path should be less than or equal to 36. */
-API int iotcon_resource_create(const char *uri_path,
- iotcon_resource_types_h res_types,
- iotcon_resource_interfaces_h ifaces,
- int properties,
- iotcon_request_handler_cb cb,
- void *user_data,
- iotcon_resource_h *resource_handle)
-{
- int ret;
- unsigned int sub_id;
- const gchar **type_array, **iface_array;
- GError *error = NULL;
- iotcon_resource_h resource;
- int64_t signal_number;
- char signal_name[IC_DBUS_SIGNAL_LENGTH];
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(ICL_URI_PATH_LENGTH_MAX < strlen(uri_path),
- IOTCON_ERROR_INVALID_PARAMETER, "Invalid uri_path(%s)", uri_path);
- RETV_IF(NULL == res_types, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_handle, IOTCON_ERROR_INVALID_PARAMETER);
-
- resource = calloc(1, sizeof(struct icl_resource));
- if (NULL == resource) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- type_array = icl_dbus_resource_types_to_array(res_types);
- if (NULL == type_array) {
- ERR("icl_dbus_resource_types_to_array() Fail");
- free(resource);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- iface_array = icl_dbus_resource_interfaces_to_array(ifaces);
- if (NULL == iface_array) {
- ERR("icl_dbus_resource_interfaces_to_array() Fail");
- free(type_array);
- free(resource);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- ic_dbus_call_register_resource_sync(icl_dbus_get_object(), uri_path, type_array, iface_array,
- properties, false, &signal_number, &(resource->handle), NULL, &error);
- if (error) {
- ERR("ic_dbus_call_register_resource_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- free(iface_array);
- free(type_array);
- free(resource);
- return ret;
- }
- free(iface_array);
- free(type_array);
-
- if (0 == resource->handle) {
- ERR("iotcon-daemon Fail");
- free(resource);
- return IOTCON_ERROR_IOTIVITY;
- }
-
- resource->cb = cb;
- resource->user_data = user_data;
-
- resource->uri_path = ic_utils_strdup(uri_path);
- resource->types = icl_resource_types_ref(res_types);
- resource->ifaces = icl_resource_interfaces_ref(ifaces);
- resource->properties = properties;
-
- snprintf(signal_name, sizeof(signal_name), "%s_%llx", IC_DBUS_SIGNAL_REQUEST_HANDLER,
- signal_number);
-
- sub_id = icl_dbus_subscribe_signal(signal_name, resource, _icl_resource_conn_cleanup,
- _icl_request_handler);
- if (0 == sub_id) {
- ERR("icl_dbus_subscribe_signal() Fail");
- iotcon_resource_interfaces_destroy(resource->ifaces);
- iotcon_resource_types_destroy(resource->types);
- free(resource->uri_path);
- free(resource);
- return IOTCON_ERROR_DBUS;
- }
-
- resource->sub_id = sub_id;
-
- *resource_handle = resource;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_destroy(iotcon_resource_h resource)
-{
- FN_CALL;
- int ret;
- GError *error = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 == resource->handle) { /* iotcon dbus disconnected */
- WARN("Invalid Resource handle");
- iotcon_resource_interfaces_destroy(resource->ifaces);
- iotcon_resource_types_destroy(resource->types);
- if (resource->observers)
- iotcon_observers_destroy(resource->observers);
- free(resource->uri_path);
- free(resource);
- return IOTCON_ERROR_NONE;
- }
-
- if (NULL == icl_dbus_get_object()) {
- ERR("icl_dbus_get_object() return NULL");
- return IOTCON_ERROR_DBUS;
- }
-
- ic_dbus_call_unregister_resource_sync(icl_dbus_get_object(), resource->handle, NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_unregister_resource_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
- resource->handle = 0;
-
- icl_dbus_unsubscribe_signal(resource->sub_id);
- resource->sub_id = 0;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_bind_interface(iotcon_resource_h resource, const char *iface)
-{
- FN_CALL;
- int ret;
- GError *error = NULL;
- iotcon_resource_interfaces_h resource_ifaces;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
- if (0 == resource->sub_id) {
- ERR("Invalid Resource handle");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- ret = iotcon_resource_interfaces_clone(resource->ifaces, &resource_ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_clone() Fail(%d)", ret);
- return ret;
- }
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, iface);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
- iotcon_resource_interfaces_destroy(resource_ifaces);
- return ret;
- }
-
- ic_dbus_call_bind_interface_sync(icl_dbus_get_object(), resource->handle,
- iface, &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_bind_interface_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- iotcon_resource_interfaces_destroy(resource_ifaces);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- iotcon_resource_interfaces_destroy(resource_ifaces);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- iotcon_resource_interfaces_destroy(resource->ifaces);
- resource->ifaces = resource_ifaces;
-
- return ret;
-}
-
-
-API int iotcon_resource_bind_type(iotcon_resource_h resource, const char *resource_type)
-{
- FN_CALL;
- int ret;
- GError *error = NULL;
- iotcon_resource_types_h resource_types;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resource_type, IOTCON_ERROR_INVALID_PARAMETER);
- if (0 == resource->sub_id) {
- ERR("Invalid Resource handle");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- ret = iotcon_resource_types_clone(resource->types, &resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_clone() Fail(%d)", ret);
- return ret;
- }
-
- ret = iotcon_resource_types_add(resource_types, resource_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_add() Fail(%d)", ret);
- iotcon_resource_types_destroy(resource_types);
- return ret;
- }
-
- ic_dbus_call_bind_type_sync(icl_dbus_get_object(), resource->handle, resource_type,
- &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_bind_type_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- iotcon_resource_types_destroy(resource_types);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- iotcon_resource_types_destroy(resource_types);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- iotcon_resource_types_destroy(resource->types);
- resource->types = resource_types;
-
- return ret;
-}
-
-API int iotcon_resource_set_request_handler(iotcon_resource_h resource,
- iotcon_request_handler_cb cb, void *user_data)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- DBG("Request handler is changed");
- resource->cb = cb;
- resource->user_data = user_data;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_bind_child_resource(iotcon_resource_h parent,
- iotcon_resource_h child)
-{
- GError *error = NULL;
- int i, ret;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(parent == child, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 == parent->sub_id) {
- ERR("Invalid Resource handle(parent)");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- if (0 == child->sub_id) {
- ERR("Invalid Resource handle(child)");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
- if (child == parent->children[i]) {
- ERR("Child resource was already bound to parent resource.");
- return IOTCON_ERROR_ALREADY;
- }
- }
-
- for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
- if (NULL == parent->children[i]) {
- ic_dbus_call_bind_resource_sync(icl_dbus_get_object(), parent->handle,
- child->handle, &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_bind_resource_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- parent->children[i] = child;
-
- return IOTCON_ERROR_NONE;
- }
- }
-
- ERR("There is no slot to bind a child resource");
- return IOTCON_ERROR_OUT_OF_MEMORY;
-}
-
-
-API int iotcon_resource_unbind_child_resource(iotcon_resource_h parent,
- iotcon_resource_h child)
-{
- GError *error = NULL;
- int i, ret;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 == parent->sub_id) {
- ERR("Invalid Resource handle(parent)");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- if (0 == child->sub_id) {
- ERR("Invalid Resource handle(child)");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- ic_dbus_call_unbind_resource_sync(icl_dbus_get_object(), parent->handle,
- child->handle, &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_unbind_resource_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
- if (child == parent->children[i])
- parent->children[i] = NULL;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_get_number_of_children(iotcon_resource_h resource, int *number)
-{
- int i;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == number, IOTCON_ERROR_INVALID_PARAMETER);
-
- *number = 0;
- for (i = 0; i < ICL_CONTAINED_RESOURCES_MAX; i++) {
- if (resource->children[i])
- *number += 1;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_get_nth_child(iotcon_resource_h parent, int index,
- iotcon_resource_h *child)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == parent, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == child, IOTCON_ERROR_INVALID_PARAMETER);
- if ((index < 0) || (ICL_CONTAINED_RESOURCES_MAX <= index)) {
- ERR("Invalid index(%d)", index);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- *child = parent->children[index];
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_resource_get_uri_path(iotcon_resource_h resource, char **uri_path)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == uri_path, IOTCON_ERROR_INVALID_PARAMETER);
-
- *uri_path = resource->uri_path;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-/* The content of the resource should not be freed by user. */
-API int iotcon_resource_get_types(iotcon_resource_h resource,
- iotcon_resource_types_h *types)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == types, IOTCON_ERROR_INVALID_PARAMETER);
-
- *types = resource->types;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_get_interfaces(iotcon_resource_h resource,
- iotcon_resource_interfaces_h *ifaces)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == ifaces, IOTCON_ERROR_INVALID_PARAMETER);
-
- *ifaces = resource->ifaces;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_resource_get_properties(iotcon_resource_h resource, int *properties)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == properties, IOTCON_ERROR_INVALID_PARAMETER);
-
- *properties = resource->properties;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_resource_notify(iotcon_resource_h resource,
- iotcon_representation_h repr, iotcon_observers_h observers, iotcon_qos_e qos)
-{
- int ret;
- GError *error = NULL;
- GVariant *obs;
- GVariant *repr_gvar;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resource, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (0 == resource->sub_id) {
- ERR("Invalid Resource handle");
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- repr_gvar = icl_dbus_representation_to_gvariant(repr);
- if (NULL == repr_gvar) {
- ERR("icl_representation_to_gvariant() Fail");
- return IOTCON_ERROR_SYSTEM;
- }
-
- if (observers)
- obs = icl_dbus_observers_to_gvariant(observers);
- else
- obs = icl_dbus_observers_to_gvariant(resource->observers);
-
- ic_dbus_call_notify_sync(icl_dbus_get_object(), resource->handle, repr_gvar, obs, qos,
- &ret, NULL, &error);
- if (error) {
- ERR("ic_dbus_call_notify_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- g_variant_unref(obs);
- g_variant_unref(repr_gvar);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_H__
-
-#include <stdint.h>
-
-#include "iotcon-types.h"
-
-#include "icl-dbus.h"
-
-/**
- * @brief The maximum number of children resources which can be held in a parent resource.
- *
- * @since_tizen 3.0
- */
-#define ICL_CONTAINED_RESOURCES_MAX 5
-
-/**
- * @brief The maximum length of uri_path which can be held in a resource.
- *
- * @since_tizen 3.0
- */
-#define ICL_URI_PATH_LENGTH_MAX 36
-
-struct icl_notify_msg {
- char *iface;
- iotcon_representation_h repr;
-};
-
-struct icl_resource {
- char *uri_path;
- int properties;
- iotcon_resource_types_h types;
- iotcon_resource_interfaces_h ifaces;
- iotcon_request_handler_cb cb;
- void *user_data;
- unsigned int sub_id;
- int64_t handle;
- iotcon_resource_h children[ICL_CONTAINED_RESOURCES_MAX];
- iotcon_observers_h observers;
-};
-
-#endif /*__IOT_CONNECTIVITY_MANAGER_LIBRARY_RESOURCE_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <errno.h>
-#include <glib.h>
-
-#include "iotcon.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-dbus.h"
-#include "icl-dbus-type.h"
-#include "icl-resource.h"
-#include "icl-representation.h"
-#include "icl-options.h"
-#include "icl-request.h"
-#include "icl-response.h"
-
-/* the last index of iotcon_response_result_e */
-#define ICL_RESPONSE_RESULT_MAX (IOTCON_RESPONSE_FORBIDDEN + 1)
-
-API int iotcon_response_create(iotcon_request_h request,
- iotcon_response_h *response)
-{
- FN_CALL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == request, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == response, IOTCON_ERROR_INVALID_PARAMETER);
-
- iotcon_response_h resp = calloc(1, sizeof(struct icl_resource_response));
- if (NULL == resp) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- resp->oic_request_h = request->oic_request_h;
- resp->oic_resource_h = request->oic_resource_h;
-
- *response = resp;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_response_destroy(iotcon_response_h resp)
-{
- RET_IF(NULL == resp);
-
- if (resp->repr)
- iotcon_representation_destroy(resp->repr);
- if (resp->header_options)
- iotcon_options_destroy(resp->header_options);
- if (resp->iface)
- free(resp->iface);
- free(resp);
-}
-
-API int iotcon_response_get_options(iotcon_response_h resp,
- iotcon_options_h *options)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == options, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resp->header_options, IOTCON_ERROR_NO_DATA);
-
- *options = resp->header_options;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_response_get_representation(iotcon_response_h resp,
- iotcon_representation_h *repr)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == repr, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == resp->repr, IOTCON_ERROR_NO_DATA);
-
- *repr = resp->repr;
-
- return IOTCON_ERROR_NONE;
-
-}
-
-API int iotcon_response_get_result(iotcon_response_h resp,
- iotcon_response_result_e *result)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == result, IOTCON_ERROR_INVALID_PARAMETER);
-
- *result = resp->result;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_response_set_result(iotcon_response_h resp,
- iotcon_response_result_e result)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (result < IOTCON_RESPONSE_OK || ICL_RESPONSE_RESULT_MAX <= result) {
- ERR("Invalid result(%d)", result);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
- resp->result = result;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_response_set_representation(iotcon_response_h resp, const char *iface,
- iotcon_representation_h repr)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == iface, IOTCON_ERROR_INVALID_PARAMETER);
-
- free(resp->iface);
- resp->iface = strdup(iface);
-
- if (repr)
- repr = icl_representation_ref(repr);
-
- if (resp->repr)
- iotcon_representation_destroy(resp->repr);
-
- resp->repr = repr;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_response_set_options(iotcon_response_h resp,
- iotcon_options_h options)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (options)
- options = icl_options_ref(options);
-
- if (resp->header_options)
- iotcon_options_destroy(resp->header_options);
-
- resp->header_options = options;
-
- return IOTCON_ERROR_NONE;
-}
-
-static bool _icl_response_representation_child_cb(iotcon_representation_h child,
- void *user_data)
-{
- char *iface = user_data;
-
- if (IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_BATCH, iface))
- child->visibility = ICL_VISIBILITY_REPR;
- else
- child->visibility = ICL_VISIBILITY_PROP;
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-
-static int _icl_response_check_representation_visibility(iotcon_response_h resp)
-{
- int ret;
-
- RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
- if (NULL == resp->repr)
- return IOTCON_ERROR_NONE;
-
- iotcon_representation_h first = resp->repr;
-
- DBG("interface type of response : %s", resp->iface);
-
- if (IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_LINK, resp->iface)
- || IC_STR_EQUAL == strcmp(IOTCON_INTERFACE_BATCH, resp->iface))
- first->visibility = ICL_VISIBILITY_NONE;
- else
- first->visibility = ICL_VISIBILITY_REPR;
-
- ret = iotcon_representation_foreach_children(first,
- _icl_response_representation_child_cb, resp->iface);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_foreach_children() Fail(%d)", ret);
- return ret;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_response_send(iotcon_response_h resp)
-{
- FN_CALL;
- int ret;
- GError *error = NULL;
- GVariant *arg_response;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
- RETV_IF(NULL == resp, IOTCON_ERROR_INVALID_PARAMETER);
-
- ret = _icl_response_check_representation_visibility(resp);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("_icl_response_check_representation_visibility() Fail(%d)", ret);
- return ret;
- }
-
- arg_response = icl_dbus_response_to_gvariant(resp);
- ic_dbus_call_send_response_sync(icl_dbus_get_object(), arg_response, &ret, NULL,
- &error);
- if (error) {
- ERR("ic_dbus_call_send_response_sync() Fail(%s)", error->message);
- ret = icl_dbus_convert_dbus_error(error->code);
- g_error_free(error);
- g_variant_unref(arg_response);
- return ret;
- }
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon-daemon Fail(%d)", ret);
- return icl_dbus_convert_daemon_error(ret);
- }
-
- return IOTCON_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESPONSE_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESPONSE_H__
-
-#include <stdint.h>
-#include "iotcon-types.h"
-
-typedef enum {
- ICL_VISIBILITY_NONE = 0,
- ICL_VISIBILITY_REPR = (1 << 0),
- ICL_VISIBILITY_PROP = (1 << 1),
-} icl_visibility_e;
-
-
-struct icl_resource_response {
- iotcon_options_h header_options;
- char *iface;
- int result;
- iotcon_representation_h repr;
- int64_t oic_request_h;
- int64_t oic_resource_h;
-};
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_RESPONSE_H__ */
+++ /dev/null
-/* Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-
-#include "iotcon-types.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-list.h"
-#include "icl-value.h"
-#include "icl-representation.h"
-#include "icl-state.h"
-
-iotcon_state_h icl_state_ref(iotcon_state_h state)
-{
- RETV_IF(NULL == state, NULL);
- RETV_IF(state->ref_count <= 0, NULL);
-
- state->ref_count++;
-
- return state;
-}
-
-
-API int iotcon_state_create(iotcon_state_h *ret_state)
-{
- errno = 0;
- iotcon_state_h state;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == ret_state, IOTCON_ERROR_INVALID_PARAMETER);
-
- state = calloc(1, sizeof(struct icl_state_s));
- if (NULL == state) {
- ERR("calloc() Fail(%d)", errno);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- state->hash_table = g_hash_table_new_full(g_str_hash, g_str_equal, free,
- icl_value_destroy);
- state->ref_count = 1;
-
- *ret_state = state;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API void iotcon_state_destroy(iotcon_state_h state)
-{
- RET_IF(NULL == state);
-
- state->ref_count--;
-
- if (0 != state->ref_count)
- return;
-
- g_hash_table_destroy(state->hash_table);
- free(state);
-}
-
-
-API int iotcon_state_remove(iotcon_state_h state, const char *key)
-{
- gboolean ret = FALSE;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup(%s) Fail", key);
- return IOTCON_ERROR_NO_DATA;
- }
-
- ret = g_hash_table_remove(state->hash_table, key);
- if (FALSE == ret) {
- ERR("g_hash_table_remove(%s) Fail", key);
- return IOTCON_ERROR_NO_DATA;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_state_get_int(iotcon_state_h state, const char *key, int *val)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- icl_basic_s *real = (icl_basic_s*)value;
- if (IOTCON_TYPE_INT != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.i;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_int(iotcon_state_h state, const char *key, int val)
-{
- iotcon_value_h value;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_int(val);
- if (NULL == value) {
- ERR("icl_value_create_int(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_bool(iotcon_state_h state, const char *key, bool *val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_BOOL != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.b;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_bool(iotcon_state_h state, const char *key, bool val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_bool(val);
- if (NULL == value) {
- ERR("icl_value_create_bool(%d) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_double(iotcon_state_h state, const char *key, double *val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_DOUBLE != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.d;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_double(iotcon_state_h state, const char *key, double val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_double(val);
- if (NULL == value) {
- ERR("icl_value_create_double(%f) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_str(iotcon_state_h state, const char *key, char **val)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- if (IOTCON_TYPE_STR != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->val.s;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_str(iotcon_state_h state, const char *key, char *val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_str(val);
- if (NULL == value) {
- ERR("icl_value_create_str(%s) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_byte_str(iotcon_state_h state, const char *key,
- unsigned char **val, int *len)
-{
- iotcon_value_h value = NULL;
- icl_val_byte_str_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == len, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_val_byte_str_s*)value;
- if (IOTCON_TYPE_BYTE_STR != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *val = real->s;
- *len = real->len;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_byte_str(iotcon_state_h state, const char *key,
- unsigned char *val, int len)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(len <= 0, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_byte_str(val, len);
- if (NULL == value) {
- ERR("icl_value_create_byte_str() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_is_null(iotcon_state_h state, const char *key, bool *is_null)
-{
- icl_basic_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == is_null, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = (iotcon_value_h) g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_basic_s*)value;
- *is_null = (IOTCON_TYPE_NULL == real->type) ? true : false;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_null(iotcon_state_h state, const char *key)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_null();
- if (NULL == value) {
- ERR("icl_value_create_null() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_list(iotcon_state_h state, const char *key, iotcon_list_h *list)
-{
- iotcon_value_h value = NULL;
- icl_val_list_s *real = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_val_list_s*)value;
- if (IOTCON_TYPE_LIST != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *list = real->list;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_list(iotcon_state_h state, const char *key, iotcon_list_h list)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == list, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_list(list);
- if (NULL == value) {
- ERR("icl_value_create_list() Fail");
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_state(iotcon_state_h src, const char *key, iotcon_state_h *dest)
-{
- icl_val_state_s *real = NULL;
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == src, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == dest, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(src->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
-
- real = (icl_val_state_s*)value;
- if (IOTCON_TYPE_STATE != real->type) {
- ERR("Invalid Type(%d)", real->type);
- return IOTCON_ERROR_INVALID_TYPE;
- }
-
- *dest = real->state;
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_add_state(iotcon_state_h state, const char *key, iotcon_state_h val)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == val, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = icl_value_create_state(val);
- if (NULL == value) {
- ERR("icl_value_create_state(%p) Fail", val);
- return IOTCON_ERROR_OUT_OF_MEMORY;
- }
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-API int iotcon_state_get_type(iotcon_state_h state, const char *key,
- iotcon_type_e *type)
-{
- iotcon_value_h value = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == type, IOTCON_ERROR_INVALID_PARAMETER);
-
- value = g_hash_table_lookup(state->hash_table, key);
- if (NULL == value) {
- ERR("g_hash_table_lookup() Fail");
- return IOTCON_ERROR_NO_DATA;
- }
- *type = value->type;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value)
-{
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == key, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_hash_table_replace(state->hash_table, ic_utils_strdup(key), value);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_state_get_keys_count(iotcon_state_h state, unsigned int *count)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == count, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state->hash_table, IOTCON_ERROR_INVALID_PARAMETER);
-
- *count = g_hash_table_size(state->hash_table);
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone)
-{
- int ret;
-
- iotcon_state_h temp = NULL;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == state_clone, IOTCON_ERROR_INVALID_PARAMETER);
-
- if (state->hash_table) {
- ret = iotcon_state_create(&temp);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- return ret;
- }
-
- g_hash_table_foreach(state->hash_table, (GHFunc)icl_state_clone_foreach, temp);
- }
-
- *state_clone = temp;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-void icl_state_clone_foreach(char *key, iotcon_value_h src_val, iotcon_state_h dest_state)
-{
- FN_CALL;
- iotcon_value_h copied_val;
-
- copied_val = icl_value_clone(src_val);
- if (NULL == copied_val) {
- ERR("icl_value_clone() Fail");
- return;
- }
-
- icl_state_set_value(dest_state, key, copied_val);
-}
-
-
-API int iotcon_state_foreach(iotcon_state_h state, iotcon_state_cb cb, void *user_data)
-{
- GHashTableIter iter;
- gpointer key;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == state, IOTCON_ERROR_INVALID_PARAMETER);
- RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
-
- g_hash_table_iter_init(&iter, state->hash_table);
- while (g_hash_table_iter_next(&iter, &key, NULL)) {
- if (IOTCON_FUNC_STOP == cb(state, key, user_data))
- break;
- }
-
- return IOTCON_ERROR_NONE;
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_STATE_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_STATE_H__
-
-#include "icl-value.h"
-#include "icl-representation.h"
-
-int icl_state_set_value(iotcon_state_h state, const char *key, iotcon_value_h value);
-
-void icl_state_clone_foreach(char *key, iotcon_value_h src_val,
- iotcon_state_h dest_state);
-
-iotcon_state_h icl_state_ref(iotcon_state_h state);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_STATE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <errno.h>
-
-#include "iotcon-types.h"
-#include "iotcon-representation.h"
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-representation.h"
-#include "icl-list.h"
-#include "icl-state.h"
-#include "icl-value.h"
-
-static iotcon_value_h _icl_value_create(int type)
-{
- iotcon_value_h ret_val;
-
- switch (type) {
- case IOTCON_TYPE_INT:
- case IOTCON_TYPE_BOOL:
- case IOTCON_TYPE_DOUBLE:
- case IOTCON_TYPE_STR:
- case IOTCON_TYPE_NULL:
- ret_val = calloc(1, sizeof(icl_basic_s));
- break;
- case IOTCON_TYPE_BYTE_STR:
- ret_val = calloc(1, sizeof(icl_val_byte_str_s));
- break;
- case IOTCON_TYPE_LIST:
- ret_val = calloc(1, sizeof(icl_val_list_s));
- break;
- case IOTCON_TYPE_STATE:
- ret_val = calloc(1, sizeof(icl_val_state_s));
- break;
- default:
- ERR("Invalid Type(%d)", type);
- return NULL;
- }
-
- if (NULL == ret_val) {
- ERR("calloc() Fail(%d)", errno);
- return NULL;
- }
-
- ret_val->type = type;
-
- return ret_val;
-}
-
-
-iotcon_value_h icl_value_create_null()
-{
- iotcon_value_h value;
-
- value = _icl_value_create(IOTCON_TYPE_NULL);
- if (NULL == value) {
- ERR("_icl_value_create(NULL) Fail");
- return NULL;
- }
-
- return value;
-}
-
-iotcon_value_h icl_value_create_int(int val)
-{
- icl_basic_s *value;
-
- value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_INT);
- if (NULL == value) {
- ERR("_icl_value_create(INT:%d) Fail", val);
- return NULL;
- }
-
- value->val.i = val;
-
- return (iotcon_value_h)value;
-}
-
-iotcon_value_h icl_value_create_bool(bool val)
-{
- icl_basic_s *value;
-
- value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_BOOL);
- if (NULL == value) {
- ERR("_icl_value_create(BOOL:%d) Fail", val);
- return NULL;
- }
-
- value->val.b = val;
-
- return (iotcon_value_h)value;
-}
-
-iotcon_value_h icl_value_create_double(double val)
-{
- icl_basic_s *value;
-
- value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_DOUBLE);
- if (NULL == value) {
- ERR("_icl_value_create(DOUBLE:%f) Fail", val);
- return NULL;
- }
-
- value->val.d = val;
-
- return (iotcon_value_h)value;
-}
-
-iotcon_value_h icl_value_create_str(const char *val)
-{
- icl_basic_s *value;
-
- RETV_IF(NULL == val, NULL);
-
- value = (icl_basic_s*)_icl_value_create(IOTCON_TYPE_STR);
- if (NULL == value) {
- ERR("_icl_value_create(STR:%s) Fail", val);
- return NULL;
- }
-
- value->val.s = ic_utils_strdup(val);
-
- return (iotcon_value_h)value;
-}
-
-
-iotcon_value_h icl_value_create_byte_str(const unsigned char *val, int len)
-{
- icl_val_byte_str_s *value;
-
- RETV_IF(NULL == val, NULL);
-
- value = (icl_val_byte_str_s*)_icl_value_create(IOTCON_TYPE_BYTE_STR);
- if (NULL == value) {
- ERR("_icl_value_create(BYTE STRING) Fail");
- return NULL;
- }
-
- value->s = calloc(len, sizeof(unsigned char));
- if (NULL == value->s) {
- ERR("calloc() Fail(%d)", errno);
- free(value);
- return NULL;
- }
- memcpy(value->s, val, len);
- value->len = len;
-
- return (iotcon_value_h)value;
-}
-
-
-iotcon_value_h icl_value_create_list(iotcon_list_h val)
-{
- icl_val_list_s *value;
-
- value = (icl_val_list_s*)_icl_value_create(IOTCON_TYPE_LIST);
- if (NULL == value) {
- ERR("_icl_value_create(LIST) Fail");
- return NULL;
- }
-
- value->list = icl_list_ref(val);
-
- return (iotcon_value_h)value;
-}
-
-iotcon_value_h icl_value_create_state(iotcon_state_h val)
-{
- icl_val_state_s *value;
-
- value = (icl_val_state_s*)_icl_value_create(IOTCON_TYPE_STATE);
- if (NULL == value) {
- ERR("_icl_value_create(state) Fail");
- return NULL;
- }
-
- value->state = icl_state_ref(val);
-
- return (iotcon_value_h)value;
-}
-
-int icl_value_get_int(iotcon_value_h value, int *val)
-{
- icl_basic_s *real = (icl_basic_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_INT != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->val.i;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_value_get_bool(iotcon_value_h value, bool *val)
-{
- icl_basic_s *real = (icl_basic_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BOOL != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->val.b;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_value_get_double(iotcon_value_h value, double *val)
-{
- icl_basic_s *real = (icl_basic_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_DOUBLE != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->val.d;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_value_get_str(iotcon_value_h value, char **val)
-{
- icl_basic_s *real = (icl_basic_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STR != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->val.s;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icl_value_get_byte_str(iotcon_value_h value, unsigned char **val, int *len)
-{
- icl_val_byte_str_s *real = (icl_val_byte_str_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_BYTE_STR != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *val = real->s;
- *len = real->len;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list)
-{
- icl_val_list_s *real = (icl_val_list_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_LIST != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *list = real->list;
-
- return IOTCON_ERROR_NONE;
-}
-
-int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state)
-{
- icl_val_state_s *real = (icl_val_state_s*)value;
-
- RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
- RETVM_IF(IOTCON_TYPE_STATE != real->type, IOTCON_ERROR_INVALID_PARAMETER,
- "Invalid Type(%d)", real->type);
-
- *state = real->state;
-
- return IOTCON_ERROR_NONE;
-}
-
-
-void icl_value_destroy(gpointer data)
-{
- int ret;
- iotcon_value_h value;
- iotcon_list_h list;
- iotcon_state_h state;
-
- RET_IF(NULL == data);
-
- value = data;
-
- int type = value->type;
- switch (type) {
- case IOTCON_TYPE_STR:
- free(((icl_basic_s*)value)->val.s);
- case IOTCON_TYPE_INT:
- case IOTCON_TYPE_BOOL:
- case IOTCON_TYPE_DOUBLE:
- case IOTCON_TYPE_NULL:
- break;
- case IOTCON_TYPE_BYTE_STR:
- free(((icl_val_byte_str_s*)value)->s);
- break;
- case IOTCON_TYPE_LIST:
- ret = icl_value_get_list(value, &list);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_list() Fail(%d)", ret);
- break;
- }
- iotcon_list_destroy(list);
- break;
- case IOTCON_TYPE_STATE:
- ret = icl_value_get_state(value, &state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("icl_value_get_state() Fail(%d)", ret);
- break;
- }
- iotcon_state_destroy(state);
- break;
- default:
- ERR("Invalid type(%d)", type);
- break;
- }
- free(value);
-}
-
-
-iotcon_value_h icl_value_clone(iotcon_value_h src)
-{
- iotcon_value_h dest = NULL;
- icl_basic_s *real = (icl_basic_s*)src;
-
- RETV_IF(NULL == src, NULL);
-
- switch (src->type) {
- case IOTCON_TYPE_INT:
- dest = icl_value_create_int(real->val.i);
- break;
- case IOTCON_TYPE_BOOL:
- dest = icl_value_create_bool(real->val.b);
- break;
- case IOTCON_TYPE_DOUBLE:
- dest = icl_value_create_double(real->val.d);
- break;
- case IOTCON_TYPE_STR:
- dest = icl_value_create_str(real->val.s);
- break;
- case IOTCON_TYPE_NULL:
- dest = icl_value_create_null();
- break;
- case IOTCON_TYPE_BYTE_STR:
- dest = icl_value_create_byte_str(((icl_val_byte_str_s*)real)->s,
- ((icl_val_byte_str_s*)real)->len);
- break;
- case IOTCON_TYPE_LIST:
- dest = icl_value_create_list(((icl_val_list_s*)real)->list);
- break;
- case IOTCON_TYPE_STATE:
- dest = icl_value_create_state(((icl_val_state_s*)real)->state);
- break;
- default:
- ERR("Invalid type(%d)", src->type);
- break;
- }
-
- if (NULL == dest)
- ERR("ic_value_create_xxx(%d) Fail", src->type);
-
- return dest;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_VALUE_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_VALUE_H__
-
-#include <glib.h>
-
-#include "iotcon-types.h"
-
-struct icl_value_s {
- int type;
-};
-
-typedef struct {
- int type;
- union {
- int i;
- bool b;
- double d;
- char *s;
- } val;
-} icl_basic_s;
-
-typedef struct {
- int type;
- unsigned char *s;
- int len;
-} icl_val_byte_str_s;
-
-typedef struct {
- int type;
- struct icl_list_s *list;
-} icl_val_list_s;
-
-typedef struct {
- int type;
- struct icl_state_s *state;
-} icl_val_state_s;
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_REPRESENTATION_MODULE
- * @brief The handle of representation value.
- * @details iotcon_value_h is an opaque data structure to have variant datatype and
- * store values along with information about the type of that value.\n
- * The range of possible values is determined by the type.\n
- * The type of iotcon_value_h should be one of them\n
- * #IOTCON_TYPE_INT\n
- * #IOTCON_TYPE_BOOL\n
- * #IOTCON_TYPE_DOUBLE\n
- * #IOTCON_TYPE_STR\n
- * #IOTCON_TYPE_NULL\n
- * #IOTCON_TYPE_BYTE_STR\n
- * #IOTCON_TYPE_LIST\n
- * #IOTCON_TYPE_STATE
- *
- * @since_tizen 3.0
- */
-typedef struct icl_value_s* iotcon_value_h;
-
-iotcon_value_h icl_value_create_null();
-iotcon_value_h icl_value_create_int(int val);
-iotcon_value_h icl_value_create_bool(bool val);
-iotcon_value_h icl_value_create_double(double val);
-iotcon_value_h icl_value_create_str(const char *val);
-iotcon_value_h icl_value_create_byte_str(const unsigned char *val, int len);
-iotcon_value_h icl_value_create_list(iotcon_list_h val);
-iotcon_value_h icl_value_create_state(iotcon_state_h val);
-
-
-int icl_value_get_int(iotcon_value_h value, int *val);
-int icl_value_get_bool(iotcon_value_h value, bool *val);
-int icl_value_get_double(iotcon_value_h value, double *val);
-int icl_value_get_str(iotcon_value_h value, char **val);
-int icl_value_get_byte_str(iotcon_value_h value, unsigned char **val, int *len);
-int icl_value_get_list(iotcon_value_h value, iotcon_list_h *list);
-int icl_value_get_state(iotcon_value_h value, iotcon_state_h *state);
-
-void icl_value_destroy(gpointer data);
-
-iotcon_value_h icl_value_clone(iotcon_value_h src);
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_VALUE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <glib.h>
-#include <glib-object.h>
-
-#include "ic-utils.h"
-#include "icl.h"
-#include "icl-dbus.h"
-
-API int iotcon_connect(void)
-{
- int ret;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
-
-#if !GLIB_CHECK_VERSION(2, 35, 0)
- g_type_init();
-#endif
-
- ret = icl_dbus_start();
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_dbus_start() Fail(%d)", ret);
-
- return ret;
-}
-
-
-API void iotcon_disconnect(void)
-{
- icl_dbus_stop();
-}
-
-API int iotcon_get_timeout(int *timeout_seconds)
-{
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- RETV_IF(NULL == timeout_seconds, IOTCON_ERROR_INVALID_PARAMETER);
-
- *timeout_seconds = icl_dbus_get_timeout();
-
- return IOTCON_ERROR_NONE;
-}
-
-
-API int iotcon_set_timeout(int timeout_seconds)
-{
- int ret;
-
- RETV_IF(false == ic_utils_check_oic_feature_supported(), IOTCON_ERROR_NOT_SUPPORTED);
- if (ICL_DBUS_TIMEOUT_MAX < timeout_seconds || timeout_seconds <= 0) {
- ERR("timeout_seconds(%d) must be in range from 1 to 3600", timeout_seconds);
- return IOTCON_ERROR_INVALID_PARAMETER;
- }
-
- ret = icl_dbus_set_timeout(timeout_seconds);
- if (IOTCON_ERROR_NONE != ret)
- ERR("icl_dbus_set_timeout() Fail(%d)", ret);
-
- return ret;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_LIBRARY_H__
-#define __IOT_CONNECTIVITY_MANAGER_LIBRARY_H__
-
-#include "iotcon.h"
-#include "ic-common.h"
-#include "ic-log.h"
-
-#ifdef API
-#undef API
-#endif
-#define API __attribute__((visibility("default")))
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_LIBRARY_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_CLIENT_H__
-#define __IOT_CONNECTIVITY_MANAGER_CLIENT_H__
-
-#include <iotcon-types.h>
-#include <iotcon-remote-resource.h>
-
-/**
- * @file iotcon-client.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_CLIENT_MODULE Client
- *
- * @brief Iotcon Client provides API for client side.
- *
- * @section CAPI_IOT_CONNECTIVITY_CLIENT_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_CLIENT_MODULE_OVERVIEW Overview
- * This API set consists of client side API for @ref CAPI_IOT_CONNECTIVITY_CLIENT_REMOTE_RESOURCE_MODULE.
- *
- * @section CAPI_IOT_CONNECTIVITY_CLIENT_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Specifies the type of function passed to iotcon_add_presence_cb().
- * @details Called when client receive presence events from the server.
- * The @a response handle contains about presence information.
- *
- * @since_tizen 3.0
- *
- * @param[in] presence The presence handle
- * @param[in] err The error code(0 on success, otherwise a negative error value)
- * @param[in] response The presence response handle
- * @param[in] user_data The user data to pass to the function
- *
- * @pre The callback must be registered using iotcon_add_presence_cb()
- *
- * @see iotcon_add_presence_cb()
- * @see iotcon_remove_presence_cb()
- * @see iotcon_presence_response_get_connectivity_type()
- * @see iotcon_presence_response_get_host_address()
- * @see iotcon_presence_response_get_resource_type()
- * @see iotcon_presence_response_get_result()
- * @see iotcon_presence_response_get_trigger()
- */
-typedef void (*iotcon_presence_cb)(iotcon_presence_h presence, iotcon_error_e err,
- iotcon_presence_response_h response, void *user_data);
-
-/**
- * @brief Adds callback to a server to receive presence events.
- * @details Request to receive presence to an interested server's resource with @a resource_type.\n
- * If succeed to subscribe, iotcon_presence_cb() will be invoked when the server sends presence.\n
- * A server sends presence events when adds/removes/alters a resource or start/stop presence.\n
- * @a host_address could be #IOTCON_MULTICAST_ADDRESS for IPv4 multicast.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks The length of @a resource_type should be less than or equal to 61.\n
- * The @a resource_type must start with a lowercase alphabetic character, followed by a sequence
- * of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.\n
- * You must destroy @a presence by calling iotcon_unsubscribe_presence()
- * if @a presence is no longer needed.
- *
- * @param[in] host_address The address or addressable name of the server
- * @param[in] connectivity_type The connectivity type
- * @param[in] resource_type A resource type that a client has interested in
- * @param[in] cb The callback function to invoke
- * @param[in] user_data The user data to pass to the function
- * @param[out] presence_handle The generated presence handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @post When the resource receive presence, iotcon_presence_cb() will be called.
- *
- * @see iotcon_start_presence()
- * @see iotcon_stop_presence()
- * @see iotcon_remove_presence_cb()
- * @see iotcon_presence_cb()
- */
-int iotcon_add_presence_cb(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- const char *resource_type,
- iotcon_presence_cb cb,
- void *user_data,
- iotcon_presence_h *presence_handle);
-
-/**
- * @brief Removes callback to a server's presence events.
- * @details Request not to receive server's presence any more.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] presence_handle The presence handle to be unsubscribed
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_start_presence()
- * @see iotcon_stop_presence()
- * @see iotcon_add_presence_cb()
- * @see iotcon_presence_cb()
- */
-int iotcon_remove_presence_cb(iotcon_presence_h presence_handle);
-
-/**
- * @brief Gets host address from the presence handle
- *
- * @since_tizen 3.0
- *
- * @remarks @a host_address must not be released using free().
- *
- * @param[in] presence The handle of the presence
- * @param[out] host_address The host address of the presence
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_presence_get_connectivity_type()
- * @see iotcon_presence_get_resource_type()
- */
-int iotcon_presence_get_host_address(iotcon_presence_h presence, char **host_address);
-
-/**
- * @brief Gets connectivity type from the presence handle
- * @details The @a connectivity_type could be one of #iotcon_connectivity_type_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] presence The handle of the presence
- * @param[out] connectivity_type The connectivity type of the presence
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_presence_get_host_address()
- * @see iotcon_presence_get_resource_type()
- */
-int iotcon_presence_get_connectivity_type(iotcon_presence_h presence,
- iotcon_connectivity_type_e *connectivity_type);
-
-/**
- * @brief Gets resource type from the presence handle
- *
- * @since_tizen 3.0
- *
- * @remarks @a resource_type must not be released using free().
- *
- * @param[in] presence The handle of the presence
- * @param[out] resource_type The resource type of the presence
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_presence_get_host_address()
- * @see iotcon_presence_get_connectivity_type()
- */
-int iotcon_presence_get_resource_type(iotcon_presence_h presence,
- char **resource_type);
-
-/**
- * @brief Gets result from the presence response handle
- *
- * @details The @a result could be one of #iotcon_presence_result_e.
- * @since_tizen 3.0
- *
- * @param[in] response The handle of the presence response
- * @param[out] result The result code
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_presence_response_get_trigger()
- * @see iotcon_presence_response_get_host_address()
- * @see iotcon_presence_response_get_connectivity_type()
- * @see iotcon_presence_response_get_resource_type()
- */
-int iotcon_presence_response_get_result(iotcon_presence_response_h response,
- iotcon_presence_result_e *result);
-
-/**
- * @brief Gets trigger from the presence response handle
- *
- * @details The @a trigger could be one of #iotcon_presence_trigger_e.
- * It is set only if a response result is IOTCON_PRESENCE_OK.
- * @since_tizen 3.0
- *
- * @param[in] response The handle of the presence response
- * @param[out] trigger The presence trigger value.
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_presence_response_get_result()
- * @see iotcon_presence_response_get_host_address()
- * @see iotcon_presence_response_get_connectivity_type()
- * @see iotcon_presence_response_get_resource_type()
- */
-int iotcon_presence_response_get_trigger(iotcon_presence_response_h response,
- iotcon_presence_trigger_e *trigger);
-
-/**
- * @brief Gets host address from the presence response handle
- *
- * @since_tizen 3.0
- *
- * @remarks @a host_address must not be released using free().
- *
- * @param[in] response The handle of the presence response
- * @param[out] host_address The host address of the presence response
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_presence_response_get_result()
- * @see iotcon_presence_response_get_trigger()
- * @see iotcon_presence_response_get_connectivity_type()
- * @see iotcon_presence_response_get_resource_type()
- */
-int iotcon_presence_response_get_host_address(iotcon_presence_response_h response,
- char **host_address);
-
-/**
- * @brief Gets connectivity type from the presence response handle
- *
- * @details The @a connectivity_type could be one of #iotcon_connectivity_type_e.
- * @since_tizen 3.0
- *
- * @param[in] response The handle of the presence response
- * @param[out] connectivity_type The connectivity type of the presence response
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_presence_response_get_result()
- * @see iotcon_presence_response_get_trigger()
- * @see iotcon_presence_response_get_host_address()
- * @see iotcon_presence_response_get_resource_type()
- */
-int iotcon_presence_response_get_connectivity_type(iotcon_presence_response_h response,
- iotcon_connectivity_type_e *connectivity_type);
-
-/**
- * @brief Gets resource type from the presence response handle
- *
- * @since_tizen 3.0
- *
- * @remarks @a resource_type must not be released using free().
- *
- * @param[in] response The handle of the presence response
- * @param[out] resource_type The resource type of the presence response
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_presence_response_get_result()
- * @see iotcon_presence_response_get_trigger()
- * @see iotcon_presence_response_get_host_address()
- * @see iotcon_presence_response_get_connectivity_type()
- */
-int iotcon_presence_response_get_resource_type(iotcon_presence_response_h response,
- char **resource_type);
-
-/**
- * @brief Specifies the type of function passed to iotcon_find_resource().
- * @details Called when a resource is found from the remote server.
- * The @a result could be one of #iotcon_error_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of resource which is found
- * @param[in] result The result code (Lesser than 0 on fail, otherwise a response result value)
- * @param[in] user_data The user data to pass to the function
- *
- * @pre The callback must be registered using iotcon_find_resource()
- *
- * @see iotcon_find_resource()
- */
-typedef void (*iotcon_found_resource_cb)(iotcon_remote_resource_h resource,
- iotcon_error_e result, void *user_data);
-
-/**
- * @brief Finds resources, asynchronously.
- * @details Request to find a resource of @a host_address server with @a resource_type.\n
- * @a host_address could be #IOTCON_MULTICAST_ADDRESS for multicast.\n
- * If succeed to find the resource, iotcon_found_resource_cb() will be invoked with
- * information of the resource.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks The length of @a resource_type should be less than or equal to 61.\n
- * The @a resource_type must start with a lowercase alphabetic character, followed by a sequence
- * of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.\n
- *
- * @param[in] host_address The address or addressable name of server
- * @param[in] connectivity_type The connectivity type
- * @param[in] resource_type The resource type specified as a filter for the resource
- * @param[in] is_secure The flag for secure communication with the server
- * @param[in] cb The callback function to invoke
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @pre iotcon_connect() should be called to connect a connection to the iotcon.
- * @post iotcon_found_resource_cb() will be invoked.
- *
- * @see iotcon_found_resource_cb()
- * @see iotcon_set_timeout()
- */
-int iotcon_find_resource(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- const char *resource_type,
- bool is_secure,
- iotcon_found_resource_cb cb,
- void *user_data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_get_device_info().
- * @details The @a result could be one of #iotcon_error_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] device_info the device information from remote server.
- * @param[in] result The result code (0 on success, other wise a negative error value)
- * @param[in] user_data The user data to pass to the function
- *
- * @pre iotcon_get_device_info() will invoke this callback function.
- *
- * @see iotcon_get_device_info()
- * @see iotcon_device_info_get_property()
- */
-typedef void (*iotcon_device_info_cb)(iotcon_device_info_h device_info,
- iotcon_error_e result, void *user_data);
-
-/**
- * @brief Gets the device information of remote server, asynchronously.
- * @details Request device information to server and pass the information by calling
- * iotcon_device_info_cb().\n
- * @a host_address could be #IOTCON_MULTICAST_ADDRESS for multicast.\n
- * If succeed to getting device information, iotcon_device_info_cb() will be invoked with
- * information.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] host_address The host address of remote server
- * @param[in] connectivity_type The connectivity type
- * @param[in] cb The callback function to invoke
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @pre iotcon_connect() should be called to connect a connection to the iotcon.
- * @post iotcon_device_info_cb() will be invoked.
- *
- * @see iotcon_device_info_cb()
- * @see iotcon_device_info_get_property()
- * @see iotcon_set_timeout()
- */
-int iotcon_get_device_info(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- iotcon_device_info_cb cb,
- void *user_data);
-
-/**
- * @brief Gets device properties from the device information handle
- *
- * @since_tizen 3.0
- *
- * @remarks @a value must not be released using free().
- *
- * @param[in] device_info The handle of the device information
- * @param[in] property The properties of the device information
- * @param[out] value The value of the property
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_device_info_cb()
- * @see iotcon_get_device_info()
- */
-int iotcon_device_info_get_property(iotcon_device_info_h device_info,
- iotcon_device_info_e property, char **value);
-
-/**
- * @brief Specifies the type of function passed to iotcon_get_platform_info().
- * @details The @a result could be one of #iotcon_error_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] platform_info The platform information from remote server.
- * @param[in] result The result code (0 on success, other wise a negative error value)
- * @param[in] user_data The user data to pass to the function
- *
- * @pre iotcon_get_platform_info() will invoke this callback function.
- *
- * @see iotcon_get_platform_info()
- * @see iotcon_platform_info_get_property()
- */
-typedef void (*iotcon_platform_info_cb)(iotcon_platform_info_h platform_info,
- iotcon_error_e result, void *user_data);
-
-/**
- * @brief Gets the platform information of remote server, asynchronously.
- * @details Request platform information to server and pass the information by calling
- * iotcon_platform_info_cb().\n
- * @a host_address could be #IOTCON_MULTICAST_ADDRESS for multicast.\n
- * If succeed to getting platform information, iotcon_platform_info_cb() will be invoked
- * with information.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] host_address The host address of remote server
- * @param[in] connectivity_type The connectivity type
- * @param[in] cb The callback function to invoke
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- *
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @pre iotcon_connect() should be called to connect a connection to the iotcon.
- * @post iotcon_platform_info_cb() will be invoked.
- *
- * @see iotcon_platform_info_cb()
- * @see iotcon_platform_info_get_property()
- * @see iotcon_set_timeout()
- */
-int iotcon_get_platform_info(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- iotcon_platform_info_cb cb,
- void *user_data);
-
-/**
- * @brief Gets platform properties from the platform information handle
- *
- * @since_tizen 3.0
- *
- * @remarks @a value must not be released using free().
- *
- * @param[in] platform_info The handle of the platform information
- * @param[in] property The properties of the platform information
- * @param[out] value The value of the property
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_platform_info_cb()
- * @see iotcon_get_platform_info()
- */
-int iotcon_platform_info_get_property(iotcon_platform_info_h platform_info,
- iotcon_platform_info_e property, char **value);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_CLIENT_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
-#define __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-constant.h
- */
-
-/**
- * @addtogroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
- *
- * @{
- */
-
-/**
- * @brief The IP Address for multicast.
- *
- * @since_tizen 3.0
- */
-#define IOTCON_MULTICAST_ADDRESS NULL /**< Multicast Address */
-
-/**
- * @brief Use this value as the return value to stop foreach function.
- *
- * @since_tizen 3.0
- */
-#define IOTCON_FUNC_STOP false
-
-/**
- * @brief Use this value as the return value to continue foreach function.
- *
- * @since_tizen 3.0
- */
-#define IOTCON_FUNC_CONTINUE true
-
-/**
- * @brief Default Interface
- *
- * @since_tizen 3.0
- */
-#define IOTCON_INTERFACE_DEFAULT "oic.if.baseline"
-
-/**
- * @brief List Links Interface which is used to list the references to other resources contained in a resource
- *
- * @since_tizen 3.0
- */
-#define IOTCON_INTERFACE_LINK "oic.if.ll"
-
-/**
- * @brief Batch Interface which is used to manipulate (GET, PUT, POST, DELETE) on other resource contained in a resource
- *
- * @since_tizen 3.0
- */
-#define IOTCON_INTERFACE_BATCH "oic.if.b"
-
-/**
- * @brief Group Interface which is used to manipulate (GET, PUT, POST) a group of remote resources
- *
- * @since_tizen 3.0
- */
-#define IOTCON_INTERFACE_GROUP "oic.mi.grp"
-
-/**
- * @brief Read-Only Interface which is used to limit the methods that can be applied to a resource to GET only
- *
- * @since_tizen 3.0
- */
-#define IOTCON_INTERFACE_READONLY "oic.if.r"
-
-/**
- * @brief Enumeration for type of observation.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_OBSERVE_NO_TYPE = 0, /**< Indicates no option */
- IOTCON_OBSERVE_REGISTER = 1, /**< Indicates action of registering observation*/
- IOTCON_OBSERVE_DEREGISTER = 2, /**< Indicates action of unregistering observation */
-} iotcon_observe_type_e;
-
-/**
- * @brief Enumeration for policy of observation.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER = 0, /**< Indicates observation request for most up-to-date notifications only */
- IOTCON_OBSERVE_ACCEPT_OUT_OF_ORDER = 1 /**< Indicates observation request for all notifications including stale notifications */
-} iotcon_observe_policy_e;
-
-/**
- * @brief Enumeration for of connectivities which can be held in a resource.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_CONNECTIVITY_IPV4 = 0, /**< Indicates Internet Protocol version 4 connectivity */
- IOTCON_CONNECTIVITY_IPV6, /**< Indicates Internet Protocol version 6 connectivity */
- IOTCON_CONNECTIVITY_BT_EDR, /**< Indicates Bluetooth Enhanced Data Rate connectivity */
- IOTCON_CONNECTIVITY_BT_LE, /**< Indicates Bluetooth Low Energy connectivity */
- IOTCON_CONNECTIVITY_ALL, /**< Indicates all connectivities */
-} iotcon_connectivity_type_e;
-
-/**
- * @brief Enumeration for property which can be held in a resource.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_RESOURCE_NO_PROPERTY = 0, /**< Indicates resource uninitialized */
- IOTCON_RESOURCE_DISCOVERABLE = (1 << 0), /**< Indicates resource that is allowed to be discovered */
- IOTCON_RESOURCE_OBSERVABLE = (1 << 1), /**< Indicates resource that is allowed to be observed */
- IOTCON_RESOURCE_ACTIVE = (1 << 2), /**< Indicates resource initialized and activated */
- IOTCON_RESOURCE_SLOW = (1 << 3), /**< Indicates resource which takes some delay to respond */
- IOTCON_RESOURCE_SECURE = (1 << 4), /**< Indicates secure resource */
- IOTCON_RESOURCE_EXPLICIT_DISCOVERABLE = (1 << 5), /**< When this bit is set, the resource is allowed to be discovered only if discovery request contains an explicit querystring. */
-} iotcon_resource_property_e;
-
-/**
- * @brief Enumeration for type of request.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_REQUEST_UNKNOWN = 0, /**< Indicates none */
- IOTCON_REQUEST_GET = 1, /**< Indicates get method of request */
- IOTCON_REQUEST_PUT = 2, /**< Indicates put method of request */
- IOTCON_REQUEST_POST = 3, /**< Indicates post method of request */
- IOTCON_REQUEST_DELETE = 4, /**< Indicates delete method of request */
-} iotcon_request_type_e;
-
-/**
- * @brief Enumeration for result of response.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_RESPONSE_OK = 0, /**< Indicates result of response for success */
- IOTCON_RESPONSE_ERROR, /**< Indicates result of response for something error */
- IOTCON_RESPONSE_RESOURCE_CREATED, /**< Indicates result of response for resource has created */
- IOTCON_RESPONSE_RESOURCE_DELETED, /**< Indicates result of response for resource has deleted */
- IOTCON_RESPONSE_SLOW, /**< Indicates result of response for slow resource */
- IOTCON_RESPONSE_FORBIDDEN, /**< Indicates result of response for accessing unauthorized resource */
-} iotcon_response_result_e;
-
-/**
- * @brief Enumeration for result of presence.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_PRESENCE_OK = 0, /**< Indicates for successful action of presence */
- IOTCON_PRESENCE_STOPPED, /**< Indicates for stopped action of presence */
- IOTCON_PRESENCE_TIMEOUT, /**< Indicates for no response of presence for some time */
-} iotcon_presence_result_e;
-
-/**
- * @brief Enumeration for operation of presence response.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_PRESENCE_RESOURCE_CREATED, /**< Indicates for resource creation operation of server */
- IOTCON_PRESENCE_RESOURCE_UPDATED, /**< Indicates for resource update operation of server */
- IOTCON_PRESENCE_RESOURCE_DESTROYED, /**< Indicates for resource destruction operation of server */
-} iotcon_presence_trigger_e;
-
-/**
- * @brief Enumeration for types of representation that is able to have.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_TYPE_NONE = 0, /**< Indicates for representation that have no type */
- IOTCON_TYPE_INT, /**< Indicates for representation that have int type */
- IOTCON_TYPE_BOOL, /**< Indicates for representation that have bool type */
- IOTCON_TYPE_DOUBLE, /**< Indicates for representation that have double type */
- IOTCON_TYPE_STR, /**< Indicates for representation that have string type */
- IOTCON_TYPE_BYTE_STR, /**< Indicates for representation that have byte string type */
- IOTCON_TYPE_NULL, /**< Indicates for representation that have null type */
- IOTCON_TYPE_LIST, /**< Indicates for representation that have list type */
- IOTCON_TYPE_STATE, /**< Indicates for representation that have another representation type */
-} iotcon_type_e;
-
-/**
- * @brief Enumeration for properties of device information.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_DEVICE_INFO_NAME = 0, /**< Indicates human friendly name for device */
- IOTCON_DEVICE_INFO_SPEC_VER, /**< Indicates spec version of the core specification */
- IOTCON_DEVICE_INFO_ID, /**< Indicates unique identifier for OIC device */
- IOTCON_DEVICE_INFO_DATA_MODEL_VER, /**< Indicates version of the specs this device data model is implemented to */
-} iotcon_device_info_e;
-
-/**
- * @brief Enumeration for properties of platform information.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_PLATFORM_INFO_ID = 0, /**< Indicates platform identifier */
- IOTCON_PLATFORM_INFO_MANUF_NAME, /**< Indicates name of manufacturer */
- IOTCON_PLATFORM_INFO_MANUF_URL, /**< Indicates URL to manufacturer */
- IOTCON_PLATFORM_INFO_MODEL_NUMBER, /**< Indicates model number as designated by manufacturer */
- IOTCON_PLATFORM_INFO_DATE_OF_MANUF, /**< Indicates manufacturing date of device */
- IOTCON_PLATFORM_INFO_PLATFORM_VER, /**< Indicates version of platform defined by manufacturer */
- IOTCON_PLATFORM_INFO_OS_VER, /**< Indicates version of platform resident OS */
- IOTCON_PLATFORM_INFO_HARDWARE_VER, /**< Indicates version of platform hardware */
- IOTCON_PLATFORM_INFO_FIRMWARE_VER, /**< Indicates version of device firmware */
- IOTCON_PLATFORM_INFO_SUPPORT_URL, /**< Indicates URL that points to support information from manufacturer */
- IOTCON_PLATFORM_INFO_SYSTEM_TIME, /**< Indicates reference time for the device */
-} iotcon_platform_info_e;
-
-/**
- * @brief Enumeration for states of remote resource.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_REMOTE_RESOURCE_ALIVE, /**< Indicates remote resource is alive */
- IOTCON_REMOTE_RESOURCE_LOST_SIGNAL, /**< Indicates remote resource is lost */
-} iotcon_remote_resource_state_e;
-
-/**
- * @brief Enumeration for quality of service.
- *
- * @since_tizen 3.0
- */
-typedef enum {
- IOTCON_QOS_LOW, /**< Indicates low quality of service */
- IOTCON_QOS_HIGH, /**< Indicates high quality of service */
-} iotcon_qos_e;
-
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_CONSTANT_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_ERRORS_H__
-#define __IOT_CONNECTIVITY_MANAGER_ERRORS_H__
-
-#include <tizen.h>
-
-#ifndef TZ_VER_3
-#define TIZEN_ERROR_IOTCON -0x01C80000
-#endif
-
-/**
- * @file iotcon-errors.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
- * @brief Enumeration for Iotcon error code.
- * @since_tizen 3.0
- *
- * @{
- */
-typedef enum
-{
- IOTCON_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
- IOTCON_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
- IOTCON_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
- IOTCON_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
- IOTCON_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
- IOTCON_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
- IOTCON_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data available */
- IOTCON_ERROR_TIMEOUT = TIZEN_ERROR_TIMED_OUT, /**< Time out */
- IOTCON_ERROR_IOTIVITY = TIZEN_ERROR_IOTCON | 0x01, /**< Iotivity errors */
- IOTCON_ERROR_REPRESENTATION = TIZEN_ERROR_IOTCON | 0x02, /**< Representation errors */
- IOTCON_ERROR_INVALID_TYPE = TIZEN_ERROR_IOTCON | 0x03, /**< Invalid type */
- IOTCON_ERROR_ALREADY = TIZEN_ERROR_IOTCON | 0x04, /**< Already */
- IOTCON_ERROR_DBUS = TIZEN_ERROR_IOTCON | 0x05, /**< D-Bus errors */
- IOTCON_ERROR_SYSTEM = TIZEN_ERROR_IOTCON | 0x06, /**< System errors */
-}iotcon_error_e;
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_ERRORS_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__
-#define __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file iotcon-internal.h
- */
-
-/**
- * @brief Starts presence of a server.
- * @details Use this function to send server's announcements to clients.\n
- * Server can call this function when online for the first time or come back from offline to online.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks If @a time_to_live is 0, server will set default value as 60 seconds.\n
- * If @a time_to_live is very big, server will set maximum value as (60 * 60 * 24) seconds.
- * (24 hours)
- *
- * @param[in] time_to_live The interval of announcing presence in seconds.
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_stop_presence()
- * @see iotcon_add_presence_cb()
- * @see iotcon_remove_presence_cb()
- */
-int iotcon_start_presence(unsigned int time_to_live);
-
-/**
- * @brief Stops presence of a server.
- * @details Use this function to stop sending server's announcements to clients.
- * Server can call this function when terminating, entering to offline or out of network.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_start_presence()
- * @see iotcon_add_presence_cb()
- * @see iotcon_remove_presence_cb()
- */
-int iotcon_stop_presence(void);
-
-/**
- * @brief Gets the time interval of monitoring & caching API of remote resource.
- * @details This API get the time interval of iotcon_remote_resource_start_monitoring(),
- * and iotcon_remote_resource_start_caching().\n
- * The functions operate GET method, every saved time interval.
- * Default time interval is 10 seconds.
- *
- * @since_tizen 3.0
- *
- * @param[out] time_interval Seconds for time interval
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_set_time_interval()
- * @see iotcon_remote_resource_start_monitoring()
- * @see iotcon_remote_resource_start_caching()
- */
-int iotcon_remote_resource_get_time_interval(int *time_interval);
-
-/**
- * @brief Sets the time interval of monitoring & caching API of remote resource.
- * @details This API set the time interval of iotcon_remote_resource_start_monitoring(),
- * and iotcon_remote_resource_start_caching().
- *
- * @since_tizen 3.0
- *
- * @param[in] time_interval Seconds for time interval (must be in range from 1 to 3600)
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_time_interval()
- * @see iotcon_remote_resource_start_monitoring()
- * @see iotcon_remote_resource_start_caching()
- */
-int iotcon_remote_resource_set_time_interval(int time_interval);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_INTERNAL_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_LIST_H__
-#define __IOT_CONNECTIVITY_MANAGER_STRUCT_LIST_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-list.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE List
- *
- * @brief Iotcon List provides API to get data from list and set data to list.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_OVERVIEW Overview
- * The iotcon list API provides list of bool, integer, double, string, byte string, list and state handle.
- *
- * Example :
- * @code
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret;
- iot types;
-
- ret = iotcon_request_get_types(request, &types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_REQUEST_GET & types) {
- iotcon_response_h response = NULL;
- iotcon_representation_h representation = NULL;
- iotcon_state_h state = NULL;
- iotcon_list_h list = NULL;
-
- ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_representation_create(&representation);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ...
-
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_list_create(IOTCON_TYPE_INT, &list);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_list_add_int(list, 1);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(list);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_list_add_int(list, 2);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(list);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_list_add_int(list, 10);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(list);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = itocon_state_set_list(state, "ids", list);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(list);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_representation_set_state(representation, state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(list);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ...
-
- ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT,
- representation);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(list);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(list);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- iotcon_list_destroy(list);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- }
- ...
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new list handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a list by calling iotcon_list_destroy()
- * if @a list is no longer needed.
- *
- * @param[in] type The type of list
- * @param[out] list A newly allocated list handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_list_create(iotcon_type_e type, iotcon_list_h *list);
-
-/**
- * @brief Destroys a list handle.
- * @details Releases a @a list and its internal data.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the list
- *
- * @return void
- */
-void iotcon_list_destroy(iotcon_list_h list);
-
-/**
- * @brief Adds a new element integer value into the list at the given position.
- * @details If @a pos is negative, or is larger than the number of elements in the list,
- * the new value is added on to the end of the list.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] val The new integer value
- * @param[in] pos The position to insert value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_list_add_int(iotcon_list_h list, int val, int pos);
-
-/**
- * @brief Adds a new element boolean value into the list at the given position.
- * @details If @a pos is negative, or is larger than the number of elements in the list,
- * the new value is added on to the end of the list.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] val The new boolean value
- * @param[in] pos The position to insert value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_list_add_bool(iotcon_list_h list, bool val, int pos);
-
-/**
- * @brief Adds a new element double value into the list at the given position.
- * @details If @a pos is negative, or is larger than the number of elements in the list,
- * the new value is added on to the end of the list.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] val The new double value
- * @param[in] pos The position to insert value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_list_add_double(iotcon_list_h list, double val, int pos);
-
-/**
- * @brief Adds a new element string value into the list at the given position.
- * @details If @a pos is negative, or is larger than the number of elements in the list,
- * the new value is added on to the end of the list.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] val The new char value
- * @param[in] pos The position to insert value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_list_add_str(iotcon_list_h list, char *val, int pos);
-
-/**
- * @brief Adds a new element byte string value into the list at the given position.
- * @details If @a pos is negative, or is larger than the number of elements in the list,
- * the new value is added on to the end of the list.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] val The new byte string value
- * @param[in] len The length of @a val
- * @param[in] pos The position to insert value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_list_add_byte_str(iotcon_list_h list, unsigned char *val, int len, int pos);
-
-/**
- * @brief Adds a new element list into the list at the given position.
- * @details If @a pos is negative, or is larger than the number of elements in the list,
- * the new value is added on to the end of the list.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] val The new list value
- * @param[in] pos The position to insert value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_list_add_list(iotcon_list_h list, iotcon_list_h val, int pos);
-
-/**
- * @brief Adds a new element state value into the list at the given position.
- * @details If @a pos is negative, or is larger than the number of elements in the list,
- * the new value is added on to the end of the list.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] val The new state value
- * @param[in] pos The position to insert value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_list_add_state(iotcon_list_h list, iotcon_state_h val, int pos);
-
-/**
- * @brief Gets the integer value at the given position.
- * @details Iterates over the list until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] pos The position
- * @param[out] val The integer value to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_REPRESENTATION Representation errors
- */
-int iotcon_list_get_nth_int(iotcon_list_h list, int pos, int *val);
-
-/**
- * @brief Gets the boolean value at the given position.
- * @details Iterates over the list until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] pos The position
- * @param[out] val The boolean value to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_REPRESENTATION Representation errors
- */
-int iotcon_list_get_nth_bool(iotcon_list_h list, int pos, bool *val);
-
-/**
- * @brief Gets the double value at the given position.
- * @details Iterates over the list until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] pos The position
- * @param[out] val The double value to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_REPRESENTATION Representation errors
- */
-int iotcon_list_get_nth_double(iotcon_list_h list, int pos, double *val);
-
-/**
- * @brief Gets the string value at the given position.
- * @details Iterates over the list until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @remarks @a val must not be released using free().
- *
- * @param[in] list The list handle
- * @param[in] pos The position
- * @param[out] val The string value to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_REPRESENTATION Representation errors
- */
-int iotcon_list_get_nth_str(iotcon_list_h list, int pos, char **val);
-
-/**
- * @brief Gets the string value at the given position.
- * @details Iterates over the list until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @remarks @a val must not be released using free().
- *
- * @param[in] list The list handle
- * @param[in] pos The position
- * @param[out] val The byte string value to get
- * @param[out] len The length of the @a val
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_REPRESENTATION Representation errors
- */
-int iotcon_list_get_nth_byte_str(iotcon_list_h list, int pos, unsigned char **val,
- int *len);
-
-/**
- * @brief Gets the list value at the given position.
- * @details Iterates over the list until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @remarks @a dest must not be released using iotcon_list_destroy().
- *
- * @param[in] src The list handle
- * @param[in] pos The position
- * @param[out] dest The list value to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_REPRESENTATION Representation errors
- */
-int iotcon_list_get_nth_list(iotcon_list_h src, int pos, iotcon_list_h *dest);
-
-/**
- * @brief Gets the state value at the given position.
- * @details Iterates over the list until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @remarks @a state must not be released using iotcon_state_destroy().
- *
- * @param[in] list The list handle
- * @param[in] pos The position
- * @param[out] state The state value to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_REPRESENTATION Representation errors
- */
-int iotcon_list_get_nth_state(iotcon_list_h list, int pos, iotcon_state_h *state);
-
-/**
- * @brief Removes the value at the given position.
- * @details Iterates over the list until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[in] pos The position to delete
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- */
-int iotcon_list_remove_nth(iotcon_list_h list, int pos);
-
-/**
- * @brief Gets the type of the list.
- * @details It gets the data type of value related the @a key in @a state.
- * The data type could be one of #iotcon_type_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The list handle
- * @param[out] type The data type of list.
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_list_get_type(iotcon_list_h list, iotcon_type_e *type);
-
-/**
- * @brief Gets the number of elements in a list.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the list
- * @param[out] length The length of list
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_list_get_length(iotcon_list_h list, unsigned int *length);
-
-/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_int()
- *
- * @since_tizen 3.0
- *
- * @param[in] pos The number of the integer value (0 being the first)
- * @param[in] value The integer value
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_list_foreach_int() will invoke this callback function.
- *
- * @see iotcon_list_foreach_int()
- */
-typedef bool (*iotcon_list_int_cb)(int pos, int value, void *user_data);
-
-/**
- * @brief Gets all integer values of the given list by invoking the callback function.
- * @details iotcon_list_int_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the list
- * @param[in] cb The callback function to get each integer value
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_list_int_cb() will be called for each item.
- *
- * @see iotcon_list_int_cb()
- */
-int iotcon_list_foreach_int(iotcon_list_h list, iotcon_list_int_cb cb, void *user_data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_bool()
- *
- * @since_tizen 3.0
- *
- * @param[in] pos The number of the boolean value (0 being the first)
- * @param[in] value The boolean value
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_list_foreach_bool() will invoke this callback function.
- *
- * @see iotcon_list_foreach_bool()
- */
-typedef bool (*iotcon_list_bool_cb)(int pos, bool value, void *user_data);
-
-/**
- * @brief Gets all boolean values of the given list by invoking the callback function.
- * @details iotcon_list_bool_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the list
- * @param[in] cb The callback function to get each boolean value
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_list_bool_cb() will be called for each item.
- *
- * @see iotcon_list_bool_cb()
- */
-int iotcon_list_foreach_bool(iotcon_list_h list, iotcon_list_bool_cb cb, void *user_data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_double()
- *
- * @since_tizen 3.0
- *
- * @param[in] pos The number of the double value (0 being the first)
- * @param[in] value The double value
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_list_foreach_double() will invoke this callback function.
- *
- * @see iotcon_list_foreach_double()
- */
-typedef bool (*iotcon_list_double_cb)(int pos, double value, void *user_data);
-
-/**
- * @brief Gets all double values of the given list by invoking the callback function.
- * @details iotcon_list_double_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the list
- * @param[in] cb The callback function to get each double value
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_list_double_cb() will be called for each item.
- *
- * @see iotcon_list_double_cb()
- */
-int iotcon_list_foreach_double(iotcon_list_h list, iotcon_list_double_cb cb,
- void *user_data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_byte_str()
- *
- * @since_tizen 3.0
- *
- * @param[in] pos The number of the string value (0 being the first)
- * @param[in] value The byte string value
- * @param[in] len The length of @a value
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_list_foreach_byte_str() will invoke this callback function.
- *
- * @see iotcon_list_foreach_byte_str()
- */
-typedef bool (*iotcon_list_byte_str_cb)(int pos, const unsigned char *value, int len,
- void *user_data);
-
-/**
- * @brief Gets all string values of the given list by invoking the callback function.
- * @details iotcon_list_byte_str_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the list
- * @param[in] cb The callback function to get each string value
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_list_byte_str_cb() will be called for each item.
- *
- * @see iotcon_list_byte_str_cb()
- */
-int iotcon_list_foreach_byte_str(iotcon_list_h list, iotcon_list_byte_str_cb cb,
- void *user_data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_str()
- *
- * @since_tizen 3.0
- *
- * @param[in] pos The number of the string value (0 being the first)
- * @param[in] value The string value
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_list_foreach_str() will invoke this callback function.
- *
- * @see iotcon_list_foreach_str()
- */
-typedef bool (*iotcon_list_str_cb)(int pos, const char *value, void *user_data);
-
-/**
- * @brief Gets all string values of the given list by invoking the callback function.
- * @details iotcon_list_str_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the list
- * @param[in] cb The callback function to get each string value
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_list_str_cb() will be called for each item.
- *
- * @see iotcon_list_str_cb()
- */
-int iotcon_list_foreach_str(iotcon_list_h list, iotcon_list_str_cb cb, void *user_data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_list()
- *
- * @since_tizen 3.0
- *
- * @param[in] pos The number of the list value (0 being the first)
- * @param[in] value The list value
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_list_foreach_list() will invoke this callback function.
- *
- * @see iotcon_list_foreach_list()
- */
-typedef bool (*iotcon_list_list_cb)(int pos, iotcon_list_h value, void *user_data);
-
-/**
- * @brief Gets all sub lists of the given list by invoking the callback function.
- * @details iotcon_list_list_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the origin list
- * @param[in] cb The callback function to get each sub list
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_list_list_cb() will be called for each item.
- *
- * @see iotcon_list_list_cb()
- */
-int iotcon_list_foreach_list(iotcon_list_h list, iotcon_list_list_cb cb, void *user_data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_list_foreach_state()
- *
- * @since_tizen 3.0
- *
- * @param[in] pos The number of the state value (0 being the first)
- * @param[in] value The state value
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_list_foreach_state() will invoke this callback function.
- *
- * @see iotcon_list_foreach_state()
- */
-typedef bool (*iotcon_list_state_cb)(int pos, iotcon_state_h value, void *user_data);
-
-/**
- * @brief Gets all state of the given list by invoking the callback function.
- * @details iotcon_list_state_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] list The handle to the list
- * @param[in] cb The callback function to get each state
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_list_state_cb() will be called for each item.
- *
- * @see iotcon_list_state_cb()
- */
-int iotcon_list_foreach_state(iotcon_list_h list, iotcon_list_state_cb cb, void *user_data);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_LIST_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_SERVER_LITE_RESOURCE_H__
-#define __IOT_CONNECTIVITY_MANAGER_SERVER_LITE_RESOURCE_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-lite-resource.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_SERVER_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_SERVER_LITE_RESOURCE_MODULE Lite Resource
- *
- * @brief Iotcon Lite Resource provides API to encapsulate resources.
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_LITE_RESOURCE_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_LITE_RESOURCE_MODULE_OVERVIEW Overview
- * This API provides that the users manages resources without request handler.
- * When client request by CRUD functions, internal default request handler will be invoked.
- * The default request handler will create response and send to client automatically.
- * When updated state by iotcon_lite_update_state(), changes will notify to observers.
- *
- * Example :
- * @code
-#include <iotcon.h>
-...
-static iotcon_lite_resource_h _resource;
-
-static bool _state_changed_cb(iotcon_lite_resource_h resource, iotcon_state_h state, void *user_data)
-{
- return true;
-}
-
-static void _create_light_resource()
-{
- int ret;
- iotcon_lite_resource_h resource = NULL;
- iotcon_resource_types_h resource_types = NULL;
- iotcon_state_h state = NULL;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_resource_types_add(resource_types, "org.tizen.light");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_state_add_bool(state, "power", true);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_state_add_int(state, "brightness", 75);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_lite_resource_create("/light/1", resource_types,
- IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, state,
- _state_changed_cb, NULL, &resource);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- iotcon_state_destroy(state);
- iotcon_resource_types_destroy(resource_types);
-
- _resource = resource;
-}
-
-static void _update_brightness(int brightness)
-{
- int ret;
- iotcon_state_h state = NULL;
- iotcon_state_h state_clone = NULL;
-
- ret = iotcon_lite_resource_get_state(_resource, &state);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_state_clone(state, &state_clone);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_state_add_int(state_clone, "brightness", brightness);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state_clone);
- return;
- }
-
- ret = iotcon_lite_resource_update_state(_resource, state_clone);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state_clone);
- return;
- }
-
- iotcon_state_destroy(state_clone);
-}
-
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_LITE_RESOURCE_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Specifies the type of function passed to iotcon_lite_resource_create().
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the lite resource
- * @param[in] state The state of the lite resource
- * @param[in] user_data The user data to pass to the function
- *
- * @pre The callback must be registered using iotcon_lite_resource_create()
- *
- * @return true to accept post request, otherwise false to reject it.
- *
- * @see iotcon_lite_resource_create()
- */
-typedef bool (*iotcon_lite_resource_post_request_cb)(iotcon_lite_resource_h resource,
- iotcon_state_h state, void *user_data);
-
-
-/**
- * @brief Creates a lite resource handle and registers the resource in server
- * @details Registers a resource specified by @a uri_path, @a res_types, @a state which have
- * @a properties in Iotcon server.\n
- * When client requests some operations, it send a response to client, automatically.\n
- * The @a properties can contain multiple properties like
- * IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks @a uri_path length must be less than or equal 36.\n
- * You must destroy @a resource_handle by calling iotcon_lite_resource_destroy()
- * if @a remote_handle is no longer needed.
- *
- * @param[in] uri_path The URI path of the resource
- * @param[in] res_types The list of type of the resource
- * @param[in] properties The property of the resource\n Set of #iotcon_resource_property_e
- * @param[in] state The state handle to set
- * @param[in] cb The callback function to add into callback list
- * @param[in] user_data The user data to pass to the callback function
- * @param[out] resource_handle The handle of the resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_lite_resource_destroy()
- */
-int iotcon_lite_resource_create(const char *uri_path,
- iotcon_resource_types_h res_types,
- int properties,
- iotcon_state_h state,
- iotcon_lite_resource_post_request_cb cb,
- void *user_data,
- iotcon_lite_resource_h *resource_handle);
-
-/**
- * @brief Destroys the resource and releases its data.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks When a normal variable is used, there are only dbus error and permission\n
- * denied error. If the errors of this API are not handled, then you must check\n
- * whether dbus is running and an application have the privileges for the API.
- *
- * @param[in] resource The handle of the lite resource to be unregistered
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_lite_resource_create()
- */
-int iotcon_lite_resource_destroy(iotcon_lite_resource_h resource);
-
-/**
- * @brief Updates state into the lite resource handle
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the lite resource
- * @param[in] state The state handle to update
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_lite_resource_get_state()
- */
-int iotcon_lite_resource_update_state(iotcon_lite_resource_h resource,
- iotcon_state_h state);
-
-/**
- * @brief Gets state from the lite resource handle
- *
- * @since_tizen 3.0
- *
- * @remarks @a state must not be released using iotcon_state_destroy().
- *
- * @param[in] resource The handle of the lite resource
- * @param[out] state The state handle of the lite resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_lite_resource_update_state()
- */
-int iotcon_lite_resource_get_state(iotcon_lite_resource_h resource,
- iotcon_state_h *state);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_SERVER_LITE_RESOURCE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_SERVER_OBSERVERS_H__
-#define __IOT_CONNECTIVITY_MANAGER_SERVER_OBSERVERS_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-observers.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_SERVER_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_SERVER_OBSERVERS_MODULE Observers
- *
- * @brief Iotcon Observers provides API to manage client observing a resource.
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_OBSERVERS_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_OBSERVERS_MODULE_OVERVIEW Overview
- * The iotcon overview API provides methods for managing oberve id.
- *
- * Example :
- * @code
-#include <iotcon.h>
-static iotcon_observers_h _observers;
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret, observe_id;
- iotcon_request_type_e types;
- iotcon_observe_type_e observe_type;
- iotcon_representation_h repr = NULL;
-
- ...
- ret = iotcon_request_get_types(request, &types);
- if (IOTCON_ERROR_NONE != ret)
- return;
- ...
-
- if (IOTCON_REQUEST_PUT & types) {
- iotcon_state_h state = NULL;
- iotcon_representation_h repr = NULL;
- ...
-
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(repr);
- return;
- }
- ...
- ret = iotcon_resource_notify(resource, repr, _observers, IOTCON_QOS_HIGH);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return;
- }
-
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- }
-
- ret = iotcon_request_get_observe_type(request, &observe_type);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_OBSERVE_REGISTER == observe_type) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (NULL == _observers) {
- ret = iotcon_observers_create(&_observers);
- if (IOTCON_ERROR_NONE != ret)
- return;
- }
- ret = iotcon_observers_add(_observers, observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
- ...
- } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (NULL == _observers)
- return;
-
- ret = iotcon_observers_remove(_observers, observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
- ...
- }
- ...
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_OBSERVERS_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new observers handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a observers by calling iotcon_observers_destroy()
- * if @a observers is no longer needed.
- *
- * @param[out] observers A newly allocated list of observers handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_observers_destroy()
- * @see iotcon_observers_add()
- * @see iotcon_observers_remove()
- */
-int iotcon_observers_create(iotcon_observers_h *observers);
-
-/**
- * @brief Destroys a observers handle.
- *
- * @since_tizen 3.0
- *
- * @param[in] observers The handle of the observers
- *
- * @return void
- *
- * @see iotcon_observers_create()
- * @see iotcon_observers_add()
- * @see iotcon_observers_remove()
- */
-void iotcon_observers_destroy(iotcon_observers_h observers);
-
-/**
- * @brief Adds a observer id into the observers handle
- *
- * @since_tizen 3.0
- *
- * @param[in] observers The handle of the observers
- * @param[in] obs_id The id to be appended to observers
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_observers_create()
- * @see iotcon_observers_destroy()
- * @see iotcon_observers_remove()
- */
-int iotcon_observers_add(iotcon_observers_h observers, int obs_id);
-
-/**
- * @brief Removes id from the observers.
- *
- * @since_tizen 3.0
- *
- * @param[in] observers observers The handle of the observers
- * @param[in] obs_id The id to be removed from observers
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_observers_create()
- * @see iotcon_observers_destroy()
- * @see iotcon_observers_add()
- */
-int iotcon_observers_remove(iotcon_observers_h observers, int obs_id);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_SERVER_OBSERVERS_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_OPTIONS_H__
-#define __IOT_CONNECTIVITY_MANAGER_STRUCT_OPTIONS_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-options.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE Options
- *
- * @brief Iotcon Options provides API to manage options.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE_OVERVIEW Overview
- * The iotcon options API provides methods for managing vendor specific options of coap packet.\n
- * See more about coap packet in http://tools.ietf.org/html/rfc7252.
- *
- * Example (Client side) :
- * @code
-#include <iotcon.h>
-...
-static void _request_get_with_option(iotcon_remote_resource_h resource)
-{
- int i;
- int ret;
- unsigned short opt_id = 3000;
- const char *opt_val = "12345";
- iotcon_options_h options = NULL;
-
- ..
- ret = iotcon_options_create(&options);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_options_add(options, opt_id, opt_val);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_options_destroy(options);
- return;
- }
-
- ret = iotcon_remote_resource_set_options(resource, options);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_options_destroy(options);
- return;
- }
-
- ret = iotcon_remote_resource_get(resource, NULL, _on_get, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_options_destroy(options);
- return;
- }
-
- iotcon_options_destroy(options);
- ...
-}
- * @endcode
- *
- * Example (Server side) :
- * @code
-#include <iotcon.h>
-...
-static bool _options_foreach(unsigned short id, const char *data, void *user_data)
-{
- // handle options
- return IOTCON_FUNC_CONTINUE;
-}
-
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret;
- iotcon_options_h options;
-
- ret = iotcon_request_get_options(request, &options);
- if (IOTCON_ERROR_NONE == ret && options) {
- ret = iotcon_options_foreach(options, _options_foreach, NULL);
- if (IOTCON_ERROR_NONE != ret)
- return;
- }
- ...
-}
-
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new option handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a options by calling iotcon_options_destroy()
- * if @a options is no longer needed.
- *
- * @param[out] options A newly allocated option handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_options_destroy()
- * @see iotcon_options_add()
- * @see iotcon_options_remove()
- * @see iotcon_options_lookup()
- */
-int iotcon_options_create(iotcon_options_h *options);
-
-/**
- * @brief Destroys an option handle.
- *
- * @since_tizen 3.0
- *
- * @param[in] options The handle of the options
- *
- * @return void
- *
- * @see iotcon_options_create()
- * @see iotcon_options_add()
- * @see iotcon_options_remove()
- * @see iotcon_options_lookup()
- */
-void iotcon_options_destroy(iotcon_options_h options);
-
-/**
- * @brief Adds a new id and a correspoding data into the options.
- *
- * @since_tizen 3.0
- * @remarks iotcon_options_h can have up to 2 options. \n
- * option id is always situated between 2048 and 3000. \n
- * Length of option data is less than or equal to 15.
- *
- * @param[in] options The handle of the options
- * @param[in] id The id of the option to insert
- * @param[in] data The string data to insert into the options
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_options_create()
- * @see iotcon_options_destroy()
- * @see iotcon_options_remove()
- * @see iotcon_options_lookup()
- */
-int iotcon_options_add(iotcon_options_h options, unsigned short id,
- const char *data);
-
-/**
- * @brief Removes the id and its associated data from the options.
- *
- * @since_tizen 3.0
- *
- * @param[in] options The handle of the options
- * @param[in] id The id of the option to delete
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_options_create()
- * @see iotcon_options_destroy()
- * @see iotcon_options_add()
- * @see iotcon_options_lookup()
- */
-int iotcon_options_remove(iotcon_options_h options, unsigned short id);
-
-/**
- * @brief Looks up data at the given id from the options.
- *
- * @since_tizen 3.0
- *
- * @remarks @a data must not be released using free().
- *
- * @param[in] options The handle of the options
- * @param[in] id The id of the option to lookup
- * @param[out] data Found data from options
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_options_create()
- * @see iotcon_options_destroy()
- * @see iotcon_options_add()
- * @see iotcon_options_remove()
- */
-int iotcon_options_lookup(iotcon_options_h options, unsigned short id, char **data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_options_foreach()
- *
- * @since_tizen 3.0
- *
- * @param[in] id The information of the option
- * @param[in] data The data of the option
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_options_foreach() will invoke this callback function.
- *
- * @see iotcon_options_foreach()
- */
-typedef bool (*iotcon_options_foreach_cb)(unsigned short id, const char *data,
- void *user_data);
-
-/**
- * @brief Gets all datas of the options by invoking the callback function.
- * @details iotcon_options_foreach_cb() will be called for each option.\n
- * If iotcon_options_foreach_cb() returns false, iteration will be stop.
- *
- * @since_tizen 3.0
- *
- * @param[in] options The handle of the options
- * @param[in] cb The callback function to get data
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_options_foreach_cb() will be called for each option.
- *
- * @see iotcon_options_foreach_cb()
- */
-int iotcon_options_foreach(iotcon_options_h options, iotcon_options_foreach_cb cb,
- void *user_data);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_OPTIONS_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_QUERY_H__
-#define __IOT_CONNECTIVITY_MANAGER_STRUCT_QUERY_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-query.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE Query
- *
- * @brief Iotcon Query provides API to manage query.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE_OVERVIEW Overview
- * The iotcon query API provides methods for managing query of request.
- *
- * Example (Client side) :
- * @code
-#include <iotcon.h>
-...
-static void _request_get(iotcon_remote_resource_h resource)
-{
- int ret;
- iotcon_query_h query = NULL;
-
- ret = iotcon_query_create(&query);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_query_add(query, "key", "value");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_query_destroy(query);
- return;
- }
-
- ret = iotcon_remote_resource_get(resource, query, _on_get, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_query_destroy(query);
- return;
- }
-
- iotcon_query_destroy(query);
-}
- * @endcode
- *
- * Example (Server side) :
- * @code
-#include <iotcon.h>
-...
-static bool _query_foreach(const char *key, const char *value, void *user_data)
-{
- // handle query
- return IOTCON_FUNC_CONTINUE;
-}
-
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret;
- iotcon_query_h query = NULL;
-
- ret = iotcon_request_get_query(request, &query);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_ERROR_NONE == ret && query) {
- ret = iotcon_query_foreach(query, _query_foreach, NULL);
- if (IOTCON_ERROR_NONE != ret)
- return;
- }
- ...
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new query handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a query by calling iotcon_query_destroy()
- * if @a query is no longer needed.
- *
- * @param[out] query A newly allocated query handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_query_destroy()
- * @see iotcon_query_add()
- * @see iotcon_query_remove()
- * @see iotcon_query_lookup()
- */
-int iotcon_query_create(iotcon_query_h *query);
-
-/**
- * @brief Destroys a query handle.
- *
- * @since_tizen 3.0
- *
- * @param[in] query The handle of the query
- *
- * @return void
- *
- * @see iotcon_query_create()
- * @see iotcon_query_add()
- * @see iotcon_query_remove()
- * @see iotcon_query_lookup()
- */
-void iotcon_query_destroy(iotcon_query_h query);
-
-/**
- * @brief Gets resource type from the query.
- *
- * @since_tizen 3.0
- *
- * @remarks @a type must not be released using free().
- *
- * @param[in] query The handle of the query
- * @param[out] resource_type Found resource type from query
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_query_create()
- * @see iotcon_query_destroy()
- * @see iotcon_query_add()
- * @see iotcon_query_remove()
- * @see iotcon_query_set_resource_type()
- */
-int iotcon_query_get_resource_type(iotcon_query_h query, char **resource_type);
-
-/**
- * @brief Gets resource interface from the query.
- *
- * @since_tizen 3.0
- *
- * @remarks @a resource_iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
- * @remarks @a resource_iface must not be released using free().
- *
- * @param[in] query The handle of the query
- * @param[out] resource_iface Found resource interface from query
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- *
- * @see iotcon_query_create()
- * @see iotcon_query_destroy()
- * @see iotcon_query_add()
- * @see iotcon_query_remove()
- * @see iotcon_query_set_interface()
- */
-int iotcon_query_get_interface(iotcon_query_h query, char **resource_iface);
-
-/**
- * @brief Sets the resource type into the query.
- *
- * @since_tizen 3.0
- *
- * @param[in] query The handle of the query
- * @param[in] resource_type The resoure type to set into the query
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_query_create()
- * @see iotcon_query_destroy()
- * @see iotcon_query_add()
- * @see iotcon_query_remove()
- * @see iotcon_query_lookup()
- * @see iotcon_query_get_resource_type()
- */
-int iotcon_query_set_resource_type(iotcon_query_h query, const char *resource_type);
-
-/**
- * @brief Sets the resource interface into the query.
- *
- * @since_tizen 3.0
- *
- * @remarks @a resource_iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
- *
- * @param[in] query The handle of the query
- * @param[in] resource_iface The resource interface to add into the query
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_query_create()
- * @see iotcon_query_destroy()
- * @see iotcon_query_add()
- * @see iotcon_query_remove()
- * @see iotcon_query_lookup()
- * @see iotcon_query_get_interface()
- */
-int iotcon_query_set_interface(iotcon_query_h query, const char *resource_iface);
-
-/**
- * @brief Adds a new key and correspoding value into the query.
- *
- * @since_tizen 3.0
- * @remarks The full length of query should be less than or equal to 64.
- *
- * @param[in] query The handle of the query
- * @param[in] key The key of the query to insert
- * @param[in] value The string data to insert into the query
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_query_create()
- * @see iotcon_query_destroy()
- * @see iotcon_query_remove()
- * @see iotcon_query_lookup()
- */
-int iotcon_query_add(iotcon_query_h query, const char *key, const char *value);
-
-/**
- * @brief Removes the key and its associated value from the query.
- *
- * @since_tizen 3.0
- *
- * @param[in] query The handle of the query
- * @param[in] key The key of the option to delete
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_query_create()
- * @see iotcon_query_destroy()
- * @see iotcon_query_add()
- * @see iotcon_query_lookup()
- */
-int iotcon_query_remove(iotcon_query_h query, const char *key);
-
-/**
- * @brief Looks up data at the given key from the query.
- *
- * @since_tizen 3.0
- *
- * @remarks @a data must not be released using free().
- *
- * @param[in] query The handle of the query
- * @param[in] key The key of the query to lookup
- * @param[out] data Found data from query
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_query_create()
- * @see iotcon_query_destroy()
- * @see iotcon_query_add()
- * @see iotcon_query_remove()
- */
-int iotcon_query_lookup(iotcon_query_h query, const char *key, char **data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_query_foreach()
- *
- * @since_tizen 3.0
- *
- * @param[in] key The key of the query
- * @param[in] value The value of the query
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_query_foreach() will invoke this callback function.
- *
- * @see iotcon_query_foreach()
- */
-typedef bool (*iotcon_query_foreach_cb)(const char *key, const char *value,
- void *user_data);
-
-/**
- * @brief Gets all datas of the query by invoking the callback function.
- * @details iotcon_query_foreach_cb() will be called for each query.\n
- * If iotcon_query_foreach_cb() returns false, iteration will be stop.
- *
- * @since_tizen 3.0
- *
- * @param[in] query The handle of the query
- * @param[in] cb The callback function to get data
- * @param[in] user_data The user data to be passed to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_query_foreach_cb() will be called for each query.
- *
- * @see iotcon_query_foreach_cb()
- */
-int iotcon_query_foreach(iotcon_query_h query, iotcon_query_foreach_cb cb,
- void *user_data);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_QUERY_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_CLIENT_REMOTE_RESOURCE_H__
-#define __IOT_CONNECTIVITY_MANAGER_CLIENT_REMOTE_RESOURCE_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-remote-resource.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_CLIENT_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_CLIENT_REMOTE_RESOURCE_MODULE Remote Resource
- *
- * @brief Iotcon Remote Resource provides API to manage remote resource.
- *
- * @section CAPI_IOT_CONNECTIVITY_CLIENT_REMOTE_RESOURCE_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_CLIENT_REMOTE_RESOURCE_MODULE_OVERVIEW Overview
- * The iotcon remote resource API provides methods for managing resource handle and send request.
- *
- * Example :
- * @code
-#include <iotcon.h>
-...
-static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err,
- iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
-{
- if (IOTCON_ERROR_NONE != err)
- return;
-
- // handle get result
- ...
-}
-
-static void _on_find(iotcon_remote_resource_h resource, iotcon_error_e result,
- void *user_data)
-{
- int ret;
- iotcon_remote_resource_h resource_clone = NULL;
-
- if (IOTCON_ERROR_NONE != result)
- return;
-
- if (NULL == resource)
- return;
-
- // clone handle
- ret = iotcon_remote_resource_clone(resource, &resource_clone);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- // request get
- ret = iotcon_remote_resource_get(resource_clone, NULL, _on_get, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_remote_resource_destroy(resource_clone);
- return;
- }
-
- ...
-}
-
-static void _find_light_resource()
-{
- int ret;
-
- ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
- "org.tizen.light", false, _on_find, NULL);
- if (IOTCON_ERROR_NONE != ret)
- return;
-}
-
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_CLIENT_REMOTE_RESOURCE_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new resource handle.
- * @details Creates a resource proxy object so that iotcon_remote_resource_get(),
- * iotcon_remote_resource_put(), iotcon_remote_resource_post(),
- * iotcon_remote_resource_delete(), iotcon_remote_resource_observe_register(),
- * iotcon_remote_resource_start_caching() and iotcon_remote_resource_start_monitoring()
- * API can be used without discovering the object in advance.\n
- * To use this API, you should provide all of the details required to correctly contact and
- * observe the object.\n
- * If not, you should discover the resource object manually.\n
- * The @a properties can contain multiple properties like
- * IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.\n
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a remote_resource by calling iotcon_remote_resource_destroy()
- * if @a remote_resource is no longer needed.
- *
- * @param[in] host_address The host address of the resource
- * @param[in] connectivity_type The connectivity type
- * @param[in] uri_path The URI path of the resource
- * @param[in] properties The properties of the resource\n Set of #iotcon_resource_property_e
- * @param[in] resource_types The resource types of the resource. For example, "core.light"
- * @param[in] resource_ifaces The resource interfaces of the resource.
- * @param[out] remote_resource Generated resource handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_remote_resource_destroy()
- * @see iotcon_remote_resource_clone()
- */
-int iotcon_remote_resource_create(const char *host_address,
- iotcon_connectivity_type_e connectivity_type,
- const char *uri_path,
- int properties,
- iotcon_resource_types_h resource_types,
- iotcon_resource_interfaces_h resource_ifaces,
- iotcon_remote_resource_h *remote_resource);
-
-/**
- * @brief Destroys a resource handle.
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the resource
- *
- * @return void
- *
- * @see iotcon_remote_resource_create()
- * @see iotcon_remote_resource_clone()
- */
-void iotcon_remote_resource_destroy(iotcon_remote_resource_h resource);
-
-/**
- * @brief Clones a clone of a remote resource.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a dest by calling iotcon_remote_resource_destroy()
- * if @a dest is no longer needed.
- *
- * @param[in] src The Source of resource
- * @param[out] dest The cloned resource handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_create()
- * @see iotcon_remote_resource_destroy()
- */
-int iotcon_remote_resource_clone(iotcon_remote_resource_h src, iotcon_remote_resource_h *dest);
-
-/**
- * @brief Specifies the type of observe callback passed to iotcon_remote_resource_observe_register().
- * The @a err could be one of #iotcon_error_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the remote resource
- * @param[in] err The error code
- * @param[in] sequence_number The sequence number of observe
- * @param[in] response The handle of the response
- * @param[in] user_data The user data passed from the callback registration function
- *
- * @pre The callback must be registered using iotcon_remote_resource_observe_register()
- *
- * @see iotcon_remote_resource_observe_register()
- * @see iotcon_remote_resource_observe_deregister()
- * @see iotcon_resource_notify()
- */
-typedef void (*iotcon_remote_resource_observe_cb)(iotcon_remote_resource_h resource,
- iotcon_error_e err, int sequence_number, iotcon_response_h response, void *user_data);
-
-/**
- * @brief Registers observe callback on the resource
- * @details When server sends notification message, iotcon_remote_resource_observe_cb() will be called.
- * The @a observe_policy could be one of #iotcon_observe_policy_e.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the resource
- * @param[in] observe_policy The type to specify how client wants to observe.
- * @param[in] query The query to send to server
- * @param[in] cb The callback function to get notifications from server
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @post When the @a resource receive notification message, iotcon_remote_resource_observe_cb() will be called.
- *
- * @see iotcon_remote_resource_observe_cb()
- * @see iotcon_remote_resource_observe_deregister()
- * @see iotcon_resource_notify()
- */
-int iotcon_remote_resource_observe_register(iotcon_remote_resource_h resource,
- iotcon_observe_policy_e observe_policy,
- iotcon_query_h query,
- iotcon_remote_resource_observe_cb cb,
- void *user_data);
-
-/**
- * @brief Deregisters observe callback on the resource
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_remote_resource_observe_cb()
- * @see iotcon_remote_resource_observe_register()
- * @see iotcon_resource_notify()
- */
-int iotcon_remote_resource_observe_deregister(iotcon_remote_resource_h resource);
-
-/**
- * @brief Specifies the type of response function.
- * @details The function passed to iotcon_remote_resource_get(), iotcon_remote_resource_put(),
- * iotcon_remote_resource_post(), iotcon_remote_resource_delete().
- * The @a err could be one of #iotcon_error_e.
- * The @a request_type could be one of #iotcon_request_type_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the resource
- * @param[in] err The error code
- * @param[in] request_type The request type
- * @param[in] response The handle of the response
- * @param[in] user_data The user data passed from the callback registration function
- *
- * @pre The callback must be registered using iotcon_remote_resource_get(),
- * iotcon_remote_resource_put(), iotcon_remote_resource_post(), iotcon_remote_resource_delete()
- *
- * @see iotcon_remote_resource_get()
- * @see iotcon_remote_resource_put()
- * @see iotcon_remote_resource_post()
- * @see iotcon_remote_resource_delete()
- */
-typedef void (*iotcon_remote_resource_response_cb)(iotcon_remote_resource_h resource,
- iotcon_error_e err,
- iotcon_request_type_e request_type,
- iotcon_response_h response,
- void *user_data);
-
-/**
- * @brief Gets the attributes of a resource, asynchronously.
- * @details When server sends response on get request, iotcon_remote_resource_response_cb() will be called.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the resource
- * @param[in] query The query to send to server
- * @param[in] cb The callback function
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @post When the client receive get response, iotcon_remote_resource_response_cb() will be called.
- *
- * @see iotcon_remote_resource_response_cb()
- * @see iotcon_set_timeout()
- */
-int iotcon_remote_resource_get(iotcon_remote_resource_h resource, iotcon_query_h query,
- iotcon_remote_resource_response_cb cb, void *user_data);
-
-/**
- * @brief Puts the representation of a resource, asynchronously.
- * @details When server sends response on put request, iotcon_remote_resource_response_cb() will be called.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the resource
- * @param[in] repr The handle of the representation
- * @param[in] query The query to send to server
- * @param[in] cb The callback function
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @post When the client receive put response, iotcon_remote_resource_response_cb() will be called.
- *
- * @see iotcon_remote_resource_response_cb()
- * @see iotcon_set_timeout()
- */
-int iotcon_remote_resource_put(iotcon_remote_resource_h resource,
- iotcon_representation_h repr,
- iotcon_query_h query,
- iotcon_remote_resource_response_cb cb,
- void *user_data);
-
-/**
- * @brief Posts on a resource, asynchronously.
- * @details When server sends response on post request, iotcon_remote_resource_response_cb() will be called.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the resource
- * @param[in] repr The handle of the representation
- * @param[in] query The query to send to server
- * @param[in] cb The callback function
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @post When the client receive post response, iotcon_remote_resource_response_cb() will be called.
- *
- * @see iotcon_remote_resource_response_cb()
- * @see iotcon_set_timeout()
- */
-int iotcon_remote_resource_post(iotcon_remote_resource_h resource,
- iotcon_representation_h repr,
- iotcon_query_h query,
- iotcon_remote_resource_response_cb cb,
- void *user_data);
-
-/**
- * @brief Deletes a resource, asynchronously.
- * @details When server sends response on delete request, iotcon_remote_resource_response_cb() will be called.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the resource
- * @param[in] cb The callback function
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @post When the client receive delete response, iotcon_remote_resource_response_cb() will be called.
- *
- * @see iotcon_remote_resource_response_cb()
- * @see iotcon_set_timeout()
- */
-int iotcon_remote_resource_delete(iotcon_remote_resource_h resource,
- iotcon_remote_resource_response_cb cb, void *user_data);
-
-/**
- * @brief Specifies the type of function passed to iotcon_remote_resource_start_caching().
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the remote resource
- * @param[in] representation The handle of the representation
- * @param[in] user_data The user data to pass to the function
- *
- * @pre The callback must be registered using iotcon_remote_resource_start_caching()
- *
- * @see iotcon_remote_resource_start_caching()
- * @see iotcon_remote_resource_stop_caching()
- */
-typedef void (*iotcon_remote_resource_cached_representation_changed_cb)(
- iotcon_remote_resource_h resource,
- iotcon_representation_h representation,
- void *user_data);
-
-/**
- * @brief Starts caching of a remote resource.
- * @details Use this function to start caching the resource's attribute.\n
- * Although, remote resource is not observable, it keeps the representation up-to-date.
- * Because It checks whether representation is changed, periodically.\n
- * The default checking interval is 10 seconds, but it may be changed by an administrator.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the remote resource to be cached
- * @param[in] cb The callback function to add into callback list
- * @param[in] user_data The user data to pass to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_ALREADY Already done
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_remote_resource_stop_caching()
- * @see iotcon_remote_resource_cached_representation_changed_cb()
- */
-int iotcon_remote_resource_start_caching(iotcon_remote_resource_h resource,
- iotcon_remote_resource_cached_representation_changed_cb cb, void *user_data);
-
-/**
- * @brief Stops caching of a remote resource.
- * @details Use this function to stop caching the resource's attribute.\n
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the remote resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_remote_resource_start_caching()
- * @see iotcon_remote_resource_cached_representation_changed_cb()
- */
-int iotcon_remote_resource_stop_caching(iotcon_remote_resource_h resource);
-
-/**
- * @brief Specifies the type of function passed to iotcon_remote_resource_start_monitoring().
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the remote resource
- * @param[in] state The state of the remote resource
- * @param[in] user_data The user data to pass to the function
- *
- * @pre The callback must be registered using iotcon_remote_resource_start_monitoring()
- *
- * @see iotcon_remote_resource_start_monitoring()
- * @see iotcon_remote_resource_stop_monitoring()
- */
-typedef void (*iotcon_remote_resource_state_changed_cb)(iotcon_remote_resource_h resource,
- iotcon_remote_resource_state_e state, void *user_data);
-
-/**
- * @brief Starts monitoring of a remote resource.
- * @details When remote resource's state are changed, registered callbacks will be called
- * in turn. Although, remote resource does not call iotcon_start_presence(), it knows
- * the state of resource. Because it checks the state of resource, periodically.\n
- * The default checking interval is 10 seconds, but it may be changed by an administrator.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the remote resource
- * @param[in] cb The callback function to add into callback list
- * @param[in] user_data The user data to pass to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_ALREADY Already done
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_remote_resource_stop_monitoring()
- * @see iotcon_remote_resource_state_changed_cb()
- */
-int iotcon_remote_resource_start_monitoring(iotcon_remote_resource_h resource,
- iotcon_remote_resource_state_changed_cb cb, void *user_data);
-
-/**
- * @brief Stops monitoring of a remote resource.
- * @details Use this function to stop monitoring the remote resource.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the remote resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_remote_resource_start_monitoring()
- * @see iotcon_remote_resource_state_changed_cb()
- */
-int iotcon_remote_resource_stop_monitoring(iotcon_remote_resource_h resource);
-
-/**
- * @brief Gets an URI path of the remote resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a uri_path must not be released using free().
- *
- * @param[in] resource The handle of the remote resource
- * @param[out] uri_path The URI path of the remote resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_host_address()
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_device_id()
- * @see iotcon_remote_resource_get_types()
- * @see iotcon_remote_resource_get_interfaces()
- * @see iotcon_remote_resource_get_properties()
- * @see iotcon_remote_resource_set_options()
- */
-int iotcon_remote_resource_get_uri_path(iotcon_remote_resource_h resource,
- char **uri_path);
-
-/**
- * @brief Gets connectivity type of the remote resource
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the remote resource
- * @param[out] connectivity_type The connectivity type of the remote resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
-
- * @see iotcon_remote_resource_get_uri_path()
- * @see iotcon_remote_resource_get_host_address()
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_device_id()
- * @see iotcon_remote_resource_get_types()
- * @see iotcon_remote_resource_get_interfaces()
- * @see iotcon_remote_resource_get_properties()
- * @see iotcon_remote_resource_set_options()
- */
-int iotcon_remote_resource_get_connectivity_type(iotcon_remote_resource_h resource,
- iotcon_connectivity_type_e *connectivity_type);
-
-/**
- * @brief Gets an host address of the remote resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a host_address must not be released using free().
- *
- * @param[in] resource The handle of the remote resource
- * @param[out] host_address The host address of the remote resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_uri_path()
- * @see iotcon_remote_resource_get_device_id()
- * @see iotcon_remote_resource_get_types()
- * @see iotcon_remote_resource_get_interfaces()
- * @see iotcon_remote_resource_get_properties()
- * @see iotcon_remote_resource_set_options()
- */
-int iotcon_remote_resource_get_host_address(iotcon_remote_resource_h resource,
- char **host_address);
-
-/**
- * @brief Gets an device id of the remote resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a device_id must not be released using free().
- *
- * @param[in] resource The handle of the remote resource
- * @param[out] device_id The device id of the remote resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_uri_path()
- * @see iotcon_remote_resource_get_host_address()
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_types()
- * @see iotcon_remote_resource_get_interfaces()
- * @see iotcon_remote_resource_get_properties()
- * @see iotcon_remote_resource_set_options()
- */
-int iotcon_remote_resource_get_device_id(iotcon_remote_resource_h resource,
- char **device_id);
-
-/**
- * @brief Gets resource types of the remote resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a types must not be released using iotcon_resource_types_destroy().
- *
- * @param[in] resource The handle of the remote resource
- * @param[out] types The resource types of the remote resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_uri_path()
- * @see iotcon_remote_resource_get_host_address()
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_device_id()
- * @see iotcon_remote_resource_get_interfaces()
- * @see iotcon_remote_resource_get_properties()
- * @see iotcon_remote_resource_set_options()
- */
-int iotcon_remote_resource_get_types(iotcon_remote_resource_h resource,
- iotcon_resource_types_h *types);
-
-/**
- * @brief Gets resource interfaces of the remote resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
- *
- * @param[in] resource The handle of the remote resource
- * @param[out] ifaces The resource interfaces of the remote resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_uri_path()
- * @see iotcon_remote_resource_get_host_address()
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_device_id()
- * @see iotcon_remote_resource_get_types()
- * @see iotcon_remote_resource_get_properties()
- * @see iotcon_remote_resource_set_options()
- */
-int iotcon_remote_resource_get_interfaces(iotcon_remote_resource_h resource,
- iotcon_resource_interfaces_h *ifaces);
-
-/**
- * @brief Checks whether the remote resource is observable or not.
- *
- * @details The @a properties can contain multiple properties like
- * IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the resource
- * @param[out] properties The Properties of the resource\n Set of #iotcon_resource_property_e
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_uri_path()
- * @see iotcon_remote_resource_get_host_address()
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_device_id()
- * @see iotcon_remote_resource_get_types()
- * @see iotcon_remote_resource_get_interfaces()
- * @see iotcon_remote_resource_set_options()
- */
-int iotcon_remote_resource_get_properties(iotcon_remote_resource_h resource,
- int *properties);
-
-
-/**
- * @brief Gets options of the remote resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a options must not be released using iotcon_options_destroy().
- *
- * @param[in] resource The handle of the remote resource
- * @param[out] options The handle of the header options
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_uri_path()
- * @see iotcon_remote_resource_get_host_address()
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_device_id()
- * @see iotcon_remote_resource_get_types()
- * @see iotcon_remote_resource_get_interfaces()
- * @see iotcon_remote_resource_set_options()
- * @see iotcon_remote_resource_get_properties()
- */
-int iotcon_remote_resource_get_options(iotcon_remote_resource_h resource,
- iotcon_options_h *options);
-
-/**
- * @brief Sets options into the remote resource
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the remote resource
- * @param[in] options The handle of the header options
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_remote_resource_get_uri_path()
- * @see iotcon_remote_resource_get_host_address()
- * @see iotcon_remote_resource_get_connectivity_type()
- * @see iotcon_remote_resource_get_device_id()
- * @see iotcon_remote_resource_get_types()
- * @see iotcon_remote_resource_get_interfaces()
- * @see iotcon_remote_resource_get_options()
- * @see iotcon_remote_resource_get_properties()
- */
-int iotcon_remote_resource_set_options(iotcon_remote_resource_h resource,
- iotcon_options_h options);
-
-/**
- * @brief Gets cached representation from the remote resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a representation must not be released using iotcon_representation_destroy().
- *
- * @param[in] resource The handle of the remote resource
- * @param[out] representation The handle of the representation
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data
- */
-int iotcon_remote_resource_get_cached_representation(
- iotcon_remote_resource_h resource,
- iotcon_representation_h *representation);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_CLIENT_REMOTE_RESOURCE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_REPRESENTATION_H__
-#define __IOT_CONNECTIVITY_MANAGER_STRUCT_REPRESENTATION_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-representation.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE Representation
- *
- * @brief Iotcon Representation provides API to manage representation
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE_OVERVIEW Overview
- * The Iotcon Representation API provides data type of resp_repr handling.\n
- * A resp_repr is a payload of a request or a response.\n
- * It has uri_path, list of resource interfaces, list of resource types and its attributes.\n
- * Attributes have capabilties to store and retrieve integer, boolean, double, string,
- * byte string, list, null, resp_repr.\n
- * A list is a container that includes number of datas of same type.\n
- * It has capabilties to store and retrieve integer, boolean, double, string, byte string,
- * list, null, resp_repr.
- *
- * Example :
- *@code
-#include <iotcon.h>
-...
-{
- int ret;
- iotcon_representation_h repr;
- iotcon_resource_types_h types;
- iotcon_list_h bright_step_list;
-
- ret = iotcon_representation_create(&resp_repr);
- if (IOTCON_ERROR_NONE != ret) {
- return;
- }
-
- ret = iotcon_representation_set_uri_path(resp_repr, "/a/light");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_resource_types_create(&types);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_resource_types_add(types, "core.light");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_representation_set_resource_types(resp_repr, types);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_representation_set_resource_interfaces(resp_repr, IOTCON_INTERFACE_LINK);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_state_add_str(resp_repr, "type", "lamp");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_state_add_str(resp_repr, "where", "desk");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_state_add_double(resp_repr, "default_bright", 200.0);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_state_add_str(resp_repr, "unit", "lux");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_state_add_bool(resp_repr, "bright_step", true);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_list_create(IOTCON_TYPE_DOUBLE, &bright_step_list);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_list_add_double(bright_step_list, 100.0, -1);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(bright_step_list);
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_list_add_double(bright_step_list, 200.0, -1);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(bright_step_list);
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_list_add_double(bright_step_list, 300.0, -1);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(bright_step_list);
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_list_add_double(bright_step_list, 400.0, -1);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(bright_step_list);
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_list_add_double(bright_step_list, 500.0, -1);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(bright_step_list);
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- ret = iotcon_state_add_list(resp_repr, "bright_step_list", bright_step_list);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_list_destroy(bright_step_list);
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
- return;
- }
-
- iotcon_list_destroy(bright_step_list);
- iotcon_resource_types_destroy(types);
- iotcon_representation_destroy(resp_repr);
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new representation handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a repr by calling iotcon_representation_destroy()
- * if @a repr is no longer needed.
- *
- * @param[out] repr A newly allocated representation handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_representation_destroy()
- */
-int iotcon_representation_create(iotcon_representation_h *repr);
-
-/**
- * @brief Destroys a representation.
- * @details Releases a @a representation and its internal data.
- *
- * @since_tizen 3.0
- *
- * @param[in] repr The representation handle to free
- *
- * @return void
- *
- * @see iotcon_representation_create()
- */
-void iotcon_representation_destroy(iotcon_representation_h repr);
-
-/**
- * @brief Clones from the source representation.
- * @details Makes a deep copy of a source representation.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a dest by calling iotcon_representation_destroy()
- * if @a dest is no longer needed.
- *
- * @param[in] src Source of representation to be copied
- * @param[out] dest Clone of a source representation
- *
- * @return Clone of a source representation, otherwise NULL on failure
- * @retval iotcon_representation_h Success
- * @retval NULL Failure
- */
-int iotcon_representation_clone(const iotcon_representation_h src,
- iotcon_representation_h *dest);
-
-/**
- * @brief Appends resource type name.
- *
- * @since_tizen 3.0
- * @remarks Stored string is replaced with @a uri_path. If @a uri_path is NULL, stored string
- * is set by NULL.
- *
- * @param[in] repr The handle to the Representation
- * @param[in] uri_path The URI of resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_set_uri_path(iotcon_representation_h repr,
- const char *uri_path);
-
-/**
- * @brief Gets an URI path from the representation.
- *
- * @since_tizen 3.0
- *
- * @remarks @a uri_path must not be released using free().
- *
- * @param[in] repr The representation handle
- * @param[out] uri_path The URI path to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_get_uri_path(iotcon_representation_h repr, char **uri_path);
-
-/**
- * @brief Sets resource type list to the Representation.
- *
- * @since_tizen 3.0
- * @remarks Stored list is replaced with @a types. If @a types is NULL, stored list is set
- * by NULL.
- * @param[in] repr The handle to the Representation
- * @param[in] types The resource type list
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_set_resource_types(iotcon_representation_h repr,
- iotcon_resource_types_h types);
-
-/**
- * @brief Gets list of resource type from the representation.
- *
- * @since_tizen 3.0
- *
- * @remarks @a types must not be released using iotcon_resource_types_destroy().
- *
- * @param[in] repr The representation handle
- * @param[out] types The list of resource types to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_get_resource_types(iotcon_representation_h repr,
- iotcon_resource_types_h *types);
-
-/**
- * @brief Sets list of resource interfaces to the representation.
- *
- * @since_tizen 3.0
- *
- * @remarks Stored list is replaced with @a ifaces. If @a ifaces is NULL, stored list is set
- * by NULL.
- *
- * @param[in] repr The representation handle
- * @param[in] ifaces The list of resource interfaces
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_set_resource_interfaces(iotcon_representation_h repr,
- iotcon_resource_interfaces_h ifaces);
-
-/**
- * @brief Gets list of resource interfaces from the representation.
- *
- * @since_tizen 3.0
- *
- * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
- *
- * @param[in] repr The representation handle
- * @param[out] ifaces The list of resource interfaces to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_get_resource_interfaces(iotcon_representation_h repr,
- iotcon_resource_interfaces_h *ifaces);
-
-/**
- * @brief Sets a new state handle into the representation.
- *
- * @since_tizen 3.0
- *
- * @param[in] repr The representation handle
- * @param[in] state The state handle to set newly
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_set_state(iotcon_representation_h repr, iotcon_state_h state);
-
-/**
- * @brief Gets a state handle in the representation.
- *
- * @since_tizen 3.0
- *
- * @remarks @a state must not be released using iotcon_state_destroy().
- *
- * @param[in] repr The representation handle
- * @param[in] state The state handle to get
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_get_state(iotcon_representation_h repr, iotcon_state_h *state);
-
-/**
- * @brief Adds a new child representation on to the end of the parent representation
- * @details Duplicated child representation is allowed to append.
- *
- * @since_tizen 3.0
- *
- * @param[in] parent The parent representation handle
- * @param[in] child The child representation handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_add_child(iotcon_representation_h parent,
- iotcon_representation_h child);
-
-/**
- * @brief Removes a child representation from parent representation without freeing.
- *
- * @since_tizen 3.0
- *
- * @param[in] parent The parent representation handle
- * @param[in] child The child representation handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_remove_child(iotcon_representation_h parent,
- iotcon_representation_h child);
-
-/**
- * @brief Specifies the type of function passed to iotcon_representation_foreach_children()
- *
- * @since_tizen 3.0
- *
- * @param[in] child The child representation handle
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_representation_foreach_children() will invoke this callback function.
- *
- * @see iotcon_representation_foreach_children()
- *
- */
-typedef bool (*iotcon_children_cb)(iotcon_representation_h child, void *user_data);
-
-/**
- * @brief Calls a function for each children representation of parent.
- * @details iotcon_children_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] parent The parent representation handle
- * @param[in] cb The callback function to invoke
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_children_cb() will be called for each child.
- *
- * @see iotcon_children_cb()
- */
-int iotcon_representation_foreach_children(iotcon_representation_h parent,
- iotcon_children_cb cb, void *user_data);
-
-/**
- * @brief Gets the number of children representation in the parent representation
- *
- * @since_tizen 3.0
- *
- * @param[in] parent The parent representation handle
- * @param[out] count The number of children representation
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_representation_get_children_count(iotcon_representation_h parent,
- unsigned int *count);
-
-/**
- * @brief Gets the child representation at the given position.
- * @details Iterates over the parent until it reaches the @a pos-1 position.
- *
- * @since_tizen 3.0
- *
- * @remarks @a child must not be released using iotcon_representation_destroy().
- *
- * @param[in] parent The parent representation handle
- * @param[in] pos The position of the child representation
- * @param[out] child The handle to the child representation
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- */
-int iotcon_representation_get_nth_child(iotcon_representation_h parent, int pos,
- iotcon_representation_h *child);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_REPRESENTATION_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_SERVER_REQUEST_H__
-#define __IOT_CONNECTIVITY_MANAGER_SERVER_REQUEST_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-request.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_SERVER_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_SERVER_REQUEST_MODULE Request
- *
- * @brief Iotcon Request provides API to manage client's request.
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_REQUEST_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_REQUEST_MODULE_OVERVIEW Overview
- * The iotcon request API provides methods for managing request handle.
- *
- * Example :
- * @code
-#include <iotcon.h>
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret, observe_id;
- iotcon_request_type_e types;
- iotcon_observe_type_e observe_type;
- iotcon_options_h options = NULL;
- iotcon_query_h query = NULL;
- iotcon_representation_h repr = NULL;
-
- ret = iotcon_request_get_options(request, &options);
- if (IOTCON_ERROR_NONE == ret && options) {
- // handle options
- ...
- }
-
- ret = iotcon_request_get_query(request, &query);
- if (IOTCON_ERROR_NONE == ret && query) {
- // handle query
- ...
- }
-
- ret = iotcon_request_get_types(request, &types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_REQUEST_GET & types) {
- // handle get
- ...
- }
- if (IOTCON_REQUEST_PUT & types) {
- // handle put
- ret = iotcon_request_get_representation(request, &repr);
- if (IOTCON_ERROR_NONE != ret)
- return;
- ...
- }
- if (IOTCON_REQUEST_POST & types) {
- // handle post
- ret = iotcon_request_get_representation(request, &repr);
- if (IOTCON_ERROR_NONE != ret)
- return;
- ...
- }
- if (IOTCON_REQUEST_DELETE & types) {
- // handle delete
- ret = iotcon_request_get_representation(request, &repr);
- if (IOTCON_ERROR_NONE != ret)
- return;
- ...
- }
-
- ret = iotcon_request_get_observe_type(request, &observe_type);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_OBSERVE_REGISTER == observe_type) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
- // handle register observe
- ...
- } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret)
- return;
- // handle deregister observe
- ...
- }
- ...
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_REQUEST_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Gets host address of the request
- *
- * @since_tizen 3.0
- *
- * @remarks @a host_address must not be released using free().
- *
- * @param[in] request The handle of the request
- * @param[out] host_address The host address of the request
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_request_get_connectivity_type()
- * @see iotcon_request_get_representation()
- * @see iotcon_request_get_request_type()
- * @see iotcon_request_get_options()
- * @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_type()
- * @see iotcon_request_get_observe_id()
- */
-int iotcon_request_get_host_address(iotcon_request_h request,
- char **host_address);
-
-/**
- * @brief Gets connectivity type of the request
- *
- * @since_tizen 3.0
- *
- * @param[in] request The handle of the request
- * @param[out] connectivity_type The connectivity type of the request
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_request_get_host_address()
- * @see iotcon_request_get_representation()
- * @see iotcon_request_get_request_type()
- * @see iotcon_request_get_options()
- * @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_type()
- * @see iotcon_request_get_observe_id()
- */
-int iotcon_request_get_connectivity_type(iotcon_request_h request,
- iotcon_connectivity_type_e *connectivity_type);
-
-/**
- * @brief Gets an representation of the request
- *
- * @since_tizen 3.0
- *
- * @remarks @a repr must not be released using iotcon_representation_destroy().
- *
- * @param[in] request The handle of the request
- * @param[out] repr The representation of the request
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_request_get_host_address()
- * @see iotcon_request_get_connectivity_type()
- * @see iotcon_request_get_request_type()
- * @see iotcon_request_get_options()
- * @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_type()
- * @see iotcon_request_get_observe_id()
- */
-int iotcon_request_get_representation(iotcon_request_h request,
- iotcon_representation_h *repr);
-
-/**
- * @brief Gets type of the request
- * @details @a type could be one of the #iotcon_request_type_e
- *
- * @since_tizen 3.0
- *
- * @param[in] request The handle of the request
- * @param[out] type The types of the request.
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_request_get_host_address()
- * @see iotcon_request_get_connectivity_type()
- * @see iotcon_request_get_representation()
- * @see iotcon_request_get_options()
- * @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_type()
- * @see iotcon_request_get_observe_id()
- */
-int iotcon_request_get_request_type(iotcon_request_h request, iotcon_request_type_e *type);
-
-/**
- * @brief Gets options of the request
- *
- * @since_tizen 3.0
- *
- * @remarks @a options must not be released using iotcon_options_destroy().
- *
- * @param[in] request The handle of the request
- * @param[out] options The options of the request
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_request_get_host_address()
- * @see iotcon_request_get_connectivity_type()
- * @see iotcon_request_get_representation()
- * @see iotcon_request_get_request_type()
- * @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_type()
- * @see iotcon_request_get_observe_id()
- */
-int iotcon_request_get_options(iotcon_request_h request, iotcon_options_h *options);
-
-/**
- * @brief Gets query of the request
- *
- * @since_tizen 3.0
- *
- * @remarks @a query must not be released using iotcon_query_destroy().
- *
- * @param[in] request The handle of the request
- * @param[out] query The query of the request
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_request_get_host_address()
- * @see iotcon_request_get_connectivity_type()
- * @see iotcon_request_get_representation()
- * @see iotcon_request_get_request_type()
- * @see iotcon_request_get_options()
- * @see iotcon_request_get_observe_type()
- * @see iotcon_request_get_observe_id()
- */
-int iotcon_request_get_query(iotcon_request_h request, iotcon_query_h *query);
-
-/**
- * @brief Gets observation action of the request
- *
- * @since_tizen 3.0
- * @details The @a observe_type could be one of #iotcon_observe_type_e.
- *
- * @param[in] request The handle of the request
- * @param[out] observe_type The observation type of the request
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_request_get_host_address()
- * @see iotcon_request_get_connectivity_type()
- * @see iotcon_request_get_representation()
- * @see iotcon_request_get_request_type()
- * @see iotcon_request_get_options()
- * @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_id()
- */
-int iotcon_request_get_observe_type(iotcon_request_h request,
- iotcon_observe_type_e *observe_type);
-
-/**
- * @brief Gets observation id of the request
- *
- * @since_tizen 3.0
- *
- * @param[in] request The handle of the request
- * @param[out] observe_id The id of the observer
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_request_get_host_address()
- * @see iotcon_request_get_connectivity_type()
- * @see iotcon_request_get_representation()
- * @see iotcon_request_get_request_type()
- * @see iotcon_request_get_options()
- * @see iotcon_request_get_query()
- * @see iotcon_request_get_observe_type()
- */
-int iotcon_request_get_observe_id(iotcon_request_h request, int *observe_id);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_SERVER_REQUEST_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_INTERFACES_H__
-#define __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_INTERFACES_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-resource-interfaces.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE Resource Interfaces
- *
- * @brief Iotcon Resource Interfaces provides API to manage resource interfaces.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_OVERVIEW Overview
- * The iotcon resource interfaces API provides methods for managing handle and add, remove resource interfaces.
- * A resource interface indicates a class or category of resources.
- *
- * Example :
- * @code
-#include <iotcon.h>
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- // handle request
- ...
-}
-
-static void _create_light_resource()
-{
- int ret;
- iotcon_resource_h resource = NULL;
- iotcon_resource_interfaces_h resource_ifaces = NULL;
- iotcon_resource_interfaces_h resource_types = NULL;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_resource_types_add(resource_types, "org.tizen.light");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_interfaces_create(&resource_ifaces);
- if (IOTCON_ERROR_NONE != ret)
- iotcon_resource_types_destroy(resource_types);
- return;
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_create("/light/1", resource_types, resource_ifaces,
- IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, _request_handler, NULL, &resource);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_INTERFACES_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new resource interfaces handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a ifaces by calling iotcon_resource_interfaces_destroy()
- * if @a ifaces is no longer needed.
- *
- * @param[out] ifaces A newly allocated list of resource ifaces handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_interfaces_destroy()
- * @see iotcon_resource_interfaces_add()
- * @see iotcon_resource_interfaces_remove()
- * @see iotcon_resource_interfaces_clone()
- */
-int iotcon_resource_interfaces_create(iotcon_resource_interfaces_h *ifaces);
-
-/**
- * @brief Destroys a resource ifaces handle.
- *
- * @since_tizen 3.0
- *
- * @param[in] ifaces The handle of the resource ifaces
- *
- * @return void
- *
- * @see iotcon_resource_interfaces_create()
- * @see iotcon_resource_interfaces_add()
- * @see iotcon_resource_interfaces_remove()
- * @see iotcon_resource_interfaces_clone()
- */
-void iotcon_resource_interfaces_destroy(iotcon_resource_interfaces_h ifaces);
-
-/**
- * @brief Inserts a resource iface into the list.
- *
- * @since_tizen 3.0
- *
- * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
- *
- * @param[in] ifaces The handle of the resource ifaces
- * @param[in] iface The string data to insert into the resource ifaces
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_interfaces_create()
- * @see iotcon_resource_interfaces_destroy()
- * @see iotcon_resource_interfaces_remove()
- * @see iotcon_resource_interfaces_clone()
- */
-int iotcon_resource_interfaces_add(iotcon_resource_interfaces_h ifaces,
- const char *iface);
-
-/**
- * @brief Delete a resource iface form the list.
- *
- * @since_tizen 3.0
- *
- * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
- *
- * @param[in] ifaces The handle of the resource ifaces
- * @param[in] iface The string data to delete from the resource ifaces
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- *
- * @see iotcon_resource_interfaces_create()
- * @see iotcon_resource_interfaces_destroy()
- * @see iotcon_resource_interfaces_add()
- * @see iotcon_resource_interfaces_clone()
- */
-int iotcon_resource_interfaces_remove(iotcon_resource_interfaces_h ifaces,
- const char *iface);
-
-/**
- * @brief Specifies the iface of function passed to iotcon_resource_interfaces_foreach()
- *
- * @since_tizen 3.0
- *
- * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
- *
- * @param[in] iface The value of the resource ifaces
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_resource_interfaces_foreach() will invoke this callback function.
- *
- * @see iotcon_resource_interfaces_foreach()
- */
-typedef bool (*iotcon_resource_interfaces_foreach_cb)(const char *iface, void *user_data);
-
-/**
- * @brief Gets all of the resource ifaces of the list by invoking the callback function.
- * @details iotcon_resource_interfaces_foreach_cb() will be called for each iface.\n
- * If iotcon_resource_interfaces_foreach_cb() returns false, iteration will be stop.
- *
- * @since_tizen 3.0
- *
- * @param[in] ifaces The handle of resource ifaces
- * @param[in] cb The callback function to get data
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_resource_interfaces_foreach() will be called for each iface.
- *
- * @see iotcon_resource_interfaces_foreach_cb()
- */
-int iotcon_resource_interfaces_foreach(iotcon_resource_interfaces_h ifaces,
- iotcon_resource_interfaces_foreach_cb cb, void *user_data);
-
-/**
- * @brief Clones the resource ifaces handle.
- * @details Makes a deep copy of a source list of resource ifaces.
- *
- * @since_tizen 3.0
- *
- * @remarks You must @a destroy dest by calling iotcon_resource_interfaces_destroy()
- * if @a dest is no longer needed.
- *
- * @param[in] src The origin handle of the resource ifaces
- * @param[out] dest Clone of a source list of resource ifaces
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_interfaces_create()
- * @see iotcon_resource_interfaces_destroy()
- * @see iotcon_resource_interfaces_add()
- * @see iotcon_resource_interfaces_remove()
- */
-int iotcon_resource_interfaces_clone(iotcon_resource_interfaces_h src,
- iotcon_resource_interfaces_h *dest);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_INTERFACES_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_TYPES_H__
-#define __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_TYPES_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-resource-types.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_TYPES_MODULE Resource Types
- *
- * @brief Iotcon Resource Types provides API to manage resource types.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_TYPES_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_TYPES_MODULE_OVERVIEW Overview
- * The iotcon resource types API provides methods for managing handle and add, remove resource types.
- * A resource type indicates a class or category of resources.
- *
- * Example :
- * @code
-#include <iotcon.h>
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- // handle request
- ...
-}
-
-static void _create_light_resource()
-{
- int ret;
- iotcon_resource_h resource = NULL;
- iotcon_resource_interfaces_h resource_ifaces = NULL;
- iotcon_resource_interfaces_h resource_types = NULL;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_resource_types_add(resource_types, "org.tizen.light");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_interfaces_create(&resource_ifaces);
- if (IOTCON_ERROR_NONE != ret)
- iotcon_resource_types_destroy(resource_types);
- return;
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_create("/light/1", resource_types, resource_ifaces,
- IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE, _request_handler, NULL, &resource);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_TYPES_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new resource types handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a types by calling iotcon_resource_types_destroy()
- * if @a types is no longer needed.
- *
- * @param[out] types A newly allocated list of resource types handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_types_destroy()
- * @see iotcon_resource_types_add()
- * @see iotcon_resource_types_remove()
- * @see iotcon_resource_types_clone()
- */
-int iotcon_resource_types_create(iotcon_resource_types_h *types);
-
-/**
- * @brief Destroys a resource types handle.
- *
- * @since_tizen 3.0
- *
- * @param[in] types The handle of the resource types
- *
- * @return void
- *
- * @see iotcon_resource_types_create()
- * @see iotcon_resource_types_add()
- * @see iotcon_resource_types_remove()
- * @see iotcon_resource_types_clone()
- */
-void iotcon_resource_types_destroy(iotcon_resource_types_h types);
-
-/**
- * @brief Inserts a resource type into the list.
- *
- * @since_tizen 3.0
- * @remarks The length of @a type should be less than or equal to 61.\n
- * The @a type must start with a lowercase alphabetic character, followed by a sequence
- * of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.\n
- * Duplicate strings are not allowed.
- *
- * @param[in] types The handle of the resource types
- * @param[in] type The string data to insert into the resource types (e.g. "org.tizen.light")
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_types_create()
- * @see iotcon_resource_types_destroy()
- * @see iotcon_resource_types_remove()
- * @see iotcon_resource_types_clone()
- */
-int iotcon_resource_types_add(iotcon_resource_types_h types, const char *type);
-
-/**
- * @brief Delete a resource type form the list.
- *
- * @since_tizen 3.0
- *
- * @param[in] types The handle of the resource types
- * @param[in] type The string data to delete from the resource types
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- *
- * @see iotcon_resource_types_create()
- * @see iotcon_resource_types_destroy()
- * @see iotcon_resource_types_add()
- * @see iotcon_resource_types_clone()
- */
-int iotcon_resource_types_remove(iotcon_resource_types_h types, const char *type);
-
-/**
- * @brief Specifies the type of function passed to iotcon_resource_types_foreach()
- *
- * @since_tizen 3.0
- *
- * @param[in] type The value of the resource types
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_resource_types_foreach() will invoke this callback function.
- *
- * @see iotcon_resource_types_foreach()
- */
-typedef bool (*iotcon_resource_types_foreach_cb)(const char *type, void *user_data);
-
-/**
- * @brief Gets all of the resource types of the list by invoking the callback function.
- * @details iotcon_resource_types_foreach_cb() will be called for each type.\n
- * If iotcon_resource_types_foreach_cb() returns false, iteration will be stop.
- *
- * @since_tizen 3.0
- *
- * @param[in] types The handle of resource types
- * @param[in] cb The callback function to get data
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_resource_types_foreach() will be called for each type.
- *
- * @see iotcon_resource_types_foreach_cb()
- */
-int iotcon_resource_types_foreach(iotcon_resource_types_h types,
- iotcon_resource_types_foreach_cb cb, void *user_data);
-
-/**
- * @brief Clones the resource types handle.
- * @details Makes a deep copy of a source list of resource types.
- *
- * @since_tizen 3.0
- *
- * @remarks You must @a destroy dest by calling iotcon_resource_types_destroy()
- * if @a dest is no longer needed.
- *
- * @param[in] src The origin handle of the resource types
- * @param[out] dest Clone of a source list of resource types
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_types_create()
- * @see iotcon_resource_types_destroy()
- * @see iotcon_resource_types_add()
- * @see iotcon_resource_types_remove()
- */
-int iotcon_resource_types_clone(iotcon_resource_types_h src,
- iotcon_resource_types_h *dest);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_RESOURCE_TYPES_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_SERVER_RESOURCE_H__
-#define __IOT_CONNECTIVITY_MANAGER_SERVER_RESOURCE_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-resource.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_SERVER_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_SERVER_RESOURCE_MODULE Resource
- *
- * @brief Iotcon Resource provides API to manage resource.
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_RESOURCE_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_RESOURCE_MODULE_OVERVIEW Overview
- * The iotcon resource API provides methods for managing handle and resource information.
- *
- * Example :
- * @code
-#include <iotcon.h>
-
-static iotcon_resource_h _resource_room;
-
-static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
-{
- // handle request
- ...
-}
-
-static void _door_request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
-{
- // handle request
- ...
-}
-
-static void _create_resource()
-{
- int ret;
- int properties;
- iotcon_resource_interfaces_h resource_ifaces = NULL;
- iotcon_resource_interfaces_h resource_types = NULL;
- iotcon_resource_h resource_door = NULL;
-
- // 1. create room resource
- properties = IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_resource_types_add(resource_types, "org.tizen.room");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_interfaces_create(&resource_ifaces);
- if (IOTCON_ERROR_NONE != ret)
- iotcon_resource_types_destroy(resource_types);
- return;
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_LINK);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_BATCH);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
-
- ret = iotcon_resource_create("/room/1", resource_types, resource_ifaces,
- properties, _room_request_handler, NULL, &_resource_room);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- return;
- }
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
-
- // 2. create door resource
- properties = IOTCON_RESOURCE_OBSERVABLE;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_destroy(_resource_room);
- _resource_room = NULL;
- return;
- }
-
- ret = iotcon_resource_types_add(resource_types, "org.tizen.door");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_types_destroy(resource_types);
- iotcon_resource_destroy(_resource_room);
- _resource_room = NULL;
- return;
- }
-
- ret = iotcon_resource_interfaces_create(&resource_ifaces);
- if (IOTCON_ERROR_NONE != ret)
- iotcon_resource_types_destroy(resource_types);
- iotcon_resource_destroy(_resource_room);
- return;
-
- ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- iotcon_resource_destroy(_resource_room);
- return;
- }
-
- ret = iotcon_resource_create("/door/1", resource_types, resource_ifaces,
- properties, _door_request_handler, NULL, &resource_door);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
- iotcon_resource_destroy(_resource_room);
- _resource_room = NULL;
- return;
- }
- iotcon_resource_interfaces_destroy(resource_ifaces);
- iotcon_resource_types_destroy(resource_types);
-
- // 3. bind door resouce to room resource
- ret = iotcon_resource_bind_child_resource(_resource_room, resource_door);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_resource_destroy(resource_door);
- iotcon_resource_destroy(_resource_room);
- _resource_room = NULL;
- return;
- }
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_RESOURCE_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Specifies the type of function passed to iotcon_resource_create() and
- * iotcon_resource_set_request_handler()
- * @details Called when server receive request from the client.
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The resource requested
- * @param[in] request The request from client
- * @param[in] user_data The user data to pass to the function
- *
- * @pre The callback must be registered using iotcon_resource_create()
- *
- * @see iotcon_resource_create()
- * @see iotcon_resource_set_request_handler()
- */
-typedef void (*iotcon_request_handler_cb)(iotcon_resource_h resource,
- iotcon_request_h request, void *user_data);
-
-/**
- * @brief Creates a resource handle and registers the resource in server
- * @details Registers a resource specified by @a uri_path, @a res_types, @a ifaces which have
- * @a properties in Iotcon server.\n
- * When client find the registered resource, iotcon_request_handler_cb() will be called automatically.\n
- * @a uri_path format would be relative URI path like '/a/light'\n
- * @a res_types is a list of resource types. Create a iotcon_resource_types_h handle and
- * add types string to it.\n
- * @a ifaces is a list of resource interfaces. Create a iotcon_resource_interfaces_h handle and
- * add interfaces string to it.\n
- * @a properties also can contain multiple properties like
- * IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.\n
- * iotcon_request_handler_cb() will be called when receive CRUD request to the registered
- * resource.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks @a uri_path length must be less than or equal 36.\n
- * You must destroy @a resource by calling iotcon_resource_destroy()
- * if @a resource is no longer needed.
- *
- * @param[in] uri_path The URI path of the resource
- * @param[in] res_types The list of type of the resource
- * @param[in] ifaces The list of interface of the resource
- * @param[in] properties The properties of the resource\n Set of #iotcon_resource_property_e
- * @param[in] cb The request handler callback function
- * @param[in] user_data The user data to pass to the callback function
- * @param[out] resource_handle The handle of the resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_IOTIVITY Iotivity errors
- * @retval #IOTCON_ERROR_DBUS Dbus errors
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @post When the resource receive CRUD request, iotcon_request_handler_cb() will be called.
- *
- * @see iotcon_resource_destroy()
- * @see iotcon_resource_bind_interface()
- * @see iotcon_resource_bind_type()
- * @see iotcon_resource_set_request_handler()
- * @see iotcon_resource_bind_child_resource()
- * @see iotcon_resource_unbind_child_resource()
- * @see iotcon_request_handler_cb()
- */
-int iotcon_resource_create(const char *uri_path,
- iotcon_resource_types_h res_types,
- iotcon_resource_interfaces_h ifaces,
- int properties,
- iotcon_request_handler_cb cb,
- void *user_data,
- iotcon_resource_h *resource_handle);
-
-/**
- * @brief Destroys the resource and releases its data.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks When a normal variable is used, there are only dbus error and permission\n
- * denied error. If the errors of this API are not handled, then you must check\n
- * whether dbus is running and an application have the privileges for the API.
- *
- * @param[in] resource_handle The handle of the resource to be unregistered
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_resource_create()
- * @see iotcon_resource_bind_interface()
- * @see iotcon_resource_bind_type()
- * @see iotcon_resource_set_request_handler()
- * @see iotcon_resource_bind_child_resource()
- * @see iotcon_resource_unbind_child_resource()
- * @see iotcon_request_handler_cb()
- */
-int iotcon_resource_destroy(iotcon_resource_h resource_handle);
-
-/**
- * @brief Binds an interface to the resource
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
- *
- * @param[in] resource The handle of the resource
- * @param[in] iface The interface to be bound to the resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_resource_create()
- * @see iotcon_resource_destroy()
- * @see iotcon_resource_bind_type()
- * @see iotcon_resource_set_request_handler()
- * @see iotcon_resource_bind_child_resource()
- * @see iotcon_resource_unbind_child_resource()
- * @see iotcon_request_handler_cb()
- */
-int iotcon_resource_bind_interface(iotcon_resource_h resource, const char *iface);
-
-/**
- * @brief Binds a type to the resource
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @remarks The length of @a resource_type should be less than or equal to 61.\n
- * The @a resource_type must start with a lowercase alphabetic character, followed by a sequence
- * of lowercase alphabetic, numeric, ".", or "-" characters, and contains no white space.\n
- *
- * @param[in] resource_handle The handle of the resource
- * @param[in] resource_type The type to be bound to the resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_resource_create()
- * @see iotcon_resource_destroy()
- * @see iotcon_resource_bind_interface()
- * @see iotcon_resource_set_request_handler()
- * @see iotcon_resource_bind_child_resource()
- * @see iotcon_resource_unbind_child_resource()
- * @see iotcon_request_handler_cb()
- */
-int iotcon_resource_bind_type(iotcon_resource_h resource_handle,
- const char *resource_type);
-
-/**
- * @brief Binds a request handler to the resource
- * @details When the resource receive CRUD request, iotcon_request_handler_cb() will be
- * called.
- *
- * @since_tizen 3.0
- *
- * @remarks Registered callback function will be replaced with the new @a cb.\n
- *
- * @param[in] resource The handle of the resource
- * @param[in] cb The request handler to be bound to the resource
- * @param[in] user_data The user data to pass to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_create()
- * @see iotcon_resource_destroy()
- * @see iotcon_resource_bind_interface()
- * @see iotcon_resource_bind_type()
- * @see iotcon_resource_bind_child_resource()
- * @see iotcon_resource_unbind_child_resource()
- * @see iotcon_request_handler_cb()
- */
-int iotcon_resource_set_request_handler(iotcon_resource_h resource,
- iotcon_request_handler_cb cb, void *user_data);
-
-/**
- * @brief Binds a child resource into the parent resource.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] parent The handle of the parent resource
- * @param[in] child The handle of the child resource to be added to the parent resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_ALREADY Already done
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_resource_create()
- * @see iotcon_resource_destroy()
- * @see iotcon_resource_bind_interface()
- * @see iotcon_resource_bind_type()
- * @see iotcon_resource_set_request_handler()
- * @see iotcon_resource_unbind_child_resource()
- * @see iotcon_request_handler_cb()
- */
-int iotcon_resource_bind_child_resource(iotcon_resource_h parent,
- iotcon_resource_h child);
-
-/**
- * @brief Unbinds a child resource from the parent resource.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] parent The handle of the parent resource
- * @param[in] child The handle of the child resource to be unbound from the parent resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_resource_create()
- * @see iotcon_resource_destroy()
- * @see iotcon_resource_bind_interface()
- * @see iotcon_resource_bind_type()
- * @see iotcon_resource_set_request_handler()
- * @see iotcon_resource_bind_child_resource()
- * @see iotcon_request_handler_cb()
- */
-int iotcon_resource_unbind_child_resource(iotcon_resource_h parent,
- iotcon_resource_h child);
-
-/**
- * @brief Notifies specific clients that resource's attributes have changed.
- * @details If @a observers is @c NULL, the @a msg will notify to all observers.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resource The handle of the resource
- * @param[in] repr The handle of the representation
- * @param[in] observers The handle of the observers.
- * @param[in] qos The quality of service for message transfer.
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_REPRESENTATION Representation error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- *
- * @see iotcon_remote_resource_observe_cb()
- * @see iotcon_remote_resource_observe_register()
- * @see iotcon_remote_resource_observe_deregister()
- * @see iotcon_observers_create()
- * @see iotcon_observers_destroy()
- * @see iotcon_observers_add()
- * @see iotcon_observers_remove()
- */
-int iotcon_resource_notify(iotcon_resource_h resource, iotcon_representation_h repr,
- iotcon_observers_h observers, iotcon_qos_e qos);
-
-/**
- * @brief Gets the number of children resources of the resource
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the resource
- * @param[out] number The number of children resources
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_get_nth_child()
- * @see iotcon_resource_get_uri_path()
- * @see iotcon_resource_get_types()
- * @see iotcon_resource_get_interfaces()
- * @see iotcon_resource_get_properties()
- */
-int iotcon_resource_get_number_of_children(iotcon_resource_h resource, int *number);
-
-/**
- * @brief Gets the child resource at the given index in the parent resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a child must not be released using iotcon_resource_destroy().
- *
- * @param[in] parent The handle of the parent resource
- * @param[in] index The index of the child resource
- * @param[out] child The child resource at the index
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_get_number_of_children()
- * @see iotcon_resource_get_uri_path()
- * @see iotcon_resource_get_types()
- * @see iotcon_resource_get_interfaces()
- * @see iotcon_resource_get_properties()
- */
-int iotcon_resource_get_nth_child(iotcon_resource_h parent, int index,
- iotcon_resource_h *child);
-
-/**
- * @brief Gets an URI path of the resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a uri_path must not be released using free().
- *
- * @param[in] resource The handle of the resource
- * @param[out] uri_path The URI path of the resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_get_number_of_children()
- * @see iotcon_resource_get_nth_child()
- * @see iotcon_resource_get_types()
- * @see iotcon_resource_get_interfaces()
- * @see iotcon_resource_get_properties()
- */
-int iotcon_resource_get_uri_path(iotcon_resource_h resource, char **uri_path);
-
-/**
- * @brief Gets the list of types in the resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a types must not be released using iotcon_resource_types_destroy().
- *
- * @param[in] resource The handle of the resource
- * @param[out] types The types of the resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_get_number_of_children()
- * @see iotcon_resource_get_nth_child()
- * @see iotcon_resource_get_uri_path()
- * @see iotcon_resource_get_interfaces()
- * @see iotcon_resource_get_properties()
- */
-int iotcon_resource_get_types(iotcon_resource_h resource, iotcon_resource_types_h *types);
-
-/**
- * @brief Gets the interfaces of the resource
- *
- * @since_tizen 3.0
- *
- * @remarks @a ifaces must not be released using iotcon_resource_interfaces_destroy().
- *
- * @param[in] resource The handle of the resource
- * @param[out] ifaces The interfaces of the resource
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_get_number_of_children()
- * @see iotcon_resource_get_nth_child()
- * @see iotcon_resource_get_uri_path()
- * @see iotcon_resource_get_types()
- * @see iotcon_resource_get_properties()
- */
-int iotcon_resource_get_interfaces(iotcon_resource_h resource,
- iotcon_resource_interfaces_h *ifaces);
-
-/**
- * @brief Gets the properties in the resource
- * @details @a properties can contain multiple properties like
- * IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE.
- *
- * @since_tizen 3.0
- *
- * @param[in] resource The handle of the resource
- * @param[out] properties The properties of resource\n Set of #iotcon_resource_property_e
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_resource_get_number_of_children()
- * @see iotcon_resource_get_nth_child()
- * @see iotcon_resource_get_uri_path()
- * @see iotcon_resource_get_types()
- * @see iotcon_resource_get_interfaces()
- */
-int iotcon_resource_get_properties(iotcon_resource_h resource, int *properties);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_SERVER_RESOURCE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_COMMON_RESPONSE_H__
-#define __IOT_CONNECTIVITY_MANAGER_COMMON_RESPONSE_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-response.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE Response
- *
- * @brief Iotcon Response provides API to manage response.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE_OVERVIEW Overview
- * The iotcon response API provides methos for managing handle and get response information.
- *
- * Example (Client side) :
- * @code
-#include <iotcon.h>
-
-static void _state_foreach(iotcon_state_h state, const char *key, void *user_data)
-{
- // handle state
- ...
-}
-
-static void _on_get(iotcon_remote_resource_h resource, iotcon_error_e err,
- iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
-{
- int ret;
- iotcon_response_result_e response_result;
- iotcon_representation_h repr = NULL;
- iotcon_state_h state = NULL;
-
- if (IOTCON_ERROR_NONE != err)
- return;
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_RESPONSE_OK != response_result)
- return;
-
- ret = iotcon_response_get_representation(response, &repr);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_representation_get_state(repr, &state);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_state_foreach(state, _state_foreach, NULL);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ...
-}
-
-static void _request_get(iotcon_remote_resource_h resource)
-{
- int ret;
- ret = iotcon_remote_resource_get(resource, NULL, _on_get, NULL);
- if (IOTCON_ERROR_NONE != ret)
- return;
-}
- * @endcode
- *
- *
- * Example (Server side) :
- * @code
-#include <iotcon.h>
-
-static iotcon_state_h _create_state()
-{
- int ret;
- iotcon_state_h state = NULL;
-
- // create & set state
- ...
-
- return state;
-}
-
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request, void *user_data)
-{
- int ret;
- int types;
- iotcon_query_h query = NULL;
-
- ret = iotcon_request_get_types(request, &types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_request_get_query(request, &query);
- if (IOTCON_ERROR_NONE == ret && query) {
- ret = iotcon_query_get_interface(request, &iface);
- if (IOTCON_ERROR_NONE != ret)
- return;
- }
-
- if (IOTCON_REQUEST_GET & types) {
- iotcon_response_h response = NULL;
- iotcon_representation_h repr = NULL;
- iotcon_state_h state = NULL;
-
- ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_response_set_result(response, IOTCON_RESPONSE_OK);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_representation_set_uri_path(repr, "/light/1");
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(repr);
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_representation_set_state(resopnse, _create_state());
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(repr);
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT, repr);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(repr);
- iotcon_response_destroy(response);
- return;
- }
-
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(repr);
- iotcon_response_destroy(response);
- return;
- }
-
- iotcon_representation_destroy(repr);
- iotcon_response_destroy(response);
- }
- ...
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a response handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a response by calling iotcon_response_destroy()
- * if @a response is no longer needed.
- *
- * @param[in] request The handle of received request handle
- * @param[out] response Generated response handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_response_destroy()
- * @see iotcon_response_set()
- */
-int iotcon_response_create(iotcon_request_h request, iotcon_response_h *response);
-
-/**
- * @brief Destroys a response handle.
- *
- * @since_tizen 3.0
- *
- * @param[in] resp The handle of the response
- *
- * @see iotcon_response_create()
- * @see iotcon_response_set()
- */
-void iotcon_response_destroy(iotcon_response_h resp);
-
-
-/**
- * @brief Gets header options of the response
- *
- * @since_tizen 3.0
- *
- * @remarks @a options must not be released using iotcon_options_destroy().
- *
- * @param[in] resp The handle of the response
- * @param[out] options The handle of the header options
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data
- *
- * @see iotcon_response_get_representation()
- * @see iotcon_response_get_result()
- */
-int iotcon_response_get_options(iotcon_response_h resp, iotcon_options_h *options);
-
-/**
- * @brief Gets representation of the response
- *
- * @since_tizen 3.0
- *
- * @remarks @a repr must not be released using iotcon_representation_destroy().
- *
- * @param[in] resp The handle of the response
- * @param[out] repr The handle of the representation
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data
- *
- * @see iotcon_response_get_options()
- * @see iotcon_response_get_result()
- */
-int iotcon_response_get_representation(iotcon_response_h resp, iotcon_representation_h *repr);
-
-/**
- * @brief Gets result of the response
- *
- * @since_tizen 3.0
- *
- * @param[in] resp The handle of the response
- * @param[out] result The result of the response
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_response_get_options()
- * @see iotcon_response_get_representation()
- */
-int iotcon_response_get_result(iotcon_response_h resp,
- iotcon_response_result_e *result);
-
-
-/**
- * @brief Sets result into the response
- * @details The @a result could be one of #iotcon_response_result_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] resp The handle of the response
- * @param[in] result The result to set
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_response_create()
- * @see iotcon_response_destroy()
- */
-int iotcon_response_set_result(iotcon_response_h resp, iotcon_response_result_e result);
-
-/**
- * @brief Sets representation into the response
- *
- * @since_tizen 3.0
- *
- * @remarks @a iface could be a value such as #IOTCON_INTERFACE_DEFAULT.
- *
- * @param[in] resp The handle of the response
- * @param[in] iface The interface of the representation
- * @param[in] repr The representation of the response
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_response_create()
- * @see iotcon_response_destroy()
- */
-int iotcon_response_set_representation(iotcon_response_h resp, const char *iface,
- iotcon_representation_h repr);
-
-/**
- * @brief Sets header options into the response
- *
- * @since_tizen 3.0
- *
- * @param[in] resp The handle of the response
- * @param[in] options The header options of the response
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- *
- * @see iotcon_response_create()
- * @see iotcon_response_destroy()
- */
-int iotcon_response_set_options(iotcon_response_h resp, iotcon_options_h options);
-
-/**
- * @brief Send response for incoming request.
- *
- * @since_tizen 3.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/network.get
- * @privilege %http://tizen.org/privilege/d2d.datasharing
- *
- * @param[in] resp The handle of the response to send
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- * @retval #IOTCON_ERROR_SYSTEM System error
- * @retval #IOTCON_ERROR_PERMISSION_DENIED Permission denied
- */
-int iotcon_response_send(iotcon_response_h resp);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_COMMON_RESPONSE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_SERVER_H__
-#define __IOT_CONNECTIVITY_MANAGER_SERVER_H__
-
-#include <iotcon-resource.h>
-#include <iotcon-lite-resource.h>
-#include <iotcon-response.h>
-#include <iotcon-observers.h>
-#include <iotcon-request.h>
-
-/**
- * @file iotcon-server.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_SERVER_MODULE Server
- *
- * @brief Iotcon Server provides API for server side.
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_SERVER_MODULE_OVERVIEW Overview
- * This API set consists of server side API for
- * @ref CAPI_IOT_CONNECTIVITY_SERVER_RESOURCE_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_SERVER_LITE_RESOURCE_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_SERVER_OBSERVERS_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_SERVER_REQUEST_MODULE.
- *
- * @{
- */
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_SERVER_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_STRUCT_STATE_H__
-#define __IOT_CONNECTIVITY_MANAGER_STRUCT_STATE_H__
-
-#include <iotcon-types.h>
-
-/**
- * @file iotcon-state.h
- */
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE State
- *
- * @brief Iotcon State provides API to manage state.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_HEADER Required Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_OVERVIEW Overview
- * The iotcon state API provides string key based hash table.
- *
- * Example :
- * @code
-#include <iotcon.h>
-...
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret;
- int types;
-
- ret = iotcon_request_get_types(request, &types);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- if (IOTCON_REQUEST_GET & types) {
- iotcon_response_h response = NULL;
- iotcon_representation_h representation = NULL;
- iotcon_state_h state = NULL;
-
- ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret)
- return;
-
- ret = iotcon_representation_create(&representation);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ...
-
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_state_add_bool(state, "power", true);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = itocon_state_set_int(state, "brightness", 75);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_representation_set_state(representation, state);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ...
-
- ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT,
- representation);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- return;
- }
-
- iotcon_state_destroy(state);
- iotcon_representation_destroy(representation);
- iotcon_response_destroy(resopnse);
- }
- ...
-}
- * @endcode
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Creates a new state handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a state by calling iotcon_state_destroy()
- * if @a state is no longer needed.
- *
- * @param[out] state A newly allocated state handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_state_destroy()
- */
-int iotcon_state_create(iotcon_state_h *state);
-
-/**
- * @brief Destroys a state.
- * @details Releases a @a state and its internal data.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle to free
- *
- * @return void
- *
- * @see iotcon_state_create()
- */
-void iotcon_state_destroy(iotcon_state_h state);
-
-/**
- * @brief Clones a state handle.
- *
- * @since_tizen 3.0
- *
- * @remarks You must destroy @a state_clone by calling iotcon_state_destroy()
- * if @a state_clone is no longer needed.
- *
- * @param[in] state The state handle
- * @param[out] state_clone The cloned state handle
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @see iotcon_state_create()
- * @see iotcon_state_destroy()
- */
-int iotcon_state_clone(iotcon_state_h state, iotcon_state_h *state_clone);
-
-/**
- * @brief Adds a new key and integer value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_int(iotcon_state_h state, const char *key, int val);
-
-/**
- * @brief Adds a new key and boolean value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_bool(iotcon_state_h state, const char *key, bool val);
-
-/**
- * @brief Adds a new key and double value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_double(iotcon_state_h state, const char *key, double val);
-
-/**
- * @brief Adds a new key and string value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_str(iotcon_state_h state, const char *key, char *val);
-
-/**
- * @brief Adds a new key and byte string value into the state.
- * @details If @a key is already exists, current value will be replaced with new @a val.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] val The value
- * @param[in] len The length of @a val
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_byte_str(iotcon_state_h state, const char *key, unsigned char *val,
- int len);
-
-/**
- * @brief Adds a new key and list value into the state.
- * @details If @a key is already exists, current list will be replaced with new @a list.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] list The value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_list(iotcon_state_h state, const char *key, iotcon_list_h list);
-
-/**
- * @brief Adds a new key and state value into the state.
- * @details If @a key is already exists, current state will be replaced with new @a src.
- *
- * @since_tizen 3.0
- *
- * @param[in] dest The state handle
- * @param[in] key The key
- * @param[in] src The state handle to set newly
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_state(iotcon_state_h dest, const char *key, iotcon_state_h src);
-
-/**
- * @brief Adds a new key with NULL value into the state.
- * @details If @a key is already exists, current value will be replaced with NULL
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key to be set NULL
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_add_null(iotcon_state_h state, const char *key);
-
-/**
- * @brief Gets the integer value from the given key.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The integer value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_int(iotcon_state_h state, const char *key, int *val);
-
-/**
- * @brief Gets the boolean value from the given key.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The boolean value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_bool(iotcon_state_h state, const char *key, bool *val);
-
-/**
- * @brief Gets the double value from the given key.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The double value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_double(iotcon_state_h state, const char *key, double *val);
-
-/**
- * @brief Gets the string value from the given key.
- *
- * @since_tizen 3.0
- *
- * @remarks @a val must not be released using free().
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The string value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_str(iotcon_state_h state, const char *key, char **val);
-
-/**
- * @brief Gets the byte string value from the given key.
- *
- * @since_tizen 3.0
- *
- * @remarks @a val must not be released using free().
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] val The byte string value
- * @param[out] len The length of @a val
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_byte_str(iotcon_state_h state, const char *key, unsigned char **val,
- int *len);
-
-/**
- * @brief Gets the list value from the given key.
- *
- * @since_tizen 3.0
- *
- * @remarks @a list must not be released using iotcon_list_destroy().
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] list The list value
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_list(iotcon_state_h state, const char *key, iotcon_list_h *list);
-
-/**
- * @brief Gets the state value from the given key.
- *
- * @since_tizen 3.0
- *
- * @remarks @a state must not be released using iotcon_state_destroy().
- *
- * @param[in] src The state handle
- * @param[in] key The key
- * @param[out] dest The state value at the key
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- * @retval #IOTCON_ERROR_INVALID_TYPE Invalid type
- */
-int iotcon_state_get_state(iotcon_state_h src, const char *key, iotcon_state_h *dest);
-
-/**
- * @brief Checks whether the value of given key is NULL or not.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] is_null true if the type of the given key is null, otherwise false
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_is_null(iotcon_state_h state, const char *key, bool *is_null);
-
-/**
- * @brief Removes the key and its associated value from the state.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- */
-int iotcon_state_remove(iotcon_state_h state, const char *key);
-
-/**
- * @brief Gets the type of a value at the given key.
- * @details It gets the data type of value related the @a key in @a state.
- * The data type could be one of #iotcon_type_e.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[out] type The data type of value related the key in state handle.
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_NO_DATA No data available
- */
-int iotcon_state_get_type(iotcon_state_h state, const char *key,
- iotcon_type_e *type);
-
-/**
- * @brief Specifies the type of function passed to iotcon_state_foreach()
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] key The key
- * @param[in] user_data The user data to pass to the function
- *
- * @return true to continue with the next iteration of the loop,
- * otherwise false to break out of the loop. #IOTCON_FUNC_CONTINUE and #IOTCON_FUNC_STOP
- * are more friendly values for the return.
- *
- * @pre iotcon_state_foreach() will invoke this callback function.
- *
- * @see iotcon_state_foreach()
- */
-typedef bool (*iotcon_state_cb)(iotcon_state_h state, const char *key, void *user_data);
-
-/**
- * @brief Calls a function for each element of state.
- * @details iotcon_state_cb() will be called for each child.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[in] cb The callback function to invoke
- * @param[in] user_data The user data to pass to the function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @post iotcon_state_cb() will be called for each child.
- *
- * @see iotcon_state_cb()
- */
-int iotcon_state_foreach(iotcon_state_h state, iotcon_state_cb cb, void *user_data);
-
-/**
- * @brief Gets the number of keys in the state.
- *
- * @since_tizen 3.0
- *
- * @param[in] state The state handle
- * @param[out] count The number of keys
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- */
-int iotcon_state_get_keys_count(iotcon_state_h state, unsigned int *count);
-
-/**
- * @}
- */
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_STRUCT_STATE_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_TYPES_H__
-#define __IOT_CONNECTIVITY_MANAGER_TYPES_H__
-
-#include <tizen_type.h>
-
-#include <iotcon-constant.h>
-
-/**
- * @file iotcon-types.h
- */
-
-
-/**
- * @ingroup CAPI_IOT_CONNECTIVITY_MODULE
- * @defgroup CAPI_IOT_CONNECTIVITY_COMMON_MODULE Common
- *
- * @brief Iotcon Common API provides the set of definitions to use server and client API.
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_MODULE_HEADER Header
- * \#include <iotcon.h>
- *
- * @section CAPI_IOT_CONNECTIVITY_COMMON_MODULE_OVERVIEW Overview
- * This API set consists of data structures for
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_RESOURCE_TYPES_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_QUERY_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_OPTIONS_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_REPRESENTATION_STATE_LIST_MODULE,
- * @ref CAPI_IOT_CONNECTIVITY_COMMON_RESPONSE_MODULE.
- *
- * @{
- */
-
-/**
- * @brief The handle of resource.
- * @details @a iotcon_resource_h is an opaque data structure to represent registered
- * resource by server. A resource has host_address, uri_path, resource types, interfaces
- * and internal handle. If observable attribute of resource is true, client can observe
- * this resource. When client request by CRUD functions, handler will be invoked
- * if registered. It could contain other resource as children.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_resource* iotcon_resource_h;
-
-/**
- * @brief The handle of lite resource.
- * @details @a iotcon_lite_resource_h is an opaque data structure to represent registered
- * resource by server. A resource has host_address, uri_path, resource types, and internal
- * handle. If observable attribute of resource is true, client can observe
- * this resource.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_lite_resource* iotcon_lite_resource_h;
-
-/**
-* @brief The handle of response
-* @details @a iotcon_response_h is an opaque data structure to respond to client.
-* @a iotcon_response_h is a data type of server's response which consists of result,
-* header options, query, representation.
-*
-*
-* @since_tizen 3.0
-*/
-typedef struct icl_resource_response* iotcon_response_h;
-
-/**
- * @brief The handle of observers.
- * @details The list of observer ids.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_observers* iotcon_observers_h;
-
-/**
-* @brief The handle of request
-* @details @a iotcon_request_h is an opaque data structure to request to a particular resource.
-* @a iotcon_request_h is a data type of client's request which consists of header options,
-* query, representation.
-*
-* @since_tizen 3.0
-*/
-typedef struct icl_resource_request* iotcon_request_h;
-
-/**
- * @brief The handle of remote resource
- * @details When Client success to find out resource from remote server,
- * server's resource information is reorganized as @a iotcon_remote_resource_h by Iotcon.
- * Client can request CRUD to server by using this.
- * @a iotcon_remote_resource_h is an opaque data structure to have host_address, uri_path,
- * resource types, interfaces, options and device id.
- * If observable attribute is true, remote resource is observable.
- * When you observe remote resource, observe_handle will be set.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_remote_resource* iotcon_remote_resource_h;
-
-/**
- * @brief The handle of presence.
- * @details @a iotcon_presence_h is a handle of presence subscription.
- * It is used to cancel presence.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_presence* iotcon_presence_h;
-
-/**
- * @brief The handle of presence response.
- * @details @a iotcon_presence_response_h is a handle of presence response subscription.\n
- * It is used to get the information of presence response from server.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_presence_response* iotcon_presence_response_h;
-
-/**
- * @brief The handle of device information.
- * @details @a iotcon_device_info_h is a handle of device information.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_device_info* iotcon_device_info_h;
-
-/**
- * @brief The handle of platform information.
- * @details @a iotcon_platform_info_h is a handle of platform information.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_platform_info* iotcon_platform_info_h;
-
-/**
- * @brief The handle of resource interface
- * @details @a iotcon_resource_interfaces_h is an opaque data structure to have list
- * of resource interfaces. A resource interface is datatype of string.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_resource_ifaces* iotcon_resource_interfaces_h;
-
-/**
- * @brief The handle of resource types
- * @details @a iotcon_resource_types_h is an opaque data structure to have list
- * of resource types. A resource type is datatype of string.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_resource_types* iotcon_resource_types_h;
-
-/**
- * @brief The handle of options
- * @details @a iotcon_options_h is an opaque data structure to have attribute value map
- * which consists of a key and a value.
- * Datatype of key is integer and value is string.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_options* iotcon_options_h;
-
-/**
- * @brief The handle of query
- * @details @a iotcon_query_h is an opaque data structure to have attribute value map
- * which consists of key and value.
- * Data ype of both key and value are string.
- * @a iotcon_query_h also have length.
- * The length is total length of all keys and values of map.
- * The length should be less than or equal to 64.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_query* iotcon_query_h;
-
-/**
- * @brief The handle of representation.
- * @details @a iotcon_representation_h is an opaque data structure to have uri_path,
- * list of resource types and interfaces.
- * It could contain other representation as children.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_representation_s* iotcon_representation_h;
-
-/**
- * @brief The handle of list which is consist of iotcon_value_h type values.
- * @details @a iotcon_list_h is an opaque data structure.
- *
- * @since_tizen 3.0
- */
-typedef struct icl_list_s* iotcon_list_h;
-
-/**
- * @brief The handle of state.
- * @details @a iotcon_state_h is an opaque data structure to have attribute value map.
- * Attribute value map consists of a key and a value.
- * Datatype of the key is string and the value should be one of them #IOTCON_TYPE_INT,
- * #IOTCON_TYPE_BOOL, #IOTCON_TYPE_DOUBLE, #IOTCON_TYPE_STR, #IOTCON_TYPE_NULL,
- * #IOTCON_TYPE_LIST and #IOTCON_TYPE_STATE
- *
- * @since_tizen 3.0
- */
-typedef struct icl_state_s* iotcon_state_h;
-
-/**
- * @}
- */
-
-#include <iotcon-list.h>
-#include <iotcon-query.h>
-#include <iotcon-state.h>
-#include <iotcon-options.h>
-#include <iotcon-representation.h>
-#include <iotcon-resource-types.h>
-#include <iotcon-resource-interfaces.h>
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_TYPES_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_H__
-#define __IOT_CONNECTIVITY_MANAGER_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <iotcon-types.h>
-#include <iotcon-errors.h>
-#include <iotcon-server.h>
-#include <iotcon-client.h>
-
-/**
- * @file iotcon.h
- */
-
-/**
- *
- * @addtogroup CAPI_IOT_CONNECTIVITY_MODULE
- *
- * @section CAPI_IOT_CONNECTIVITY_MODULE_FEATURE Related Features
- * This API is related with the following features:\n
- * - http://tizen.org/feature/iot.oic\n
- *
- * It is recommended to design feature related codes in your application for reliability.\n
- *
- * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
- *
- * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
- *
- * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature Element</b>.</a>
- *
- * @{
- */
-
-/**
- * @brief Connects to the iotcon service.
- * @details Call this function to start Iotcon.
- *
- * @since_tizen 3.0
- *
- * @remarks You must free all resources of the Iotcon by calling iotcon_disconnect()
- * if Iotcon API is no longer needed.
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_DBUS Dbus error
- *
- * @see iotcon_disconnect()
- * @see iotcon_add_connection_changed_cb()
- * @see iotcon_remove_connection_changed_cb()
- */
-int iotcon_connect(void);
-
-/**
- * @brief Disconnects from the iotcon service.
- * @details Frees the resources allocated to Iotcon.
- *
- * @since_tizen 3.0
- *
- * @remarks This function must be called if Iotcon API is no longer needed.
- *
- * @return void
- *
- * @see iotcon_connect()
- * @see iotcon_add_connection_changed_cb()
- * @see iotcon_remove_connection_changed_cb()
- */
-void iotcon_disconnect(void);
-
-/**
- * @brief Gets the timeout seconds of asynchronous API.
- * @details This API get the timeout of iotcon_get_device_info(),
- * iotcon_get_platform_info(), iotcon_find_resource(),
- * iotcon_remote_resource_get(), iotcon_remote_resource_put(),
- * iotcon_remote_resource_post() and iotcon_remote_resource_delete().
- *
- * @since_tizen 3.0
- *
- * @param[out] timeout_seconds Seconds for timeout
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @pre iotcon_connect() should be called to connect a connection to the iotcon.
- *
- * @see iotcon_set_timeout()
- */
-int iotcon_get_timeout(int *timeout_seconds);
-
-/**
- * @brief Sets the timeout seconds of asynchrous APIs.
- * @details This API set the timeout of iotcon_get_device_info(),
- * iotcon_get_platform_info(), iotcon_find_resource(),
- * iotcon_remote_resource_get(), iotcon_remote_resource_put(),
- * iotcon_remote_resource_post() and iotcon_remote_resource_delete().\n
- * Default timeout interval value is 30.
- *
- * @since_tizen 3.0
- *
- * @param[in] timeout_seconds Seconds for timeout (must be in range from 1 to 3600)
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_DBUS Dbus error
- *
- * @pre iotcon_connect() should be called to connect a connection to the iotcon.
- *
- * @see iotcon_get_timeout()
- */
-int iotcon_set_timeout(int timeout_seconds);
-
-/**
- * @brief Specifies the type of function passed to iotcon_add_connection_changed_cb() and
- * iotcon_remove_connection_changed_cb().
- *
- * @since_tizen 3.0
- *
- * @param[in] is_connected The status of connection
- * @param[in] user_data The user data to pass to the function
- *
- * @pre The callback must be registered using iotcon_add_connection_changed_cb()\n
- * The callback must be unregistered using iotcon_remove_connection_changed_cb()\n
- *
- * @see iotcon_connect()
- * @see iotcon_disconnect()
- * @see iotcon_add_connection_changed_cb()
- * @see iotcon_remove_connection_changed_cb()
- */
-typedef void (*iotcon_connection_changed_cb)(bool is_connected, void *user_data);
-
-/**
- * @brief Adds a callback to Iotcon
- * @details When Iotcon connection status is changed with unexpected reason, registered
- * callbacks will be called in turn. The handles(e.g. iotcon_resource_h,
- * iotcon_remote_resource_h, ...) are validate no more after broken connection.
- * The handles must creates again when connection recovered.
- *
- * @since_tizen 3.0
- *
- * @param[in] cb The callback function to add into callback list
- * @param[in] user_data The user data to pass to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #IOTCON_ERROR_ALREADY Already done
- * @retval #IOTCON_ERROR_OUT_OF_MEMORY Out of memory
- * @retval #IOTCON_ERROR_DBUS Dbus error
- *
- * @pre iotcon_connect() should be called to connect a connection to the iotcon.
- *
- * @see iotcon_connect()
- * @see iotcon_disconnect()
- * @see iotcon_remove_connection_changed_cb()
- * @see iotcon_connection_changed_cb()
- */
-int iotcon_add_connection_changed_cb(iotcon_connection_changed_cb cb, void *user_data);
-
-/**
- * @brief Removes the callback from the callback list.
- * @details Finds out the callback passing to parameter from registered callbacks, then remove it.
- *
- * @since_tizen 3.0
- *
- * @param[in] cb The callback function to remove from callback list
- * @param[in] user_data The user data to pass to the callback function
- *
- * @return 0 on success, otherwise a negative error value.
- * @retval #IOTCON_ERROR_NONE Successful
- * @retval #IOTCON_ERROR_NOT_SUPPORTED Not supported
- * @retval #IOTCON_ERROR_INVALID_PARAMETER Invalid parameter
- *
- * @pre iotcon_connect() should be called to connect a connection to the iotcon.
- *
- * @see iotcon_connect()
- * @see iotcon_disconnect()
- * @see iotcon_add_connection_changed_cb()
- * @see iotcon_connection_changed_cb()
- */
-int iotcon_remove_connection_changed_cb(iotcon_connection_changed_cb cb, void *user_data);
-
-/**
- * @}
- */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_H__ */
+++ /dev/null
-prefix=@CMAKE_INSTALL_PREFIX@
-exec_prefix=${prefix}/bin
-libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDE_INSTALL_DIR@/@CLIENT@
-
-Name: @CLIENT@
-Description: IoT Connectivity Manager
-Version: @FULLVER@
-Requires:
-Libs: -L${libdir} -l@CLIENT@
-Cflags: -I${includedir}
+++ /dev/null
-<manifest>
- <define>
- <domain name="iotcon" />
- <permit>
- <smack permit="system::use_internet" type="w" />
- <smack permit="dbus" type="rwx" />
- <smack permit="system::debugging_network" type="w" />
- </permit>
- <request>
- <smack request="system::use_internet" type="w" />
- <smack request="dbus" type="rwx" />
- <smack request="device::app_logging" type="w" />
- <smack request="device::sys_logging" type="w" />
- <smack request="system::homedir" type="x" />
- <smack request="tizen::vconf::setting::admin" type="rl" />
- <smack request="tizen::vconf::public::r::platform::rw" type="rl" />
-
- <smack request="bluez" type="rw" />
- <smack request="bt-service::public" type="w" />
- <smack request="privilege::tizen::bluetooth" type="rw" />
-
- <smack request="connman" type="rw" />
- <smack request="connman::get" type="rw" />
- <smack request="net-config" type="rw" />
- <smack request="privilege::tizen::network.get" type="rw" />
- <smack request="telephony_framework::api_ps_public" type="rw" />
- <smack request="telephony_framework::properties" type="rw" />
- <smack request="telephony_framework::properties" type="rw" />
- <smack request="tizen::vconf::network" type="r" />
-
- <smack request="system::debugging_network" type="w" />
- </request>
- </define>
- <assign>
- <filesystem path="/usr/share/license/iotcon" label="_" />
- <filesystem path="/usr/lib/libiotcon.so.*" label="_" />
-
- <dbus name="org.tizen.iotcon.dbus" own="iotcon" bus="system">
- <node name="/org/tizen/iotcon/dbus">
- <interface name="org.tizen.iotcon.dbus">
- <annotation name="com.tizen.smack" value="iotcon"/>
- </interface>
- </node>
- </dbus>
- </assign>
- <request>
- <domain name="iotcon" />
- </request>
-</manifest>
+++ /dev/null
-[Unit]
-Description=Tizen IoT Connectivity
-
-[Service]
-Type=simple
-ExecStart=/usr/bin/iotcon-daemon
-Restart=always
-User=system
-Group=system
-SmackProcessLabel=iotcon
-
-[Install]
-WantedBy=multi-user.target
+++ /dev/null
-<manifest>
- <define>
- <domain name="iotcon-test" />
- <request>
- <smack request="iotcon" type="rw" />
- <smack request="device::app_logging" type="w" />
- <smack request="device::sys_logging" type="w" />
- </request>
- </define>
- <assign>
- <filesystem path="/usr/share/license/iotcon-test" label="_" />
- </assign>
- <request>
- <domain name="iotcon-test" />
- </request>
-</manifest>
+++ /dev/null
-<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
- "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
-
-<busconfig>
- <policy context="default">
- <allow own="@DBUS_INTERFACE@"/>
- <allow send_destination="@DBUS_INTERFACE@" send_interface="@DBUS_INTERFACE@"/>
- </policy>
-</busconfig>
+++ /dev/null
-<manifest>
- <request>
- <domain name="_" />
- </request>
-</manifest>
+++ /dev/null
-[Unit]
-Description=Tizen IoT Connectivity
-
-[Service]
-Type=simple
-ExecStart=/usr/bin/iotcon-daemon
-Restart=always
-User=iotcon
-
-[Install]
-WantedBy=multi-user.target
+++ /dev/null
-Name: iotcon
-Summary: Tizen IoT Connectivity
-Version: 0.0.7
-Release: 0
-Group: Network & Connectivity/Service
-License: Apache-2.0
-Source0: %{name}-%{version}.tar.gz
-Source1: %{name}.service
-Source2: %{name}-old.service
-Source1001: %{name}.manifest
-Source1002: %{name}-old.manifest
-Source1003: %{name}-test-old.manifest
-Source1004: %{name}.conf.in
-BuildRequires: cmake
-BuildRequires: boost-devel
-BuildRequires: pkgconfig(glib-2.0)
-BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(capi-base-common)
-BuildRequires: pkgconfig(capi-system-info)
-BuildRequires: pkgconfig(capi-system-system-settings)
-BuildRequires: pkgconfig(iotivity)
-%if 0%{?tizen_version_major} >= 3
-BuildRequires: pkgconfig(cynara-client)
-BuildRequires: pkgconfig(cynara-session)
-BuildRequires: pkgconfig(cynara-creds-gdbus)
-%endif
-%if "%{tizen}" == "2.3"
-BuildRequires: python-xml
-%endif
-%if 0%{?tizen_version_major} >= 3
-Requires(post): /usr/bin/getent, /usr/sbin/useradd, /usr/sbin/groupadd
-%endif
-Requires(post): /sbin/ldconfig, /usr/bin/systemctl
-Requires(postun): /sbin/ldconfig, /usr/bin/systemctl
-
-%define _unitdir /usr/lib/systemd/system
-%define _dbus_interface org.tizen.iotcon.dbus
-
-%description
-Tizen IoT Connectivity Service & Library(Client) based on Iotivity
-
-
-%package devel
-Summary: TizenIoT Connectivity(devel)
-Group: Network & Connectivity/Development
-Requires: %{name} = %{version}
-
-%description devel
-IoT Connectivity Manager development Kit
-
-
-%package test
-Summary: Tizen IoT Connectivity(test)
-Group: Network & Connectivity/Testing
-Requires: %{name} = %{version}
-
-%description test
-Tizen IoT Connectivity Test Programs
-
-
-%prep
-%setup -q
-chmod g-w %_sourcedir/*
-%if 0%{?tizen_version_major} < 3
-cp %{SOURCE2} ./%{name}.service
-cp %{SOURCE1002} ./%{name}.manifest
-cp %{SOURCE1003} ./%{name}-test.manifest
-%else
-cp %{SOURCE1} ./%{name}.service
-cp %{SOURCE1001} ./%{name}.manifest
-cp %{SOURCE1001} ./%{name}-test.manifest
-%endif
-
-
-%build
-%if 0%{?tizen_version_major} < 3
-TZ_VER_3=0
-%else
-TZ_VER_3=1
-%endif
-
-export LDFLAGS+="-Wl,--as-needed"
-MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DBIN_INSTALL_DIR:PATH=%{_bindir} \
- -DTZ_VER_3=${TZ_VER_3} -DDBUS_INTERFACE=%{_dbus_interface}
-
-
-%install
-rm -rf %{buildroot}
-%make_install
-
-mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants
-cp -af %{name}.service %{buildroot}%{_unitdir}/
-ln -s ../%{name}.service %{buildroot}%{_unitdir}/multi-user.target.wants/%{name}.service
-
-%if 0%{?tizen_version_major} < 3
-mkdir -p %{buildroot}/%{_datadir}/license
-cp LICENSE.APLv2 %{buildroot}/%{_datadir}/license/%{name}
-cp LICENSE.APLv2 %{buildroot}/%{_datadir}/license/%{name}-test
-%else
-sed -i 's/@DBUS_INTERFACE@/%{_dbus_interface}/g' %{SOURCE1004}
-mkdir -p %{buildroot}/%{_sysconfdir}/dbus-1/system.d
-cp -af %{SOURCE1004} %{buildroot}%{_sysconfdir}/dbus-1/system.d/%{name}.conf
-%endif
-
-
-%post
-%if 0%{?tizen_version_major} >= 3
-getent group iotcon > /dev/null || groupadd -r iotcon
-getent passwd iotcon > /dev/null || useradd -r -g iotcon -d '/var/lib/empty' -s /sbin/nologin -c "iotcon daemon" iotcon
-%endif
-
-systemctl daemon-reload
-if [ $1 == 1 ]; then
- systemctl restart %{name}.service
-fi
-/sbin/ldconfig
-
-%postun
-if [ $1 == 0 ]; then
- systemctl stop %{name}.service
-fi
-systemctl daemon-reload
-/sbin/ldconfig
-
-
-%files
-%manifest %{name}.manifest
-%defattr(-,root,root,-)
-%{_bindir}/%{name}-daemon
-%{_libdir}/lib%{name}.so.*
-%{_unitdir}/%{name}.service
-%{_unitdir}/multi-user.target.wants/%{name}.service
-%if 0%{?tizen_version_major} < 3
-%{_datadir}/license/%{name}
-%else
-%config %{_sysconfdir}/dbus-1/system.d/%{name}.conf
-%license LICENSE.APLv2
-%endif
-
-%files devel
-%defattr(-,root,root,-)
-%{_libdir}/lib%{name}.so
-%{_libdir}/pkgconfig/%{name}.pc
-%{_includedir}/%{name}/*.h
-
-%files test
-%manifest %{name}-test.manifest
-%defattr(-,root,root,-)
-%{_bindir}/iotcon-test-*
-%if 0%{?tizen_version_major} < 3
-%{_datadir}/license/%{name}-test
-%else
-%license LICENSE.APLv2
-%endif
--- /dev/null
+Name: org.tizen.iotcon-ptc-test
+Summary: IoTCon PTC Test companion applications
+Version: 0.0.3
+Release: 0
+Group: Network & Connectivity/Testing
+License: Apache-2.0
+Source0: %{name}-%{version}.tar.gz
+Source1: %{name}1.manifest
+Source2: %{name}2.manifest
+BuildRequires: cmake
+BuildRequires: boost-devel
+BuildRequires: gettext-tools
+BuildRequires: pkgconfig(capi-appfw-application)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(efl-extension)
+BuildRequires: pkgconfig(elementary)
+BuildRequires: pkgconfig(iotcon)
+BuildRequires: pkgconfig(libtzplatform-config)
+Requires(post): tizen-platform-config-tools
+
+%description
+IoTCon Applications for test internal APIs
+
+%package -n %{name}1
+Summary: IoTCon PTC Test1
+Group: Network & Connectivity/Testing
+
+%description -n %{name}1
+IoTCon Application for test internal APIs (#1)
+
+%package -n %{name}2
+Summary: IoTCon PTC Test2
+Group: Network & Connectivity/Testing
+
+%description -n %{name}2
+IoTCon Application for test internal APIs (#2)
+
+%prep
+%setup -q
+chmod g-w %_sourcedir/*
+cp %{SOURCE1} ./%{name}1.manifest
+cp %{SOURCE2} ./%{name}2.manifest
+%define _app_home_dir %{TZ_SYS_RO_APP}
+%define _app_icon_dir %{TZ_SYS_RO_ICONS}/default/small
+%define _app_manifest_dir %{TZ_SYS_RO_PACKAGES}
+
+
+%build
+%cmake . \
+ -DCMAKE_INSTALL_PREFIX=%{_app_home_dir} \
+ -DAPP_ICON_DIR=%{_app_icon_dir} \
+ -DFULLVER=%{version} \
+ -DMANIFEST_DIR=%{_app_manifest_dir}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+%post
+chsmack -e "System::Privileged" /usr/bin/tpk-backend
+tpk-backend -y %{name}1 --preload
+chsmack -e "User" /usr/bin/tpk-backend
+
+%post -n %{name}2
+chsmack -e "System::Privileged" /usr/bin/tpk-backend
+tpk-backend -y %{name}2 --preload
+chsmack -e "User" /usr/bin/tpk-backend
+
+%files -n %{name}1
+%manifest %{name}1.manifest
+%defattr(-,root,root,-)
+%{_app_home_dir}/%{name}1/*
+%{_app_icon_dir}/%{name}1.png
+%{_app_manifest_dir}/%{name}1.xml
+
+%files -n %{name}2
+%manifest %{name}2.manifest
+%defattr(-,root,root,-)
+%{_app_home_dir}/%{name}2/*
+%{_app_icon_dir}/%{name}2.png
+%{_app_manifest_dir}/%{name}2.xml
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+<manifest>
+ <request>
+ <domain name="_"/>
+ </request>
+</manifest>
--- /dev/null
+FILE(GLOB SRCS *.c)
+SET(PKGS capi-appfw-application dlog iotcon libtzplatform-config)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED ${PKGS})
+INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${pkgs_LIBRARY_DIRS})
+
+ADD_EXECUTABLE(${PROJECT_NAME}1 ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}1 ${pkgs_LIBRARIES})
+INSTALL(TARGETS ${PROJECT_NAME}1 DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}1/bin)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}1.xml DESTINATION ${MANIFEST_DIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}1.png DESTINATION ${APP_ICON_DIR})
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. 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.
+ */
+
+#undef LOG_TAG
+#define LOG_TAG "IOTCON_PTC_TEST1"
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. 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 <stdio.h>
+#include <app.h>
+#include <iotcon.h>
+#include <dlog.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <tzplatform_config.h>
+#include "log.h"
+
+#define PTC_TEST1_APP_ID "org.tizen.iotcon-ptc-test1"
+#define PTC_TEST1_SVR_DB_PATH tzplatform_mkpath(TZ_USER_APP, PTC_TEST1_APP_ID"/data/svr-db.dat")
+
+static int _create_svr_db1(const char *path)
+{
+ int fd;
+ int ret;
+
+ const uint8_t cbor_binary[] = {
+ 0xBF, 0x63, 0x61, 0x63, 0x6C, 0x59, 0x02, 0x47, 0xA4, 0x66, 0x61, 0x63,
+ 0x6C, 0x69, 0x73, 0x74, 0xA1, 0x64, 0x61, 0x63, 0x65, 0x73, 0x82, 0xA3,
+ 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75, 0x75, 0x69, 0x64,
+ 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73,
+ 0x83, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x68, 0x2F, 0x6F, 0x69, 0x63,
+ 0x2F, 0x72, 0x65, 0x73, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63,
+ 0x2E, 0x77, 0x6B, 0x2E, 0x72, 0x65, 0x73, 0x62, 0x69, 0x66, 0x81, 0x69,
+ 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x6C, 0x6C, 0x63, 0x72, 0x65,
+ 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69,
+ 0x63, 0x2F, 0x64, 0x62, 0x72, 0x74, 0x81, 0x68, 0x6F, 0x69, 0x63, 0x2E,
+ 0x77, 0x6B, 0x2E, 0x64, 0x62, 0x69, 0x66, 0x82, 0x6F, 0x6F, 0x69, 0x63,
+ 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
+ 0x68, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65,
+ 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69,
+ 0x63, 0x2F, 0x70, 0x62, 0x72, 0x74, 0x81, 0x68, 0x6F, 0x69, 0x63, 0x2E,
+ 0x77, 0x6B, 0x2E, 0x70, 0x62, 0x69, 0x66, 0x82, 0x6F, 0x6F, 0x69, 0x63,
+ 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
+ 0x68, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65,
+ 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73, 0x69, 0x6F,
+ 0x6E, 0x02, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75,
+ 0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72,
+ 0x63, 0x65, 0x73, 0x84, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F,
+ 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x64, 0x6F, 0x78, 0x6D,
+ 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64,
+ 0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
+ 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
+ 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6E, 0x2F,
+ 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x70, 0x73, 0x74, 0x61,
+ 0x74, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E,
+ 0x70, 0x73, 0x74, 0x61, 0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69,
+ 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E,
+ 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66,
+ 0x6C, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x61, 0x63,
+ 0x6C, 0x62, 0x72, 0x74, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E,
+ 0x61, 0x63, 0x6C, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
+ 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
+ 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F,
+ 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x63, 0x72, 0x65, 0x64,
+ 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x63,
+ 0x72, 0x65, 0x64, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
+ 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
+ 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73,
+ 0x69, 0x6F, 0x6E, 0x06, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75,
+ 0x75, 0x69, 0x64, 0x78, 0x24, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D,
+ 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x62, 0x72, 0x74, 0x81, 0x69, 0x6F, 0x69,
+ 0x63, 0x2E, 0x72, 0x2E, 0x61, 0x63, 0x6C, 0x62, 0x69, 0x66, 0x81, 0x6F,
+ 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C,
+ 0x69, 0x6E, 0x65, 0x65, 0x70, 0x73, 0x74, 0x61, 0x74, 0x58, 0x9D, 0xA9,
+ 0x64, 0x69, 0x73, 0x6F, 0x70, 0xF4, 0x62, 0x63, 0x6D, 0x02, 0x62, 0x74,
+ 0x6D, 0x00, 0x62, 0x6F, 0x6D, 0x04, 0x62, 0x73, 0x6D, 0x04, 0x6A, 0x64,
+ 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30,
+ 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x6A,
+ 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30,
+ 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x70,
+ 0x73, 0x74, 0x61, 0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63,
+ 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
+ 0x64, 0x64, 0x6F, 0x78, 0x6D, 0x58, 0xE9, 0xBF, 0x64, 0x6F, 0x78, 0x6D,
+ 0x73, 0x81, 0x00, 0x66, 0x6F, 0x78, 0x6D, 0x73, 0x65, 0x6C, 0x00, 0x63,
+ 0x73, 0x63, 0x74, 0x01, 0x65, 0x6F, 0x77, 0x6E, 0x65, 0x64, 0xF4, 0x6A,
+ 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24,
+ 0x38, 0x62, 0x65, 0x66, 0x38, 0x64, 0x32, 0x30, 0x2D, 0x61, 0x32, 0x36,
+ 0x35, 0x2D, 0x31, 0x31, 0x65, 0x36, 0x2D, 0x62, 0x36, 0x30, 0x35, 0x2D,
+ 0x35, 0x30, 0x62, 0x37, 0x63, 0x33, 0x61, 0x62, 0x37, 0x62, 0x31, 0x30,
+ 0x6C, 0x64, 0x65, 0x76, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69,
+ 0x64, 0x78, 0x24, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D,
+ 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30,
+ 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75,
+ 0x69, 0x64, 0x78, 0x24, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30,
+ 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x72, 0x78, 0x2E, 0x6F, 0x72, 0x67, 0x2E, 0x69,
+ 0x6F, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2E, 0x64, 0x70, 0x63, 0xF5,
+ 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64,
+ 0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
+ 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0xFF
+ };
+
+ fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0660);
+ if (fd < 0) {
+ SLOGE("open() Fail(%d)", errno);
+ return 1;
+ }
+
+ ret = write(fd, cbor_binary, sizeof(cbor_binary));
+ if (ret <= 0) {
+ SLOGE("write() Fail(%d)", errno);
+ close(fd);
+ return 1;
+ }
+ close(fd);
+
+ return 0;
+}
+
+static void _create_resource()
+{
+ int ret;
+ iotcon_lite_resource_h lite_resource;
+ iotcon_resource_types_h types;
+ iotcon_attributes_h attributes;
+
+ SLOGD("_create_resource()");
+
+ ret = iotcon_resource_types_create(&types);
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_resource_types_create() Fail(%d)", ret);
+ ret = iotcon_resource_types_add(types, "res.ptc");
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_resource_types_add() Fail(%d)", ret);
+
+ ret = iotcon_attributes_create(&attributes);
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_attributes_create() Fail(%d)", ret);
+ ret = iotcon_attributes_add_int(attributes, "attr", 1);
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_attributes_add_int() Fail(%d)", ret);
+
+ ret = iotcon_lite_resource_create("/res/ptc1",
+ types,
+ IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_SECURE,
+ attributes,
+ NULL,
+ NULL,
+ &lite_resource);
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_lite_resource_create() Fail(%d)", ret);
+
+ iotcon_attributes_destroy(attributes);
+ iotcon_resource_types_destroy(types);
+}
+
+static bool ui_app_create(void *data)
+{
+ SLOGI("App created!!!");
+ int ret;
+
+ SLOGD("remove(%s)", PTC_TEST1_SVR_DB_PATH);
+ if (-1 == remove(PTC_TEST1_SVR_DB_PATH))
+ SLOGE("remove() Fail(%d)", errno);
+
+ _create_svr_db1(PTC_TEST1_SVR_DB_PATH);
+
+ ret = iotcon_initialize(PTC_TEST1_SVR_DB_PATH);
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_initialize(%s) Fail(%d)", PTC_TEST1_SVR_DB_PATH, ret);
+
+ ret = iotcon_set_device_name(PTC_TEST1_APP_ID);
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_set_device_name() Fail(%d)", ret);
+
+ _create_resource();
+
+ return true;
+}
+
+static void ui_app_control(app_control_h app_control, void *data)
+{
+ char *operation;
+
+ app_control_get_operation(app_control, &operation);
+ SLOGD("operation(%s)", operation);
+
+ if (!strcmp(operation, APP_CONTROL_OPERATION_DEFAULT)) {
+ app_control_h reply;
+ app_control_create(&reply);
+ app_control_reply_to_launch_request(reply, app_control, APP_CONTROL_RESULT_SUCCEEDED);
+ app_control_destroy(reply);
+ }
+}
+
+static void ui_app_terminate(void *data)
+{
+ /* Release all resources. */
+}
+
+static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_LANGUAGE_CHANGED*/
+ return;
+}
+
+static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
+ return;
+}
+
+static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_REGION_FORMAT_CHANGED*/
+}
+
+static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_LOW_BATTERY*/
+}
+
+static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_LOW_MEMORY*/
+}
+
+int main(int argc, char *argv[])
+{
+ char ad[50] = {0,};
+ int ret = 0;
+
+ ui_app_lifecycle_callback_s event_callback = {0,};
+ app_event_handler_h handlers[5] = {NULL, };
+
+ event_callback.create = ui_app_create;
+ event_callback.terminate = ui_app_terminate;
+ event_callback.app_control = ui_app_control;
+
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
+
+ ret = ui_app_main(argc, argv, &event_callback, &ad);
+ if (ret != APP_ERROR_NONE)
+ SLOGE("app_main() is failed. err = %d", ret);
+
+ return ret;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns="http://tizen.org/ns/packages" package="org.tizen.iotcon-ptc-test1" api-version="3.0" version="0.0.1" type="rpm">
+ <ui-application appid="org.tizen.iotcon-ptc-test1" exec="/usr/apps/org.tizen.iotcon-ptc-test1/bin/org.tizen.iotcon-ptc-test1" type="capp" multiple="false" taskmanage="true" nodisplay="false">
+ <label>IoTCon PTC Test1</label>
+ <icon>org.tizen.iotcon-ptc-test1.png</icon>
+ <background-category value="background-network" />
+ <app-control>
+ <operation name="http://tizen.org/appcontrol/operation/default"/>
+ </app-control>
+ </ui-application>
+ <privileges>
+ <privilege>http://tizen.org/privilege/network.get</privilege>
+ <privilege>http://tizen.org/privilege/internet</privilege>
+ </privileges>
+</manifest>
+
--- /dev/null
+FILE(GLOB SRCS *.c)
+SET(PKGS capi-appfw-application dlog iotcon libtzplatform-config)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED ${PKGS})
+INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${pkgs_LIBRARY_DIRS})
+
+ADD_EXECUTABLE(${PROJECT_NAME}2 ${SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}2 ${pkgs_LIBRARIES})
+INSTALL(TARGETS ${PROJECT_NAME}2 DESTINATION ${CMAKE_INSTALL_PREFIX}/${PROJECT_NAME}2/bin)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}2.xml DESTINATION ${MANIFEST_DIR})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}2.png DESTINATION ${APP_ICON_DIR})
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. 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.
+ */
+
+#undef LOG_TAG
+#define LOG_TAG "IOTCON_PTC_TEST2"
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. 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 <stdio.h>
+#include <app.h>
+#include <iotcon.h>
+#include <dlog.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <tzplatform_config.h>
+#include "log.h"
+
+#define PTC_TEST2_APP_ID "org.tizen.iotcon-ptc-test2"
+#define PTC_TEST2_SVR_DB_PATH tzplatform_mkpath(TZ_USER_APP, PTC_TEST2_APP_ID"/data/svr-db.dat")
+
+static int _create_svr_db2(const char *path)
+{
+ int fd;
+ int ret;
+ const uint8_t cbor_binary[] = {
+ 0xBF, 0x63, 0x61, 0x63, 0x6C, 0x59, 0x02, 0x47, 0xA4, 0x66, 0x61, 0x63,
+ 0x6C, 0x69, 0x73, 0x74, 0xA1, 0x64, 0x61, 0x63, 0x65, 0x73, 0x82, 0xA3,
+ 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75, 0x75, 0x69, 0x64,
+ 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x73,
+ 0x83, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x68, 0x2F, 0x6F, 0x69, 0x63,
+ 0x2F, 0x72, 0x65, 0x73, 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63,
+ 0x2E, 0x77, 0x6B, 0x2E, 0x72, 0x65, 0x73, 0x62, 0x69, 0x66, 0x81, 0x69,
+ 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x6C, 0x6C, 0x63, 0x72, 0x65,
+ 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69,
+ 0x63, 0x2F, 0x64, 0x62, 0x72, 0x74, 0x81, 0x68, 0x6F, 0x69, 0x63, 0x2E,
+ 0x77, 0x6B, 0x2E, 0x64, 0x62, 0x69, 0x66, 0x82, 0x6F, 0x6F, 0x69, 0x63,
+ 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
+ 0x68, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65,
+ 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x66, 0x2F, 0x6F, 0x69,
+ 0x63, 0x2F, 0x70, 0x62, 0x72, 0x74, 0x81, 0x68, 0x6F, 0x69, 0x63, 0x2E,
+ 0x77, 0x6B, 0x2E, 0x70, 0x62, 0x69, 0x66, 0x82, 0x6F, 0x6F, 0x69, 0x63,
+ 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
+ 0x68, 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x72, 0x63, 0x72, 0x65,
+ 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73, 0x69, 0x6F,
+ 0x6E, 0x02, 0xA3, 0x6B, 0x73, 0x75, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x75,
+ 0x75, 0x69, 0x64, 0x61, 0x2A, 0x69, 0x72, 0x65, 0x73, 0x6F, 0x75, 0x72,
+ 0x63, 0x65, 0x73, 0x84, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F,
+ 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x64, 0x6F, 0x78, 0x6D,
+ 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64,
+ 0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
+ 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
+ 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6E, 0x2F,
+ 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x70, 0x73, 0x74, 0x61,
+ 0x74, 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E,
+ 0x70, 0x73, 0x74, 0x61, 0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69,
+ 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E,
+ 0x65, 0x63, 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66,
+ 0x6C, 0x2F, 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x61, 0x63,
+ 0x6C, 0x62, 0x72, 0x74, 0x81, 0x69, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E,
+ 0x61, 0x63, 0x6C, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
+ 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
+ 0x72, 0x65, 0x6C, 0x60, 0xA4, 0x64, 0x68, 0x72, 0x65, 0x66, 0x6D, 0x2F,
+ 0x6F, 0x69, 0x63, 0x2F, 0x73, 0x65, 0x63, 0x2F, 0x63, 0x72, 0x65, 0x64,
+ 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x63,
+ 0x72, 0x65, 0x64, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
+ 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0x63,
+ 0x72, 0x65, 0x6C, 0x60, 0x6A, 0x70, 0x65, 0x72, 0x6D, 0x69, 0x73, 0x73,
+ 0x69, 0x6F, 0x6E, 0x06, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75,
+ 0x75, 0x69, 0x64, 0x78, 0x24, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D,
+ 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x62, 0x72, 0x74, 0x81, 0x69, 0x6F, 0x69,
+ 0x63, 0x2E, 0x72, 0x2E, 0x61, 0x63, 0x6C, 0x62, 0x69, 0x66, 0x81, 0x6F,
+ 0x6F, 0x69, 0x63, 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C,
+ 0x69, 0x6E, 0x65, 0x65, 0x70, 0x73, 0x74, 0x61, 0x74, 0x58, 0x9D, 0xA9,
+ 0x64, 0x69, 0x73, 0x6F, 0x70, 0xF4, 0x62, 0x63, 0x6D, 0x02, 0x62, 0x74,
+ 0x6D, 0x00, 0x62, 0x6F, 0x6D, 0x04, 0x62, 0x73, 0x6D, 0x04, 0x6A, 0x64,
+ 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30,
+ 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x6A,
+ 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30,
+ 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D,
+ 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x62, 0x72, 0x74, 0x81, 0x6B, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x70,
+ 0x73, 0x74, 0x61, 0x74, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63,
+ 0x2E, 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65,
+ 0x64, 0x64, 0x6F, 0x78, 0x6D, 0x58, 0xE9, 0xBF, 0x64, 0x6F, 0x78, 0x6D,
+ 0x73, 0x81, 0x00, 0x66, 0x6F, 0x78, 0x6D, 0x73, 0x65, 0x6C, 0x00, 0x63,
+ 0x73, 0x63, 0x74, 0x01, 0x65, 0x6F, 0x77, 0x6E, 0x65, 0x64, 0xF4, 0x6A,
+ 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x75, 0x75, 0x69, 0x64, 0x78, 0x24,
+ 0x38, 0x62, 0x34, 0x65, 0x32, 0x37, 0x36, 0x65, 0x2D, 0x61, 0x32, 0x36,
+ 0x35, 0x2D, 0x31, 0x31, 0x65, 0x36, 0x2D, 0x38, 0x36, 0x63, 0x30, 0x2D,
+ 0x35, 0x30, 0x62, 0x37, 0x63, 0x33, 0x61, 0x62, 0x37, 0x62, 0x31, 0x30,
+ 0x6C, 0x64, 0x65, 0x76, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75, 0x69,
+ 0x64, 0x78, 0x24, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x2D,
+ 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30,
+ 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x6A, 0x72, 0x6F, 0x77, 0x6E, 0x65, 0x72, 0x75, 0x75,
+ 0x69, 0x64, 0x78, 0x24, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x2D, 0x30,
+ 0x30, 0x30, 0x30, 0x2D, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
+ 0x30, 0x30, 0x30, 0x30, 0x72, 0x78, 0x2E, 0x6F, 0x72, 0x67, 0x2E, 0x69,
+ 0x6F, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2E, 0x64, 0x70, 0x63, 0xF5,
+ 0x62, 0x72, 0x74, 0x81, 0x6A, 0x6F, 0x69, 0x63, 0x2E, 0x72, 0x2E, 0x64,
+ 0x6F, 0x78, 0x6D, 0x62, 0x69, 0x66, 0x81, 0x6F, 0x6F, 0x69, 0x63, 0x2E,
+ 0x69, 0x66, 0x2E, 0x62, 0x61, 0x73, 0x65, 0x6C, 0x69, 0x6E, 0x65, 0xFF
+ };
+
+ fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0660);
+ if (fd < 0) {
+ SLOGE("open() Fail(%d)", errno);
+ return 1;
+ }
+
+ ret = write(fd, cbor_binary, sizeof(cbor_binary));
+ if (ret <= 0) {
+ SLOGE("write() Fail(%d)", errno);
+ close(fd);
+ return 1;
+ }
+ close(fd);
+
+ return 0;
+}
+
+static bool ui_app_create(void *data)
+{
+ SLOGI("App created!!!");
+ int ret;
+
+ SLOGD("remove(%s)", PTC_TEST2_SVR_DB_PATH);
+ if (-1 == remove(PTC_TEST2_SVR_DB_PATH))
+ SLOGE("remove() Fail(%d)", errno);
+
+ SLOGD("_create_svr_db2(%s)", PTC_TEST2_SVR_DB_PATH);
+ _create_svr_db2(PTC_TEST2_SVR_DB_PATH);
+
+ ret = iotcon_initialize(PTC_TEST2_SVR_DB_PATH);
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_initialize(%s) Fail(%d)", PTC_TEST2_SVR_DB_PATH, ret);
+
+ ret = iotcon_set_device_name(PTC_TEST2_APP_ID);
+ if (IOTCON_ERROR_NONE != ret)
+ SLOGE("iotcon_set_device_name() Fail(%d)", ret);
+
+ return true;
+}
+
+static void ui_app_control(app_control_h app_control, void *data)
+{
+ char *operation;
+
+ app_control_get_operation(app_control, &operation);
+ SLOGD("operation(%s)", operation);
+
+ if (!strcmp(operation, APP_CONTROL_OPERATION_DEFAULT)) {
+ app_control_h reply;
+ app_control_create(&reply);
+ app_control_reply_to_launch_request(reply, app_control, APP_CONTROL_RESULT_SUCCEEDED);
+ app_control_destroy(reply);
+ }
+}
+
+static void ui_app_terminate(void *data)
+{
+ /* Release all resources. */
+}
+
+static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_LANGUAGE_CHANGED*/
+ return;
+}
+
+static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
+ return;
+}
+
+static void ui_app_region_changed(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_REGION_FORMAT_CHANGED*/
+}
+
+static void ui_app_low_battery(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_LOW_BATTERY*/
+}
+
+static void ui_app_low_memory(app_event_info_h event_info, void *user_data)
+{
+ /*APP_EVENT_LOW_MEMORY*/
+}
+
+int main(int argc, char *argv[])
+{
+ char ad[50] = {0,};
+ int ret = 0;
+
+ ui_app_lifecycle_callback_s event_callback = {0,};
+ app_event_handler_h handlers[5] = {NULL, };
+
+ event_callback.create = ui_app_create;
+ event_callback.terminate = ui_app_terminate;
+ event_callback.app_control = ui_app_control;
+
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
+ ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
+
+ ret = ui_app_main(argc, argv, &event_callback, &ad);
+ if (ret != APP_ERROR_NONE)
+ SLOGE("app_main() is failed. err = %d", ret);
+
+ return ret;
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns="http://tizen.org/ns/packages" package="org.tizen.iotcon-ptc-test2" api-version="3.0" version="0.0.1" type="rpm">
+ <ui-application appid="org.tizen.iotcon-ptc-test2" exec="/usr/apps/org.tizen.iotcon-ptc-test2/bin/org.tizen.iotcon-ptc-test2" type="capp" multiple="false" taskmanage="true" nodisplay="false">
+ <label>IoTCon PTC Test2</label>
+ <icon>org.tizen.iotcon-ptc-test2.png</icon>
+ <background-category value="background-network" />
+ <app-control>
+ <operation name="http://tizen.org/appcontrol/operation/default"/>
+ </app-control>
+ </ui-application>
+ <privileges>
+ <privilege>http://tizen.org/privilege/network.get</privilege>
+ <privilege>http://tizen.org/privilege/internet</privilege>
+ </privileges>
+</manifest>
+
+++ /dev/null
-LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/include)
-
-SET(IOTCON_TEST_BASIC_CLIENT "iotcon-test-basic-client")
-SET(IOTCON_TEST_BASIC_SERVER "iotcon-test-basic-server")
-SET(IOTCON_TEST_BASIC_CLIENT_SRCS "iotcon-test-basic-client.c")
-SET(IOTCON_TEST_BASIC_SERVER_SRCS "iotcon-test-basic-server.c")
-
-SET(IOTCON_TEST_DEVICE_CLIENT "iotcon-test-device-client")
-SET(IOTCON_TEST_DEVICE_CLIENT_SRCS "iotcon-test-device-client.c")
-
-SET(IOTCON_TEST_IFACE_CLIENT "iotcon-test-iface-client")
-SET(IOTCON_TEST_IFACE_SERVER "iotcon-test-iface-server")
-SET(IOTCON_TEST_IFACE_CLIENT_SRCS "iotcon-test-iface-client.c")
-SET(IOTCON_TEST_IFACE_SERVER_SRCS "iotcon-test-iface-server.c")
-
-SET(IOTCON_TEST_ENCAP_CLIENT "iotcon-test-encap-client")
-SET(IOTCON_TEST_ENCAP_SERVER "iotcon-test-encap-server")
-SET(IOTCON_TEST_ENCAP_CLIENT_SRCS "iotcon-test-encap-client.c")
-SET(IOTCON_TEST_ENCAP_SERVER_SRCS "iotcon-test-encap-server.c")
-
-pkg_check_modules(test_pkgs REQUIRED dlog glib-2.0)
-INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS})
-LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
-
-ADD_EXECUTABLE(${IOTCON_TEST_BASIC_CLIENT} ${IOTCON_TEST_BASIC_CLIENT_SRCS})
-TARGET_LINK_LIBRARIES(${IOTCON_TEST_BASIC_CLIENT} ${test_pkgs_LIBRARIES} ${CLIENT})
-INSTALL(TARGETS ${IOTCON_TEST_BASIC_CLIENT} DESTINATION ${BIN_INSTALL_DIR})
-
-ADD_EXECUTABLE(${IOTCON_TEST_BASIC_SERVER} ${IOTCON_TEST_BASIC_SERVER_SRCS})
-TARGET_LINK_LIBRARIES(${IOTCON_TEST_BASIC_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT})
-INSTALL(TARGETS ${IOTCON_TEST_BASIC_SERVER} DESTINATION ${BIN_INSTALL_DIR})
-
-ADD_EXECUTABLE(${IOTCON_TEST_DEVICE_CLIENT} ${IOTCON_TEST_DEVICE_CLIENT_SRCS})
-TARGET_LINK_LIBRARIES(${IOTCON_TEST_DEVICE_CLIENT} ${test_pkgs_LIBRARIES} ${CLIENT})
-INSTALL(TARGETS ${IOTCON_TEST_DEVICE_CLIENT} DESTINATION ${BIN_INSTALL_DIR})
-
-ADD_EXECUTABLE(${IOTCON_TEST_IFACE_CLIENT} ${IOTCON_TEST_IFACE_CLIENT_SRCS})
-TARGET_LINK_LIBRARIES(${IOTCON_TEST_IFACE_CLIENT} ${test_pkgs_LIBRARIES} ${CLIENT})
-INSTALL(TARGETS ${IOTCON_TEST_IFACE_CLIENT} DESTINATION ${BIN_INSTALL_DIR})
-
-ADD_EXECUTABLE(${IOTCON_TEST_IFACE_SERVER} ${IOTCON_TEST_IFACE_SERVER_SRCS})
-TARGET_LINK_LIBRARIES(${IOTCON_TEST_IFACE_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT})
-INSTALL(TARGETS ${IOTCON_TEST_IFACE_SERVER} DESTINATION ${BIN_INSTALL_DIR})
-
-ADD_EXECUTABLE(${IOTCON_TEST_ENCAP_CLIENT} ${IOTCON_TEST_ENCAP_CLIENT_SRCS})
-TARGET_LINK_LIBRARIES(${IOTCON_TEST_ENCAP_CLIENT} ${test_pkgs_LIBRARIES} ${CLIENT})
-INSTALL(TARGETS ${IOTCON_TEST_ENCAP_CLIENT} DESTINATION ${BIN_INSTALL_DIR})
-
-ADD_EXECUTABLE(${IOTCON_TEST_ENCAP_SERVER} ${IOTCON_TEST_ENCAP_SERVER_SRCS})
-TARGET_LINK_LIBRARIES(${IOTCON_TEST_ENCAP_SERVER} ${test_pkgs_LIBRARIES} ${CLIENT})
-INSTALL(TARGETS ${IOTCON_TEST_ENCAP_SERVER} DESTINATION ${BIN_INSTALL_DIR})
-
+++ /dev/null
- IoTCon(Tizen IoT Connectivity) Test Program
-
-
-If you install the "iotcon package", you can test operations of iotcon.
-The result of test is printed out through DLOG. If you specify the LOG_TAG value
-to 'ICTEST'(&'IOTCON'), you can see the output of test programs.
-
-There are four pairs of test programs.
-
-
-1. Basic Test
-
-It is for testing CRUDN methods. A client can require CRUDN operations to server's resource
-through iotcon_remote_resource_get/put/post/delete() and iotcon_remote_resource_observe_register().
-
- $ /usr/bin/iotcon-test-basic-server
- $ /usr/bin/iotcon-test-basic-client
-
-
-2. Interface Test
-
-You can check the operations of resource that contains child resources. If the client
-require GET operation to server's parent resource, server sends response with representation
-including children's information. The contents of information are decided by the resource
-interface set by server. Client can send desired interface with request to server.
-
- $ /usr/bin/iotcon-test-iface-server
- $ /usr/bin/iotcon-test-iface-client
-
-
-3. Get Device/Platform Information Test
-
-Because device information and platform information are set by iotcon, you can check the
-information through iotcon_get_device_info() and iotcon_get_platform_info().
-
- $ /usr/bin/iotcon-test-device-client
-
-
-4. Resource Encapsulation Test
-
-It is for testing resource encapsulation. Resource Encapsulation consists of lite resource,
-resource monitoring, and resource caching. If the server uses lite resource, there is no
-need to create a request handler. The client can check resource's state
-using iotcon_remote_resource_start_monitoring(). Also, the client can keep the resource's
-representation up to date using iotcon_remote_resource_start_caching().
-
- $ /usr/bin/iotcon-test-encap-server
- $ /usr/bin/iotcon-test-encap-client
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-#include <tizen_type.h>
-
-#include <iotcon.h>
-#include "test.h"
-
-static char *door_resource_device_id;
-static GList *device_id_list;
-
-#define DOOR_RESOURCE_URI_PREFIX "/door"
-#define DOOR_RESOURCE_TYPE "org.tizen.door"
-
-static void _on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
- iotcon_request_type_e request_type, iotcon_response_h response, void *user_data);
-
-static void _on_observe(iotcon_remote_resource_h resource, iotcon_error_e err,
- int sequece_number, iotcon_response_h response, void *user_data)
-{
- int ret;
- bool opened;
- static int i = 0;
- iotcon_state_h state;
- iotcon_representation_h repr;
- iotcon_response_result_e response_result;
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_RESPONSE_OK != response_result) {
- ERR("_on_response_observe Response error(%d)", response_result);
- return;
- }
-
- ret = iotcon_response_get_representation(response, &repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_representation() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_representation_get_state(repr, &state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_state_get_bool(state, "opened", &opened);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
- return;
- }
-
- INFO("notify_cb information");
- switch (opened) {
- case true:
- INFO("[Door] opened.");
- break;
- case false:
- INFO("[Door] closed.");
- break;
- default:
- break;
- }
-
- if (5 == i++) {
- iotcon_remote_resource_observe_deregister(resource);
- iotcon_remote_resource_destroy(resource);
- }
-}
-
-static void _on_response_delete(iotcon_remote_resource_h resource,
- iotcon_response_h response, void *user_data)
-{
- int ret;
- iotcon_response_result_e response_result;
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_RESPONSE_OK != response_result
- && IOTCON_RESPONSE_RESOURCE_DELETED != response_result) {
- ERR("_on_response_delete Response error(%d)", response_result);
- return;
- }
- INFO("DELETE request was successful");
-
- /* delete callback operations */
-
- iotcon_remote_resource_destroy(resource);
-}
-
-static void _on_response_post(iotcon_remote_resource_h resource,
- iotcon_response_h response, void *user_data)
-{
- int ret;
- iotcon_state_h recv_state;
- char *host, *created_uri_path;
- iotcon_connectivity_type_e connectivity_type;
- iotcon_response_result_e response_result;
- iotcon_resource_types_h types = NULL;
- iotcon_resource_interfaces_h ifaces = NULL;
- iotcon_remote_resource_h new_door_resource;
- iotcon_representation_h recv_repr = NULL;
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_RESPONSE_OK != response_result
- && IOTCON_RESPONSE_RESOURCE_CREATED != response_result) {
- ERR("_on_response_post Response error(%d)", response_result);
- return;
- }
- INFO("POST request was successful");
-
- ret = iotcon_response_get_representation(response, &recv_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_representation() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_representation_get_state(recv_repr, &recv_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_state_get_str(recv_state, "createduripath", &created_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_str() Fail(%d)", ret);
- return;
- }
- DBG("New resource created : %s", created_uri_path);
-
- ret = iotcon_remote_resource_get_host_address(resource, &host);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_host_address() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_remote_resource_get_connectivity_type(resource, &connectivity_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_connectivity_type() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_remote_resource_get_types(resource, &types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_types() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_remote_resource_get_interfaces(resource, &ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_remote_resource_create(host, connectivity_type, created_uri_path,
- IOTCON_RESOURCE_NO_PROPERTY, types, ifaces, &new_door_resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_create() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_remote_resource_delete(new_door_resource, _on_response, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_delete() Fail(%d)", ret);
- iotcon_remote_resource_destroy(new_door_resource);
- return;
- }
-}
-
-static void _on_response_put(iotcon_remote_resource_h resource, iotcon_response_h response,
- void *user_data)
-{
- int ret;
- iotcon_response_result_e response_result;
- iotcon_representation_h send_repr;
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_RESPONSE_OK != response_result) {
- ERR("_on_response_put Response error(%d)", response_result);
- return;
- }
- INFO("PUT request was successful");
-
- ret = iotcon_representation_create(&send_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return;
- }
-
- /* send POST request */
- ret = iotcon_remote_resource_post(resource, send_repr, NULL, _on_response, NULL);
- if (IOTCON_ERROR_NONE != ret)
- ERR("iotcon_remote_resource_post() Fail(%d)", ret);
-
- iotcon_representation_destroy(send_repr);
-}
-
-static void _on_response_get(iotcon_remote_resource_h resource,
- iotcon_response_h response, void *user_data)
-{
- int ret;
- bool opened = true;
- iotcon_response_result_e response_result;
- iotcon_representation_h send_repr;
- iotcon_representation_h recv_repr;
- iotcon_state_h send_state;
- iotcon_state_h recv_state = NULL;
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_RESPONSE_OK != response_result) {
- ERR("_on_response_get Response error(%d)", response_result);
- return;
- }
-
- /* get the resource host address */
- char *resource_host = NULL;
- iotcon_remote_resource_get_host_address(resource, &resource_host);
- INFO("resource host : %s", resource_host);
-
- ret = iotcon_response_get_representation(response, &recv_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_representation() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_representation_get_state(recv_repr, &recv_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_state_get_bool(recv_state, "opened", &opened);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_representation_create(&send_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_state_create(&send_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_representation_destroy(send_repr);
- return;
- }
-
- ret = iotcon_state_add_bool(send_state, "opened", !opened);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
- iotcon_representation_destroy(send_repr);
- return;
- }
-
- ret = iotcon_representation_set_state(send_repr, send_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
- iotcon_representation_destroy(send_repr);
- return;
- }
-
- iotcon_state_destroy(send_state);
-
- /* send PUT request */
- ret = iotcon_remote_resource_put(resource, send_repr, NULL, _on_response, NULL);
- if (IOTCON_ERROR_NONE != ret)
- ERR("iotcon_remote_resource_put() Fail(%d)", ret);
-
- iotcon_representation_destroy(send_repr);
-}
-
-static bool _get_res_iface_cb(const char *string, void *user_data)
-{
- char *resource_uri_path = user_data;
-
- DBG("[%s] resource interface : %s", resource_uri_path, string);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-static bool _get_res_type_cb(const char *string, void *user_data)
-{
- char *resource_uri_path = user_data;
-
- DBG("[%s] resource type : %s", resource_uri_path, string);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-static void _presence_handler(iotcon_presence_h presence, iotcon_error_e err,
- iotcon_presence_response_h response, void *user_data)
-{
- char *host_address;
- char *resource_type;
- int ret;
- iotcon_presence_result_e result;
- iotcon_presence_trigger_e trigger;
- iotcon_connectivity_type_e connectivity_type;
-
- RETM_IF(IOTCON_ERROR_NONE != err, "_presence_handler error(%d)", err);
-
- ret = iotcon_presence_response_get_result(response, &result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_result() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_PRESENCE_OK == result) {
- ret = iotcon_presence_response_get_trigger(response, &trigger);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_trigger() Fail(%d)", ret);
- return;
- }
- }
-
- ret = iotcon_presence_response_get_host_address(response, &host_address);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_host_address() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_presence_response_get_connectivity_type(response, &connectivity_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_connectivity_type() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_presence_response_get_resource_type(response, &resource_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_presence_response_get_resource_type() Fail(%d)", ret);
- return;
- }
-
- INFO("_presence_handler");
- INFO("result : %d", result);
- if (IOTCON_PRESENCE_OK == result)
- INFO("trigger : %d", trigger);
- INFO("host_address : %s", host_address);
- INFO("resource_type : %s", resource_type);
-}
-
-static int _device_id_compare(const void *a, const void *b)
-{
- return strcmp(a, b);
-}
-
-static void _on_response(iotcon_remote_resource_h resource, iotcon_error_e err,
- iotcon_request_type_e request_type, iotcon_response_h response, void *user_data)
-{
- RETM_IF(IOTCON_ERROR_NONE != err, "_on_response error(%d)", err);
- INFO("request(%d) was successful", request_type);
-
- switch (request_type) {
- case IOTCON_REQUEST_GET:
- _on_response_get(resource, response, user_data);
- break;
- case IOTCON_REQUEST_PUT:
- _on_response_put(resource, response, user_data);
- break;
- case IOTCON_REQUEST_POST:
- _on_response_post(resource, response, user_data);
- break;
- case IOTCON_REQUEST_DELETE:
- _on_response_delete(resource, response, user_data);
- break;
- default:
- ERR("Invalid request type (%d)", request_type);
- return;
- }
-}
-
-static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
- void *user_data)
-{
- int ret;
- GList *node;
- char *resource_host;
- char *resource_uri_path;
- char *resource_device_id;
- iotcon_presence_h presence_handle;
- iotcon_resource_types_h resource_types;
- iotcon_resource_interfaces_h resource_interfaces;
- iotcon_connectivity_type_e connectivity_type;
- iotcon_remote_resource_h resource_clone = NULL;
-
- RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result(%d)", result);
-
- if (NULL == resource)
- return;
-
- INFO("===== resource found =====");
-
- /* get the resource URI */
- ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_uri_path() Fail(%d)", ret);
- return;
- }
-
- /* get the device unique id.
- * this is unique per-server independent on how it was discovered. */
- ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_device_id() Fail(%d)", ret);
- return;
- }
- DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id);
-
- node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
-
- if (node && TEST_STR_EQUAL == strncmp(DOOR_RESOURCE_URI_PREFIX, resource_uri_path,
- strlen(DOOR_RESOURCE_URI_PREFIX))) {
- DBG("uri_path \"%s\" already found. skip !", resource_uri_path);
- return;
- }
-
- door_resource_device_id = strdup(resource_device_id);
- if (NULL == door_resource_device_id) {
- ERR("strdup(door_resource_device_id) Fail");
- return;
- }
-
- device_id_list = g_list_append(device_id_list, door_resource_device_id);
-
- /* get the resource host address */
- ret = iotcon_remote_resource_get_host_address(resource, &resource_host);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_host_address() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
- DBG("[%s] resource host : %s", resource_uri_path, resource_host);
-
- ret = iotcon_remote_resource_get_connectivity_type(resource, &connectivity_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_connectivity_type() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- /* get the resource interfaces */
- ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
- resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- /* get the resource types */
- ret = iotcon_remote_resource_get_types(resource, &resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_types() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb,
- resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_add_presence_cb(resource_host, connectivity_type, DOOR_RESOURCE_TYPE,
- _presence_handler, NULL, &presence_handle);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_add_presence_cb() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- if (TEST_STR_EQUAL == strncmp(DOOR_RESOURCE_URI_PREFIX, resource_uri_path,
- strlen(DOOR_RESOURCE_URI_PREFIX))) {
- iotcon_query_h query;
-
- ret = iotcon_remote_resource_clone(resource, &resource_clone);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_clone() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_remote_resource_observe_register(resource_clone,
- IOTCON_OBSERVE_IGNORE_OUT_OF_ORDER, NULL, _on_observe, NULL);
-
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_observe_register() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_query_create(&query);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_query_create() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_query_add(query, "query_key", "query_value");
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_query_add() Fail(%d)", ret);
- iotcon_query_destroy(query);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- /* send GET Request */
- ret = iotcon_remote_resource_get(resource_clone, query, _on_response, NULL);
- if (IOTCON_ERROR_NONE != ret)
- ERR("iotcon_remote_resource_get() Fail(%d)", ret);
-
- iotcon_query_destroy(query);
- }
-
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
-}
-
-int main(int argc, char **argv)
-{
- FN_CALL;
- int ret;
- GMainLoop *loop;
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* connect iotcon */
- ret = iotcon_connect();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_connect() Fail(%d)", ret);
- return -1;
- }
-
- /* find door typed resources */
- ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
- DOOR_RESOURCE_TYPE, false, _found_resource, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_find_resource() Fail(%d)", ret);
- iotcon_disconnect();
- return -1;
- }
-
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
-
- g_list_free_full(device_id_list, free);
-
- /* disconnect iotcon */
- iotcon_disconnect();
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-
-#include <iotcon.h>
-#include <iotcon-internal.h>
-#include "test.h"
-
-#define DOOR_RESOURCE_URI "/door/1"
-#define DOOR_RESOURCE_URI2 "/door/2"
-#define DOOR_RESOURCE_TYPE "org.tizen.door"
-
-/* Door Resource */
-typedef struct _door_resource_s {
- bool state;
- char *uri_path;
- char *type;
- iotcon_resource_interfaces_h ifaces;
- int properties;
- iotcon_resource_h handle;
- iotcon_observers_h observers;
- iotcon_representation_h repr;
-} door_resource_s;
-
-static bool _resource_created;
-
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data);
-
-static int _set_door_resource(door_resource_s *door)
-{
- int ret;
-
- door->state = false;
-
- door->uri_path = strdup(DOOR_RESOURCE_URI);
- if (NULL == door->uri_path) {
- ERR("strdup(%s) Fail", DOOR_RESOURCE_URI);
- return -1;
- }
-
- door->type = strdup(DOOR_RESOURCE_TYPE);
- if (NULL == door->type) {
- ERR("strdup(%s) Fail", DOOR_RESOURCE_TYPE);
- free(door->uri_path);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_create(&door->ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
- free(door->type);
- free(door->uri_path);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_add(door->ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
- iotcon_resource_interfaces_destroy(door->ifaces);
- free(door->type);
- free(door->uri_path);
- return -1;
- }
-
- door->properties = IOTCON_RESOURCE_DISCOVERABLE;
-
- ret = iotcon_observers_create(&door->observers);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_observers_create() Fail");
- iotcon_resource_interfaces_destroy(door->ifaces);
- free(door->type);
- free(door->uri_path);
- return -1;
- }
-
- return 0;
-}
-
-static void _free_door_resource(door_resource_s *door)
-{
- iotcon_observers_destroy(door->observers);
- iotcon_resource_interfaces_destroy(door->ifaces);
- free(door->type);
- free(door->uri_path);
-}
-
-static void _check_door_state(door_resource_s door)
-{
- if (false == door.state)
- INFO("[Door] closed.");
- else
- INFO("[Door] opened.");
-}
-
-static iotcon_resource_h _create_door_resource(char *uri_path, char *type,
- iotcon_resource_interfaces_h ifaces, int properties, void *user_data)
-{
- int ret;
- iotcon_resource_h handle;
- iotcon_resource_types_h resource_types;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_create() Fail(%d)", ret);
- return NULL;
- }
-
- ret = iotcon_resource_types_add(resource_types, type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_add() Fail(%d)", ret);
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- /* register door resource */
- ret = iotcon_resource_create(uri_path, resource_types, ifaces, properties,
- _request_handler, user_data, &handle);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_create() Fail");
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- iotcon_resource_types_destroy(resource_types);
-
- return handle;
-}
-
-static int _send_response(iotcon_request_h request, iotcon_representation_h repr,
- iotcon_response_result_e result)
-{
- int ret;
- iotcon_response_h response;
-
- ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_create() Fail(%d)", ret);
- return -1;
- }
-
- ret = iotcon_response_set_result(response, result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_set_result() Fail(%d)", ret);
- iotcon_response_destroy(response);
- return -1;
- }
-
- ret = iotcon_response_set_representation(response, IOTCON_INTERFACE_DEFAULT, repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_set_representation() Fail(%d)", ret);
- iotcon_response_destroy(response);
- return -1;
- }
-
- /* send Representation to the client */
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_send() Fail(%d)", ret);
- iotcon_response_destroy(response);
- return -1;
- }
-
- iotcon_response_destroy(response);
-
- return 0;
-}
-
-static iotcon_representation_h _get_door_representation(door_resource_s *door)
-{
- int ret;
- iotcon_state_h state;
- iotcon_representation_h repr;
-
- /* create a door Representation */
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return NULL;
- }
-
- /* create a door state */
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_representation_set_uri_path(repr, door->uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_state_add_bool(state, "opened", door->state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_representation_set_state(repr, state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- iotcon_state_destroy(state);
-
- return repr;
-}
-
-static int _request_handler_get(door_resource_s *door, iotcon_request_h request)
-{
- int ret;
- iotcon_representation_h resp_repr;
- INFO("GET request");
-
- resp_repr = _get_door_representation(door);
- if (NULL == resp_repr) {
- ERR("_get_door_representation() Fail");
- return -1;
- }
-
- ret = _send_response(request, resp_repr, IOTCON_RESPONSE_OK);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
- iotcon_representation_destroy(resp_repr);
- return -1;
- }
-
- iotcon_representation_destroy(resp_repr);
-
- return 0;
-}
-
-static int _set_door_representation(door_resource_s *door, iotcon_representation_h repr)
-{
- int ret;
- bool bval;
- iotcon_state_h state;
-
- ret = iotcon_representation_get_state(repr, &state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
- return -1;
- }
-
- ret = iotcon_state_get_bool(state, "opened", &bval);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
- return -1;
- }
-
- door->state = bval;
-
- return 0;
-}
-
-static int _request_handler_put(door_resource_s *door, iotcon_request_h request)
-{
- int ret;
- iotcon_representation_h req_repr, resp_repr;
- INFO("PUT request");
-
- ret = iotcon_request_get_representation(request, &req_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_representation() Fail(%d)", ret);
- return -1;
- }
-
- ret = _set_door_representation(door, req_repr);
- if (0 != ret) {
- ERR("_set_door_representation() Fail(%d)", ret);
- return -1;
- }
-
- _check_door_state(*door);
-
- resp_repr = _get_door_representation(door);
- if (NULL == resp_repr) {
- ERR("_get_door_representation() Fail");
- return -1;
- }
-
- ret = _send_response(request, resp_repr, IOTCON_RESPONSE_OK);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
- iotcon_representation_destroy(resp_repr);
- return -1;
- }
-
- /* notify */
- ret = iotcon_resource_notify(door->handle, resp_repr, door->observers, IOTCON_QOS_HIGH);
- if (IOTCON_ERROR_NONE != ret)
- ERR("iotcon_resource_notify() Fail(%d)", ret);
-
- iotcon_representation_destroy(resp_repr);
-
- return 0;
-}
-
-static gboolean _door_state_changer(gpointer user_data)
-{
- int ret;
- static int i = 0;
- iotcon_representation_h repr;
- door_resource_s *door = user_data;
-
- if ((5 == i++) || NULL == door->observers)
- return G_SOURCE_REMOVE;
-
- if (false == door->state) {
- door->state = true;
- INFO("[Door] closed -> opened");
- } else {
- door->state = false;
- INFO("[Door] opened -> closed");
- }
-
- INFO("NOTIFY!");
-
- repr = _get_door_representation(door);
- if (NULL == repr) {
- ERR("_get_door_representation() Fail");
- return G_SOURCE_REMOVE;
- }
-
- ret = iotcon_resource_notify(door->handle, repr, door->observers, IOTCON_QOS_HIGH);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_notify() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return G_SOURCE_REMOVE;
- }
-
- iotcon_representation_destroy(repr);
- return G_SOURCE_CONTINUE;
-}
-
-static int _request_handler_post(door_resource_s *door, iotcon_request_h request)
-{
- int ret;
- iotcon_state_h resp_state;
- iotcon_representation_h resp_repr = NULL;
- iotcon_resource_h new_door_handle;
- INFO("POST request");
-
- if (_resource_created) {
- ERR("Resource(%s) is already created", DOOR_RESOURCE_URI2);
- return -1;
- }
-
- new_door_handle = _create_door_resource(DOOR_RESOURCE_URI2, door->type,
- door->ifaces, IOTCON_RESOURCE_NO_PROPERTY, door);
- if (NULL == new_door_handle) {
- ERR("_create_door_resource() Fail");
- return -1;
- }
- _resource_created = true;
-
- /* send information that new resource was created */
- ret = iotcon_representation_create(&resp_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return -1;
- }
-
- ret = iotcon_state_create(&resp_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_representation_destroy(resp_repr);
- return -1;
- }
-
- ret = iotcon_state_add_str(resp_state, "createduripath", DOOR_RESOURCE_URI2);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_str() Fail(%d)", ret);
- iotcon_state_destroy(resp_state);
- iotcon_representation_destroy(resp_repr);
- return -1;
- }
-
- ret = iotcon_representation_set_state(resp_repr, resp_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(resp_state);
- iotcon_representation_destroy(resp_repr);
- return -1;
- }
-
- iotcon_state_destroy(resp_state);
-
- ret = _send_response(request, resp_repr, IOTCON_RESPONSE_RESOURCE_CREATED);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
- iotcon_representation_destroy(resp_repr);
- return -1;
- }
-
- iotcon_representation_destroy(resp_repr);
-
- return 0;
-}
-
-static int _request_handler_delete(iotcon_resource_h resource, iotcon_request_h request)
-{
- int ret;
- INFO("DELETE request");
-
- ret = iotcon_resource_destroy(resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_unregiser_resource() Fail(%d)", ret);
- return -1;
- }
-
- ret = _send_response(request, NULL, IOTCON_RESPONSE_RESOURCE_DELETED);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
- return -1;
- }
-
- return 0;
-}
-
-static bool _query_cb(const char *key, const char *value, void *user_data)
-{
- INFO("key : %s, value : %s", key, value);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- door_resource_s *door;
- iotcon_query_h query;
- int ret, observe_id;
- iotcon_request_type_e type;
- iotcon_observe_type_e observe_type;
- char *host_address;
-
- RET_IF(NULL == request);
-
- ret = iotcon_request_get_host_address(request, &host_address);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_host_address() Fail(%d)", ret);
- _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
- return;
- }
- INFO("host_address : %s", host_address);
-
- ret = iotcon_request_get_query(request, &query);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_query() Fail(%d)", ret);
- _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
- return;
- }
- if (query)
- iotcon_query_foreach(query, _query_cb, NULL);
-
- ret = iotcon_request_get_request_type(request, &type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_types() Fail(%d)", ret);
- _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
- return;
- }
-
-
- door = user_data;
-
- if (IOTCON_REQUEST_GET == type)
- ret = _request_handler_get(door, request);
-
- else if (IOTCON_REQUEST_PUT == type)
- ret = _request_handler_put(door, request);
-
- else if (IOTCON_REQUEST_POST == type)
- ret = _request_handler_post(door, request);
-
- else if (IOTCON_REQUEST_DELETE == type)
- ret = _request_handler_delete(resource, request);
-
- if (0 != ret) {
- _send_response(request, NULL, IOTCON_RESPONSE_ERROR);
- return;
- }
-
- ret = iotcon_request_get_observe_type(request, &observe_type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_type() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_OBSERVE_REGISTER == observe_type) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_id() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_observers_add(door->observers, observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_observers_add() Fail(%d)", ret);
- return;
- }
- } else if (IOTCON_OBSERVE_DEREGISTER == observe_type) {
- ret = iotcon_request_get_observe_id(request, &observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_observe_id() Fail(%d)", ret);
- return;
- }
- ret = iotcon_observers_remove(door->observers, observe_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_observers_remove() Fail(%d)", ret);
- return;
- }
- }
-}
-
-static gboolean _presence_timer(gpointer user_data)
-{
- static int i = 0;
- i++;
- if (i % 2)
- iotcon_stop_presence();
- else
- iotcon_start_presence(10);
-
- if (3 == i)
- return G_SOURCE_REMOVE;
-
- return G_SOURCE_CONTINUE;
-}
-
-int main(int argc, char **argv)
-{
- FN_CALL;
- int ret;
- GMainLoop *loop;
- door_resource_s my_door = {0};
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* connect iotcon */
- ret = iotcon_connect();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_connect() Fail(%d)", ret);
- return -1;
- }
-
- /* set local door resource */
- ret = _set_door_resource(&my_door);
- if (0 != ret) {
- ERR("_set_door_resource() Fail");
- iotcon_disconnect();
- return -1;
- }
-
- /* add resource options */
- ret = iotcon_resource_interfaces_add(my_door.ifaces, IOTCON_INTERFACE_BATCH);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
- _free_door_resource(&my_door);
- iotcon_disconnect();
- return -1;
- }
- my_door.properties |= IOTCON_RESOURCE_OBSERVABLE;
-
- /* add presence */
- g_timeout_add_seconds(10, _presence_timer, NULL);
- iotcon_start_presence(10);
-
- /* create new door resource */
- my_door.handle = _create_door_resource(my_door.uri_path, my_door.type, my_door.ifaces,
- my_door.properties, &my_door);
- if (NULL == my_door.handle) {
- ERR("_create_door_resource() Fail");
- _free_door_resource(&my_door);
- iotcon_disconnect();
- return -1;
- }
-
- _check_door_state(my_door);
-
- /* add observe */
- g_timeout_add_seconds(5, _door_state_changer, &my_door);
-
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
-
- iotcon_resource_destroy(my_door.handle);
-
- _free_door_resource(&my_door);
-
- /* disconnect iotcon */
- iotcon_disconnect();
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <glib.h>
-#include <iotcon.h>
-#include "test.h"
-
-static void _request_device_info(iotcon_device_info_h info, iotcon_error_e result, void *user_data)
-{
- int ret;
- char *device_name = NULL;
- char *spec_ver = NULL;
- char *device_id = NULL;
- char *data_model_ver = NULL;
-
- RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result (%d)", result);
-
- ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_NAME, &device_name);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_device_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_SPEC_VER, &spec_ver);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_device_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_ID, &device_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_device_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_DATA_MODEL_VER,
- &data_model_ver);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_device_info_get_property() Fail(%d)", ret);
- return;
- }
-
- INFO("Get Device Info");
- INFO("device_name : %s", device_name);
- INFO("spec_version : %s", spec_ver);
- INFO("device_id : %s", device_id);
- INFO("data_model_version : %s", data_model_ver);
-}
-
-static void _request_platform_info(iotcon_platform_info_h info, iotcon_error_e result, void *user_data)
-{
- int ret;
- char *platform_id = NULL;
- char *manuf_name = NULL;
- char *manuf_url = NULL;
- char *model_number = NULL;
- char *date_of_manuf = NULL;
- char *platform_ver = NULL;
- char *os_ver = NULL;
- char *hardware_ver = NULL;
- char *firmware_ver = NULL;
- char *support_url = NULL;
- char *system_time = NULL;
-
- RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result (%d)", result);
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_ID, &platform_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MANUF_NAME,
- &manuf_name);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MANUF_URL,
- &manuf_url);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MODEL_NUMBER,
- &model_number);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_DATE_OF_MANUF,
- &date_of_manuf);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_PLATFORM_VER,
- &platform_ver);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_OS_VER, &os_ver);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_HARDWARE_VER,
- &hardware_ver);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_FIRMWARE_VER,
- &firmware_ver);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_SUPPORT_URL,
- &support_url);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_SYSTEM_TIME,
- &system_time);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
- return;
- }
-
- INFO("Get Platform Info");
- INFO("platform_id : %s", platform_id);
- INFO("manuf_name : %s", manuf_name);
- INFO("manuf_url : %s", manuf_url);
- INFO("model_number : %s", model_number);
- INFO("date_of_manufacture : %s", date_of_manuf);
- INFO("platform_ver : %s", platform_ver);
- INFO("os_ver : %s", os_ver);
- INFO("hardware_ver : %s", hardware_ver);
- INFO("firmware_ver : %s", firmware_ver);
- INFO("support_url : %s", support_url);
- INFO("system_time : %s", system_time);
-}
-
-int main()
-{
- int ret;
- GMainLoop *loop;
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* connect iotcon */
- ret = iotcon_connect();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_connect() Fail(%d)", ret);
- return -1;
- }
-
- ret = iotcon_get_device_info(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
- _request_device_info, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_get_device_info() Fail(%d)", ret);
- iotcon_disconnect();
- return -1;
- }
-
- ret = iotcon_get_platform_info(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
- _request_platform_info, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_get_platform_info() Fail(%d)", ret);
- iotcon_disconnect();
- return -1;
- }
-
- g_main_loop_run(loop);
-
- g_main_loop_unref(loop);
-
- /* disconnect iotcon */
- iotcon_disconnect();
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-#include <tizen_type.h>
-
-#include <iotcon.h>
-#include "test.h"
-
-static char *door_resource_device_id;
-static GList *device_id_list;
-
-#define DOOR_RESOURCE_TYPE "org.tizen.door"
-
-static bool _get_res_iface_cb(const char *string, void *user_data)
-{
- char *resource_uri_path = user_data;
-
- DBG("[%s] resource interface : %s", resource_uri_path, string);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-static bool _get_res_type_cb(const char *string, void *user_data)
-{
- char *resource_uri_path = user_data;
-
- DBG("[%s] resource type : %s", resource_uri_path, string);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-static int _device_id_compare(const void *a, const void *b)
-{
- return strcmp(a, b);
-}
-
-static void _state_changed_cb(iotcon_remote_resource_h resource,
- iotcon_remote_resource_state_e state, void *user_data)
-{
- INFO("Resource State is Changed");
-
- switch (state) {
- case IOTCON_REMOTE_RESOURCE_ALIVE:
- INFO(" --- ALIVE");
- break;
- case IOTCON_REMOTE_RESOURCE_LOST_SIGNAL:
- INFO(" --- LOST_SIGNAL");
- break;
- default:
- break;
- }
-}
-
-static void _representation_changed_cb(iotcon_remote_resource_h resource,
- iotcon_representation_h representation, void *user_data)
-{
- int ret;
- bool opened;
- iotcon_state_h state;
-
- INFO("Resource is cached");
-
- ret = iotcon_representation_get_state(representation, &state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_state_get_bool(state, "opened", &opened);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
- return;
- }
-
- switch (opened) {
- case true:
- INFO("door is opened");
- break;
- case false:
- INFO("door is closed");
- break;
- default:
- break;
- }
-}
-
-static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
- void *user_data)
-{
- int ret;
- GList *node;
- char *resource_host;
- char *resource_uri_path;
- char *resource_device_id;
- iotcon_resource_interfaces_h resource_interfaces;
- iotcon_resource_types_h resource_types;
- iotcon_remote_resource_h cloned_resource;
-
- RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result(%d)", result);
-
- if (NULL == resource)
- return;
-
- INFO("===== resource found =====");
-
- /* get the resource URI */
- ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_uri_path() Fail(%d)", ret);
- return;
- }
-
- /* get the device unique id.
- * this is unique per-server independent on how it was discovered. */
- ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_device_id() Fail(%d)", ret);
- return;
- }
- DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id);
-
- node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
-
- door_resource_device_id = strdup(resource_device_id);
- if (NULL == door_resource_device_id) {
- ERR("strdup(door_resource_device_id) Fail");
- return;
- }
-
- device_id_list = g_list_append(device_id_list, door_resource_device_id);
-
- if (node) {
- DBG("This device(%s) is already found. skip !", door_resource_device_id);
- return;
- }
-
- /* get the resource host address */
- ret = iotcon_remote_resource_get_host_address(resource, &resource_host);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_host_address() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
- DBG("[%s] resource host : %s", resource_uri_path, resource_host);
-
- /* get the resource interfaces */
- ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
- resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- /* get the resource types */
- ret = iotcon_remote_resource_get_types(resource, &resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_types() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb,
- resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- ret = iotcon_remote_resource_clone(resource, &cloned_resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_clone() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- /* Start Monitoring */
- ret = iotcon_remote_resource_start_monitoring(cloned_resource, _state_changed_cb,
- NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_start_monitoring() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- /* Start Caching */
- ret = iotcon_remote_resource_start_caching(cloned_resource,
- _representation_changed_cb, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_start_caching() Fail(%d)", ret);
- iotcon_remote_resource_stop_monitoring(resource);
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
- return;
- }
-
- device_id_list = g_list_remove(device_id_list, door_resource_device_id);
- free(door_resource_device_id);
-}
-
-int main(int argc, char **argv)
-{
- FN_CALL;
- int ret;
- GMainLoop *loop;
- iotcon_remote_resource_h resource;
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* connect iotcon */
- ret = iotcon_connect();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_connect() Fail(%d)", ret);
- return -1;
- }
-
- /* find door typed resources */
- ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
- DOOR_RESOURCE_TYPE, false, _found_resource, &resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_find_resource() Fail(%d)", ret);
- iotcon_disconnect();
- return -1;
- }
-
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
-
- g_list_free_full(device_id_list, free);
-
- /* disconnect iotcon */
- iotcon_disconnect();
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-
-#include <iotcon.h>
-#include <iotcon-internal.h>
-#include "test.h"
-
-#define DOOR_RESOURCE_URI "/door/1"
-#define DOOR_RESOURCE_TYPE "org.tizen.door"
-
-/* Door Resource */
-typedef struct _door_resource_s {
- bool state;
- char *uri_path;
- char *type;
- int properties;
- iotcon_lite_resource_h handle;
-} door_resource_s;
-
-static int _set_door_resource(door_resource_s *door)
-{
- door->state = false;
-
- door->uri_path = strdup(DOOR_RESOURCE_URI);
- if (NULL == door->uri_path) {
- ERR("strdup(%s) Fail", DOOR_RESOURCE_URI);
- return -1;
- }
-
- door->type = strdup(DOOR_RESOURCE_TYPE);
- if (NULL == door->type) {
- ERR("strdup(%s) Fail", DOOR_RESOURCE_TYPE);
- free(door->uri_path);
- return -1;
- }
-
- door->properties = IOTCON_RESOURCE_DISCOVERABLE;
-
- return 0;
-}
-
-static void _free_door_resource(door_resource_s *door)
-{
- free(door->type);
- free(door->uri_path);
-}
-
-static void _check_door_state(door_resource_s door)
-{
- if (false == door.state)
- INFO("[Door] closed.");
- else
- INFO("[Door] opened.");
-}
-
-static gboolean _door_state_changer(gpointer user_data)
-{
- int ret;
- door_resource_s *door = user_data;
- iotcon_state_h recv_state, send_state;
-
- ret = iotcon_lite_resource_get_state(door->handle, &recv_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_lite_resource_get_state() Fail(%d)", ret);
- return G_SOURCE_CONTINUE;
- }
-
- ret = iotcon_state_get_bool(recv_state, "opened", &(door->state));
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
- return G_SOURCE_CONTINUE;
- }
-
- if (true == door->state)
- door->state = false;
- else
- door->state = true;
-
- ret = iotcon_state_create(&send_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- return G_SOURCE_CONTINUE;
- }
-
- ret = iotcon_state_add_bool(send_state, "opened", door->state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
- return G_SOURCE_CONTINUE;
- }
-
- ret = iotcon_lite_resource_update_state(door->handle, send_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_lite_resource_update_state() Fail(%d)", ret);
- iotcon_state_destroy(send_state);
- return G_SOURCE_CONTINUE;
- }
-
- iotcon_state_destroy(send_state);
-
- _check_door_state(*door);
-
- return G_SOURCE_CONTINUE;
-}
-
-static bool _door_state_changed(iotcon_lite_resource_h resource,
- iotcon_state_h state, void *user_data)
-{
- FN_CALL;
- bool opened;
- int ret;
-
- ret = iotcon_state_get_bool(state, "opened", &opened);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
- return false;
- }
- DBG("opened: %d", opened);
-
- return true;
-}
-
-static iotcon_lite_resource_h _create_door_resource(char *uri_path, char *type,
- int properties, void *user_data)
-{
- int ret;
- iotcon_state_h state;
- iotcon_lite_resource_h handle;
- iotcon_resource_types_h resource_types;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_create() Fail(%d)", ret);
- return NULL;
- }
-
- ret = iotcon_resource_types_add(resource_types, type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_add() Fail(%d)", ret);
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- ret = iotcon_state_add_bool(state, "opened", false);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- /* register door resource */
- ret = iotcon_lite_resource_create(uri_path, resource_types, properties, state,
- _door_state_changed, NULL, &handle);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_create() Fail");
- iotcon_state_destroy(state);
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- iotcon_state_destroy(state);
- iotcon_resource_types_destroy(resource_types);
-
- return handle;
-}
-
-int main(int argc, char **argv)
-{
- FN_CALL;
- int ret;
- GMainLoop *loop;
- door_resource_s my_door = {0};
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* connect iotcon */
- ret = iotcon_connect();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_connect() Fail(%d)", ret);
- return -1;
- }
-
- /* start presence */
- ret = iotcon_start_presence(10);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_start_presence() Fail(%d)", ret);
- return -1;
- }
-
- /* set local door resource */
- ret = _set_door_resource(&my_door);
- if (0 != ret) {
- ERR("_set_door_resource() Fail");
- iotcon_disconnect();
- return -1;
- }
-
- /* add resource options */
- my_door.properties |= IOTCON_RESOURCE_OBSERVABLE;
-
- /* create new door resource */
- my_door.handle = _create_door_resource(my_door.uri_path, my_door.type,
- my_door.properties, &my_door);
- if (NULL == my_door.handle) {
- ERR("_create_door_resource() Fail");
- _free_door_resource(&my_door);
- iotcon_stop_presence();
- iotcon_disconnect();
- return -1;
- }
-
- _check_door_state(my_door);
-
- g_timeout_add_seconds(7, _door_state_changer, &my_door);
-
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
-
- iotcon_lite_resource_destroy(my_door.handle);
-
- _free_door_resource(&my_door);
-
- iotcon_stop_presence();
-
- /* disconnect iotcon */
- iotcon_disconnect();
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-#include <iotcon.h>
-#include "test.h"
-
-static char *room_resource_device_id;
-static GList *device_id_list;
-
-#define ROOM_RESOURCE_TYPE "org.tizen.room"
-#define ROOM_RESOURCE_URI_PREFIX "/room"
-#define LIGHT_RESOURCE_URI_PREFIX "/light"
-#define FAN_RESOURCE_URI_PREFIX "/fan"
-
-static bool _get_int_list_cb(int pos, const int value, void *user_data)
-{
- DBG("%d", value);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-static void _print_repr(iotcon_representation_h recv_repr)
-{
- int i, ret, int_val;
- bool is_null, bool_val;
- char *uri_path, *str_val;
- iotcon_list_h list_val;
- iotcon_representation_h child_repr;
- iotcon_state_h recv_state, child_state;
- unsigned int key_count, children_count;
-
- INFO("GET request was successful");
-
- DBG("[ parent representation ]");
- ret = iotcon_representation_get_uri_path(recv_repr, &uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_uri_path() Fail(%d)", ret);
- return;
- }
- DBG("uri_path : %s", uri_path);
-
- ret = iotcon_representation_get_state(recv_repr, &recv_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_state_get_keys_count(recv_state, &key_count);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
- return;
- }
-
- if (key_count) {
- ret = iotcon_state_get_str(recv_state, "name", &str_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_str() Fail(%d)", ret);
- return;
- }
- DBG("name : %s", str_val);
-
- ret = iotcon_state_get_list(recv_state, "today_temp", &list_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_list() Fail(%d)", ret);
- return;
- }
-
- DBG("today's temperature :");
- ret = iotcon_list_foreach_int(list_val, _get_int_list_cb, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_foreach_int() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_state_is_null(recv_state, "null value", &is_null);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_is_null() Fail(%d)", ret);
- return;
- }
-
- if (is_null)
- DBG("null value is null");
- }
-
- ret = iotcon_representation_get_children_count(recv_repr, &children_count);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_children_count() Fail(%d)", ret);
- return;
- }
-
- for (i = 0; i < children_count; i++) {
- DBG("[ child representation ]");
-
- ret = iotcon_representation_get_nth_child(recv_repr, i, &child_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_nth_child(%d) Fail(%d)", i, ret);
- continue;
- }
-
- ret = iotcon_representation_get_uri_path(child_repr, &uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_uri_path() Fail(%d)", ret);
- continue;
- }
- DBG("uri_path : %s", uri_path);
-
- ret = iotcon_representation_get_state(child_repr, &child_state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_get_state() Fail(%d)", ret);
- continue;
- }
-
- if (TEST_STR_EQUAL == strncmp(LIGHT_RESOURCE_URI_PREFIX, uri_path,
- strlen(LIGHT_RESOURCE_URI_PREFIX))) {
- ret = iotcon_state_get_keys_count(child_state, &key_count);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
- continue;
- }
-
- if (key_count) {
- ret = iotcon_state_get_int(child_state, "brightness", &int_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_int() Fail(%d)", ret);
- continue;
- }
- DBG("brightness : %d", int_val);
- }
- } else if (TEST_STR_EQUAL == strncmp(FAN_RESOURCE_URI_PREFIX, uri_path,
- strlen(FAN_RESOURCE_URI_PREFIX))) {
- ret = iotcon_state_get_keys_count(child_state, &key_count);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_keys_count() Fail(%d)", ret);
- continue;
- }
- if (key_count) {
- ret = iotcon_state_get_bool(child_state, "state", &bool_val);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_get_bool() Fail(%d)", ret);
- continue;
- }
- DBG("state : %d", bool_val);
- }
- }
- }
-}
-
-static void _on_get_2nd(iotcon_remote_resource_h resource,
- iotcon_error_e err,
- iotcon_request_type_e request_type,
- iotcon_response_h response,
- void *user_data)
-{
- int ret;
- iotcon_response_result_e response_result;
- iotcon_representation_h recv_repr = NULL;
-
- RETM_IF(IOTCON_ERROR_NONE != err, "Invalid err(%d)", err);
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_response_get_representation(response, &recv_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_representation() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_RESPONSE_OK == response_result)
- _print_repr(recv_repr);
- else
- ERR("Invalid result(%d)", response_result);
-
- iotcon_remote_resource_destroy(resource);
-}
-
-static void _on_response_1st(iotcon_remote_resource_h resource,
- iotcon_error_e err,
- iotcon_request_type_e request_type,
- iotcon_response_h response,
- void *user_data)
-{
- int ret;
- iotcon_response_result_e response_result;
- iotcon_query_h query_params;
- iotcon_representation_h recv_repr = NULL;
-
- RETM_IF(IOTCON_ERROR_NONE != err, "Invalid err(%d)", err);
-
- ret = iotcon_response_get_result(response, &response_result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_result() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_response_get_representation(response, &recv_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_get_representation() Fail(%d)", ret);
- return;
- }
-
- if (IOTCON_RESPONSE_OK == response_result)
- _print_repr(recv_repr);
- else
- ERR("Invalid result(%d)", response_result);
-
- ret = iotcon_query_create(&query_params);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_query_create() Fail(%d)", ret);
- return;
- }
-
- ret = iotcon_query_set_interface(query_params, IOTCON_INTERFACE_BATCH);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_query_set_interface() Fail(%d)", ret);
- iotcon_query_destroy(query_params);
- return;
- }
-
- /* send GET request again with BATCH interface */
- ret = iotcon_remote_resource_get(resource, query_params, _on_get_2nd, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get() Fail(%d)", ret);
- iotcon_query_destroy(query_params);
- return;
- }
-
- iotcon_query_destroy(query_params);
-}
-
-static bool _get_res_iface_cb(const char *string, void *user_data)
-{
- char *resource_uri_path = user_data;
-
- DBG("[%s] resource interface : %s", resource_uri_path, string);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-static bool _get_res_type_cb(const char *string, void *user_data)
-{
- char *resource_uri_path = user_data;
-
- DBG("[%s] resource type : %s", resource_uri_path, string);
-
- return IOTCON_FUNC_CONTINUE;
-}
-
-static int _device_id_compare(const void *a, const void *b)
-{
- return strcmp(a, b);
-}
-
-static void _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
- void *user_data)
-{
- int ret;
- GList *node;
- char *resource_host;
- char *resource_uri_path;
- char *resource_device_id;
- iotcon_resource_interfaces_h resource_interfaces;
- iotcon_resource_types_h resource_types;
- iotcon_remote_resource_h cloned_resource;
-
- RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result(%d)", result);
-
- if (NULL == resource)
- return;
-
- INFO("===== resource found =====");
-
- /* get the resource URI */
- ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_uri_path() Fail(%d)", ret);
- return;
- }
-
- /* get the resource device id */
- ret = iotcon_remote_resource_get_device_id(resource, &resource_device_id);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_device_id() Fail(%d)", ret);
- return;
- }
- DBG("[%s] resource device id : %s", resource_uri_path, resource_device_id);
-
- node = g_list_find_custom(device_id_list, resource_device_id, _device_id_compare);
-
- if (node && TEST_STR_EQUAL == strncmp(ROOM_RESOURCE_URI_PREFIX, resource_uri_path,
- strlen(ROOM_RESOURCE_URI_PREFIX))) {
- DBG("uri_path \"%s\" already found. skip !", resource_uri_path);
- return;
- }
-
- room_resource_device_id = strdup(resource_device_id);
- if (NULL == room_resource_device_id) {
- ERR("strdup(room_resource_device_id) Fail");
- return;
- }
-
- device_id_list = g_list_append(device_id_list, room_resource_device_id);
-
- /* get the resource host address */
- ret = iotcon_remote_resource_get_host_address(resource, &resource_host);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_host_address() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, room_resource_device_id);
- free(room_resource_device_id);
- return;
- }
- DBG("[%s] resource host : %s", resource_uri_path, resource_host);
-
- /* get the resource interfaces */
- ret = iotcon_remote_resource_get_interfaces(resource, &resource_interfaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_interfaces() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, room_resource_device_id);
- free(room_resource_device_id);
- return;
- }
-
- ret = iotcon_resource_interfaces_foreach(resource_interfaces, _get_res_iface_cb,
- resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_foreach() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, room_resource_device_id);
- free(room_resource_device_id);
- return;
- }
-
- /* get the resource types */
- ret = iotcon_remote_resource_get_types(resource, &resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_get_types() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, room_resource_device_id);
- free(room_resource_device_id);
- return;
- }
- ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb,
- resource_uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_foreach() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, room_resource_device_id);
- free(room_resource_device_id);
- return;
- }
-
- if (TEST_STR_EQUAL == strncmp(ROOM_RESOURCE_URI_PREFIX, resource_uri_path,
- strlen(ROOM_RESOURCE_URI_PREFIX))) {
- ret = iotcon_remote_resource_clone(resource, &cloned_resource);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_remote_resource_clone() Fail(%d)", ret);
- device_id_list = g_list_remove(device_id_list, room_resource_device_id);
- free(room_resource_device_id);
- return;
- }
-
- /* send GET request */
- ret = iotcon_remote_resource_get(cloned_resource, NULL, _on_response_1st, NULL);
- if (IOTCON_ERROR_NONE != ret)
- ERR("iotcon_remote_resource_get() Fail(%d)", ret);
- }
-
- device_id_list = g_list_remove(device_id_list, room_resource_device_id);
- free(room_resource_device_id);
-}
-
-int main(int argc, char **argv)
-{
- FN_CALL;
- int ret;
- GMainLoop *loop;
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* connect iotcon */
- ret = iotcon_connect();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_connect() Fail(%d)", ret);
- return -1;
- }
-
- /* find room typed resources */
- ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
- ROOM_RESOURCE_TYPE, false, _found_resource, NULL);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_find_resource() Fail(%d)", ret);
- iotcon_disconnect();
- return -1;
- }
-
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
-
- g_list_free_full(device_id_list, free);
-
- /* disconnect iotcon */
- iotcon_disconnect();
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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 <stdlib.h>
-#include <glib.h>
-
-#include <iotcon.h>
-#include "test.h"
-
-#define ROOM_RESOURCE_URI "/room/1"
-#define ROOM_RESOURCE_TYPE "org.tizen.room"
-#define LIGHT_RESOURCE_URI "/light/1"
-#define LIGHT_RESOURCE_TYPE "org.tizen.light"
-#define FAN_RESOURCE_URI "/fan/1"
-#define FAN_RESOURCE_TYPE "org.tizen.fan"
-
-/* Light Resource */
-typedef struct _light_resource_s {
- int brightness;
- char *uri_path;
- char *type;
- iotcon_resource_interfaces_h ifaces;
- int properties;
- iotcon_resource_h handle;
-} light_resource_s;
-
-/* Fan Resource */
-typedef struct _fan_resource_s {
- bool state;
- char *uri_path;
- char *type;
- iotcon_resource_interfaces_h ifaces;
- int properties;
- iotcon_resource_h handle;
-} fan_resource_s;
-
-/* Room Resource */
-typedef struct _room_resource_s {
- char *name;
- int today_temp[5];
- char *uri_path;
- char *type;
- iotcon_resource_interfaces_h ifaces;
- int properties;
- iotcon_resource_h handle;
- light_resource_s *child_light;
- fan_resource_s *child_fan;
-} room_resource_s;
-
-static int _set_room_resource(room_resource_s *room)
-{
- int ret;
-
- room->name = strdup("Michael's Room");
- if (NULL == room->name) {
- ERR("strdup() Fail");
- return -1;
- }
-
- room->today_temp[0] = 13;
- room->today_temp[1] = 19;
- room->today_temp[2] = 24;
- room->today_temp[3] = 21;
- room->today_temp[4] = 14;
-
- room->uri_path = strdup(ROOM_RESOURCE_URI);
- if (NULL == room->uri_path) {
- ERR("strdup(%s) Fail", ROOM_RESOURCE_URI);
- free(room->name);
- return -1;
- }
-
- room->type = strdup(ROOM_RESOURCE_TYPE);
- if (NULL == room->type) {
- ERR("strdup(%s) Fail", ROOM_RESOURCE_TYPE);
- free(room->uri_path);
- free(room->name);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_create(&room->ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
- free(room->type);
- free(room->uri_path);
- free(room->name);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_add(room->ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
- iotcon_resource_interfaces_destroy(room->ifaces);
- free(room->type);
- free(room->uri_path);
- free(room->name);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_add(room->ifaces, IOTCON_INTERFACE_BATCH);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
- iotcon_resource_interfaces_destroy(room->ifaces);
- free(room->type);
- free(room->uri_path);
- free(room->name);
- return -1;
- }
-
- room->properties = IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE;
-
- return 0;
-}
-
-static void _free_room_resource(room_resource_s *room)
-{
- iotcon_resource_interfaces_destroy(room->ifaces);
- free(room->type);
- free(room->uri_path);
- free(room->name);
-}
-
-static int _set_light_resource(light_resource_s *light)
-{
- int ret;
-
- light->brightness = 50;
-
- light->uri_path = strdup(LIGHT_RESOURCE_URI);
- if (NULL == light->uri_path) {
- ERR("strdup(%s) Fail", LIGHT_RESOURCE_URI);
- return -1;
- }
-
- light->type = strdup(LIGHT_RESOURCE_TYPE);
- if (NULL == light->type) {
- ERR("strdup(%s) Fail", LIGHT_RESOURCE_TYPE);
- free(light->uri_path);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_create(&light->ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
- free(light->type);
- free(light->uri_path);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_add(light->ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
- iotcon_resource_interfaces_destroy(light->ifaces);
- free(light->type);
- free(light->uri_path);
- return -1;
- }
-
- light->properties = IOTCON_RESOURCE_NO_PROPERTY;
-
- return 0;
-}
-
-static void _free_light_resource(light_resource_s *light)
-{
- iotcon_resource_interfaces_destroy(light->ifaces);
- free(light->type);
- free(light->uri_path);
-}
-
-static int _set_fan_resource(fan_resource_s *fan)
-{
- int ret;
-
- fan->state = false;
-
- fan->uri_path = strdup(FAN_RESOURCE_URI);
- if (NULL == fan->uri_path) {
- ERR("strdup(%s) Fail", FAN_RESOURCE_URI);
- return -1;
- }
-
- fan->type = strdup(FAN_RESOURCE_TYPE);
- if (NULL == fan->type) {
- ERR("strdup(%s) Fail", FAN_RESOURCE_TYPE);
- free(fan->uri_path);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_create(&fan->ifaces);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_create() Fail(%d)", ret);
- free(fan->type);
- free(fan->uri_path);
- return -1;
- }
-
- ret = iotcon_resource_interfaces_add(fan->ifaces, IOTCON_INTERFACE_DEFAULT);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_interfaces_add() Fail(%d)", ret);
- iotcon_resource_interfaces_destroy(fan->ifaces);
- free(fan->type);
- free(fan->uri_path);
- return -1;
- }
-
- fan->properties = IOTCON_RESOURCE_NO_PROPERTY;
-
- return 0;
-}
-
-static void _free_fan_resource(fan_resource_s *fan)
-{
- iotcon_resource_interfaces_destroy(fan->ifaces);
- free(fan->type);
- free(fan->uri_path);
-}
-
-static iotcon_resource_h _create_resource(char *uri_path,
- char *type,
- iotcon_resource_interfaces_h ifaces,
- int properties,
- iotcon_request_handler_cb cb,
- void *user_data)
-{
- int ret;
- iotcon_resource_h handle;
- iotcon_resource_types_h resource_types;
-
- ret = iotcon_resource_types_create(&resource_types);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_create() Fail(%d)", ret);
- return NULL;
- }
-
- ret = iotcon_resource_types_add(resource_types, type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_types_add() Fail(%d)", ret);
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- ret = iotcon_resource_create(uri_path, resource_types, ifaces, properties, cb,
- user_data, &handle);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_create() Fail(%d)", ret);
- iotcon_resource_types_destroy(resource_types);
- return NULL;
- }
-
- iotcon_resource_types_destroy(resource_types);
-
- return handle;
-}
-
-static int _send_response(iotcon_request_h request, iotcon_representation_h repr,
- const char *iface, iotcon_response_result_e result)
-{
- int ret;
- iotcon_response_h response;
-
- ret = iotcon_response_create(request, &response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_create() Fail(%d)", ret);
- return -1;
- }
-
- ret = iotcon_response_set_representation(response, iface, repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_set_representation() Fail(%d)", ret);
- iotcon_response_destroy(response);
- return -1;
- }
-
- ret = iotcon_response_set_result(response, result);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_set_result() Fail(%d)", ret);
- iotcon_response_destroy(response);
- return -1;
- }
-
- /* send Representation to the client */
- ret = iotcon_response_send(response);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_response_send() Fail(%d)", ret);
- iotcon_response_destroy(response);
- return -1;
- }
-
- iotcon_response_destroy(response);
-
- return 0;
-}
-
-static iotcon_representation_h _get_light_representation(light_resource_s *light)
-{
- int ret;
- iotcon_state_h state;
- iotcon_representation_h repr;
-
- /* create a light Representation */
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return NULL;
- }
-
- ret = iotcon_representation_set_uri_path(repr, light->uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- /* create a light state */
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_state_add_int(state, "brightness", light->brightness);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_int() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- /* Set a light state into light Representation */
- ret = iotcon_representation_set_state(repr, state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- iotcon_state_destroy(state);
-
- return repr;
-}
-
-static int _light_request_handler_get(light_resource_s *light, iotcon_request_h request)
-{
- int ret;
- iotcon_representation_h repr;
-
- INFO("GET request - Light");
-
- repr = _get_light_representation(light);
- if (NULL == repr) {
- ERR("_get_light_representation() Fail");
- return -1;
- }
-
- ret = _send_response(request, repr, IOTCON_INTERFACE_DEFAULT, IOTCON_RESPONSE_OK);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return -1;
- }
-
- iotcon_representation_destroy(repr);
-
- return 0;
-}
-
-
-static iotcon_representation_h _get_fan_representation(fan_resource_s *fan)
-{
- int ret;
- iotcon_state_h state;
- iotcon_representation_h repr;
-
- /* create a fan Representation */
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return NULL;
- }
-
- ret = iotcon_representation_set_uri_path(repr, fan->uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- /* create a fan state */
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_state_add_bool(state, "state", fan->state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_bool() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- /* Set a light state into light Representation */
- ret = iotcon_representation_set_state(repr, state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- iotcon_state_destroy(state);
-
- return repr;
-}
-
-static int _fan_request_handler_get(fan_resource_s *fan, iotcon_request_h request)
-{
- int ret;
- iotcon_representation_h repr;
-
- INFO("GET request - Fan");
-
- repr = _get_fan_representation(fan);
- if (NULL == repr) {
- ERR("_get_fan_representation() Fail");
- return -1;
- }
-
- ret = _send_response(request, repr, IOTCON_INTERFACE_DEFAULT,
- IOTCON_RESPONSE_OK);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return -1;
- }
-
- iotcon_representation_destroy(repr);
-
- return 0;
-}
-
-static iotcon_representation_h _get_room_representation(room_resource_s *room)
-{
- int ret;
- iotcon_state_h state;
- iotcon_list_h today_temp;
- iotcon_representation_h repr, light_repr, fan_repr;
-
- /* create a room Representation */
- ret = iotcon_representation_create(&repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_create() Fail(%d)", ret);
- return NULL;
- }
-
- ret = iotcon_representation_set_uri_path(repr, room->uri_path);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_uri_path() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- /* create a room state */
- ret = iotcon_state_create(&state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_create() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_state_add_str(state, "name", room->name);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_str() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- /* set null */
- ret = iotcon_state_add_null(state, "null value");
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_null() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_list_create(IOTCON_TYPE_INT, &today_temp);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_create() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_list_add_int(today_temp, room->today_temp[0], -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_add_int() Fail(%d)", ret);
- iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_list_add_int(today_temp, room->today_temp[1], -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_add_int() Fail(%d)", ret);
- iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_list_add_int(today_temp, room->today_temp[2], -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_add_int() Fail(%d)", ret);
- iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_list_add_int(today_temp, room->today_temp[3], -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_add_int() Fail(%d)", ret);
- iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_list_add_int(today_temp, room->today_temp[4], -1);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_list_add_int() Fail(%d)", ret);
- iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_state_add_list(state, "today_temp", today_temp);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_state_add_list() Fail(%d)", ret);
- iotcon_list_destroy(today_temp);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- iotcon_list_destroy(today_temp);
-
- /* Set a room state into room Representation */
- ret = iotcon_representation_set_state(repr, state);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_set_state() Fail(%d)", ret);
- iotcon_state_destroy(state);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- iotcon_state_destroy(state);
-
- light_repr = _get_light_representation(room->child_light);
- if (NULL == light_repr) {
- ERR("_get_light_representation() fail");
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_representation_add_child(repr, light_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_add_child() Fail(%d)", ret);
- iotcon_representation_destroy(light_repr);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- iotcon_representation_destroy(light_repr);
-
- fan_repr = _get_fan_representation(room->child_fan);
- if (NULL == fan_repr) {
- ERR("_get_fan_representation() fail");
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- ret = iotcon_representation_add_child(repr, fan_repr);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_representation_add_child() Fail(%d)", ret);
- iotcon_representation_destroy(fan_repr);
- iotcon_representation_destroy(repr);
- return NULL;
- }
-
- iotcon_representation_destroy(fan_repr);
-
- return repr;
-}
-
-static int _room_request_handler_get(room_resource_s *room, iotcon_request_h request)
-{
- int ret;
- iotcon_query_h query;
- iotcon_representation_h repr;
- char *iface = IOTCON_INTERFACE_DEFAULT;
-
- INFO("GET request - Room");
-
- repr = _get_room_representation(room);
- if (NULL == repr) {
- ERR("_get_room_representation() Fail");
- return -1;
- }
-
- ret = iotcon_request_get_query(request, &query);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_query() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return -1;
- }
-
- if (query) {
- ret = iotcon_query_get_interface(query, &iface);
- if (IOTCON_ERROR_NO_DATA == ret) {
- iface = IOTCON_INTERFACE_DEFAULT;
- } else if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_query_get_interface() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return -1;
- }
- }
-
- ret = _send_response(request, repr, iface, IOTCON_RESPONSE_OK);
- if (0 != ret) {
- ERR("_send_response() Fail(%d)", ret);
- iotcon_representation_destroy(repr);
- return -1;
- }
-
- iotcon_representation_destroy(repr);
-
- return 0;
-}
-
-static void _light_request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret;
- iotcon_request_type_e type;
- light_resource_s *light = user_data;
- char *iface = IOTCON_INTERFACE_DEFAULT;
-
- RET_IF(NULL == request);
-
- ret = iotcon_request_get_request_type(request, &type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_types() Fail(%d)", ret);
- _send_response(request, NULL, iface, IOTCON_RESPONSE_ERROR);
- return;
- }
-
- if (IOTCON_REQUEST_GET == type) {
- ret = _light_request_handler_get(light, request);
- if (0 != ret)
- _send_response(request, NULL, iface, IOTCON_RESPONSE_ERROR);
- } else {
- _send_response(request, NULL, iface, IOTCON_RESPONSE_FORBIDDEN);
- }
-}
-
-static void _fan_request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- int ret;
- iotcon_request_type_e type;
- fan_resource_s *fan = user_data;
- char *iface = IOTCON_INTERFACE_DEFAULT;
-
- RET_IF(NULL == request);
-
- ret = iotcon_request_get_request_type(request, &type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_types() Fail(%d)", ret);
- _send_response(request, NULL, iface, IOTCON_RESPONSE_ERROR);
- return;
- }
-
- if (IOTCON_REQUEST_GET == type) {
- ret = _fan_request_handler_get(fan, request);
- if (0 != ret)
- _send_response(request, NULL, iface, IOTCON_RESPONSE_ERROR);
- } else {
- _send_response(request, NULL, iface, IOTCON_RESPONSE_FORBIDDEN);
- }
-}
-
-static void _room_request_handler(iotcon_resource_h resource, iotcon_request_h request,
- void *user_data)
-{
- FN_CALL;
- int ret;
- iotcon_request_type_e type;
- char *host_address;
- room_resource_s *room = user_data;
- char *iface = IOTCON_INTERFACE_DEFAULT;
-
- RET_IF(NULL == request);
-
- ret = iotcon_request_get_host_address(request, &host_address);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_host_address() Fail(%d)", ret);
- _send_response(request, NULL, iface, IOTCON_RESPONSE_ERROR);
- return;
- }
- INFO("host address : %s", host_address);
-
- ret = iotcon_request_get_request_type(request, &type);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_request_get_types() Fail(%d)", ret);
- _send_response(request, NULL, iface, IOTCON_RESPONSE_ERROR);
- return;
- }
-
- if (IOTCON_REQUEST_GET == type) {
- ret = _room_request_handler_get(room, request);
- if (0 != ret)
- _send_response(request, NULL, iface, IOTCON_RESPONSE_ERROR);
- } else {
- _send_response(request, NULL, iface, IOTCON_RESPONSE_FORBIDDEN);
- }
-}
-
-int main(int argc, char **argv)
-{
- FN_CALL;
- int ret;
- GMainLoop *loop;
- room_resource_s room = {0};
- light_resource_s light = {0};
- fan_resource_s fan = {0};
-
- loop = g_main_loop_new(NULL, FALSE);
-
- /* connect iotcon */
- ret = iotcon_connect();
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_connect() Fail(%d)", ret);
- return -1;
- }
-
- /* set resource */
- ret = _set_room_resource(&room);
- if (0 != ret) {
- ERR("_set_room_resource() Fail(%d)", ret);
- iotcon_disconnect();
- return -1;
- }
-
- ret = _set_light_resource(&light);
- if (0 != ret) {
- ERR("_set_room_resource() Fail(%d)", ret);
- _free_room_resource(&room);
- iotcon_disconnect();
- return -1;
- }
-
- ret = _set_fan_resource(&fan);
- if (0 != ret) {
- ERR("_set_room_resource() Fail(%d)", ret);
- _free_room_resource(&room);
- _free_light_resource(&light);
- iotcon_disconnect();
- return -1;
- }
-
- room.child_light = &light;
- room.child_fan = &fan;
-
- /* register room resource */
- room.handle = _create_resource(room.uri_path, room.type, room.ifaces, room.properties,
- _room_request_handler, &room);
- if (NULL == room.handle) {
- ERR("_create_resource() Fail");
- _free_fan_resource(&fan);
- _free_light_resource(&light);
- _free_room_resource(&room);
- iotcon_disconnect();
- return -1;
- }
-
- /* register light resource */
- light.handle = _create_resource(light.uri_path, light.type, light.ifaces,
- light.properties, _light_request_handler, &light);
- if (NULL == light.handle) {
- ERR("_create_resource() Fail");
- iotcon_resource_destroy(room.handle);
- _free_fan_resource(&fan);
- _free_light_resource(&light);
- _free_room_resource(&room);
- iotcon_disconnect();
- return -1;
- }
-
- ret = iotcon_resource_bind_child_resource(room.handle, light.handle);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_bind_child_resource() Fail");
- iotcon_resource_destroy(light.handle);
- iotcon_resource_destroy(room.handle);
- _free_fan_resource(&fan);
- _free_light_resource(&light);
- _free_room_resource(&room);
- iotcon_disconnect();
- return -1;
- }
-
- /* register fan resource */
- fan.handle = _create_resource(fan.uri_path, fan.type, fan.ifaces, fan.properties,
- _fan_request_handler, &fan);
- if (NULL == fan.handle) {
- ERR("_create_resource() Fail");
- iotcon_resource_destroy(light.handle);
- iotcon_resource_destroy(room.handle);
- _free_fan_resource(&fan);
- _free_light_resource(&light);
- _free_room_resource(&room);
- iotcon_disconnect();
- return -1;
- }
-
- ret = iotcon_resource_bind_child_resource(room.handle, fan.handle);
- if (IOTCON_ERROR_NONE != ret) {
- ERR("iotcon_resource_bind_child_resource() Fail");
- iotcon_resource_destroy(fan.handle);
- iotcon_resource_destroy(light.handle);
- iotcon_resource_destroy(room.handle);
- _free_fan_resource(&fan);
- _free_light_resource(&light);
- _free_room_resource(&room);
- iotcon_disconnect();
- return -1;
- }
-
- g_main_loop_run(loop);
- g_main_loop_unref(loop);
-
- iotcon_resource_destroy(fan.handle);
- iotcon_resource_destroy(light.handle);
- iotcon_resource_destroy(room.handle);
- _free_fan_resource(&fan);
- _free_light_resource(&light);
- _free_room_resource(&room);
-
- /* disconnect iotcon */
- iotcon_disconnect();
-
- return 0;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd 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.
- */
-#ifndef __IOT_CONNECTIVITY_MANAGER_TEST_H__
-#define __IOT_CONNECTIVITY_MANAGER_TEST_H__
-
-/* for strcmp() */
-#define TEST_STR_EQUAL 0
-
-#define ICTEST_LOGRED "\033[0;31m"
-#define ICTEST_LOGGREEN "\033[0;32m"
-#define ICTEST_LOGBROWN "\033[0;33m"
-#define ICTEST_LOGBLUE "\033[0;34m"
-#define ICTEST_LOGEND "\033[0;m"
-
-#undef _DBG
-#undef _INFO
-#undef _WARN
-#undef _ERR
-
-#undef DBG
-#undef INFO
-#undef WARN
-#undef ERR
-
-#define TIZEN_DEBUG_ENABLE
-#define LOG_TAG "ICTEST"
-#include <dlog.h>
-
-#define _DBG(fmt, arg...) SLOGD(fmt, ##arg)
-#define _INFO(fmt, arg...) SLOGI(fmt, ##arg)
-#define _WARN(fmt, arg...) SLOGW(fmt, ##arg)
-#define _ERR(fmt, arg...) SLOGE(fmt, ##arg)
-
-#if 0
-#define _DBG(fmt, arg...) \
- printf("[IoTConTest]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
-#define _INFO(fmt, arg...) \
- printf("[IoTConTest]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
-#define _WARN(fmt, arg...) \
- printf("[IoTConTest]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
-#define _ERR(fmt, arg...) \
- printf("[IoTConTest]%s(%d):" fmt "\n", __FUNCTION__, __LINE__, ##arg)
-#endif
-
-#define ICTEST_DEBUGGING
-
-#ifdef ICTEST_DEBUGGING
-
-#define FN_CALL _INFO(">>>>>>>> called")
-#define FN_END _INFO("<<<<<<<< ended")
-#define DBG(fmt, arg...) _DBG(fmt, ##arg)
-#define WARN(fmt, arg...) _WARN(ICTEST_LOGBROWN fmt ICTEST_LOGEND, ##arg)
-#define ERR(fmt, arg...) _ERR(ICTEST_LOGRED fmt ICTEST_LOGEND, ##arg)
-#define INFO(fmt, arg...) _INFO(ICTEST_LOGBLUE fmt ICTEST_LOGEND, ##arg)
-#define SECURE_DBG(fmt, arg...) SECURE_SLOGD(fmt, ##arg)
-#define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
-#define ABORT() abort()
-
-#else /* ICTEST_DEBUGGING */
-
-#define FN_CALL
-#define FN_END
-#define DBG(fmt, arg...)
-#define WARN(fmt, arg...)
-#define ERR(fmt, arg...) _ERR(fmt, ##arg)
-#define INFO(fmt, arg...)
-#define SECURE_DBG(fmt, arg...)
-#define SECURE_ERR(fmt, arg...) SECURE_SLOGE(fmt, ##arg)
-#define ABORT()
-
-#endif /* ICTEST_DEBUGGING */
-
-#define RET_IF(expr) \
- do { \
- if (expr) { \
- ERR("(%s)", #expr); \
- return; \
- }\
- } while(0)
-
-#define RETV_IF(expr, val) \
- do {\
- if (expr) { \
- ERR("(%s)", #expr); \
- return (val); \
- } \
- } while(0)
-
-#define RETM_IF(expr, fmt, arg...) \
- do {\
- if (expr) { \
- ERR(fmt, ##arg); \
- return; \
- }\
- } while(0)
-
-#define RETVM_IF(expr, val, fmt, arg...) \
- do {\
- if (expr) { \
- ERR(fmt, ##arg); \
- return (val); \
- } \
- } while(0)
-
-#define ERR_IF(expr) \
- do { \
- if (expr) { \
- ERR("(%s)", #expr); \
- } \
- } while (0)
-
-#define WARN_IF(expr, fmt, arg...) \
- do { \
- if (expr) { \
- WARN(fmt, ##arg); \
- } \
- } while (0)
-
-#endif /* __IOT_CONNECTIVITY_MANAGER_TEST_H__ */