From 0ad61020040e15329d41ce344df6d84aa9ac9678 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Fri, 1 Feb 2013 13:51:37 +0000 Subject: [PATCH] Update the liveinfo Change-Id: Id3f3685514578cc67f3510c8727f84d6b52a8ca1 --- packaging/org.tizen.data-provider-master.spec | 2 +- src/buffer_handler.c | 2 +- src/server.c | 18 ++-- util_liveinfo/include/node.h | 11 ++- util_liveinfo/src/liveinfo.c | 123 +++++++++++++++++++++++++- util_liveinfo/src/node.c | 106 ++++++++++++++++++---- 6 files changed, 231 insertions(+), 31 deletions(-) diff --git a/packaging/org.tizen.data-provider-master.spec b/packaging/org.tizen.data-provider-master.spec index 4ac6984..8d901f3 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.15.5 +Version: 0.15.6 Release: 1 Group: framework/livebox License: Flora License diff --git a/src/buffer_handler.c b/src/buffer_handler.c index f82faa5..0df7254 100644 --- a/src/buffer_handler.c +++ b/src/buffer_handler.c @@ -1106,7 +1106,7 @@ static inline int sync_for_pixmap(struct buffer *buffer) * \NOTE * XCreatePixmap can only uses 24 bits depth only. */ - xim = XShmCreateImage(disp, visual, 24/* (s_info.depth << 3) */, ZPixmap, NULL, &si, gem->w, gem->h); + xim = XShmCreateImage(disp, visual, 24 /* (gem->depth << 3) */, ZPixmap, NULL, &si, gem->w, gem->h); if (xim == NULL) { if (shmdt(si.shmaddr) < 0) ErrPrint("shmdt: %s\n", strerror(errno)); diff --git a/src/server.c b/src/server.c index 2a481b7..0b9be5b 100644 --- a/src/server.c +++ b/src/server.c @@ -4911,6 +4911,7 @@ static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct p char *var; char *val; FILE *fp; + int ret = -EINVAL; if (packet_get(packet, "sss", &cmd, &var, &val) != 3) { ErrPrint("Invalid argument\n"); @@ -4923,11 +4924,18 @@ static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct p goto out; } - if (!strcmp(var, "debug")) { - if (!strcmp(cmd, "set")) { - g_conf.debug_mode = !strcmp(val, "true"); - } else if (!strcmp(cmd, "get")) { + if (!strcasecmp(var, "debug")) { + if (!strcasecmp(cmd, "set")) { + g_conf.debug_mode = !strcasecmp(val, "on"); + } else if (!strcasecmp(cmd, "get")) { } + ret = g_conf.debug_mode; + } else if (!strcasecmp(var, "slave_max_load")) { + if (!strcasecmp(cmd, "set")) { + g_conf.slave_max_load = atoi(val); + } else if (!strcasecmp(cmd, "get")) { + } + ret = g_conf.slave_max_load; } liveinfo_open_fifo(info); @@ -4936,7 +4944,7 @@ static struct packet *liveinfo_master_ctrl(pid_t pid, int handle, const struct p liveinfo_close_fifo(info); goto out; } - fprintf(fp, "%d\nEOD\n", g_conf.debug_mode); + fprintf(fp, "%d\nEOD\n", ret); liveinfo_close_fifo(info); out: diff --git a/util_liveinfo/include/node.h b/util_liveinfo/include/node.h index 61a5922..812b59e 100644 --- a/util_liveinfo/include/node.h +++ b/util_liveinfo/include/node.h @@ -11,9 +11,9 @@ struct node; #define NODE_WRITE 0x02 #define NODE_EXEC 0x04 -extern struct node *node_find(const struct node *node, char *path); +extern struct node *node_find(const struct node *node, const char *path); extern struct node *node_create(struct node *parent, const char *name, enum node_type type); -extern void node_destroy(struct node *node); +extern void *node_destroy(struct node *node); extern struct node * const node_next_sibling(const struct node *node); extern struct node * const node_prev_sibling(const struct node *node); @@ -32,5 +32,10 @@ extern const enum node_type const node_type(const struct node *node); extern const char * const node_name(const struct node *node); -extern char *node_to_abspath(struct node *node); +extern char *node_to_abspath(const struct node *node); + +extern int node_age(struct node *node); +extern void node_set_age(struct node *node, int age); + +extern void node_delete(struct node *node, void (del_cb)(struct node *node)); /* End of a file */ diff --git a/util_liveinfo/src/liveinfo.c b/util_liveinfo/src/liveinfo.c index 18e913b..fe9a97e 100644 --- a/util_liveinfo/src/liveinfo.c +++ b/util_liveinfo/src/liveinfo.c @@ -99,6 +99,8 @@ static struct info { int input_fd; int verbose; + + int age; } s_info = { .fifo_handle = -EINVAL, .fd = -EINVAL, @@ -110,6 +112,7 @@ static struct info { .cmd = NOP, .input_fd = STDIN_FILENO, .verbose = 0, + .age = 0, }; char *optarg; @@ -141,6 +144,49 @@ static inline void prompt(const char *cmdline) free(path); } +static void provider_del_cb(struct node *node) +{ + struct slave *info; + + info = node_data(node); + if (!info) + return; + + free(info->pkgname); + free(info->abi); + free(info->state); + free(info); +} + +static void package_del_cb(struct node *node) +{ + struct package *info; + + info = node_data(node); + if (!info) + return; + + free(info->pkgid); + free(info->slavename); + free(info->abi); + free(info); +} + +static void inst_del_cb(struct node *node) +{ + struct instance *info; + + info = node_data(node); + if (!info) + return; + + free(info->id); + free(info->cluster); + free(info->category); + free(info->state); + free(info); +} + static inline void ls(void) { struct node *node; @@ -148,6 +194,7 @@ static inline void ls(void) int is_package; int is_provider; int is_instance; + struct node *next_node; if (!(node_mode(s_info.targetdir) & NODE_READ)) { printf("Access denied\n"); @@ -162,16 +209,41 @@ static inline void ls(void) while (node) { if (is_package) { struct package *info; + + next_node = node_next_sibling(node); + if (node_age(node) != s_info.age) { + node_delete(node, package_del_cb); + node = next_node; + continue; + } + info = node_data(node); printf(" %3d %20s %5s ", info->inst_count, info->slavename ? info->slavename : "-", info->abi ? info->abi : "-"); } else if (is_provider) { struct slave *info; + + next_node = node_next_sibling(node); + if (node_age(node) != s_info.age) { + node_delete(node, provider_del_cb); + node = next_node; + continue; + } + info = node_data(node); printf(" %3d %5s %5.2f ", info->loaded_inst, info->abi ? info->abi : "-", info->ttl); } else if (is_instance) { struct instance *info; struct stat stat; char buf[4096]; + + next_node = node_next_sibling(node); + + if (node_age(node) != s_info.age) { + node_delete(node, inst_del_cb); + node = next_node; + continue; + } + info = node_data(node); printf(" %5.2f %6s %10s %10s %4dx%-4d ", info->period, info->state, info->cluster, info->category, info->width, info->height); @@ -191,6 +263,7 @@ static inline void ls(void) node = node_next_sibling(node); cnt++; } + printf("Total: %d\n", cnt); } @@ -212,6 +285,27 @@ static void send_slave_list(void) com_core_packet_send_only(s_info.fd, packet); packet_destroy(packet); s_info.cmd = SLAVE_LIST; + s_info.age++; +} + +/*! + * var = debug, slave_max_load + * cmd = set / get + */ +static void send_command(const char *cmd, const char *var, const char *val) +{ + struct packet *packet; + + if (s_info.cmd != NOP) { + printf("Previous command is not finished\n"); + return; + } + + packet = packet_create_noack("master_ctrl", "sss", cmd, var, val); + com_core_packet_send_only(s_info.fd, packet); + packet_destroy(packet); + s_info.cmd = MASTER_CTRL; + s_info.age++; } static void send_pkg_list(void) @@ -232,6 +326,7 @@ static void send_pkg_list(void) com_core_packet_send_only(s_info.fd, packet); packet_destroy(packet); s_info.cmd = PKG_LIST; + s_info.age++; } static void send_inst_delete(void) @@ -269,8 +364,8 @@ static void send_inst_delete(void) 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 = INST_CTRL; + s_info.age++; } static void send_inst_list(const char *pkgname) @@ -291,6 +386,7 @@ static void send_inst_list(const char *pkgname) com_core_packet_send_only(s_info.fd, packet); packet_destroy(packet); s_info.cmd = INST_LIST; + s_info.age++; } static inline void help(void) @@ -302,6 +398,7 @@ static inline void help(void) 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("set [debug] [on|off] Set the control variable of master provider\n"); printf("exit - \n"); printf("quit - \n"); printf("----------------------------------------------------------------------------\n"); @@ -384,11 +481,23 @@ static inline void do_command(const char *cmd) return; } - if (sscanf(cmd, "%255[^ ] %4095s", command, argument) == 2) + if (sscanf(cmd, "%255[^ ] %4095[^\\0]", command, argument) == 2) cmd = command; if (!strcasecmp(cmd, "exit") || !strcasecmp(cmd, "quit")) { ecore_main_loop_quit(); + } else if (!strcasecmp(cmd, "set")) { + char variable[4096] = { '0', }; + char value[4096] = { '0', }; + + if (sscanf(argument, "%4095[^ ] %4095[^ ]", variable, value) != 2) { + printf("Invalid argument(%s): set [VAR] [VAL]\n", argument); + goto out; + } + + send_command(cmd, variable, value); + } else if (!strcasecmp(cmd, "get")) { + send_command(cmd, argument, ""); } else if (!strcasecmp(cmd, "ls")) { const char *name; struct node *parent; @@ -639,6 +748,8 @@ static void processing_line_buffer(const char *buffer) pkginfo->abi = NULL; } + node_set_age(node, s_info.age); + pkginfo->slavename = strdup(slavename); if (!pkginfo->slavename) printf("Error: %s\n", strerror(errno)); @@ -676,6 +787,9 @@ static void processing_line_buffer(const char *buffer) } else { slaveinfo = node_data(node); } + + node_set_age(node, s_info.age); + free(slaveinfo->pkgname); free(slaveinfo->abi); free(slaveinfo->state); @@ -729,6 +843,8 @@ static void processing_line_buffer(const char *buffer) instinfo = node_data(node); } + node_set_age(node, s_info.age); + free(instinfo->id); free(instinfo->cluster); free(instinfo->category); @@ -757,12 +873,15 @@ static void processing_line_buffer(const char *buffer) case INST_CTRL: sscanf(buffer, "%d", &i); printf("%s\n", strerror(i)); + printf("Result: %d\n", i); break; case SLAVE_CTRL: sscanf(buffer, "%d", &i); + printf("Result: %d\n", i); break; case MASTER_CTRL: sscanf(buffer, "%d", &i); + printf("Result: %d\n", i); break; default: break; diff --git a/util_liveinfo/src/node.c b/util_liveinfo/src/node.c index d807c7f..4ab1573 100644 --- a/util_liveinfo/src/node.c +++ b/util_liveinfo/src/node.c @@ -13,6 +13,7 @@ struct node { struct node *parent; unsigned char mode; + int age; struct { struct node *next; @@ -24,11 +25,11 @@ struct node { int errno; /* External symbol */ -char *node_to_abspath(struct node *node) +char *node_to_abspath(const struct node *node) { char *path; char *ptr; - struct node *tmp; + const struct node *tmp; int len = 0; tmp = node; @@ -37,7 +38,7 @@ char *node_to_abspath(struct node *node) tmp = node_parent(tmp); } - path = malloc(len + 2); /* '/' and '\0' */ + path = malloc(len + 3); /* '/' and '\0' */ if (!path) return NULL; @@ -45,8 +46,10 @@ char *node_to_abspath(struct node *node) path[0] = '/'; path[1] = '\0'; } else { - ptr = path + len; + ptr = path + len + 1; *ptr = '\0'; + ptr--; + *ptr = '/'; tmp = node; while (tmp && node_name(tmp)) { ptr -= (strlen(node_name(tmp)) + 1); @@ -63,6 +66,7 @@ static inline int next_state(int from, char ch) { switch ( ch ) { + case '\0': case '/': return 1; case '.': @@ -73,7 +77,7 @@ static inline int next_state(int from, char ch) return 4; } -static inline void abspath(char* pBuffer, char* pRet) +static inline void abspath(const char* pBuffer, char* pRet) { int idx=0; int state = 1; @@ -96,7 +100,7 @@ static inline void abspath(char* pBuffer, char* pRet) break; case 2: if ( state == 1 ) { - if ( idx > 0 ) idx --; + if ( idx > 1 ) idx --; } else { pRet[idx] = pBuffer[src_idx]; idx ++; @@ -106,11 +110,11 @@ static inline void abspath(char* pBuffer, char* pRet) // Only can go to the 1 or 4 if ( state == 1 ) { idx -= 2; - if ( idx < 0 ) idx = 0; + if ( idx < 1 ) idx = 1; - while ( idx > 0 && pRet[idx] != '/' ) idx --; - if ( idx > 0 && pRet[idx] == '/' ) idx --; - while ( idx > 0 && pRet[idx] != '/' ) idx --; + while ( idx > 1 && pRet[idx] != '/' ) idx --; /* Remove .. */ + if ( idx > 1 && pRet[idx] == '/' ) idx --; + while ( idx > 1 && pRet[idx] != '/' ) idx --; /* Remove parent folder */ } case 4: pRet[idx] = pBuffer[src_idx]; @@ -123,19 +127,32 @@ static inline void abspath(char* pBuffer, char* pRet) } } -struct node *node_find(const struct node *node, char *path) +struct node *node_find(const struct node *node, const char *path) { - int len; + int len = 0; char *ptr; char *buffer; + if (*path != '/') { + while (node->parent && path[0] == '.' && path[1] == '.') { + if (path[2] != '/' && path[2] != '\0') + break; + + path += 2; + path += (path[2] == '/'); + node = node->parent; + } + } + buffer = malloc(strlen(path) + 3); /* add 2 more bytes */ - if (!buffer) + if (!buffer) { + printf("Error: %s\n", strerror(errno)); return NULL; + } abspath(path, buffer); - ptr = buffer; + ptr = buffer; do { ptr += (*ptr == '/'); for (len = 0; ptr[len] && ptr[len] != '/'; len++); @@ -154,10 +171,8 @@ struct node *node_find(const struct node *node, char *path) } node = node->child; - if (!node) { - free(buffer); - return NULL; - } + if (!node) + break; while (node) { if (!strncmp(node->name, ptr, len) && node->name[len] == '\0') { @@ -219,10 +234,53 @@ struct node *node_create(struct node *parent, const char *name, enum node_type t return node; } -void node_destroy(struct node *node) +void *node_destroy(struct node *node) { + void *data; + + data = node->data; free(node->name); free(node); + + return data; +} + +void node_delete(struct node *node, void (del_cb)(struct node *node)) +{ + struct node *tmp; + struct node *next; + struct node *parent; + + if (node->sibling.prev) + node->sibling.prev->sibling.next = node->sibling.next; + + if (node->sibling.next) + node->sibling.next->sibling.prev = node->sibling.prev; + + if (node->parent) { + node->parent->child = NULL; + node->parent = NULL; + } + + tmp = node; + while (tmp) { + while (tmp->child) tmp = tmp->child; + + parent = tmp->parent; + next = tmp->sibling.next; + + if (del_cb) + del_cb(tmp); + + node_destroy(tmp); + + if (next) + tmp = next; + else if (parent) + tmp = parent; + else + tmp = NULL; + } } struct node * const node_next_sibling(const struct node *node) @@ -280,4 +338,14 @@ const char * const node_name(const struct node *node) return node->name; } +void node_set_age(struct node *node, int age) +{ + node->age = age; +} + +int node_age(struct node *node) +{ + return node->age; +} + /* End of a file */ -- 2.7.4