Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

ppc_log_get.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: ppc_log_get.c,v 1.3 2006/01/10 16:16:59 tat Exp $
00009  */
00010 
00011 #include "klone_conf.h"
00012 #include <string.h>
00013 #include <klone/klog.h>
00014 #include <klone/context.h>
00015 #include <klone/server.h>
00016 #include <klone/ppc.h>
00017 #include <klone/ppc_cmd.h>
00018 #include "server_s.h"
00019 #include "server_ppc_cmd.h"
00020 
00021 /* struct used for ppc command PPC_CMD_LOG_GET */
00022 struct ppc_log_get_s
00023 {
00024     int bid;                        /* calling backend ID       */
00025     ssize_t i;                      /* i-th line                */
00026     char line[KLOG_LN_SZ];          /* log line                 */
00027 };
00028 
00029 typedef struct ppc_log_get_s ppc_log_get_t;
00030 
00031 /* client function */
00032 int server_ppc_cmd_log_get(server_t *s, size_t i, char *line)
00033 {
00034     ppc_log_get_t plg;
00035     unsigned char cmd;
00036 
00037     nop_err_if (s == NULL);
00038     nop_err_if (s->ppc == NULL);
00039     nop_err_if (ctx->backend == NULL);
00040     nop_err_if (line == NULL);
00041 
00042     memset(&plg, 0, sizeof(ppc_log_get_t));
00043 
00044     plg.bid = ctx->backend->id;
00045     plg.i = i;
00046     plg.line[0] = 0;
00047 
00048     /* send the command request */
00049     dbg_err_if(ppc_write(s->ppc, ctx->pipc, PPC_CMD_LOG_GET, (char*)&plg, 
00050         sizeof(plg)) < 0);
00051 
00052     /* get the response */
00053     dbg_err_if(ppc_read(s->ppc, ctx->pipc, &cmd, (char*)&plg, sizeof(plg)) < 0);
00054 
00055     dbg_err_if(cmd != PPC_CMD_LOG_GET);
00056 
00057     nop_err_if(plg.i < 0); /* error or eof */
00058 
00059     /* copy-out the line */
00060     strncpy(line, plg.line, KLOG_LN_SZ);
00061     line[KLOG_LN_SZ - 1] = 0;
00062 
00063     return 0;
00064 err:
00065     return ~0;
00066 }
00067 
00068 /* [parent] get a log line */
00069 int server_ppc_cb_log_get(ppc_t *ppc, int fd, unsigned char cmd, char *data, 
00070     size_t size, void *vso)
00071 {
00072     server_t *s;
00073     ppc_log_get_t *plg;
00074     backend_t *be;
00075     klog_t *kl;
00076 
00077     u_unused_args(ppc, fd, cmd, size);
00078 
00079     dbg_err_if (vso == NULL);
00080     dbg_err_if (data == NULL);
00081 
00082     plg = (ppc_log_get_t *) data;
00083     s = (server_t *) vso;
00084 
00085     /* by default use server logger */
00086     kl = s->klog;
00087 
00088     /* get the logger obj of the calling backend (if any) */
00089     if(!server_get_backend_by_id(s, plg->bid, &be) && be->klog)
00090         kl = be->klog;
00091 
00092     /* get the log line */
00093     if(kl == NULL || klog_getln(kl, plg->i, plg->line))
00094         plg->i = -1; /* eof or error */
00095 
00096     /* send back the response */
00097     nop_err_if(ppc_write(s->ppc, fd, PPC_CMD_LOG_GET, (char*)plg, 
00098         sizeof(ppc_log_get_t)) < 0);
00099 
00100     return 0;
00101 err:
00102     return ~0;
00103 }
00104 

←Products
© 2005-2006 - KoanLogic S.r.l. - All rights reserved