summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSung-jae Park <nicesj.park@samsung.com>2013-01-27 12:31:32 +0000
committerSung-jae Park <nicesj.park@samsung.com>2013-01-27 12:37:27 +0000
commita43afcebe43c2d38fb7a70475ce13efe3c4e83bf (patch)
treefbc7c596398f9b7c83a738f1ce10285ca72a3273
parent00ac434def46ef3d3bfaef8c9a11d5efb314446f (diff)
downloaddata-provider-master-a43afcebe43c2d38fb7a70475ce13efe3c4e83bf.tar.gz
data-provider-master-a43afcebe43c2d38fb7a70475ce13efe3c4e83bf.tar.bz2
data-provider-master-a43afcebe43c2d38fb7a70475ce13efe3c4e83bf.zip
Add new size type
For easy home 1x1 = 207x207 3x1 = 645x207 3x3 = 645x645 Change-Id: Ie2af0f0dca6588b6869fbf75486b27994d04d5df
-rw-r--r--data/resolution.ini3
-rw-r--r--packaging/org.tizen.data-provider-master.spec2
-rw-r--r--pkgmgr_livebox/CMakeLists.txt1
-rw-r--r--pkgmgr_livebox/livebox.xml9
-rw-r--r--pkgmgr_livebox/src/service_register.c121
-rw-r--r--src/parser.c32
-rw-r--r--src/server.c62
-rw-r--r--util_liveinfo/src/liveinfo.c468
-rw-r--r--util_liveinfo/src/node.c38
9 files changed, 492 insertions, 244 deletions
diff --git a/data/resolution.ini b/data/resolution.ini
index 2bccdb6..cf4275f 100644
--- a/data/resolution.ini
+++ b/data/resolution.ini
@@ -5,3 +5,6 @@
4x2=712x354
4x3=712x533
4x4=712x712
+21x21=207x207
+23x21=645x207
+23x23=645x645
diff --git a/packaging/org.tizen.data-provider-master.spec b/packaging/org.tizen.data-provider-master.spec
index d326f37..a13920d 100644
--- a/packaging/org.tizen.data-provider-master.spec
+++ b/packaging/org.tizen.data-provider-master.spec
@@ -1,6 +1,6 @@
Name: org.tizen.data-provider-master
Summary: Master service provider for liveboxes.
-Version: 0.14.5
+Version: 0.15.0
Release: 1
Group: framework/livebox
License: Flora License
diff --git a/pkgmgr_livebox/CMakeLists.txt b/pkgmgr_livebox/CMakeLists.txt
index 529a16c..c20b5c1 100644
--- a/pkgmgr_livebox/CMakeLists.txt
+++ b/pkgmgr_livebox/CMakeLists.txt
@@ -8,6 +8,7 @@ pkg_check_modules(bin_pkgs REQUIRED
sqlite3
libxml-2.0
db-util
+ livebox-service
)
FOREACH(flag ${bin_pkgs_CFLAGS})
diff --git a/pkgmgr_livebox/livebox.xml b/pkgmgr_livebox/livebox.xml
index 8bbcffe..bbcc8c0 100644
--- a/pkgmgr_livebox/livebox.xml
+++ b/pkgmgr_livebox/livebox.xml
@@ -13,14 +13,19 @@
<setup>org.tizen.nicesj</setup>
<box type="image" mouse_event="false">
- <size>1x1</size>
- <size>2x1</size>
+ <size preview="ABSPATH">1x1</size>
+ <size preview="ABSPATH">2x1</size>
<size>2x2</size>
<size>4x1</size>
<size>4x2</size>
<size>4x3</size>
<size>4x4</size>
+ <!-- Easy home -->
+ <size>21x21</size>
+ <size preview="ABSPATH">23x21</size>
+ <size>23x23</size>
+
<script src="/opt/usr/apps/org.tizen.myapp/res/script/my.edj" group="my_group" />
</box>
diff --git a/pkgmgr_livebox/src/service_register.c b/pkgmgr_livebox/src/service_register.c
index 0a6db79..a89a0db 100644
--- a/pkgmgr_livebox/src/service_register.c
+++ b/pkgmgr_livebox/src/service_register.c
@@ -28,6 +28,8 @@
#include <libxml/tree.h>
#include <dlog.h>
+#include <livebox-service.h>
+
#include "dlist.h"
#if !defined(FLOG)
@@ -149,16 +151,6 @@ enum pd_type {
PD_TYPE_BUFFER,
};
-enum lb_size {
- LB_SIZE_1x1 = 0x01,
- LB_SIZE_2x1 = 0x02,
- LB_SIZE_2x2 = 0x04,
- LB_SIZE_4x1 = 0x08,
- LB_SIZE_4x2 = 0x10,
- LB_SIZE_4x3 = 0x20,
- LB_SIZE_4x4 = 0x40,
-};
-
struct livebox {
xmlChar *pkgid;
int secured;
@@ -184,7 +176,7 @@ struct livebox {
xmlChar *lb_group;
int size_list; /* 1x1, 2x1, 2x2, 4x1, 4x2, 4x3, 4x4 */
- xmlChar *preview[7];
+ xmlChar *preview[10];
enum pd_type pd_type;
xmlChar *pd_src;
@@ -1491,6 +1483,9 @@ static inline int livebox_destroy(struct livebox *livebox)
xmlFree(livebox->preview[4]); /* 4x2 */
xmlFree(livebox->preview[5]); /* 4x3 */
xmlFree(livebox->preview[6]); /* 4x4 */
+ xmlFree(livebox->preview[7]); /* 21x21 */
+ xmlFree(livebox->preview[8]); /* 23x21 */
+ xmlFree(livebox->preview[9]); /* 23x23 */
dlist_foreach_safe(livebox->i18n_list, l, n, i18n) {
livebox->i18n_list = dlist_remove(livebox->i18n_list, l);
@@ -1723,40 +1718,55 @@ static inline void update_box(struct livebox *livebox, xmlNodePtr node)
}
if (!xmlStrcasecmp(size, (const xmlChar *)"1x1")) {
- livebox->size_list |= LB_SIZE_1x1;
+ livebox->size_list |= LB_SIZE_TYPE_1x1;
if (xmlHasProp(node, (const xmlChar *)"preview")) {
livebox->preview[0] = xmlGetProp(node, (const xmlChar *)"preview");
}
} else if (!xmlStrcasecmp(size, (const xmlChar *)"2x1")) {
- livebox->size_list |= LB_SIZE_2x1;
+ livebox->size_list |= LB_SIZE_TYPE_2x1;
if (xmlHasProp(node, (const xmlChar *)"preview")) {
livebox->preview[1] = xmlGetProp(node, (const xmlChar *)"preview");
}
} else if (!xmlStrcasecmp(size, (const xmlChar *)"2x2")) {
- livebox->size_list |= LB_SIZE_2x2;
+ livebox->size_list |= LB_SIZE_TYPE_2x2;
if (xmlHasProp(node, (const xmlChar *)"preview")) {
livebox->preview[2] = xmlGetProp(node, (const xmlChar *)"preview");
}
} else if (!xmlStrcasecmp(size, (const xmlChar *)"4x1")) {
- livebox->size_list |= LB_SIZE_4x1;
+ livebox->size_list |= LB_SIZE_TYPE_4x1;
if (xmlHasProp(node, (const xmlChar *)"preview")) {
livebox->preview[3] = xmlGetProp(node, (const xmlChar *)"preview");
}
} else if (!xmlStrcasecmp(size, (const xmlChar *)"4x2")) {
- livebox->size_list |= LB_SIZE_4x2;
+ livebox->size_list |= LB_SIZE_TYPE_4x2;
if (xmlHasProp(node, (const xmlChar *)"preview")) {
livebox->preview[4] = xmlGetProp(node, (const xmlChar *)"preview");
}
} else if (!xmlStrcasecmp(size, (const xmlChar *)"4x3")) {
- livebox->size_list |= LB_SIZE_4x3;
+ livebox->size_list |= LB_SIZE_TYPE_4x3;
if (xmlHasProp(node, (const xmlChar *)"preview")) {
livebox->preview[5] = xmlGetProp(node, (const xmlChar *)"preview");
}
} else if (!xmlStrcasecmp(size, (const xmlChar *)"4x4")) {
- livebox->size_list |= LB_SIZE_4x4;
+ livebox->size_list |= LB_SIZE_TYPE_4x4;
if (xmlHasProp(node, (const xmlChar *)"preview")) {
livebox->preview[6] = xmlGetProp(node, (const xmlChar *)"preview");
}
+ } else if (!xmlStrcasecmp(size, (const xmlChar *)"21x21")) {
+ livebox->size_list |= LB_SIZE_TYPE_EASY_1x1;
+ if (xmlHasProp(node, (const xmlChar *)"preview")) {
+ livebox->preview[7] = xmlGetProp(node, (const xmlChar *)"preview");
+ }
+ } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x21")) {
+ livebox->size_list |= LB_SIZE_TYPE_EASY_3x1;
+ if (xmlHasProp(node, (const xmlChar *)"preview")) {
+ livebox->preview[8] = xmlGetProp(node, (const xmlChar *)"preview");
+ }
+ } else if (!xmlStrcasecmp(size, (const xmlChar *)"23x23")) {
+ livebox->size_list |= LB_SIZE_TYPE_EASY_3x3;
+ if (xmlHasProp(node, (const xmlChar *)"preview")) {
+ livebox->preview[9] = xmlGetProp(node, (const xmlChar *)"preview");
+ }
} else {
ErrPrint("Invalid size tag (%s)\n", size);
}
@@ -2037,48 +2047,66 @@ static inline int db_insert_livebox(struct livebox *livebox, const char *appid)
goto errout;
}
- if (livebox->size_list & LB_SIZE_1x1) {
- ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_1x1, (char *)livebox->preview[0]);
+ if (livebox->size_list & LB_SIZE_TYPE_1x1) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_1x1, (char *)livebox->preview[0]);
+ if (ret < 0)
+ goto errout;
+ }
+
+ if (livebox->size_list & LB_SIZE_TYPE_2x1) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_2x1, (char *)livebox->preview[1]);
+ if (ret < 0)
+ goto errout;
+ }
+
+ if (livebox->size_list & LB_SIZE_TYPE_2x2) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_2x2, (char *)livebox->preview[2]);
if (ret < 0)
goto errout;
}
- if (livebox->size_list & LB_SIZE_2x1) {
- ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_2x1, (char *)livebox->preview[1]);
+ if (livebox->size_list & LB_SIZE_TYPE_4x1) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x1, (char *)livebox->preview[3]);
if (ret < 0)
goto errout;
}
- if (livebox->size_list & LB_SIZE_2x2) {
- ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_2x2, (char *)livebox->preview[2]);
+ if (livebox->size_list & LB_SIZE_TYPE_4x2) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x2, (char *)livebox->preview[4]);
if (ret < 0)
goto errout;
}
- if (livebox->size_list & LB_SIZE_4x1) {
- ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_4x1, (char *)livebox->preview[3]);
+ if (livebox->size_list & LB_SIZE_TYPE_4x3) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x3, (char *)livebox->preview[5]);
if (ret < 0)
goto errout;
}
- if (livebox->size_list & LB_SIZE_4x2) {
- ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_4x2, (char *)livebox->preview[4]);
+ if (livebox->size_list & LB_SIZE_TYPE_4x4) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_4x4, (char *)livebox->preview[6]);
if (ret < 0)
goto errout;
}
- if (livebox->size_list & LB_SIZE_4x3) {
- ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_4x3, (char *)livebox->preview[5]);
+ if (livebox->size_list & LB_SIZE_TYPE_EASY_1x1) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_EASY_1x1, (char *)livebox->preview[7]);
if (ret < 0)
goto errout;
}
- if (livebox->size_list & LB_SIZE_4x4) {
- ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_4x4, (char *)livebox->preview[6]);
+ if (livebox->size_list & LB_SIZE_TYPE_EASY_3x1) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_EASY_3x1, (char *)livebox->preview[8]);
if (ret < 0)
goto errout;
}
+ if (livebox->size_list & LB_SIZE_TYPE_EASY_3x3) {
+ ret = db_insert_box_size((char *)livebox->pkgid, LB_SIZE_TYPE_EASY_3x3, (char *)livebox->preview[9]);
+ if (ret < 9)
+ goto errout;
+ }
+
dlist_foreach(livebox->group_list, l, group) {
/* group ID "id" */
id = db_get_group_id((char *)group->cluster, (char *)group->category);
@@ -2449,33 +2477,4 @@ int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char *appid)
return 0;
}
-/*
-int main(int argc, char *argv[])
-{
- xmlDoc *doc;
- xmlNode *root;
-
- if (argc != 2) {
- ErrPRint("Invalid argument: %s XML_FILENAME\n", argv[0]);
- return -EINVAL;
- }
-
- doc = xmlReadFile(argv[1], NULL, 0);
- if (!doc) {
- ErrPrint("Failed to parse %s\n", argv[1]);
- return -EIO;
- }
-
- root = xmlDocGetRootElement(doc);
-
- db_init();
- install_shortcut("", root);
- db_fini();
-
- xmlFreeDoc(doc);
- xmlCleanupParser();
- return 0;
-}
-*/
-
/* End of a file */
diff --git a/src/parser.c b/src/parser.c
index e7af92e..871a6ff 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -22,21 +22,13 @@
#include <Eina.h>
#include <dlog.h>
+#include <livebox-service.h>
+
#include "util.h"
#include "debug.h"
#include "conf.h"
#include "parser.h"
-enum lb_size {
- LB_SIZE_1x1 = 0x01,
- LB_SIZE_2x1 = 0x02,
- LB_SIZE_2x2 = 0x04,
- LB_SIZE_4x1 = 0x08,
- LB_SIZE_4x2 = 0x10,
- LB_SIZE_4x3 = 0x20,
- LB_SIZE_4x4 = 0x40,
-};
-
static Eina_List *s_list;
int errno;
@@ -286,19 +278,25 @@ static inline int parse_size(const char *buffer, unsigned int *size)
break;
case STOP:
if (w == 1 && h == 1) {
- *size |= LB_SIZE_1x1;
+ *size |= LB_SIZE_TYPE_1x1;
} else if (w == 2 && h == 1) {
- *size |= LB_SIZE_2x1;
+ *size |= LB_SIZE_TYPE_2x1;
} else if (w == 2 && h == 2) {
- *size |= LB_SIZE_2x2;
+ *size |= LB_SIZE_TYPE_2x2;
} else if (w == 4 && h == 1) {
- *size |= LB_SIZE_4x1;
+ *size |= LB_SIZE_TYPE_4x1;
} else if (w == 4 && h == 2) {
- *size |= LB_SIZE_4x2;
+ *size |= LB_SIZE_TYPE_4x2;
} else if (w == 4 && h == 3) {
- *size |= LB_SIZE_4x3;
+ *size |= LB_SIZE_TYPE_4x3;
} else if (w == 4 && h == 4) {
- *size |= LB_SIZE_4x4;
+ *size |= LB_SIZE_TYPE_4x4;
+ } else if (w == 21 && h == 21) {
+ *size |= LB_SIZE_TYPE_EASY_1x1;
+ } else if (w == 23 && h == 21) {
+ *size |= LB_SIZE_TYPE_EASY_3x1;
+ } else if (w == 23 && h == 23) {
+ *size |= LB_SIZE_TYPE_EASY_3x3;
} else {
ErrPrint("Invalid size type: %dx%d\n", w, h);
}
diff --git a/src/server.c b/src/server.c
index 10d4085..c87b845 100644
--- a/src/server.c
+++ b/src/server.c
@@ -4857,16 +4857,59 @@ static struct packet *liveinfo_slave_ctrl(pid_t pid, int handle, const struct pa
static struct packet *liveinfo_pkg_ctrl(pid_t pid, int handle, const struct packet *packet)
{
+ struct liveinfo *info;
+ FILE *fp;
+ char *cmd;
+ char *pkgname;
+ char *id;
+
+ if (packet_get(packet, "sss", &cmd, &pkgname, &id) != 3) {
+ ErrPrint("Invalid argument\n");
+ goto out;
+ }
+
+ info = liveinfo_find_by_pid(pid);
+ if (!info) {
+ ErrPrint("Invalid request\n");
+ goto out;
+ }
+
+ liveinfo_open_fifo(info);
+ fp = liveinfo_fifo(info);
+ if (!fp) {
+ liveinfo_close_fifo(info);
+ goto out;
+ }
+
+ if (!strcmp(cmd, "rmpack")) {
+ fprintf(fp, "%d\n", ENOSYS);
+ } else if (!strcmp(cmd, "rminst")) {
+ struct inst_info *inst;
+ inst = package_find_instance_by_id(pkgname, id);
+ if (!inst) {
+ fprintf(fp, "%d\n", ENOENT);
+ } else {
+ instance_destroy(inst);
+ fprintf(fp, "%d\n", 0);
+ }
+ }
+
+ fprintf(fp, "EOD\n");
+ liveinfo_close_fifo(info);
+
+out:
return NULL;
}
-static struct packet *liveinfo_toggle_debug(pid_t pid, int handle, const struct packet *packet)
+static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct packet *packet)
{
- double timestamp;
struct liveinfo *info;
+ char *cmd;
+ char *var;
+ char *val;
FILE *fp;
- if (packet_get(packet, "d", &timestamp) != 1) {
+ if (packet_get(packet, "sss", &cmd, &var, &val) != 3) {
ErrPrint("Invalid argument\n");
goto out;
}
@@ -4877,14 +4920,19 @@ static struct packet *liveinfo_toggle_debug(pid_t pid, int handle, const struct
goto out;
}
+ if (!strcmp(var, "debug")) {
+ if (!strcmp(cmd, "set")) {
+ g_conf.debug_mode = !strcmp(val, "true");
+ } else if (!strcmp(cmd, "get")) {
+ }
+ }
+
liveinfo_open_fifo(info);
fp = liveinfo_fifo(info);
if (!fp) {
liveinfo_close_fifo(info);
goto out;
}
-
- g_conf.debug_mode = !g_conf.debug_mode;
fprintf(fp, "%d\nEOD\n", g_conf.debug_mode);
liveinfo_close_fifo(info);
@@ -4918,8 +4966,8 @@ static struct method s_info_table[] = {
.handler = liveinfo_pkg_ctrl,
},
{
- .cmd = "toggle_debug",
- .handler = liveinfo_toggle_debug,
+ .cmd = "master_ctrl",
+ .handler = liveinfo_master_ctrl,
},
{
.cmd = NULL,
diff --git a/util_liveinfo/src/liveinfo.c b/util_liveinfo/src/liveinfo.c
index e181820..18e913b 100644
--- a/util_liveinfo/src/liveinfo.c
+++ b/util_liveinfo/src/liveinfo.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <unistd.h>
+#include <getopt.h>
#include <errno.h>
#include <libgen.h>
#include <sys/types.h>
@@ -52,6 +53,7 @@ struct package {
};
struct instance {
+ char *id;
char *cluster;
char *category;
double period;
@@ -77,8 +79,10 @@ enum command {
NOP,
PKG_LIST,
INST_LIST,
- TOGGLE_DEBUG,
SLAVE_LIST,
+ INST_CTRL,
+ SLAVE_CTRL,
+ MASTER_CTRL,
};
static struct info {
@@ -86,23 +90,57 @@ static struct info {
int fd;
Ecore_Fd_Handler *fd_handler;
Ecore_Fd_Handler *in_handler;
- int input_fd;
struct node *rootdir;
struct node *curdir;
+ struct node *targetdir;
enum command cmd;
+
+ int input_fd;
+ int verbose;
} s_info = {
.fifo_handle = -EINVAL,
.fd = -EINVAL,
.fd_handler = NULL,
.in_handler = NULL,
- .input_fd = -1,
.rootdir = NULL,
.curdir = NULL,
+ .targetdir = NULL,
.cmd = NOP,
+ .input_fd = STDIN_FILENO,
+ .verbose = 0,
};
+char *optarg;
+int errno;
+int optind;
+int optopt;
+int opterr;
+
+static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler);
+
+static Eina_Bool process_line_cb(void *data)
+{
+ input_cb(NULL, NULL);
+ return ECORE_CALLBACK_CANCEL;
+}
+
+static inline void prompt(const char *cmdline)
+{
+ char *path;
+
+ if (s_info.input_fd != STDIN_FILENO) {
+ /* To prevent recursive call, add function to the main loop (idler) */
+ ecore_idler_add(process_line_cb, NULL);
+ return;
+ }
+
+ path = node_to_abspath(s_info.curdir);
+ printf(PROMPT"%s # %s", path, cmdline ? cmdline : "");
+ free(path);
+}
+
static inline void ls(void)
{
struct node *node;
@@ -110,13 +148,17 @@ static inline void ls(void)
int is_package;
int is_provider;
int is_instance;
- char *path;
- is_package = node_name(s_info.curdir) && !strcmp(node_name(s_info.curdir), "package");
- is_provider = !is_package && node_name(s_info.curdir) && !strcmp(node_name(s_info.curdir), "provider");
- is_instance = !is_package && !is_provider && node_parent(s_info.curdir) && node_name(node_parent(s_info.curdir)) && !strcmp(node_name(node_parent(s_info.curdir)), "package");
+ if (!(node_mode(s_info.targetdir) & NODE_READ)) {
+ printf("Access denied\n");
+ return;
+ }
+
+ is_package = node_name(s_info.targetdir) && !strcmp(node_name(s_info.targetdir), "package");
+ is_provider = !is_package && node_name(s_info.targetdir) && !strcmp(node_name(s_info.targetdir), "provider");
+ is_instance = !is_package && !is_provider && node_parent(s_info.targetdir) && node_name(node_parent(s_info.targetdir)) && !strcmp(node_name(node_parent(s_info.targetdir)), "package");
- node = node_child(s_info.curdir);
+ node = node_child(s_info.targetdir);
while (node) {
if (is_package) {
struct package *info;
@@ -137,7 +179,7 @@ static inline void ls(void)
if (lstat(buf, &stat) < 0)
printf("%3d ERR ", errno);
else
- printf("%2.2lf MB ", (double)stat.st_size / 1024.0f / 1024.0f);
+ printf("%2.2lf KB ", (double)stat.st_size / 1024.0f);
}
if (node_type(node) == NODE_DIR)
@@ -150,9 +192,6 @@ static inline void ls(void)
cnt++;
}
printf("Total: %d\n", cnt);
- path = node_to_abspath(s_info.curdir);
- printf(PROMPT"%s # ", path);
- free(path);
}
static void send_slave_list(void)
@@ -195,24 +234,43 @@ static void send_pkg_list(void)
s_info.cmd = PKG_LIST;
}
-static void send_toggle_debug(void)
+static void send_inst_delete(void)
{
struct packet *packet;
+ struct node *parent;
+ const char *name;
+ struct instance *inst;
if (s_info.cmd != NOP) {
printf("Previous command is not finished\n");
return;
}
- packet = packet_create_noack("toggle_debug", "d", 0.0f);
- if (!packet) {
- printf("Failed to create a packet\n");
+ parent = node_parent(s_info.targetdir);
+ if (!parent) {
+ printf("Invalid argument\n");
return;
}
+ if (!node_parent(parent)) {
+ printf("Invalid argument\n");
+ return;
+ }
+
+ name = node_name(node_parent(parent));
+ if (!name || strcmp(name, "package")) {
+ printf("Invalid argument\n");
+ return;
+ }
+
+ inst = node_data(s_info.targetdir);
+ name = node_name(parent);
+
+ packet = packet_create_noack("pkg_ctrl", "sss", "rminst", name, inst->id);
com_core_packet_send_only(s_info.fd, packet);
packet_destroy(packet);
- s_info.cmd = TOGGLE_DEBUG;
+
+ s_info.cmd = INST_CTRL;
}
static void send_inst_list(const char *pkgname)
@@ -239,9 +297,11 @@ static inline void help(void)
{
printf("liveinfo - Livebox utility\n");
printf("------------------------------ [Command list] ------------------------------\n");
- printf("d - Change directory\n");
- printf("s - List up content as a file\n");
- printf("at - Open a file to get some detail information\n");
+ printf("cd [PATH] - Change directory\n");
+ printf("ls [ | PATH] - List up content as a file\n");
+ printf("rm [PKG_ID|INST_ID] - Delete package or instance\n");
+ printf("cat [FILE] - Open a file to get some detail information\n");
+ printf("pull [FILE] - Pull given file to host dir\n");
printf("exit - \n");
printf("quit - \n");
printf("----------------------------------------------------------------------------\n");
@@ -286,6 +346,7 @@ static inline void init_directory(void)
s_info.rootdir = node_create(NULL, NULL, NODE_DIR);
if (!s_info.rootdir)
return;
+ node_set_mode(s_info.rootdir, NODE_READ | NODE_EXEC);
node = node_create(s_info.rootdir, "provider", NODE_DIR);
if (!node) {
@@ -317,13 +378,9 @@ static inline void do_command(const char *cmd)
{
char command[256];
char argument[4096] = { '\0', };
- char *path;
- if (!strlen(cmd)) {
- char *path;
- path = node_to_abspath(s_info.curdir);
- printf(PROMPT"%s # ", path);
- free(path);
+ if (!strlen(cmd) || *cmd == '#') {
+ prompt(NULL);
return;
}
@@ -332,111 +389,132 @@ static inline void do_command(const char *cmd)
if (!strcasecmp(cmd, "exit") || !strcasecmp(cmd, "quit")) {
ecore_main_loop_quit();
- } else if (!strcasecmp(cmd, "toggle_debug")) {
- if (s_info.cmd != NOP) {
- printf("Waiting the server response\n");
- return;
+ } else if (!strcasecmp(cmd, "ls")) {
+ const char *name;
+ struct node *parent;
+
+ if (*argument) {
+ s_info.targetdir = (*argument == '/') ? s_info.rootdir : s_info.curdir;
+ s_info.targetdir = node_find(s_info.targetdir, argument);
+ } else {
+ s_info.targetdir = s_info.curdir;
}
- send_toggle_debug();
- } else if (!strcasecmp(cmd, "ls")) {
- if (node_name(s_info.curdir)) {
- if (!strcmp(node_name(s_info.curdir), "package")) {
- if (s_info.cmd != NOP) {
- printf("Waiting the server response\n");
+ if (!s_info.targetdir) {
+ printf("%s is not exists\n", argument);
+ goto out;
+ }
+
+ name = node_name(s_info.targetdir);
+ if (name) {
+ if (!strcmp(name, "package")) {
+ if (s_info.cmd == NOP) {
+ send_pkg_list();
return;
}
- send_pkg_list();
- return;
- } else if (!strcmp(node_name(s_info.curdir), "provider")) {
- if (s_info.cmd != NOP) {
- printf("Waiting the server response\n");
+
+ printf("Waiting the server response\n");
+ goto out;
+ } else if (!strcmp(name, "provider")) {
+ if (s_info.cmd == NOP) {
+ send_slave_list();
return;
}
- send_slave_list();
- return;
+
+ printf("Waiting the server response\n");
+ goto out;
}
}
- if (node_parent(s_info.curdir) && node_name(node_parent(s_info.curdir))) {
- if (!strcmp(node_name(node_parent(s_info.curdir)), "package")) {
+ parent = node_parent(s_info.targetdir);
+ if (parent && node_name(parent)) {
+ if (!strcmp(node_name(parent), "package")) {
if (s_info.cmd != NOP) {
printf("Waiting the server response\n");
- return;
+ goto out;
}
- send_inst_list(node_name(s_info.curdir));
+ send_inst_list(name);
return;
}
}
ls();
} else if (!strcasecmp(cmd, "cd")) {
- struct node *node;
-
- if (!strcmp(argument, "."))
- return;
+ if (!*argument)
+ goto out;
if (s_info.cmd != NOP) {
printf("Waiting the server response\n");
- return;
+ goto out;
}
- if (!strcmp(argument, "..")) {
- if (node_parent(s_info.curdir) == NULL)
- return;
+ s_info.targetdir = (*argument == '/') ? s_info.rootdir : s_info.curdir;
+ s_info.targetdir = node_find(s_info.targetdir, argument);
+ if (!s_info.targetdir) {
+ printf("%s is not exists\n", argument);
+ goto out;
+ }
+
+ if (node_type(s_info.targetdir) != NODE_DIR) {
+ printf("Unable change directory to %s\n", argument);
+ goto out;
+ }
- s_info.curdir = node_parent(s_info.curdir);
+ if (!(node_mode(s_info.targetdir) & NODE_EXEC)) {
+ printf("Access denied %s\n", argument);
+ goto out;
}
- node = node_child(s_info.curdir);
- while (node) {
- if (!strcmp(node_name(node), argument)) {
- if (node_type(node) != NODE_DIR)
- printf("Unable to go into the %s\n", node_name(node));
- else
- s_info.curdir = node;
+ s_info.curdir = s_info.targetdir;
+ } else if (!strcasecmp(cmd, "rm")) {
+ if (!*argument)
+ goto out;
- break;
- }
+ if (s_info.cmd != NOP) {
+ printf("Waiting the server response\n");
+ goto out;
+ }
+
+ s_info.targetdir = (*argument == '/') ? s_info.rootdir : s_info.curdir;
+ s_info.targetdir = node_find(s_info.targetdir, argument);
+ if (!s_info.targetdir) {
+ printf("%s is not exists\n", argument);
+ goto out;
+ }
- node = node_next_sibling(node);
+ if (!(node_mode(s_info.targetdir) & NODE_WRITE)) {
+ printf("Access denied %s\n", argument);
+ goto out;
}
- if (!node)
- printf("Not found: %s\n", argument);
- path = node_to_abspath(s_info.curdir);
- printf(PROMPT"%s # ", path);
- free(path);
+ send_inst_delete();
} else if (!strcasecmp(cmd, "help")) {
- goto errout;
+ help();
} else {
printf("Unknown command - \"help\"\n");
- path = node_to_abspath(s_info.curdir);
- printf(PROMPT"%s # ", path);
- free(path);
}
+out:
+ prompt(NULL);
return;
-
-errout:
- help();
- path = node_to_abspath(s_info.curdir);
- printf(PROMPT"%s # ", path);
- free(path);
}
static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler)
{
static int idx = 0;
static char cmd_buffer[256];
- char *path;
char ch;
int fd;
+ int ret;
- fd = ecore_main_fd_handler_fd_get(fd_handler);
- if (fd < 0) {
- printf("FD is not valid: %d\n", fd);
- return ECORE_CALLBACK_CANCEL;
+ if (fd_handler) {
+ fd = ecore_main_fd_handler_fd_get(fd_handler);
+ if (fd < 0) {
+ printf("FD is not valid: %d\n", fd);
+ return ECORE_CALLBACK_CANCEL;
+ }
+ } else {
+ fd = s_info.input_fd;
}
/*!
@@ -447,42 +525,50 @@ static Eina_Bool input_cb(void *data, Ecore_Fd_Handler *fd_handler)
*/
/* Silly.. Silly */
- if (read(fd, &ch, sizeof(ch)) != sizeof(ch)) {
- printf("Failed to get a byte: %s\n", strerror(errno));
- return ECORE_CALLBACK_CANCEL;
- }
+ while ((ret = read(fd, &ch, sizeof(ch))) == sizeof(ch)) {
+ switch (ch) {
+ case 0x08: /* BKSP */
+ cmd_buffer[idx] = '\0';
+ if (idx > 0) {
+ idx--;
+ cmd_buffer[idx] = ' ';
+ putc('\r', stdout);
+ prompt(cmd_buffer);
+ }
- switch (ch) {
- case 0x08: /* BKSP */
- cmd_buffer[idx] = '\0';
- if (idx > 0)
- idx--;
- cmd_buffer[idx] = ' ';
- path = node_to_abspath(s_info.curdir);
- printf("\r"PROMPT"%s # %s", path, cmd_buffer);
- cmd_buffer[idx] = '\0';
- printf("\r"PROMPT"%s # %s", path, cmd_buffer);
- free(path);
- break;
- case '\n':
- case '\r':
- cmd_buffer[idx] = '\0';
- idx = 0;
- putc((int)'\n', stdout);
- do_command(cmd_buffer);
- memset(cmd_buffer, 0, sizeof(cmd_buffer));
- break;
- default:
- cmd_buffer[idx++] = ch;
- putc((int)ch, stdout);
- if (idx == sizeof(cmd_buffer) - 1) {
cmd_buffer[idx] = '\0';
- printf("\nCommand buffer is overflow: %s\n", cmd_buffer);
+ putc('\r', stdout);
+ prompt(cmd_buffer);
+ break;
+ case '\n':
+ case '\r':
+ cmd_buffer[idx] = '\0';
idx = 0;
+ if (s_info.input_fd == STDIN_FILENO || s_info.verbose)
+ putc((int)'\n', stdout);
+ do_command(cmd_buffer);
+ memset(cmd_buffer, 0, sizeof(cmd_buffer));
+
+ /* Make a main loop processing for command handling */
+ return ECORE_CALLBACK_RENEW;
+ default:
+ cmd_buffer[idx++] = ch;
+
+ if (s_info.input_fd == STDIN_FILENO || s_info.verbose)
+ putc((int)ch, stdout);
+
+ if (idx == sizeof(cmd_buffer) - 1) {
+ cmd_buffer[idx] = '\0';
+ printf("\nCommand buffer is overflow: %s\n", cmd_buffer);
+ idx = 0;
+ }
+ break;
}
- break;
}
+ if (ret < 0 && !fd_handler)
+ ecore_main_loop_quit();
+
return ECORE_CALLBACK_RENEW;
}
@@ -506,7 +592,6 @@ static void processing_line_buffer(const char *buffer)
double period;
int width;
int height;
- int debug;
struct node *node;
struct package *pkginfo;
struct instance *instinfo;
@@ -520,7 +605,7 @@ static void processing_line_buffer(const char *buffer)
return;
}
- node = node_find(s_info.curdir, pkgname);
+ node = node_find(s_info.targetdir, pkgname);
if (!node) {
pkginfo = malloc(sizeof(*pkginfo));
if (!pkginfo) {
@@ -534,7 +619,7 @@ static void processing_line_buffer(const char *buffer)
pkginfo->primary = 1;
- node = node_create(s_info.curdir, pkgname, NODE_DIR);
+ node = node_create(s_info.targetdir, pkgname, NODE_DIR);
if (!node) {
free(pkginfo->pkgid);
free(pkginfo);
@@ -542,6 +627,7 @@ static void processing_line_buffer(const char *buffer)
return;
}
+ node_set_mode(node, NODE_READ | NODE_EXEC);
node_set_data(node, pkginfo);
} else {
pkginfo = node_data(node);
@@ -571,7 +657,7 @@ static void processing_line_buffer(const char *buffer)
printf("Invalid format : [%s]\n", buffer);
return;
}
- node = node_find(s_info.curdir, slavename);
+ node = node_find(s_info.targetdir, slavename);
if (!node) {
slaveinfo = calloc(1, sizeof(*slaveinfo));
if (!slaveinfo) {
@@ -579,12 +665,13 @@ static void processing_line_buffer(const char *buffer)
return;
}
- node = node_create(s_info.curdir, slavename, NODE_DIR);
+ node = node_create(s_info.targetdir, slavename, NODE_DIR);
if (!node) {
free(slaveinfo);
return;
}
+ node_set_mode(node, NODE_READ | NODE_EXEC);
node_set_data(node, slaveinfo);
} else {
slaveinfo = node_data(node);
@@ -594,8 +681,16 @@ static void processing_line_buffer(const char *buffer)
free(slaveinfo->state);
slaveinfo->pkgname = strdup(pkgname);
+ if (!slaveinfo->pkgname)
+ printf("Error: %s\n", strerror(errno));
+
slaveinfo->abi = strdup(abi);
+ if (!slaveinfo->abi)
+ printf("Error: %s\n", strerror(errno));
+
slaveinfo->state = strdup(state);
+ if (!slaveinfo->state)
+ printf("Error: %s\n", strerror(errno));
slaveinfo->pid = pid;
slaveinfo->secured = secured;
@@ -614,7 +709,7 @@ static void processing_line_buffer(const char *buffer)
for (i = strlen(inst_id); i > 0 && inst_id[i] != '/'; i--);
i += (inst_id[i] == '/');
- node = node_find(s_info.curdir, inst_id + i);
+ node = node_find(s_info.targetdir, inst_id + i);
if (!node) {
instinfo = calloc(1, sizeof(*instinfo));
if (!instinfo) {
@@ -622,21 +717,27 @@ static void processing_line_buffer(const char *buffer)
return;
}
- node = node_create(s_info.curdir, inst_id + i, NODE_FILE);
+ node = node_create(s_info.targetdir, inst_id + i, NODE_FILE);
if (!node) {
free(instinfo);
return;
}
+ node_set_mode(node, NODE_READ | NODE_WRITE);
node_set_data(node, instinfo);
} else {
instinfo = node_data(node);
}
+ free(instinfo->id);
free(instinfo->cluster);
free(instinfo->category);
free(instinfo->state);
+ instinfo->id = strdup(inst_id);
+ if (!instinfo->id)
+ printf("Error: %s\n", strerror(errno));
+
instinfo->cluster = strdup(cluster);
if (!instinfo->cluster)
printf("Error: %s\n", strerror(errno));
@@ -646,12 +747,22 @@ static void processing_line_buffer(const char *buffer)
printf("Error: %s\n", strerror(errno));
instinfo->state = strdup(state);
+ if (!instinfo->state)
+ printf("Error: %s\n", strerror(errno));
+
instinfo->period = period;
instinfo->width = width;
instinfo->height = height;
break;
- case TOGGLE_DEBUG:
- sscanf(buffer, "%d", &debug);
+ case INST_CTRL:
+ sscanf(buffer, "%d", &i);
+ printf("%s\n", strerror(i));
+ break;
+ case SLAVE_CTRL:
+ sscanf(buffer, "%d", &i);
+ break;
+ case MASTER_CTRL:
+ sscanf(buffer, "%d", &i);
break;
default:
break;
@@ -670,11 +781,16 @@ static inline void do_line_command(void)
case SLAVE_LIST:
ls();
break;
- case TOGGLE_DEBUG:
+ case INST_CTRL:
+ break;
+ case SLAVE_CTRL:
+ break;
+ case MASTER_CTRL:
break;
default:
break;
}
+ prompt(NULL);
}
static Eina_Bool read_cb(void *data, Ecore_Fd_Handler *fd_handler)
@@ -746,7 +862,6 @@ static int ret_cb(pid_t pid, int handle, const struct packet *packet, void *data
{
const char *fifo_name;
int ret;
- char *path;
if (packet_get(packet, "si", &fifo_name, &ret) != 2) {
printf("Invalid packet\n");
@@ -777,18 +892,18 @@ static int ret_cb(pid_t pid, int handle, const struct packet *packet, void *data
return -EFAULT;
}
- path = node_to_abspath(s_info.curdir);
- printf(PROMPT"%s # ", path);
- free(path);
+ prompt(NULL);
- if (fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK) < 0)
- printf("Error: %s\n", strerror(errno));
+ if (s_info.input_fd == STDIN_FILENO) {
+ if (fcntl(s_info.input_fd, F_SETFL, O_NONBLOCK) < 0)
+ printf("Error: %s\n", strerror(errno));
- s_info.in_handler = ecore_main_fd_handler_add(STDIN_FILENO, ECORE_FD_READ, input_cb, NULL, NULL, NULL);
- if (!s_info.in_handler) {
- printf("Failed to add a input handler\n");
- ecore_main_loop_quit();
- return -EFAULT;
+ s_info.in_handler = ecore_main_fd_handler_add(s_info.input_fd, ECORE_FD_READ, input_cb, NULL, NULL, NULL);
+ if (!s_info.in_handler) {
+ printf("Failed to add a input handler\n");
+ ecore_main_loop_quit();
+ return -EFAULT;
+ }
}
return 0;
@@ -838,6 +953,52 @@ int main(int argc, char *argv[])
.handler = NULL,
},
};
+ static struct option long_options[] = {
+ { "batchmode", required_argument, 0, 'b' },
+ { "help", no_argument, 0, 'h' },
+ { "verbose", required_argument, 0, 'v' },
+ { 0, 0, 0, 0 }
+ };
+ int option_index;
+ int c;
+
+ do {
+ c = getopt_long(argc, argv, "b:hv:", long_options, &option_index);
+ switch (c) {
+ case 'b':
+ if (!optarg || !*optarg) {
+ printf("Invalid argument\n");
+ help();
+ return -EINVAL;
+ }
+
+ if (s_info.input_fd != STDIN_FILENO) {
+ /* Close the previously, opened file */
+ close(s_info.input_fd);
+ }
+
+ s_info.input_fd = open(optarg, O_RDONLY);
+ if (s_info.input_fd < 0) {
+ printf("Unable to access %s (%s)\n", optarg, strerror(errno));
+ return -EIO;
+ }
+ break;
+ case 'h':
+ help();
+ return 0;
+ case 'v':
+ if (!optarg || !*optarg) {
+ printf("Invalid argument\n");
+ help();
+ return -EINVAL;
+ }
+
+ s_info.verbose = !strcmp(optarg, "true");
+ break;
+ default:
+ break;
+ }
+ } while (c != -1);
ecore_init();
g_type_init();
@@ -852,16 +1013,20 @@ int main(int argc, char *argv[])
return -EIO;
}
- printf("Type your command on below empty line\n");
-
- if (tcgetattr(STDIN_FILENO, &ttystate) < 0) {
- printf("Error: %s\n", strerror(errno));
- } else {
- ttystate.c_lflag &= ~(ICANON | ECHO);
- ttystate.c_cc[VMIN] = 1;
+ if (s_info.input_fd == STDIN_FILENO) {
+ printf("Type your command on below empty line\n");
- if (tcsetattr(STDIN_FILENO, TCSANOW, &ttystate) < 0)
+ if (tcgetattr(s_info.input_fd, &ttystate) < 0) {
printf("Error: %s\n", strerror(errno));
+ } else {
+ ttystate.c_lflag &= ~(ICANON | ECHO);
+ ttystate.c_cc[VMIN] = 1;
+
+ if (tcsetattr(s_info.input_fd, TCSANOW, &ttystate) < 0)
+ printf("Error: %s\n", strerror(errno));
+ }
+ } else {
+ printf("Batch mode enabled\n");
}
if (setvbuf(stdout, (char *)NULL, _IONBF, 0) != 0)
@@ -874,10 +1039,6 @@ int main(int argc, char *argv[])
fini_directory();
livebox_service_fini();
- ttystate.c_lflag |= ICANON | ECHO;
- if (tcsetattr(STDIN_FILENO, TCSANOW, &ttystate) < 0)
- printf("Error: %s\n", strerror(errno));
-
if (s_info.fd > 0) {
com_core_packet_client_fini(s_info.fd);
s_info.fd = -EINVAL;
@@ -888,6 +1049,14 @@ int main(int argc, char *argv[])
s_info.fd_handler = NULL;
}
+ if (s_info.input_fd == STDIN_FILENO) {
+ ttystate.c_lflag |= ICANON | ECHO;
+ if (tcsetattr(s_info.input_fd, TCSANOW, &ttystate) < 0)
+ printf("Error: %s\n", strerror(errno));
+ } else {
+ close(s_info.input_fd);
+ }
+
if (s_info.fifo_handle > 0) {
close(s_info.fifo_handle);
s_info.fifo_handle = -EINVAL;
@@ -899,6 +1068,7 @@ int main(int argc, char *argv[])
}
ecore_shutdown();
+ putc((int)'\n', stdout);
return 0;
}
diff --git a/util_liveinfo/src/node.c b/util_liveinfo/src/node.c
index 02d18a2..d807c7f 100644
--- a/util_liveinfo/src/node.c
+++ b/util_liveinfo/src/node.c
@@ -33,11 +33,11 @@ char *node_to_abspath(struct node *node)
tmp = node;
while (tmp && node_name(tmp)) {
- len += strlen(node_name(tmp)) + 1;
+ len += strlen(node_name(tmp)) + 1; /* trail '/' */
tmp = node_parent(tmp);
}
- path = malloc(len + 2);
+ path = malloc(len + 2); /* '/' and '\0' */
if (!path)
return NULL;
@@ -126,19 +126,42 @@ static inline void abspath(char* pBuffer, char* pRet)
struct node *node_find(const struct node *node, char *path)
{
int len;
- char *ptr = path;
+ char *ptr;
+ char *buffer;
+
+ buffer = malloc(strlen(path) + 3); /* add 2 more bytes */
+ if (!buffer)
+ return NULL;
+
+ abspath(path, buffer);
+ ptr = buffer;
do {
+ ptr += (*ptr == '/');
+ for (len = 0; ptr[len] && ptr[len] != '/'; len++);
+ if (!len)
+ break;
+
+ if (!strncmp("..", ptr, len)) {
+ ptr += len;
+ node = node->parent ? node->parent : node;
+ continue;
+ }
+
+ if (!strncmp(".", ptr, len)) {
+ ptr += len;
+ continue;
+ }
+
node = node->child;
- if (!node)
+ if (!node) {
+ free(buffer);
return NULL;
+ }
- if (*ptr == '/') ptr++;
- for (len = 0; ptr[len] && ptr[len] != '/'; len++);
while (node) {
if (!strncmp(node->name, ptr, len) && node->name[len] == '\0') {
ptr += len;
- ptr += (*ptr == '/');
break;
}
@@ -146,6 +169,7 @@ struct node *node_find(const struct node *node, char *path)
}
} while (*ptr && node);
+ free(buffer);
return (struct node *)node;
}