2 * CORBA/ORBit server side of GLogFunc object, ran by sandbox_parent()
3 * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "server-GLogFunc.h" /* self */
25 #include <glib/gmessages.h>
26 #include "captive/macros.h"
29 static void impl_Captive_GLogFunc_g_log_func
30 (impl_POA_Captive_GLogFunc *servant,const Captive_GLogMessage *g_log_message,CORBA_Environment *ev);
32 static PortableServer_ServantBase__epv impl_Captive_GLogFunc_base_epv={
33 NULL, /* _private data */
34 NULL, /* finalize routine */
35 NULL, /* default_POA routine */
37 static POA_Captive_GLogFunc__epv impl_Captive_GLogFunc_epv={
39 (gpointer)&impl_Captive_GLogFunc_g_log_func,
41 static POA_Captive_GLogFunc__vepv impl_Captive_GLogFunc_vepv={
42 &impl_Captive_GLogFunc_base_epv,
43 &impl_Captive_GLogFunc_epv,
47 Captive_GLogFunc impl_Captive_GLogFunc__create(PortableServer_POA poa,CORBA_Environment *ev)
49 Captive_GLogFunc retval;
50 impl_POA_Captive_GLogFunc *newservant;
51 PortableServer_ObjectId *objid;
53 captive_new0(newservant); /* FIXME: leak */
54 newservant->servant.vepv=&impl_Captive_GLogFunc_vepv;
56 POA_Captive_GLogFunc__init((PortableServer_Servant)newservant,ev);
57 objid=PortableServer_POA_activate_object(poa,newservant,ev);
59 retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
65 void impl_Captive_GLogFunc__destroy(impl_POA_Captive_GLogFunc *servant,CORBA_Environment *ev)
67 PortableServer_ObjectId *objid;
69 objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
70 PortableServer_POA_deactivate_object(servant->poa,objid,ev);
72 POA_Captive_GLogFunc__fini((PortableServer_Servant)servant,ev);
77 static void impl_Captive_GLogFunc_g_log_func
78 (impl_POA_Captive_GLogFunc *servant,const Captive_GLogMessage *g_log_message,CORBA_Environment *ev)
80 GLogLevelFlags log_level_use;
83 log_level_use=g_log_message->log_level;
84 /* Downgrade always-fatal 'ERROR' to 'CRITICAL' level */
85 if (log_level_use&G_LOG_LEVEL_ERROR) {
86 log_level_use=(log_level_use|G_LOG_LEVEL_CRITICAL)&~G_LOG_LEVEL_ERROR;
89 if (log_level_use&G_LOG_FLAG_FATAL) {
90 log_level_use&=~G_LOG_FLAG_FATAL;
94 g_log(G_LOG_DOMAIN,log_level_use,"sandbox: %s%s",(!fatal ? "" : "FATAL: "),g_log_message->message);
98 static void impl_Captive_Vfs_init_g_log_func_log_func
99 (const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,const Captive_GLogFunc obj /* user_data */)
101 CORBA_Environment ev;
102 Captive_GLogMessage g_log_message;
104 CORBA_exception_init(&ev);
105 g_log_message.log_level=log_level;
106 g_log_message.message=(CORBA_string)message;
107 Captive_GLogFunc_g_log_func(obj,&g_log_message,&ev);
108 g_assert(validate_CORBA_Environment(&ev));
109 CORBA_exception_free(&ev);
113 static gboolean impl_Captive_Vfs_init_g_log_func_handled=FALSE;
114 static guint impl_Captive_Vfs_init_g_log_func_handler_id;
115 static Captive_GLogFunc g_log_func_copy;
118 /* We MUST NOT touch 'captive_options' as it may not be initialized yet
120 void impl_Captive_Vfs_init_g_log_func(const Captive_GLogFunc g_log_func,gboolean debug_messages,CORBA_Environment *ev)
122 g_assert(impl_Captive_Vfs_init_g_log_func_handled==FALSE);
124 g_log_func_copy=CORBA_Object_duplicate(g_log_func,ev);
125 if (ev->_major!=CORBA_NO_EXCEPTION)
128 impl_Captive_Vfs_init_g_log_func_handler_id=g_log_set_handler(
129 G_LOG_DOMAIN, /* log_domain; "Captive" */
131 | 0 /* !G_LOG_FLAG_RECURSION */
133 | (G_LOG_LEVEL_MASK & ~(debug_messages ? 0 : 0
134 /* The same mask is in:
135 * libcaptive/sandbox/server-GLogFunc.c
136 * libcaptive/client/init.c
137 * libcaptive/client/vfs.c
139 | G_LOG_LEVEL_MESSAGE
141 | G_LOG_LEVEL_DEBUG)),
142 (GLogFunc)impl_Captive_Vfs_init_g_log_func_log_func, /* log_func */
143 (gpointer)g_log_func_copy); /* user_data */
145 impl_Captive_Vfs_init_g_log_func_handled=TRUE;
149 /* Called during child shutdown where our CORBA peer is no longer responding. */
150 void impl_Captive_Vfs_init_g_log_func_disable(void)
152 CORBA_Environment ev;
154 if (!impl_Captive_Vfs_init_g_log_func_handled)
157 g_log_remove_handler(
158 G_LOG_DOMAIN, /* log_domain; "Captive" */
159 impl_Captive_Vfs_init_g_log_func_handler_id); /* handler_id */
160 CORBA_exception_init(&ev);
161 CORBA_Object_release(g_log_func_copy,&ev);
162 g_assert(validate_CORBA_Environment(&ev));
163 CORBA_exception_free(&ev);
165 impl_Captive_Vfs_init_g_log_func_handled=FALSE;