[maemo-commits] [maemo-commits] r15426 - in projects/haf/trunk/maemo-launcher: . launcher
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Wed Apr 16 01:35:57 EEST 2008
- Previous message: [maemo-commits] r15425 - in projects/haf/trunk/maemo-launcher: . launcher
- Next message: [maemo-commits] r15427 - in projects/haf/trunk/maemo-launcher: . launcher
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: guillem Date: 2008-04-16 01:35:56 +0300 (Wed, 16 Apr 2008) New Revision: 15426 Modified: projects/haf/trunk/maemo-launcher/ChangeLog projects/haf/trunk/maemo-launcher/launcher/comm_msg.c projects/haf/trunk/maemo-launcher/launcher/comm_msg.h projects/haf/trunk/maemo-launcher/launcher/launcher.c projects/haf/trunk/maemo-launcher/launcher/test_msg.c Log: Add support for comm_msg magic word set/get functions Modified: projects/haf/trunk/maemo-launcher/ChangeLog =================================================================== --- projects/haf/trunk/maemo-launcher/ChangeLog 2008-04-15 22:35:54 UTC (rev 15425) +++ projects/haf/trunk/maemo-launcher/ChangeLog 2008-04-15 22:35:56 UTC (rev 15426) @@ -1,3 +1,16 @@ +2008-03-20 Guillem Jover <guillem.jover at nokia.com> + + * launcher/comm_msg.h (comm_msg_set_magic): New prototype. + (comm_msg_get_magic): Likewise. + * launcher/comm_msg.c (comm_msg_set_magic): New function. + (comm_msg_get_magic): Likewise. + * launcher/test_msg.c (main): Set and get the magic and check the + value being the same. + * launcher/launcher.c (LAUNCHER_STATE_SIG): Change from "MLSF0.0" + to 0x30534c4d. + (store_state): Use comm_msg_set_magic instead of comm_msg_pack_str. + (load_state): Use comm_msg_get_magic instead of comm_msg_unpack_str. + 2008-03-18 Guillem Jover <guillem.jover at nokia.com> * launcher/comm_msg.h (comm_msg_print): New prototype. Modified: projects/haf/trunk/maemo-launcher/launcher/comm_msg.c =================================================================== --- projects/haf/trunk/maemo-launcher/launcher/comm_msg.c 2008-04-15 22:35:54 UTC (rev 15425) +++ projects/haf/trunk/maemo-launcher/launcher/comm_msg.c 2008-04-15 22:35:56 UTC (rev 15426) @@ -167,7 +167,35 @@ return mem; } +/* + * High level get/set functions. + */ + bool +comm_msg_set_magic(comm_msg_t *msg, uint32_t magic) +{ + if (!comm_msg_grow(msg, sizeof(magic))) + return false; + + memcpy(msg->buf + msg->used, &magic, sizeof(magic)); + msg->used += sizeof(magic); + + return true; +} + +bool +comm_msg_get_magic(comm_msg_t *msg, uint32_t *magic) +{ + if (msg->read + sizeof(*magic) > msg->used) + return false; + + memcpy(magic, msg->buf + msg->read, sizeof(*magic)); + msg->read += sizeof(*magic); + + return true; +} + +bool comm_msg_pack_int(comm_msg_t *msg, uint32_t i) { static const uint32_t size = sizeof(i); Modified: projects/haf/trunk/maemo-launcher/launcher/comm_msg.h =================================================================== --- projects/haf/trunk/maemo-launcher/launcher/comm_msg.h 2008-04-15 22:35:54 UTC (rev 15425) +++ projects/haf/trunk/maemo-launcher/launcher/comm_msg.h 2008-04-15 22:35:56 UTC (rev 15426) @@ -37,6 +37,9 @@ bool comm_msg_send(int fd, comm_msg_t *msg); bool comm_msg_recv(int fd, comm_msg_t *msg); +bool comm_msg_set_magic(comm_msg_t *msg, uint32_t magic); +bool comm_msg_get_magic(comm_msg_t *msg, uint32_t *magic); + bool comm_msg_pack_int(comm_msg_t *msg, uint32_t i); bool comm_msg_unpack_int(comm_msg_t *msg, uint32_t *i); Modified: projects/haf/trunk/maemo-launcher/launcher/launcher.c =================================================================== --- projects/haf/trunk/maemo-launcher/launcher/launcher.c 2008-04-15 22:35:54 UTC (rev 15425) +++ projects/haf/trunk/maemo-launcher/launcher/launcher.c 2008-04-15 22:35:56 UTC (rev 15426) @@ -545,7 +545,7 @@ /* Persistence support */ -#define LAUNCHER_STATE_SIG "MLSF0.0" +#define LAUNCHER_STATE_SIG 0x30534c4d static bool store_state(kindergarten_t *childs, int invoker_fd) @@ -566,7 +566,8 @@ msg = comm_msg_new(512, 0); - comm_msg_pack_str(msg, LAUNCHER_STATE_SIG); + comm_msg_set_magic(msg, LAUNCHER_STATE_SIG); + comm_msg_pack_int(msg, invoker_fd); comm_msg_pack_int(msg, childs->used); @@ -589,7 +590,7 @@ { int i; int fd; - uint32_t w; + uint32_t w, magic; const char *s; kindergarten_t *childs; child_t *list; @@ -608,8 +609,8 @@ close(fd); - comm_msg_unpack_str(msg, &s); - if (strcmp(LAUNCHER_STATE_SIG, s) != 0) + comm_msg_get_magic(msg, &magic); + if (LAUNCHER_STATE_SIG != magic) { error("wrong signature on persistence file '%s'\n", statefilename); return NULL; Modified: projects/haf/trunk/maemo-launcher/launcher/test_msg.c =================================================================== --- projects/haf/trunk/maemo-launcher/launcher/test_msg.c 2008-04-15 22:35:54 UTC (rev 15425) +++ projects/haf/trunk/maemo-launcher/launcher/test_msg.c 2008-04-15 22:35:56 UTC (rev 15426) @@ -35,6 +35,7 @@ main() { int fd; + uint32_t magic = 0xffff5555; uint32_t w1 = 0xcafef00d, w2 = 0xdeadbeef, w3 = 0xd00d, w4 = 0xbabe; const char *s1 = "0123456789abcdef, end here."; const char *s2 = "some other more reasonable string"; @@ -46,6 +47,8 @@ msg = comm_msg_new(20, 0); + comm_msg_set_magic(msg, magic); + comm_msg_pack_int(msg, w1); comm_msg_pack_int(msg, w2); comm_msg_pack_str(msg, s1); @@ -72,8 +75,11 @@ comm_msg_recv(fd, msg); - tests_init(7); + tests_init(8); + if (comm_msg_get_magic(msg, &w)) + test_cmp_int(magic, w); + if (comm_msg_unpack_int(msg, &w)) test_cmp_int(w1, w); if (comm_msg_unpack_int(msg, &w))
- Previous message: [maemo-commits] r15425 - in projects/haf/trunk/maemo-launcher: . launcher
- Next message: [maemo-commits] r15427 - in projects/haf/trunk/maemo-launcher: . launcher
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]