summaryrefslogtreecommitdiffstats
path: root/external
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@dside.dyndns.org>2007-04-14 22:20:10 +0000
committerSuren A. Chilingaryan <csa@dside.dyndns.org>2007-04-14 22:20:10 +0000
commit8ca43646a6c87d00d5b2cb74cebf65a8d0ea5e8e (patch)
tree724ddc9ab6cb3a362051fe1e081b3ccdcd7c0d5c /external
parentb91203daf1a2b5865bfd284821c0c0b103f5b8e7 (diff)
downloadlibrcc-8ca43646a6c87d00d5b2cb74cebf65a8d0ea5e8e.tar.gz
librcc-8ca43646a6c87d00d5b2cb74cebf65a8d0ea5e8e.tar.bz2
librcc-8ca43646a6c87d00d5b2cb74cebf65a8d0ea5e8e.tar.xz
librcc-8ca43646a6c87d00d5b2cb74cebf65a8d0ea5e8e.zip
DB4 & Postponed processing
- New DB4 database type - Postponed processing in external module + User may allow external module to finish required processing before termination. This could be useful for translation services while using console applications (if network connection is slow, the external will never finish translation before program termination) - SKIP_PARRENT options are renamed to SKIP_PARENT
Diffstat (limited to 'external')
-rw-r--r--external/Makefile.am5
-rw-r--r--external/rccexternal.c44
-rw-r--r--external/rcclibtranslate.c4
3 files changed, 31 insertions, 22 deletions
diff --git a/external/Makefile.am b/external/Makefile.am
index 68d2988..51cbad9 100644
--- a/external/Makefile.am
+++ b/external/Makefile.am
@@ -6,7 +6,10 @@ bindir = $(pkgdatadir)/
rccexternal_SOURCES= rccexternal.c \
rcclibtranslate.c rcclibtranslate.h \
- ../src/rccdb4.c ../src/rccdb4.h
+ ../src/rccdb4.c ../src/rccdb4.h \
+ ../src/rcchome.c ../src/rcchome.h \
+ ../src/rcclock.c ../src/rcclock.h
+
rccexternal_LDADD= @GLIB2_LIBS@ @LIBTRANSLATE_LIBS@ @BDB_LIBS@
AM_CPPFLAGS = @GLIB2_CFLAGS@ @LIBTRANSLATE_CFLAGS@ @BDB_INCLUDES@ -I../src
diff --git a/external/rccexternal.c b/external/rccexternal.c
index b09623d..56c9882 100644
--- a/external/rccexternal.c
+++ b/external/rccexternal.c
@@ -35,12 +35,15 @@
#include <glib/gthread.h>
+#include "../src/rcchome.h"
#include "../src/rccexternal.h"
#include "rcclibtranslate.h"
#define RCC_EXIT_CHECK_TIMEOUT 10 /* seconds */
+char rcc_external_offline = 0;
+
int main() {
#ifdef HAVE_SIGNAL_H
struct sigaction act;
@@ -51,7 +54,6 @@ int main() {
int s, sd;
char addr[376];
- const char *rcc_home_dir;
struct sockaddr_un mysock, clisock;
socklen_t socksize;
@@ -61,29 +63,16 @@ int main() {
unsigned char loopflag = 1;
rcc_external_info info;
+ rcc_external_option option;
+ unsigned long option_value_long;
+
ssize_t readed;
unsigned char cmd;
-#ifdef HAVE_PWD_H
- struct passwd *pw;
-#endif /* HAVE_PWD_H */
-
-
parentpid = getppid();
mypid = getpid();
-
- rcc_home_dir = getenv ("HOME");
-#ifdef HAVE_PWD_H
- if (!rcc_home_dir) {
- setpwent ();
- pw = getpwuid(getuid ());
- endpwent ();
- if ((pw)&&(pw->pw_dir)) rcc_home_dir = pw->pw_dir;
- }
-#endif /* HAVE_PWD_H */
- if (strlen(rcc_home_dir)>256) return -1;
- if (!rcc_home_dir) rcc_home_dir = "/";
-
+
+ rccHomeSet();
rccLibTranslateInit(rcc_home_dir);
sprintf(addr,"%s/.rcc/comm/",rcc_home_dir);
@@ -140,6 +129,20 @@ int main() {
case RCC_EXTERNAL_MODULE_CONTROL:
loopflag = 0;
break;
+ case RCC_EXTERNAL_MODULE_OPTIONS:
+ readed = recv(sd,&option,sizeof(rcc_external_option),0);
+ if (readed < sizeof(rcc_external_option)) break;
+ switch(option) {
+ case RCC_EXTERNAL_OPTION_OFFLINE:
+ readed = recv (sd, &option_value_long, sizeof(unsigned long), 0);
+ if (readed < sizeof(unsigned long)) break;
+ puts("got an offline option");
+ rcc_external_offline = option_value_long?1:0;
+ break;
+ default:
+ break;
+ }
+ break;
case RCC_EXTERNAL_MODULE_LIBRTRANSLATE:
info = (rcc_external_info)malloc(sizeof(rcc_external_info_s));
if (info) info->s = sd;
@@ -154,6 +157,7 @@ int main() {
unlink(addr);
rccLibTranslateFree();
-
+ rccHomeFree();
+
return 0;
}
diff --git a/external/rcclibtranslate.c b/external/rcclibtranslate.c
index 24f44a2..c64020c 100644
--- a/external/rcclibtranslate.c
+++ b/external/rcclibtranslate.c
@@ -35,6 +35,7 @@ static GCond *cond = NULL;
static GQueue *queue = NULL;
static GThread *thread = NULL;
+extern char rcc_external_offline;
static char *rccCreateKey(const char *from, const char *to, const char *data, size_t *keysize) {
char *res;
@@ -78,7 +79,7 @@ static void *rccLibPostponed(void *info) {
to[2] = 0;
g_mutex_lock(mutex);
- while (!exitflag) {
+ while ((!exitflag)||(rcc_external_offline)) {
data = (char*)g_queue_pop_head(queue);
if (data) {
g_mutex_unlock(mutex);
@@ -103,6 +104,7 @@ static void *rccLibPostponed(void *info) {
free(data);
g_mutex_lock(mutex);
} else {
+ if (exitflag) break;
g_cond_wait(cond, mutex);
}
}