diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/list.h | 74 | ||||
-rw-r--r-- | src/deviced/dd-battery.h | 35 | ||||
-rw-r--r-- | src/deviced/dd-mmc.h | 61 | ||||
-rw-r--r-- | src/shared/battery.c | 25 | ||||
-rw-r--r-- | src/shared/common.h | 49 | ||||
-rw-r--r-- | src/shared/log.h | 45 | ||||
-rw-r--r-- | src/shared/mmc.c | 162 |
7 files changed, 451 insertions, 0 deletions
diff --git a/src/core/list.h b/src/core/list.h new file mode 100644 index 0000000..4217704 --- /dev/null +++ b/src/core/list.h @@ -0,0 +1,74 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 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 __LIST_H__ +#define __LIST_H__ + +#include <Ecore.h> + +#define EINA_LIST_APPEND(a, b) \ + a = eina_list_append(a, b) + +#define EINA_LIST_REMOVE(a, b) \ + a = eina_list_remove(a, b) + +#define EINA_LIST_REMOVE_LIST(a, b) \ + a = eina_list_remove_list(a, b) + +#define EINA_LIST_FREE_LIST(a) \ + a = eina_list_free(a) + +#define EINA_LIST_PROMOTE_LIST(a, b) \ + a = eina_list_promote_list(a, b) + +#ifdef EINA_LIST +typedef Eina_List dd_list; +#define DD_LIST_PREPEND(a, b) \ + a = eina_list_prepend(a, b) +#define DD_LIST_APPEND(a, b) \ + a = eina_list_append(a, b) +#define DD_LIST_REMOVE(a, b) \ + a = eina_list_remove(a, b) +#define DD_LIST_LENGTH(a) \ + eina_list_count(a) +#define DD_LIST_NTH(a, b) \ + eina_list_nth(a, b) +#define DD_LIST_FREE_LIST(a) \ + a = eina_list_free(a) +#define DD_LIST_FOREACH(head, elem, node) \ + EINA_LIST_FOREACH(head, elem, node) +#else +#include <glib.h> +typedef GList dd_list; +#define DD_LIST_PREPEND(a, b) \ + a = g_list_prepend(a, (gpointer)b) +#define DD_LIST_APPEND(a, b) \ + a = g_list_append(a, (gpointer)b) +#define DD_LIST_REMOVE(a, b) \ + a = g_list_remove(a, (gpointer)b) +#define DD_LIST_LENGTH(a) \ + g_list_length(a) +#define DD_LIST_NTH(a, b) \ + g_list_nth_data(a, b) +#define DD_LIST_FREE_LIST(a) \ + g_list_free(a) +#define DD_LIST_FOREACH(head, elem, node) \ + for (elem = head; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) +#endif + +#endif diff --git a/src/deviced/dd-battery.h b/src/deviced/dd-battery.h new file mode 100644 index 0000000..78fd9b3 --- /dev/null +++ b/src/deviced/dd-battery.h @@ -0,0 +1,35 @@ +/* + * deviced + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * 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 __DD_BATTERY_H__ +#define __DD_BATTERY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file dd-battery.h + * @ingroup DEVICED_LIBRARY + * @brief This file provides for control of battery + */ + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/deviced/dd-mmc.h b/src/deviced/dd-mmc.h new file mode 100644 index 0000000..d8e9f3f --- /dev/null +++ b/src/deviced/dd-mmc.h @@ -0,0 +1,61 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * 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 __DD_MMC_H__ +#define __DD_MMC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file dd-mmc.h + * @ingroup CAPI_SYSTEM_DEVICED + * @defgroup CAPI_SYSTEM_DEVICED_MMC_MODULE mmc + * @brief This file provides the API for control of mmc(sd-card) + */ + +/** + * @addtogroup CAPI_SYSTEM_DEVICED_MMC_MODULE + * @{ + */ + +/** + * @par Description: + * This API is used to mount application to mmc.\n + * @param[in] pkgid what you want to mount and execute at mmc + * @return 0 on success, -1 if failed + * @par Example + * @code + * ... + * if (mmc_mount_app2ext("com.samsung.setting") < 0) + * printf("app2ext mount failed\n"); + * ... + * @endcode + */ +int mmc_mount_app2ext(const char *pkdid); + +/** + * @} // end of CAPI_SYSTEM_DEVICED_MMC_MODULE + */ + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/shared/battery.c b/src/shared/battery.c new file mode 100644 index 0000000..7d7d238 --- /dev/null +++ b/src/shared/battery.c @@ -0,0 +1,25 @@ +/* + * deviced + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * 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 <vconf.h> +#include <errno.h> +#include <device-node.h> + +#include "log.h" +#include "dd-battery.h" diff --git a/src/shared/common.h b/src/shared/common.h new file mode 100644 index 0000000..5a3ef23 --- /dev/null +++ b/src/shared/common.h @@ -0,0 +1,49 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 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 __DD_COMMON_H__ +#define __DD_COMMON_H__ + +#include <stdio.h> +#include <stdlib.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef API +#define API __attribute__ ((visibility("default"))) +#endif + +#ifndef DEPRECATED +#define DEPRECATED __attribute__ ((deprecated)) +#endif + +#ifndef __CONSTRUCTOR__ +#define __CONSTRUCTOR__ __attribute__ ((constructor)) +#endif + +#ifndef __DESTRUCTOR__ +#define __DESTRUCTOR__ __attribute__ ((destructor)) +#endif + +#ifdef __cplusplus + +} +#endif +#endif /* __DD_COMMON_H__ */ diff --git a/src/shared/log.h b/src/shared/log.h new file mode 100644 index 0000000..1be64d7 --- /dev/null +++ b/src/shared/log.h @@ -0,0 +1,45 @@ +/* + * deviced + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * 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 __LOG_H__ +#define __LOG_H__ + +#define FEATURE_DEVICED_DLOG + +#ifdef FEATURE_DEVICED_DLOG +#define LOG_TAG "DEVICED" +#include <dlog.h> +#define _D(fmt, args...) SLOGD(fmt, ##args) +#define _I(fmt, args...) SLOGI(fmt, ##args) +#define _E(fmt, args...) SLOGE(fmt, ##args) +#define _SD(fmt, arg...) SECURE_SLOGD(fmt, ##arg) +#define _SI(fmt, arg...) SECURE_SLOGI(fmt, ##arg) +#define _SW(fmt, arg...) SECURE_SLOGW(fmt, ##arg) +#define _SE(fmt, arg...) SECURE_SLOGE(fmt, ##arg) +#else +#define _D(x, ...) do { } while (0) +#define _I(x, ...) do { } while (0) +#define _E(x, ...) do { } while (0) +#define _SD(fmt, args...) do { } while (0) +#define _SI(fmt, args...) do { } while (0) +#define _SW(fmt, args...) do { } while (0) +#define _SE(fmt, args...) do { } while (0) +#endif + +#endif diff --git a/src/shared/mmc.c b/src/shared/mmc.c new file mode 100644 index 0000000..97c47f2 --- /dev/null +++ b/src/shared/mmc.c @@ -0,0 +1,162 @@ +/* + * deviced + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. + * + * 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 <unistd.h> +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <stdarg.h> + +#include "common.h" +#include "log.h" + +#define SYSMAN_MAXARG 16 +#define SYSMAN_MAXSTR 100 +#define BUFF_MAX 255 + +struct sysnoti { + int pid; + int cmd; + char *type; + char *path; + int argc; + char *argv[SYSMAN_MAXARG]; +}; + +#define PREDEF_MOUNT_APP2EXT "mountapp2ext" + +enum sysnoti_cmd { + ADD_SYSMAN_ACTION, + CALL_SYSMAN_ACTION +}; + +#define SYSNOTI_SOCKET_PATH "/tmp/sn" + +static inline int send_int(int fd, int val) +{ + return write(fd, &val, sizeof(int)); +} + +static inline int send_str(int fd, char *str) +{ + int len; + int ret; + if (str == NULL) { + len = 0; + ret = write(fd, &len, sizeof(int)); + } else { + len = strlen(str); + if (len > SYSMAN_MAXSTR) + len = SYSMAN_MAXSTR; + write(fd, &len, sizeof(int)); + ret = write(fd, str, len); + } + return ret; +} + +static int sysnoti_send(struct sysnoti *msg) +{ + _E("--- %s: start", __FUNCTION__); + int client_len; + int client_sockfd; + int result; + struct sockaddr_un clientaddr; + int i; + + client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (client_sockfd == -1) { + _E("%s: socket create failed\n", __FUNCTION__); + return -1; + } + bzero(&clientaddr, sizeof(clientaddr)); + clientaddr.sun_family = AF_UNIX; + strncpy(clientaddr.sun_path, SYSNOTI_SOCKET_PATH, sizeof(clientaddr.sun_path) - 1); + client_len = sizeof(clientaddr); + + if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < + 0) { + _E("%s: connect failed\n", __FUNCTION__); + close(client_sockfd); + return -1; + } + + send_int(client_sockfd, msg->pid); + send_int(client_sockfd, msg->cmd); + send_str(client_sockfd, msg->type); + send_str(client_sockfd, msg->path); + send_int(client_sockfd, msg->argc); + for (i = 0; i < msg->argc; i++) + send_str(client_sockfd, msg->argv[i]); + + _E("--- %s: read", __FUNCTION__); + read(client_sockfd, &result, sizeof(int)); + + close(client_sockfd); + _E("--- %s: end", __FUNCTION__); + return result; +} + +static int deviced_call_predef_action(const char *type, int num, ...) +{ + _E("--- %s: start", __FUNCTION__); + struct sysnoti *msg; + int ret; + va_list argptr; + + int i; + char *args = NULL; + + if (type == NULL || num > SYSMAN_MAXARG) { + errno = EINVAL; + return -1; + } + + msg = malloc(sizeof(struct sysnoti)); + + if (msg == NULL) { + /* Do something for not enought memory error */ + return -1; + } + + msg->pid = getpid(); + msg->cmd = CALL_SYSMAN_ACTION; + msg->type = (char *)type; + msg->path = NULL; + + msg->argc = num; + va_start(argptr, num); + for (i = 0; i < num; i++) { + args = va_arg(argptr, char *); + msg->argv[i] = args; + } + va_end(argptr); + + _E("--- %s: send msg", __FUNCTION__); + ret = sysnoti_send(msg); + free(msg); + + _E("--- %s: end", __FUNCTION__); + return ret; +} + +API int mmc_mount_app2ext(const char *str) +{ + return deviced_call_predef_action(PREDEF_MOUNT_APP2EXT, 1, str); +} |