diff options
author | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 01:36:22 +0900 |
---|---|---|
committer | Jinkun Jang <jinkun.jang@samsung.com> | 2013-03-13 01:36:22 +0900 |
commit | fce1a668c6b85ead8992e2a14b67f9c4c952c513 (patch) | |
tree | 84328dd953acfdf8b772afd1c0d2d40cb57c92cf | |
parent | 7a90b88840d44a673b3450067b541b78a92f3e63 (diff) | |
download | device-manager-plugin-pinetrail-fce1a668c6b85ead8992e2a14b67f9c4c952c513.tar.gz device-manager-plugin-pinetrail-fce1a668c6b85ead8992e2a14b67f9c4c952c513.tar.bz2 device-manager-plugin-pinetrail-fce1a668c6b85ead8992e2a14b67f9c4c952c513.zip |
Tizen 2.1 base
-rw-r--r-- | CMakeLists.txt | 54 | ||||
-rw-r--r-- | device-manager-plugin-pinetrail.c | 351 | ||||
-rw-r--r-- | device-manager-plugin-pinetrail.h | 45 | ||||
-rw-r--r-- | device-manager-plugin-pinetrail.pc.in | 13 | ||||
-rw-r--r-- | device_engine.c | 243 | ||||
-rw-r--r-- | device_engine.h | 56 | ||||
-rw-r--r-- | devlog.h | 177 | ||||
-rw-r--r-- | packaging/device-manager-plugin-pinetrail.changes | 5 | ||||
-rw-r--r-- | packaging/device-manager-plugin-pinetrail.spec | 55 |
9 files changed, 999 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..42911bd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(device-manager-plugin-pinetrail C) + +INCLUDE(FindPkgConfig) +pkg_check_modules(rpkgs REQUIRED + vconf + dlog + devman + devman_plugin + heynoti) +ADD_DEFINITIONS(${rpkgs_CFLAGS}) + +SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRAINTS true) + +SET(SRCS + device_engine.c + device-manager-plugin-pinetrail.c) + +SET(HEADERS + device-manager-plugin-pinetrail.h) + + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(DATADIR ${CMAKE_DATADIR}) +SET(VERSION 0.2.4) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") + +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") +ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"") +ADD_DEFINITIONS("-DENABLE_DLOG_OUT -DSLP_DEBUG") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ${TARGET_SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS} "-ldl -rdynamic") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION}) + + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION lib/pkgconfig) + +FOREACH(hfile ${HEADERS}) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME}) +ENDFOREACH(hfile) diff --git a/device-manager-plugin-pinetrail.c b/device-manager-plugin-pinetrail.c new file mode 100644 index 0000000..1c87499 --- /dev/null +++ b/device-manager-plugin-pinetrail.c @@ -0,0 +1,351 @@ + +/* + * Overview: device mananger(devman) plugin for pinetrail platform + * + * Copyright (c) 2000 - 2011 Intel 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 <devman/devman.h> +#include <devman/devman_plugin_intf.h> +#include <string.h> + +#include "devlog.h" +#include "device_engine.h" + +#include "device-manager-plugin-pinetrail.h" + +#define BATTERY_PRESENT_PATH "/sys/class/power_supply/BAT1/present" +#define BATTERY_CHARGE_STATUS_PATH "/sys/class/power_supply/BAT1/status" +#define BATTERY_CHARGE_FULL_PATH "/sys/class/power_supply/BAT1/charge_full" +#define BATTERY_CHARGE_NOW_PATH "/sys/class/power_supply/BAT1/charge_now" + +#define BACKLIGHTNESS_MAX_PATH "/sys/class/backlight/intel_backlight/max_brightness" +#define BACKLIGHTNESS_PATH "/sys/class/backlight/intel_backlight/brightness" + +#define WAKEUP_COUNT_PATH "/sys/power/wakeup_count" +#define POWER_STATE_PATH "/sys/power/state" + + +#define DEVIDE(_x, _y, _z)\ + if(_y) \ +{ \ + int _tmpy = _y; \ + _z = 0; \ + while(_x >= _tmpy) \ + { \ + ++_z; \ + _tmpy += _y; \ + } \ +} + +int OEM_sys_get_backlight_max_brightness(int index, int *value) +{ + int ret = -1; + + ret = sys_get_int(BACKLIGHTNESS_MAX_PATH, value); + DBG("path[%s]value[%d]", BACKLIGHTNESS_MAX_PATH, *value); + return ret; +} + +int OEM_sys_get_backlight_brightness(int index, int *value, int power_saving) +{ + int ret = -1; + + ret = sys_get_int(BACKLIGHTNESS_PATH, value); + DBG("path[%s]value[%d]", BACKLIGHTNESS_PATH, *value); + + return ret; +} + +int OEM_sys_set_backlight_brightness(int index, int value, int power_saving) +{ + int ret = -1; + + ret = sys_set_int(BACKLIGHTNESS_PATH, value); + DBG("path[%s]value[%d]", BACKLIGHTNESS_PATH, value); + + return ret; +} + +int OEM_sys_get_power_wakeup_count(int *value) +{ + int ret = -1; + + ret = sys_get_int(WAKEUP_COUNT_PATH, value); + /* + * Fix me: with the below format output, we always run into + * SEGFAULT if *value != 0, it may from overflow/out of binds + * type issue. + */ + //DBG("path[%s], value[%d], line[%d]", WAKEUP_COUNT_PATH, *value, __LINE__); + + return ret; +} + +int OEM_sys_set_power_wakeup_count(int value) +{ + int ret = -1; + + ret = sys_set_int(WAKEUP_COUNT_PATH, value); + DBG("path[%s]value[%d]", WAKEUP_COUNT_PATH, value); + + return ret; +} + +int OEM_sys_set_power_state(int value) +{ + int ret = -1; + + if(POWER_STATE_SUSPEND == value) + ret = sys_set_str(POWER_STATE_PATH, "mem"); + DBG("path[%s], value[%d]", POWER_STATE_PATH, value); + + return ret; +} + +int OEM_sys_get_battery_present(int *value) +{ + int ret = -1; + + ret = sys_get_int(BATTERY_PRESENT_PATH, value); + DBG("path[%s], value[%d]", BATTERY_PRESENT_PATH, *value); + + return ret; +} + + +int OEM_sys_get_battery_capacity(int *value) +{ + int ret = -1; + static int charge_full = 0; + static int unit = 0; + int charge_now; + int capacity = 0; + + if(charge_full == 0) + { + ret = sys_get_int(BATTERY_CHARGE_FULL_PATH, &charge_full); + if(ret != 0) + { + ERR("get battery charge full error!"); + charge_full = 0; + return -1; + } + DEVIDE(charge_full, 100, unit); + } + + ret = sys_get_int(BATTERY_CHARGE_NOW_PATH, &charge_now); + if(ret != 0) + { + ERR("get battery charge now error!"); + return -1; + } + + DEVIDE(charge_now, unit, capacity); + *value = capacity; + DBG("battery capacity value[%d]", *value); + + return 0; +} + + +int OEM_sys_get_battery_charge_full(int *value) +{ + int capacity = 0; + + if(OEM_sys_get_battery_capacity(&capacity) < 0){ + DBG("OEM_sys_get_battery_capacity failed"); + return -1; + }else{ + if(capacity == 100){ + *value = 1; + }else{ + *value = 0; + } + } + + DBG("func[%s]value[%d]", __func__, *value); + + return 0; +} + +int OEM_sys_get_battery_charge_now(int *value) +{ + char* buf = NULL; + int ret = -1; + int len = strlen("Charging\n"); + + buf = sys_get_str(BATTERY_CHARGE_STATUS_PATH); + + if(buf){ + if(0 == strncmp(buf, "Charging\n", len )){ + *value = 1; + }else{ + *value = 0; + } + DBG("path[%s]value[%d]", BATTERY_CHARGE_STATUS_PATH, *value); + + free(buf); + ret = 0; + } + + return ret; +} + +int OEM_sys_get_null_1(int *value) +{ + int ret = -1; + ERR("this interface is not implemented"); + + return ret; +} + +int OEM_sys_set_null_1(int value) +{ + int ret = -1; + ERR("this interface is not implemented"); + + return ret; +} + + +int OEM_sys_get_null_2(int index, int *value) +{ + int ret = -1; + ERR("this interface is not implemented"); + + return ret; + +} + +int OEM_sys_set_null_2(int index, int value) +{ + int ret = -1; + ERR("this interface is not implemented"); + + return ret; + +} + + +int OEM_sys_get_null_3(char *node) +{ + int ret = -1; + ERR("this interface is not implemented"); + + return ret; + +} + + +/* devman_plugin_interface_sampledevice is the structure of the type + * OEM_sys_devman_plugin_interface in which OEM API’s which are implemented are + * defined */ + +static const OEM_sys_devman_plugin_interface devman_plugin_interface_pinetrail = { + OEM_sys_get_null_1, //int (*OEM_sys_get_display_count) (int *value); + + OEM_sys_get_null_2, //int (*OEM_sys_get_backlight_min_brightness) (int index, int *value); + OEM_sys_get_backlight_max_brightness, //int (*OEM_sys_get_backlight_max_brightness) (int index, int *value); + OEM_sys_get_backlight_brightness, //int (*OEM_sys_get_backlight_brightness) (int index, int *value, int power_saving); + OEM_sys_set_backlight_brightness, //int (*OEM_sys_set_backlight_brightness) (int index, int value, int power_saving); + + OEM_sys_get_null_2, //int (*OEM_sys_set_backlight_dimming) (int index, int *value); + OEM_sys_get_null_2, //int (*OEM_sys_get_backlight_acl_control) (int index, int *value); + OEM_sys_set_null_2, //int (*OEM_sys_set_backlight_acl_control) (int index, int value); + + OEM_sys_get_null_2, //int (*OEM_sys_get_lcd_power) (int index, int *value); + OEM_sys_set_null_2, //int (*OEM_sys_set_lcd_power) (int index, int value); + + OEM_sys_get_null_1, //int (*OEM_sys_get_image_enhance_mode) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_image_enhance_mode) (int value); + OEM_sys_get_null_1, //int (*OEM_sys_get_image_enhance_scenario) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_image_enhance_scenario) (int value); + OEM_sys_get_null_1, //int (*OEM_sys_get_image_enhance_tone) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_image_enhance_tone) (int value); + OEM_sys_get_null_1, //int (*OEM_sys_get_image_enhance_outdoor) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_image_enhance_outdoor) (int value); + + OEM_sys_get_null_1, //int (*OEM_sys_get_image_enhance_tune) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_image_enhance_tune) (int value); + + OEM_sys_get_null_1, //int (*OEM_sys_image_enhance_info) (int *value); + + OEM_sys_set_null_1, //int (*OEM_sys_set_display_frame_rate) (int value); + + OEM_sys_get_null_1, //int (*OEM_sys_get_uart_path) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_uart_path) (int value); + + OEM_sys_get_null_1, //int (*OEM_sys_get_usb_path) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_usb_path) (int value); + + OEM_sys_get_null_1, //int (*OEM_sys_get_haptic_vibetones_level_max) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_haptic_vibetones_level) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_haptic_vibetones_level) (int value); + OEM_sys_set_null_1, //int (*OEM_sys_set_haptic_vibetones_enable) (int value); + OEM_sys_set_null_1, //int (*OEM_sys_set_haptic_vibetones_oneshot) (int value); + + OEM_sys_get_battery_capacity, //int (*OEM_sys_get_battery_capacity) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_battery_capacity_raw) (int *value); + OEM_sys_get_battery_charge_full, //int (*OEM_sys_get_battery_charge_full) (int *value); + OEM_sys_get_battery_charge_now, //int (*OEM_sys_get_battery_charge_now) (int *value); + OEM_sys_get_battery_present, //int (*OEM_sys_get_battery_present) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_battery_health) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_battery_polling_required) (int *value); + + OEM_sys_get_null_1, //int (*OEM_sys_get_jack_charger_online) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_jack_earjack_online) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_jack_earkey_online) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_jack_hdmi_online) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_jack_usb_online) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_jack_cradle_online) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_jack_tvout_online) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_jack_keyboard_online) (int *value); + + OEM_sys_get_null_1, //int (*OEM_sys_get_leds_torch_max_brightness) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_leds_torch_brightness) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_leds_torch_brightness) (int value); + + OEM_sys_set_power_state, //int (*OEM_sys_set_power_state) (int value); + + OEM_sys_get_power_wakeup_count, //int (*OEM_sys_get_power_wakeup_count) (int *value); + OEM_sys_set_power_wakeup_count, //int (*OEM_sys_set_power_wakeup_count) (int value); + + OEM_sys_get_null_3, //int (*OEM_sys_get_memnotify_node) (char *node); + OEM_sys_get_null_1, //int (*OEM_sys_get_memnotify_victim_task) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_memnotify_threshold_lv1) (int value); + OEM_sys_set_null_1, //int (*OEM_sys_set_memnotify_threshold_lv2) (int value); + + OEM_sys_get_null_3, //int (*OEM_sys_get_process_monitor_node) (char *node); + OEM_sys_set_null_1, //int (*OEM_sys_set_process_monitor_mp_pnp) (int value); + OEM_sys_set_null_1, //int (*OEM_sys_set_process_monitor_mp_vip) (int value); + + OEM_sys_get_null_1, //int (*OEM_sys_get_cpufreq_cpuinfo_max_freq) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_cpufreq_cpuinfo_min_freq) (int *value); + OEM_sys_get_null_1, //int (*OEM_sys_get_cpufreq_scaling_max_freq) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_cpufreq_scaling_max_freq) (int value); + OEM_sys_get_null_1, //int (*OEM_sys_get_cpufreq_scaling_min_freq) (int *value); + OEM_sys_set_null_1, //int (*OEM_sys_set_cpufreq_scaling_min_freq) (int value); +}; + +/* The following code returns the address of the structure + * devman_plugin_interface_sampledevice as defined above*/ + +const OEM_sys_devman_plugin_interface *OEM_sys_get_devman_plugin_interface() +{ + + return &devman_plugin_interface_pinetrail; +} diff --git a/device-manager-plugin-pinetrail.h b/device-manager-plugin-pinetrail.h new file mode 100644 index 0000000..66a335c --- /dev/null +++ b/device-manager-plugin-pinetrail.h @@ -0,0 +1,45 @@ + +/* + * device manager plugin for pinetrail + * + * Copyright (c) 2000 - 2011 Intel Corp. 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 __DEVMAN_MFLD_H__ +#define __DEVMAN_MFLD_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @file device-manager-plugin-pinetrail.h + * @ingroup DEVICE_MANAGER + * @brief This file contains the API for the status of devices + * @author Tizen 1.0 + * @date 2012-05-15 + * @version 0.1 + */ +const OEM_sys_devman_plugin_interface *OEM_sys_get_devman_plugin_interface() __attribute__((visibility("default"))); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/device-manager-plugin-pinetrail.pc.in b/device-manager-plugin-pinetrail.pc.in new file mode 100644 index 0000000..2c4e82d --- /dev/null +++ b/device-manager-plugin-pinetrail.pc.in @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: device manager plugin for pinetrail +Description: device manager plugin for pinetrail +Version: @VERSION@ +Requires: devman +Libs: -L${libdir} -ldevice-manager-plugin-pinetrail -ldl +Cflags: -I${includedir} diff --git a/device_engine.c b/device_engine.c new file mode 100644 index 0000000..919915f --- /dev/null +++ b/device_engine.c @@ -0,0 +1,243 @@ +/* + * devman + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: DongGi Jang <dg0402.jang@samsung.com> + * + * 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 <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <dirent.h> +#include <unistd.h> +#include <sys/stat.h> + +#include "devlog.h" +#include "device_engine.h" + +struct device *dev_head = NULL; +#define BUFF_MAX 255 + +void add_dev(struct device *dev) +{ + dev->next = dev_head; + dev_head = dev; +} + +void print_devices() +{ + struct device *dev; + dev = dev_head; + + while (dev) { + DBG("%s - %d", dev->devname, dev->devtype); + dev = dev->next; + } +} + +void reset_devtype() +{ + struct device *dev; + dev = dev_head; + + while (dev) { + dev->devtype = -1; + dev = dev->next; + } +} + +struct device *find_device(struct device *root_dev, devtype_t devtype) +{ + struct device *dev; + + if (devtype == -1) + return NULL; + + if (root_dev == NULL) + dev = dev_head; + else + dev = root_dev; + + while (dev) { + DBG("devname = %s %d %d", dev->devname, dev->devtype, devtype); + if (dev->devtype == devtype) + return dev; + dev = dev->next; + } + + return NULL; +} + +int find_sysfs_node(char *path, char *node_name) +{ + DIR *dp; + struct dirent *entry; + + dp = opendir(path); + if (dp == NULL) { + DBG("path is not existed : %s", path); + return -1; + } + + while ((entry = readdir(dp)) != NULL) { + if (strncmp(entry->d_name, ".", 1) == 0 || + strncmp(entry->d_name, "..", 2) == 0) + continue; + else + break; + } + + /* copy node name */ + if (entry != NULL) { + if (node_name != NULL) + strncpy(node_name, entry->d_name,PATH_MAX); + + } else { + DBG("sysfs node not existed"); + if (closedir(dp) != 0) + DBG("Unable to close directory"); + return -1; + } + + if (closedir(dp) != 0) + DBG("Unable to close directory"); + return 0; +} + +int set_devtype(char *devname, devtype_t devtype) +{ + int ret; + struct device *dev; + dev = dev_head; + + while (dev) { + if (strstr(dev->devname, devname)) { + if ((strstr(dev->devname, "auto") != NULL) && + (dev->probe != NULL)) { + ret = dev->probe(); + if (ret < 0) { + DBG("auto probe failed"); + return -1; + } + } + + dev->devtype = devtype; + return 0; + } + dev = dev->next; + } + + return -1; +} + +static int sys_read_buf(char *file, char *buf) +{ + int fd; + int r; + + fd = open(file, O_RDONLY); + if (fd == -1) { + ERR("%s open error: %s", file, strerror(errno)); + return -1; + } + + r = read(fd, buf, BUFF_MAX); + if ((r >= 0) && (r <= BUFF_MAX)) + buf[r] = '\0'; + else { + ERR("%s read error: %s", file, strerror(errno)); + return -1; + } + + close(fd); + INFO("read %s, value= %s", file, buf); + return 0; +} + +static int sys_write_buf(char *file, char *buf) +{ + int fd; + int r; + + fd = open(file, O_WRONLY); + if (fd == -1) { + ERR("%s open error: %s", file, strerror(errno)); + return -1; + } + + r = write(fd, buf, strlen(buf)); + close(fd); + if (r < 0) { + ERR("%s write error: %s", file, strerror(errno)); + return -1; + } + INFO("write %s, value= %s", file, buf); + DBG("write[%s], value[%s], line[%d]", file, buf, __LINE__); + return 0; +} + +int sys_get_int(char *fname, int *val) +{ + char buf[BUFF_MAX+1]; + + if (sys_read_buf(fname, buf) == 0) { + *val = atoi(buf); + return 0; + } else { + *val = -1; + return -1; + } +} + +char *sys_get_str(char *fname) +{ + char buf[BUFF_MAX+1]; + char *r = NULL; + + if (sys_read_buf(fname, buf) == 0) + r = strdup((char *)buf); + + return r; +} + +int sys_set_int(char *fname, int val) +{ + char buf[BUFF_MAX+1]; + int r = -1; + snprintf(buf, sizeof(buf), "%d", val); + + if (sys_write_buf(fname, buf) == 0) + r = 0; + + return r; +} + +int sys_set_str(char *fname, char *val) +{ + int r = -1; + + if (val != NULL) { + if (sys_write_buf(fname, val) == 0) + r = 0; + } + + return r; +} diff --git a/device_engine.h b/device_engine.h new file mode 100644 index 0000000..4bcbd78 --- /dev/null +++ b/device_engine.h @@ -0,0 +1,56 @@ +/* + * devman + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: DongGi Jang <dg0402.jang@samsung.com> + * + * 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 __DEVICE_ENGINE_H__ +#define __DEVICE_ENGINE_H__ + +#ifndef API +#define API __attribute__ ((visibility("default"))) +#endif + +#include <stdio.h> +#include "devman.h" + +struct device { + devtype_t devtype; + char *devname; + int (*set_int) (int property, int val); + int (*get_int) (int property, int *val); + int (*probe) (void); + struct device *next; +}; + +void add_dev(struct device *dev); +struct device *find_device(struct device *root_dev, devtype_t devtype); +int set_devtype(char *devname, devtype_t devtype); +void reset_devtype(); +void print_devices(); + +int find_sysfs_node(char *path, char *node_name); + +int sys_get_int(char *fname, int *val); +int sys_set_int(char *fname, int val); +char *sys_get_str(char *fname); +int sys_set_str(char *fname, char *val); + +#endif /* __DEVICE_ENGINE_H__ */ diff --git a/devlog.h b/devlog.h new file mode 100644 index 0000000..b44b1be --- /dev/null +++ b/devlog.h @@ -0,0 +1,177 @@ +/* + * devman + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: DongGi Jang <dg0402.jang@samsung.com> + * + * 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 __DEVLOG_H__ +#define __DEVLOG_H__ + +/* + * SYSLOG_INFO(), SYSLOG_ERR(), SYSLOG_DBG() are syslog() wrappers. + * PRT_INFO(), PRT_ERR(), PRT_DBG() are fprintf() wrappers. + * + * If SLP_DEBUG is not defined, SYSLOG_DBG() and PRT_DBG() is ignored. + * + * IF SLP_SYSLOG_OUT is defined, + * INFO(), ERR(), DBG() are SYSLOG_XXX() + * IF ENABLE_DLOG_OUT is defined, + * INFO(), ERR(), DBG() are SLOGI(), SLOGE(), SLOGD() + * Otherwise, + * They are PRT_XXX() + * + * + * warn_if(exrp, fmt, ...) + * If expr is true, The fmt string is printed using ERR(). + * + * ret_if(), retv_if(), retm_if(), retvm_if() + * If expr is true, current function return. + * Postfix 'v' means that it has a return value and 'm' means that it has output message. + * + */ +#include <stdio.h> +#include <stdlib.h> + +#if defined(ENABLE_DLOG_OUT) +# define LOG_TAG "DEVMAN" +# include <dlog.h> +#else +# include <syslog.h> +# define __LOG(prio, fmt, arg...) \ + do { syslog(prio, fmt, ##arg); } while (0) +# define __LOGD(prio, fmt, arg...) \ + do { \ + if (getenv("SLP_DEBUG")) { \ + syslog(prio, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + } \ + } while (0) +#endif + +#define __PRTI(fmt, arg...) \ + do { fprintf(stdout, fmt"\n", ##arg); } while (0) +#define __PRTE(fmt, arg...) \ + do { fprintf(stderr, fmt"\n", ##arg); } while (0) +#define __PRTD(fmt, arg...) \ + do { \ + if (getenv("SLP_DEBUG")) { \ + fprintf(stdout, "[%s:%d] "fmt"\n", __FILE__, __LINE__, ##arg); \ + } \ + } while(0) +#define _NOUT(arg...) do { } while (0) + +#ifdef SLP_DEBUG +# define _LOGD __LOGD +# define _LOG __LOG +# define _PRTD __PRTD +# define _PRTI __PRTI +# define _PRTE __PRTE +#else +# define _LOGD _NOUT +# define _LOG __LOG +# define _PRTD _NOUT +# define _PRTI __PRTI +# define _PRTE __PRTE +#endif + +#define PRT_INFO(fmt, arg...) _PRTI(fmt, ##arg) +#define PRT_ERR(fmt, arg...) _PRTE(fmt, ##arg) +#define PRT_DBG(fmt, arg...) _PRTD(fmt, ##arg) + +#if defined(SLP_SYSLOG_OUT) +# define SYSLOG_INFO(fmt, arg...) _LOG(LOG_INFO, fmt, ##arg) +# define SYSLOG_ERR(fmt, arg...) _LOG(LOG_ERR, fmt, ##arg) +# define SYSLOG_DBG(fmt, arg...) _LOGD(LOG_DEBUG, fmt, ##arg) +# define INFO SYSLOG_INFO +# define ERR SYSLOG_ERR +# define DBG SYSLOG_DBG +#elif defined(ENABLE_DLOG_OUT) +# define INFO SLOGI +# define ERR SLOGE +# define DBG SLOGD +#else +# define INFO PRT_INFO +# define ERR PRT_ERR +# define DBG PRT_DBG +#endif + +#ifdef SLP_DEBUG +# define warn_if(expr, fmt, arg...) do { \ + if (expr) { \ + DBG("(%s) -> "fmt, #expr, ##arg); \ + } \ + } while (0) +# define ret_if(expr) do { \ + if (expr) { \ + DBG("(%s) -> %s() return", #expr, __FUNCTION__); \ + return; \ + } \ + } while (0) +# define retv_if(expr, val) do { \ + if (expr) { \ + DBG("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ + } while (0) +# define retm_if(expr, fmt, arg...) do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + DBG("(%s) -> %s() return", #expr, __FUNCTION__); \ + return; \ + } \ + } while (0) +# define retvm_if(expr, val, fmt, arg...) do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + DBG("(%s) -> %s() return", #expr, __FUNCTION__); \ + return (val); \ + } \ + } while (0) + +#else +# define warn_if(expr, fmt, arg...) do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + } \ + } while (0) +# define ret_if(expr) do { \ + if (expr) { \ + return; \ + } \ + } while (0) +# define retv_if(expr, val) do { \ + if (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) + +#endif + +#endif /* __DEVLOG_H__ */ diff --git a/packaging/device-manager-plugin-pinetrail.changes b/packaging/device-manager-plugin-pinetrail.changes new file mode 100644 index 0000000..0f22b25 --- /dev/null +++ b/packaging/device-manager-plugin-pinetrail.changes @@ -0,0 +1,5 @@ +* Thu Aug 02 2012 Yan Yin <yan.yin@intel.com> build/2012-07-24.074803@797e50a +- fix potential buffer overflow + +* Tue Jul 24 2012 Yan Yin <yan.yin@intel.com> e2ab75d +- Initial device manager plugin for Pinetrail platform diff --git a/packaging/device-manager-plugin-pinetrail.spec b/packaging/device-manager-plugin-pinetrail.spec new file mode 100644 index 0000000..c1b867f --- /dev/null +++ b/packaging/device-manager-plugin-pinetrail.spec @@ -0,0 +1,55 @@ +Name: device-manager-plugin-pinetrail +Summary: Device manager library for pinetrail +Version: 0.2.4 +Release: 1 +Group: TO_BE/FILLED_IN +License: LGPL 2.1 +Source0: %{name}-%{version}.tar.bz2 +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: cmake +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(heynoti) +BuildRequires: pkgconfig(devman) +BuildRequires: pkgconfig(devman_plugin) + +%description +Device manager library for pinetrail device control + + +%package devel +Summary: Device manager library for pinetrail (devel) +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} + +%description devel +Device manager library for pinetrail device control (devel) + +%prep +%setup -q -n %{name}-%{version} + +%build +cmake . -DCMAKE_INSTALL_PREFIX=/usr + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +ln -s /usr/lib/libdevice-manager-plugin-pinetrail.so.%{version} %{buildroot}/usr/lib/libslp_devman_plugin.so.%{version} +ln -s /usr/lib/libdevice-manager-plugin-pinetrail.so %{buildroot}/usr/lib/libslp_devman_plugin.so + +%post +/sbin/ldconfig + +%postun +/sbin/ldconfig + +%files +%{_libdir}/*.so* + +%files devel +%{_includedir}/device-manager-plugin-pinetrail/*.h +%{_libdir}/pkgconfig/*.pc |