|
From: <cli...@li...> - 2007-06-19 18:32:03
|
Revision: 67
http://cligg.svn.sourceforge.net/cligg/?rev=67&view=rev
Author: sithhell
Date: 2007-06-19 11:31:55 -0700 (Tue, 19 Jun 2007)
Log Message:
-----------
added ipc stuff to cligg, and a remote application to quit it
Modified Paths:
--------------
CMakeLists.txt
src/bin/CMakeLists.txt
src/bin/cligg.c
Added Paths:
-----------
src/bin/cligg_ipc.c
src/bin/cligg_ipc.h
src/bin/cligg_remote.c
Modified: CMakeLists.txt
===================================================================
--- CMakeLists.txt 2007-05-24 15:47:23 UTC (rev 66)
+++ CMakeLists.txt 2007-06-19 18:31:55 UTC (rev 67)
@@ -11,7 +11,7 @@
"Build the project using debugging code"
ON)
IF(CLIGG_DEBUG)
- set(CMAKE_C_FLAGS "-g -DDEBUG -Wall -pedantic -ansi")
+ set(CMAKE_C_FLAGS "-g -DDEBUG -Wall -pedantic -ansi -D_POSIX_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=500")
ENDIF(CLIGG_DEBUG)
# CFLAGS
Modified: src/bin/CMakeLists.txt
===================================================================
--- src/bin/CMakeLists.txt 2007-05-24 15:47:23 UTC (rev 66)
+++ src/bin/CMakeLists.txt 2007-06-19 18:31:55 UTC (rev 67)
@@ -1,8 +1,11 @@
add_executable(cligg cligg.c
cligg_eventhandler.c
cligg_modulehandler.c
- cligg_mainloop.c)
+ cligg_mainloop.c
+ cligg_ipc.c)
target_link_libraries(cligg cligglib pthread dl)
+add_executable(cligg_remote cligg_remote.c)
+
add_executable(tree_test test.c)
target_link_libraries(tree_test cligglib)
set_target_properties(cligg PROPERTIES LINK_FLAGS -rdynamic)
Modified: src/bin/cligg.c
===================================================================
--- src/bin/cligg.c 2007-05-24 15:47:23 UTC (rev 66)
+++ src/bin/cligg.c 2007-06-19 18:31:55 UTC (rev 67)
@@ -13,6 +13,7 @@
#include <cligg_eventhandler.h>
#include <cligg_mainloop.h>
#include <cligg_modulehandler.h>
+#include <cligg_ipc.h>
/**
* @file cligg.c
@@ -64,8 +65,8 @@
cligg_trigger_event("load_module", "/home/heller/projekte/cligg/src/modules/print/print.so");
cligg_trigger_event("load_module", "/home/heller/projekte/cligg/src/modules/read/read.so");
cligg_trigger_event("load_module", "/home/heller/projekte/cligg/src/modules/read/read.so");
- cligg_trigger_event("read", NULL);
- /*cligg_trigger_event("quit_cligg", NULL);*/
+ /*cligg_trigger_event("read", NULL);
+ cligg_trigger_event("quit_cligg", NULL);*/
/* TODO load the config */
@@ -75,6 +76,10 @@
/* TODO define own signal handlers */
/* exit handlers ... */
+ /* setting up ipc */
+ printf("IPC\n");
+ cligg_ipc_start();
+
/* starting the event loop */
cligg_main_begin();
/* MAGIC!! */
@@ -88,6 +93,7 @@
/* Clean up */
cligg_delete_handler();
cligg_del_modulehandler();
+ cligg_ipc_stop();
fprintf(stderr, "Good Bye!\n");
Added: src/bin/cligg_ipc.c
===================================================================
--- src/bin/cligg_ipc.c (rev 0)
+++ src/bin/cligg_ipc.c 2007-06-19 18:31:55 UTC (rev 67)
@@ -0,0 +1,89 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stddef.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <pthread.h>
+#include <errno.h>
+#include <cligg_ipc.h>
+#include <cligg_eventhandler.h>
+
+#define SOCKET_NAME "/tmp/cligg"
+#define QLEN 10
+
+static pthread_t ipc_loop;
+static int fd;
+
+static void *cligg_ipc(void *);
+
+int cligg_ipc_start(void)
+{
+ int len;
+ int err;
+ struct sockaddr_un un;
+
+ if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ return FALSE;
+
+ unlink(SOCKET_NAME);
+
+ memset(&un, 0, sizeof(un));
+ un.sun_family = AF_UNIX;
+ strcpy(un.sun_path, SOCKET_NAME);
+ len = offsetof(struct sockaddr_un, sun_path) + strlen(SOCKET_NAME);
+
+ if(bind(fd, (struct sockaddr *)&un, len) < 0) {
+ err = errno;
+ close(fd);
+ errno = err;
+ return FALSE;
+ }
+
+ if(listen(fd, QLEN) < 0) {
+ err = errno;
+ close(fd);
+ errno = err;
+ return FALSE;
+ }
+
+ if(pthread_create(&ipc_loop, NULL, cligg_ipc, &fd) != 0) {
+ fprintf(stderr, "Creation of IPC thread failed!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("socket fd %d\n", fd);
+
+ return TRUE;
+}
+
+int cligg_ipc_stop(void)
+{
+ unlink(SOCKET_NAME);
+ close(fd);
+ return TRUE;
+}
+
+static void *cligg_ipc(void *data)
+{
+ int clifd;
+ socklen_t len;
+ struct sockaddr_un un;
+ char buf[2*1024];
+ char *message[2];
+
+ while(1) {
+ len = sizeof(un);
+ if((clifd = accept(fd, (struct sockaddr *)&un, &len)) < 0) {
+ perror("accept");
+ continue;
+ }
+ len = read(clifd, buf, 1024);
+ message[0] = buf;
+ message[1] = buf+1024;
+ cligg_trigger_event(message[0], message[1]);
+ close(clifd);
+ }
+ return NULL;
+}
Added: src/bin/cligg_ipc.h
===================================================================
--- src/bin/cligg_ipc.h (rev 0)
+++ src/bin/cligg_ipc.h 2007-06-19 18:31:55 UTC (rev 67)
@@ -0,0 +1,7 @@
+#ifndef CLIGG_IPC
+#define CLIGG_IPC
+
+int cligg_ipc_start(void);
+int cligg_ipc_stop(void);
+
+#endif
Added: src/bin/cligg_remote.c
===================================================================
--- src/bin/cligg_remote.c (rev 0)
+++ src/bin/cligg_remote.c 2007-06-19 18:31:55 UTC (rev 67)
@@ -0,0 +1,73 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stddef.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <cligg.h>
+#include <cligglib.h>
+
+#define SOCKET_NAME "/tmp/cligg"
+
+static void help(void);
+static int cmp_opt(const char *, const char *, const char *);
+
+int main(int argc, char **argv)
+{
+ int fd;
+ int len;
+ int err;
+ struct sockaddr_un un;
+ char message[2][1024];
+
+ if(argc < 2) {
+ help();
+ exit(EXIT_FAILURE);
+ }
+
+ if(cmp_opt("-h", "--help", argv[1])) {
+ help();
+ exit(EXIT_SUCCESS);
+ }
+
+ if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ return -1;
+ memset(&un, 0, sizeof(un));
+ un.sun_family = AF_UNIX;
+ strcpy(un.sun_path, "/tmp/cligg");
+ len = offsetof(struct sockaddr_un, sun_path) + strlen("/tmp/cligg");
+ if(connect(fd, (struct sockaddr *)&un, len) < 0) {
+ err = errno;
+ close(fd);
+ errno = err;
+ perror("cligg_remote");
+ return EXIT_FAILURE;
+ }
+ if(cmp_opt("-q", "--quit", argv[1])) {
+ strcpy(message[0], "quit_cligg");
+ strcpy(message[1], "");
+ write(fd, message, strlen(message[0])+strlen(message[1]));
+ }
+ close(fd);
+ return EXIT_SUCCESS;
+}
+
+static void help(void)
+{
+ printf("Usage: \n");
+ printf("\t -h, --help show this help\n");
+ printf("\t -q, --quit quit cligg\n");
+ printf("\t -lm --load-module load module\n");
+ printf("\t -um --unload-module unload module\n");
+}
+
+static int cmp_opt(const char *opt1, const char *opt2, const char *arg)
+{
+ if((strcmp(opt1, arg) == 0) || (strcmp(opt2, arg) == 0))
+ return TRUE;
+ return FALSE;
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|