summaryrefslogtreecommitdiff
path: root/src/lib/adaptor_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/adaptor_api.c')
-rwxr-xr-xsrc/lib/adaptor_api.c243
1 files changed, 243 insertions, 0 deletions
diff --git a/src/lib/adaptor_api.c b/src/lib/adaptor_api.c
new file mode 100755
index 0000000..788fcca
--- /dev/null
+++ b/src/lib/adaptor_api.c
@@ -0,0 +1,243 @@
+/**
+ * @file adaptor_api.c
+ * @brief library for providing adaptor API
+
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * This software is the confidential and proprietary information
+ * of Samsung Electronics, Inc. ("Confidential Information"). You
+ * shall not disclose such Confidential Information and shall use
+ * it only in accordance with the terms of the license agreement
+ * you entered into with Samsung.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include "adaptor_api.h"
+#include "ipc_client.h"
+#include "json_util.h"
+
+/**
+ * @fn static char *__get_funcname_param_in(char *funcName)
+ * @brief This function to generate in params for container info api
+ * @param *funcName [in] function name to make json data
+ * @return *char whole json data
+ */
+static char *__get_funcname_param_in(const char *funcName)
+{
+ struct json_object *newObj;
+ const char *buf = NULL;
+ char *ret_buf = NULL;
+
+ newObj = json_object_new_object();
+ json_object_object_add(newObj, "func", json_object_new_string(funcName));
+ buf = json_object_to_json_string_ext(newObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
+
+ ret_buf = (char *)malloc(strlen(buf) + 1);
+ if (ret_buf != NULL) {
+ memset(ret_buf, 0x00, strlen(buf) + 1);
+ memcpy(ret_buf, buf, strlen(buf) + 1);
+ }
+ json_object_put(newObj);
+
+ return ret_buf;
+}
+
+/**
+ * @fn static int __get_device_reboot_param_out(char *rcvData, containers_info_s *containers_info_h)
+ * @brief This function to generate out params for container info api
+ * @param *revData [in] received data from response
+ * @return int result of function
+ */
+static int __get_device_reboot_param_out(char *rcvData)
+{
+ int ret = -1;
+ if (rcvData)
+ ret = json_getNumber(rcvData, "result");
+ else
+ printf("{%s}(%d) ERROR!!! NULL pointer of rcvData\n", __FUNCTION__, __LINE__);
+
+ return ret;
+}
+
+/**
+ * @fn static int __get_device_reboot_param_out(char *rcvData, os_info_s *os_info)
+ * @brief This function to generate out params for container info api
+ * @param *revData [in] received data from response
+ * @param *os_info [inout] fill os info into structure
+ * @return int result of function
+ */
+static int __get_os_info_param_out(char *rcvData, os_info_s *os_info)
+{
+ if (os_info) {
+ os_info->platformVer = json_getString(rcvData, "platformVer");
+ os_info->baseOSVer = json_getString(rcvData, "baseOSVer");
+ os_info->dockerVer = json_getString(rcvData, "dockerVer");
+ } else {
+ printf("{%s}(%d) ERROR!!! NULL pointer of os_info\n", __FUNCTION__, __LINE__);
+ return -1;
+ }
+ return 0;
+}
+
+/**
+ * @fn static int __get_disk_info_param_out(char *rcvData, disk_info_s *disk_info)
+ * @brief This function to generate out params for disk info api
+ * @param *revData [in] received data from response
+ * @param *disk_info [inout] fill disk info into structure
+ * @return int result of function
+ */
+static int __get_disk_info_param_out(char *rcvData, disk_info_s *disk_info)
+{
+ int index;
+ int diskCnt = 0;
+
+ diskCnt = json_getNumber(rcvData, "count");
+
+ if (disk_info) {
+ disk_info->count = diskCnt;
+ for (index = 0; index < diskCnt; index++) {
+ disk_info->disk[index].path = json_getStringFromArray(rcvData, "disk", index, "path");
+ disk_info->disk[index].free = json_getIntFromArray(rcvData, "disk", index, "free");
+ disk_info->disk[index].total = json_getIntFromArray(rcvData, "disk", index, "total");
+ disk_info->disk[index].used = json_getIntFromArray(rcvData, "disk", index, "used");
+ disk_info->disk[index].usedpercent = json_getIntFromArray(rcvData, "disk", index, "usedpercent");
+ }
+ } else {
+ printf("{%s}(%d) ERROR!!! NULL pointer of disk_info\n", __FUNCTION__, __LINE__);
+ return -1;
+ }
+ return 0;
+}
+
+/**
+ * @fn static int __get_factory_restore_param_out(char *rcvData)
+ * @brief This function to generate out params for factory restore
+ * @param *revData [in] received data from response
+ * @return int result of function
+ */
+static int __get_factory_restore_param_out(char *rcvData)
+{
+ int ret = -1;
+ if (rcvData)
+ ret = json_getNumber(rcvData, "result");
+ else
+ printf("{%s}(%d) ERROR!!! NULL pointer of rcvData\n", __FUNCTION__, __LINE__);
+
+ return ret;
+}
+
+
+API int device_reboot()
+{
+ int ret = ADAPTOR_API_ERROR_NONE;
+ char *send_data = NULL;
+ char *ret_buf = NULL;
+
+ send_data = __get_funcname_param_in(__FUNCTION__);
+ printf("Client>> SendMessage = %s\n", send_data);
+
+ if (send_data) {
+ ret = IPC_CallFunction(send_data, strlen(send_data), &ret_buf);
+ printf("Client>> IPC_CallFunction(%d), ret_buf(%p)\n", ret, ret_buf);
+ if (!ret && ret_buf) {
+ ret = __get_device_reboot_param_out(ret_buf);
+ printf("ret = %d\n", ret);
+ }
+ if (ret_buf)
+ free(ret_buf);
+ free(send_data);
+ }
+
+ return ret;
+}
+
+API int get_os_info(os_info_s * os_info)
+{
+ int ret = ADAPTOR_API_ERROR_NONE;
+ char *send_data = NULL;
+ char *ret_buf = NULL;
+
+ send_data = __get_funcname_param_in(__FUNCTION__);
+ printf("Client>> SendMessage = %s\n", send_data);
+
+ if (send_data) {
+ ret = IPC_CallFunction(send_data, strlen(send_data), &ret_buf);
+ printf("Client>> IPC_CallFunction(%d), ret_buf(%p)\n", ret, ret_buf);
+ if (!ret && ret_buf) {
+ ret = __get_os_info_param_out(ret_buf, os_info);
+ /*
+ if (!ret) {
+ printf("os_info.platformVer = %s\n", os_info->platformVer);
+ printf("os_info.baseOSVer = %s\n", os_info->baseOSVer);
+ printf("os_info.dockerVer = %s\n", os_info->dockerVer);
+ }
+ */
+ }
+ if (ret_buf)
+ free(ret_buf);
+ free(send_data);
+ }
+
+ return ret;
+}
+
+API int get_disk_info(disk_info_s *disk_info)
+{
+ int ret = ADAPTOR_API_ERROR_NONE;
+ char *send_data = NULL;
+ char *ret_buf = NULL;
+ //int index;
+
+ send_data = __get_funcname_param_in(__FUNCTION__);
+ printf("Client>> SendMessage = %s\n", send_data);
+
+ if (send_data) {
+ ret = IPC_CallFunction(send_data, strlen(send_data), &ret_buf);
+ printf("Client>> IPC_CallFunction(%d), ret_buf(%p)\n", ret, ret_buf);
+ if (!ret && ret_buf) {
+ ret = __get_disk_info_param_out(ret_buf, disk_info);
+ /*
+ if (!ret) {
+ for (index = 0; index < disk_info->count; index++) {
+ printf("disk_info[%d] path = %s\n", index, disk_info->disk[index].path);
+ printf("disk_info[%d] free = %dM\n", index, disk_info->disk[index].free);
+ printf("disk_info[%d] total = %dM\n", index, disk_info->disk[index].total);
+ printf("disk_info[%d] used = %dM\n", index, disk_info->disk[index].used);
+ printf("disk_info[%d] usedpercent = %.2f%%\n", index, (float)disk_info->disk[index].usedpercent/(float)100);
+ }
+ }
+ */
+ }
+ if (ret_buf)
+ free(ret_buf);
+ free(send_data);
+ }
+
+ return ret;
+}
+
+API int factory_restore()
+{
+ int ret = ADAPTOR_API_ERROR_NONE;
+ char *send_data = NULL;
+ char *ret_buf = NULL;
+
+ send_data = __get_funcname_param_in(__FUNCTION__);
+ printf("Client>> SendMessage = %s\n", send_data);
+
+ if (send_data) {
+ ret = IPC_CallFunction(send_data, strlen(send_data), &ret_buf);
+ printf("Client>> IPC_CallFunction(%d), ret_buf(%p)\n", ret, ret_buf);
+ if (!ret && ret_buf) {
+ ret = __get_factory_restore_param_out(ret_buf);
+ printf("ret = %d\n", ret);
+ }
+ if (ret_buf)
+ free(ret_buf);
+ free(send_data);
+ }
+
+ return ret;
+}