"Fossies" - the Fresh Open Source Software archive 
Member "evolution-brutus-1.2.35/log/brutus-log_impl.c" of archive evolution-brutus-1.2.35.tar.gz:
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Servant implementation file for a Brutus log daemon.
* Copyright (C) 2007 OMC Denmark ApS.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*/
#include <glib.h>
#include "brutus-log.h"
#include "brutus-logd.h"
static inline size_t
corba_strlen(const CORBA_char *s)
{
size_t l = 0;
for (; (CORBA_char)'\0' != *s; s++, l++)
;
return l;
}
static int
open_log(void)
{
int fd = -1;
const char *log_file_name = NULL;
char *log_file_path = NULL;
log_file_name = getenv("BRUTUS_LOG_FILE_NAME");
if (!log_file_name)
log_file_name = BRUTUS_LOG_FILE;
log_file_path = g_strconcat(getenv("HOME"), "/", BRUTUS_LOGD_DIR_NAME, "/", log_file_name, NULL);
if (!log_file_path)
return -1;
fd = g_open(log_file_path, O_CREAT | O_APPEND | O_WRONLY | O_SYNC, S_IRUSR | S_IWUSR);
g_free(log_file_path);
return fd;
}
/*** App-specific servant structures ***/
#if !defined(_typedef_impl_POA_BRUTUS_BrutusLog_)
#define _typedef_impl_POA_BRUTUS_BrutusLog_ 1
typedef struct {
POA_BRUTUS_BrutusLog servant;
PortableServer_POA poa;
/* ------ add private attributes here ------ */
int log_fd;
/* ------ ---------- end ------------ ------ */
} impl_POA_BRUTUS_BrutusLog;
#endif
/*** Implementation stub prototypes ***/
#if !defined(_decl_impl_BRUTUS_BrutusLog__destroy_)
#define _decl_impl_BRUTUS_BrutusLog__destroy_ 1
static void impl_BRUTUS_BrutusLog__destroy(impl_POA_BRUTUS_BrutusLog *servant,
CORBA_Environment *ev);
#endif
#if !defined(_decl_impl_BRUTUS_BrutusLog_commit_)
#define _decl_impl_BRUTUS_BrutusLog_commit_ 1
static void
impl_BRUTUS_BrutusLog_commit(impl_POA_BRUTUS_BrutusLog *servant,
const CORBA_char * log_entry,
CORBA_Environment *ev);
#endif
/*** epv structures ***/
#if !defined(_impl_BRUTUS_BrutusLog_base_epv_)
#define _impl_BRUTUS_BrutusLog_base_epv_ 1
static PortableServer_ServantBase__epv impl_BRUTUS_BrutusLog_base_epv = {
NULL, /* private data */
(gpointer) & impl_BRUTUS_BrutusLog__destroy, /* finalize routine */
NULL, /* default_POA routine */
};
#endif
#if !defined(_impl_BRUTUS_BrutusLog_epv_)
#define _impl_BRUTUS_BrutusLog_epv_ 1
static POA_BRUTUS_BrutusLog__epv impl_BRUTUS_BrutusLog_epv = {
NULL, /* _private */
(gpointer)&impl_BRUTUS_BrutusLog_commit,
};
#endif
/*** vepv structures ***/
#if !defined(_impl_BRUTUS_BrutusLog_vepv_)
#define _impl_BRUTUS_BrutusLog_vepv_ 1
static POA_BRUTUS_BrutusLog__vepv impl_BRUTUS_BrutusLog_vepv = {
&impl_BRUTUS_BrutusLog_base_epv,
&impl_BRUTUS_BrutusLog_epv,
};
#endif
/*** Stub implementations ***/
#if !defined(_impl_BRUTUS_BrutusLog__create_)
#define _impl_BRUTUS_BrutusLog__create_ 1
static BRUTUS_BrutusLog impl_BRUTUS_BrutusLog__create(PortableServer_POA poa, CORBA_Environment *ev)
{
BRUTUS_BrutusLog retval;
impl_POA_BRUTUS_BrutusLog *newservant;
PortableServer_ObjectId *objid;
newservant = g_new0(impl_POA_BRUTUS_BrutusLog, 1);
newservant->servant.vepv = &impl_BRUTUS_BrutusLog_vepv;
newservant->poa = (PortableServer_POA) CORBA_Object_duplicate((CORBA_Object)poa, ev);
POA_BRUTUS_BrutusLog__init((PortableServer_Servant)newservant, ev);
/* ------ init private attributes here ------ */
newservant->log_fd = open_log();
g_assert(-1 != newservant->log_fd);
/* ------ ---------- end ------------- ------ */
objid = PortableServer_POA_activate_object(poa, newservant, ev);
CORBA_free(objid);
retval = PortableServer_POA_servant_to_reference(poa, newservant, ev);
return retval;
}
#endif
#if !defined(_impl_BRUTUS_BrutusLog__destroy_)
#define _impl_BRUTUS_BrutusLog__destroy_ 1
static void
impl_BRUTUS_BrutusLog__destroy(impl_POA_BRUTUS_BrutusLog *servant, CORBA_Environment *ev)
{
CORBA_Object_release ((CORBA_Object)servant->poa, ev);
/* No further remote method calls are delegated to
* servant and you may free your private attributes. */
/* ------ free private attributes here ------ */
close(servant->log_fd);
/* ------ ---------- end ------------- ------ */
POA_BRUTUS_BrutusLog__fini((PortableServer_Servant)servant, ev);
g_free (servant);
}
#endif
#if !defined(_impl_BRUTUS_BrutusLog_commit_)
#define _impl_BRUTUS_BrutusLog_commit_ 1
static void
impl_BRUTUS_BrutusLog_commit(impl_POA_BRUTUS_BrutusLog *servant,
const CORBA_char *log_entry,
CORBA_Environment *ev)
{
while (!g_mutex_trylock(log_mutex))
g_usleep(10);
if (-1 == write(servant->log_fd, (const void*)log_entry, corba_strlen(log_entry)+sizeof(CORBA_char)))
; // to avoid compiler warning
fdatasync(servant->log_fd);
g_mutex_unlock(log_mutex);
}
#endif