};
+struct icd_platform_context {
+ unsigned int signum;
+ int res;
+ char *bus_name;
+ char *payload;
+};
+
+
struct icd_observe_context {
unsigned int signum;
int res;
}
+static int _worker_platform_cb(void *context)
+{
+ int ret;
+ GVariant *value;
+ struct icd_platform_context *ctx = context;
+
+ RETV_IF(NULL == ctx, IOTCON_ERROR_INVALID_PARAMETER);
+
+ value = g_variant_new("(s)", ctx->payload);
+
+ ret = _ocprocess_response_signal(ctx->bus_name, IC_DBUS_SIGNAL_PLATFORM, ctx->signum,
+ value);
+ if (IOTCON_ERROR_NONE != ret)
+ ERR("_ocprocess_response_signal() Fail(%d)", ret);
+
+ /* ctx was allocated from icd_ioty_ocprocess_platform_cb() */
+ free(ctx->bus_name);
+ free(ctx->payload);
+ free(ctx);
+
+ return ret;
+}
+
+
static int _ocprocess_worker(_ocprocess_fn fn, int type, const char *payload, int res,
GVariantBuilder *options, void *ctx)
{
}
+OCStackApplicationResult icd_ioty_ocprocess_platform_cb(void *ctx, OCDoHandle handle,
+ OCClientResponse *resp)
+{
+ int ret;
+ struct icd_platform_context *platform_ctx;
+ icd_sig_ctx_s *sig_context = ctx;
+
+ RETV_IF(NULL == ctx, OC_STACK_KEEP_TRANSACTION);
+
+ if (NULL == resp->resJSONPayload || '\0' == resp->resJSONPayload[0]) {
+ ERR("json payload is empty");
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ platform_ctx = calloc(1, sizeof(struct icd_platform_context));
+ if (NULL == platform_ctx) {
+ ERR("calloc() Fail(%d)", errno);
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ platform_ctx->payload = strdup(resp->resJSONPayload);
+ platform_ctx->signum = sig_context->signum;
+ platform_ctx->bus_name = ic_utils_strdup(sig_context->bus_name);
+
+ ret = _ocprocess_worker_start(_worker_platform_cb, platform_ctx);
+ if (IOTCON_ERROR_NONE != ret) {
+ ERR("_ocprocess_worker_start() Fail(%d)", ret);
+ free(platform_ctx->bus_name);
+ free(platform_ctx->payload);
+ free(platform_ctx);
+ return OC_STACK_KEEP_TRANSACTION;
+ }
+
+ /* DO NOT FREE sig_context. It MUST be freed in the ocstack */
+ /* DO NOT FREE platform_ctx. It MUST be freed in the _worker_platform_cb func */
+
+ return OC_STACK_KEEP_TRANSACTION;
+}
OCStackApplicationResult icd_ioty_ocprocess_presence_cb(void *ctx, OCDoHandle handle,
OCClientResponse* resp);
+OCStackApplicationResult icd_ioty_ocprocess_platform_cb(void *ctx, OCDoHandle handle,
+ OCClientResponse *resp);
+
#endif /*__IOT_CONNECTIVITY_MANAGER_DAEMON_IOTIVITY_THREAD_H__*/
#include "icd-ioty.h"
#include "icd-ioty-ocprocess.h"
+#define ICD_IOTY_PLATFORM_URI_PATH "/oic/p"
+
static GMutex icd_csdk_mutex;
void icd_ioty_csdk_lock()
int icd_ioty_unregister_resource(OCResourceHandle handle)
{
+ FN_CALL;
OCStackResult ret;
icd_ioty_csdk_lock();
int icd_ioty_register_platform_info(GVariant *value)
{
- // TODO : To be implemented
+ OCStackResult result;
+ OCPlatformInfo platform_info = {0};
+
+ g_variant_get(value, "(&s&s&s&s&s&s&s&s&s&s&s)",
+ &platform_info.platformID,
+ &platform_info.manufacturerName,
+ &platform_info.manufacturerUrl,
+ &platform_info.modelNumber,
+ &platform_info.dateOfManufacture,
+ &platform_info.platformVersion,
+ &platform_info.operatingSystemVersion,
+ &platform_info.hardwareVersion,
+ &platform_info.firmwareVersion,
+ &platform_info.supportUrl,
+ &platform_info.systemTime);
+
+ icd_ioty_csdk_lock();
+ result = OCSetPlatformInfo(platform_info);
+ icd_ioty_csdk_unlock();
+
+ if (OC_STACK_OK != result) {
+ ERR("OCSetPlatformInfo() Fail(%d)", result);
+ return IOTCON_ERROR_IOTIVITY;
+ }
+
return IOTCON_ERROR_NONE;
}
int icd_ioty_get_platform_info(const char *host_address, unsigned int signal_number,
const char *bus_name)
{
- // TODO : To be implemented
+ FN_CALL;
+ char *uri;
+ OCStackResult result;
+ icd_sig_ctx_s *context;
+ OCCallbackData cbdata = {0};
+ char uri_buf[PATH_MAX] = {0};
+ iotcon_connectivity_type_e conn_type = IOTCON_CONNECTIVITY_IPV4;
+
+ snprintf(uri_buf, sizeof(uri_buf), "%s:%d"ICD_IOTY_PLATFORM_URI_PATH, host_address,
+ OC_MULTICAST_PORT);
+ uri = strdup(uri_buf);
+ if (NULL == uri) {
+ ERR("strdup() Fail(%d)", errno);
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
+
+ context = calloc(1, sizeof(icd_sig_ctx_s));
+ if (NULL == context) {
+ ERR("calloc() Fail(%d)", errno);
+ free(uri);
+ return IOTCON_ERROR_OUT_OF_MEMORY;
+ }
+ context->bus_name = ic_utils_strdup(bus_name);
+ context->signum = signal_number;
+
+ cbdata.context = context;
+ cbdata.cb = icd_ioty_ocprocess_platform_cb;
+ cbdata.cd = _ioty_free_signal_context;
+
+ icd_ioty_csdk_lock();
+ /* TODO : QoS is come from lib. And user can set QoS to client structure. */
+ result = OCDoResource(NULL, OC_REST_GET, uri, NULL, NULL, conn_type, OC_HIGH_QOS,
+ &cbdata, NULL, 0);
+ icd_ioty_csdk_unlock();
+
+ free(uri);
+
+ if (OC_STACK_OK != result) {
+ ERR("OCDoResource() Fail(%d)", result);
+ free(context->bus_name);
+ free(context);
+ return IOTCON_ERROR_IOTIVITY;
+ }
+
return IOTCON_ERROR_NONE;
}
iotcon_on_observe_cb cb,
void *user_data)
{
+ FN_CALL;
int observe_handle;
GError *error = NULL;
unsigned int sub_id;
API int iotcon_observer_stop(iotcon_client_h resource)
{
+ FN_CALL;
int ret;
GError *error = NULL;
GVariant *arg_options;
GVariant *value;
value = g_variant_new("(sssssssssss)",
- ic_utils_dbus_encode_str(platform_info->platform_id),
- ic_utils_dbus_encode_str(platform_info->manuf_name),
- ic_utils_dbus_encode_str(platform_info->manuf_url),
- ic_utils_dbus_encode_str(platform_info->model_number),
- ic_utils_dbus_encode_str(platform_info->date_of_manufacture),
- ic_utils_dbus_encode_str(platform_info->platform_ver),
- ic_utils_dbus_encode_str(platform_info->os_ver),
- ic_utils_dbus_encode_str(platform_info->hardware_ver),
- ic_utils_dbus_encode_str(platform_info->firmware_ver),
- ic_utils_dbus_encode_str(platform_info->support_url),
- ic_utils_dbus_encode_str(platform_info->system_time));
+ platform_info->platform_id,
+ platform_info->manuf_name,
+ platform_info->manuf_url,
+ platform_info->model_number,
+ platform_info->date_of_manufacture,
+ platform_info->platform_ver,
+ platform_info->os_ver,
+ platform_info->hardware_ver,
+ platform_info->firmware_ver,
+ platform_info->support_url,
+ platform_info->system_time);
return value;
}
#include "iotcon.h"
#include "ic-utils.h"
#include "icl.h"
+#include "icl-repr.h"
#include "icl-dbus.h"
#include "icl-dbus-type.h"
RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
+ if (NULL == platform_info.platform_id
+ || NULL == platform_info.manuf_name
+ || NULL == platform_info.manuf_url
+ || NULL == platform_info.model_number
+ || NULL == platform_info.date_of_manufacture
+ || NULL == platform_info.platform_ver
+ || NULL == platform_info.os_ver
+ || NULL == platform_info.hardware_ver
+ || NULL == platform_info.firmware_ver
+ || NULL == platform_info.support_url
+ || NULL == platform_info.system_time) {
+ ERR("one of parameter is NULL");
+ return IOTCON_ERROR_INVALID_PARAMETER;
+ }
+
if (platform_info.manuf_name
&& (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(platform_info.manuf_name))) {
ERR("The length of manufacturer_name(%s) is invalid.", platform_info.manuf_name);
GVariant *parameters,
gpointer user_data)
{
+ FN_CALL;
+ char *repr_json = NULL;
+ iotcon_repr_h repr;
icl_platform_info_s *cb_container = user_data;
iotcon_platform_info_cb cb = cb_container->cb;
- iotcon_platform_info_s info = {0};
-
- 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_manufacture,
- &info.platform_ver,
- &info.os_ver,
- &info.hardware_ver,
- &info.firmware_ver,
- &info.support_url,
- &info.system_time);
+ g_variant_get(parameters, "(&s)", &repr_json);
+ if (IC_STR_EQUAL == strcmp(IC_STR_NULL, repr_json)) {
+ ERR("Invalid Representation");
+ return;
+ }
- info.platform_id = ic_utils_dbus_decode_str(info.platform_id);
- info.manuf_name = ic_utils_dbus_decode_str(info.manuf_name);
- 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_manufacture = ic_utils_dbus_decode_str(info.date_of_manufacture);
- 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);
+ repr = icl_repr_create_repr(repr_json);
if (cb)
- cb(info, cb_container->user_data);
+ cb(repr, cb_container->user_data);
+
+ iotcon_repr_free(repr);
}
#define IOTCON_FUNC_STOP 0
#define IOTCON_FUNC_CONTINUE 1
+#define IOTCON_PLATFORM_PLATFORM_ID "pi"
+#define IOTCON_PLATFORM_MFG_NAME "mnmn"
+#define IOTCON_PLATFORM_MFG_URL "mnml"
+#define IOTCON_PLATFORM_MODEL_NUM "mnmo"
+#define IOTCON_PLATFORM_MFG_DATE "mndt"
+#define IOTCON_PLATFORM_PLATFORM_VERSION "mnpv"
+#define IOTCON_PLATFORM_OS_VERSION "mnos"
+#define IOTCON_PLATFORM_HARDWARE_VERSION "mnhw"
+#define IOTCON_PLATFORM_FIRMWARE_VERSION "mnfv"
+#define IOTCON_PLATFORM_SUPPORT_URL "mnsl"
+#define IOTCON_PLATFORM_SYSTEM_TIME "st"
+
+
/**
* @brief Action associated with observation
*/
#endif
int iotcon_register_platform_info(iotcon_platform_info_s platform_info);
-typedef void (*iotcon_platform_info_cb)(iotcon_platform_info_s info, void *user_data);
+typedef void (*iotcon_platform_info_cb)(iotcon_repr_h repr, void *user_data);
int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
void *user_data);
#include <iotcon.h>
#include "test.h"
-static void _get_platform_info(iotcon_platform_info_s info, void *user_data)
+static void _get_platform_info(iotcon_repr_h repr, void *user_data)
{
- INFO("platform_id : %s", info.platform_id);
- INFO("manuf_name : %s", info.manuf_name);
- INFO("manuf_url : %s", info.manuf_url);
- INFO("model_number : %s", info.model_number);
- INFO("date_of_manufacture : %s", info.date_of_manufacture);
- INFO("platform_ver : %s", info.platform_ver);
- INFO("os_ver : %s", info.os_ver);
- INFO("hardware_ver : %s", info.hardware_ver);
- INFO("firmware_ver : %s", info.firmware_ver);
- INFO("support_url : %s", info.support_url);
- INFO("system_time : %s", info.system_time);
+ FN_CALL;
+ char *platform_id = NULL;
+ char *manuf_name = NULL;
+ char *manuf_url = NULL;
+ char *model_number = NULL;
+ char *date_of_manufacture = 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;
+
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_PLATFORM_ID, &platform_id);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_MFG_NAME, &manuf_name);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_MFG_URL, &manuf_url);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_MODEL_NUM, &model_number);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_MFG_DATE, &date_of_manufacture);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_PLATFORM_VERSION, &platform_ver);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_OS_VERSION, &os_ver);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_HARDWARE_VERSION, &hardware_ver);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_FIRMWARE_VERSION, &firmware_ver);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_SUPPORT_URL, &support_url);
+ iotcon_repr_get_str(repr, IOTCON_PLATFORM_SYSTEM_TIME, &system_time);
+
+ 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_manufacture);
+ 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()
{
+ FN_CALL;
GMainLoop *loop;
loop = g_main_loop_new(NULL, FALSE);
int main()
{
+ FN_CALL;
int ret;
GMainLoop *loop;