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"
27 #include <libxml/tree.h>
28 #include "../client/vfs-parent.h"
31 static void impl_Captive_GLogFunc_g_log_func
32 (impl_POA_Captive_GLogFunc *servant,const Captive_GLogMessage *g_log_message,CORBA_Environment *ev);
34 static PortableServer_ServantBase__epv impl_Captive_GLogFunc_base_epv={
35 NULL, /* _private data */
36 NULL, /* finalize routine */
37 NULL, /* default_POA routine */
39 static POA_Captive_GLogFunc__epv impl_Captive_GLogFunc_epv={
41 (gpointer)&impl_Captive_GLogFunc_g_log_func,
43 static POA_Captive_GLogFunc__vepv impl_Captive_GLogFunc_vepv={
44 &impl_Captive_GLogFunc_base_epv,
45 &impl_Captive_GLogFunc_epv,
49 Captive_GLogFunc impl_Captive_GLogFunc__create
50 (PortableServer_POA poa,CaptiveVfsParentObject *captive_vfs_parent_object,CORBA_Environment *ev)
52 Captive_GLogFunc retval;
53 impl_POA_Captive_GLogFunc *newservant;
54 PortableServer_ObjectId *objid;
56 captive_new0(newservant); /* FIXME: leak */
57 newservant->servant.vepv=&impl_Captive_GLogFunc_vepv;
59 newservant->captive_vfs_parent_object=captive_vfs_parent_object;
60 POA_Captive_GLogFunc__init((PortableServer_Servant)newservant,ev);
61 objid=PortableServer_POA_activate_object(poa,newservant,ev);
63 retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
69 void impl_Captive_GLogFunc__destroy(impl_POA_Captive_GLogFunc *servant,CORBA_Environment *ev)
71 PortableServer_ObjectId *objid;
73 objid=PortableServer_POA_servant_to_id(servant->poa,servant,ev);
74 PortableServer_POA_deactivate_object(servant->poa,objid,ev);
76 POA_Captive_GLogFunc__fini((PortableServer_Servant)servant,ev);
81 static void impl_Captive_GLogFunc_g_log_func
82 (impl_POA_Captive_GLogFunc *servant,const Captive_GLogMessage *g_log_message,CORBA_Environment *ev)
84 GLogLevelFlags log_level_use;
85 static const struct level_map {
86 GLogLevelFlags from,to;
89 /* Downgrade always-fatal 'ERROR' to 'CRITICAL' level */
90 { G_LOG_LEVEL_ERROR ,G_LOG_LEVEL_CRITICAL,"error" },
91 { G_LOG_LEVEL_CRITICAL,G_LOG_LEVEL_CRITICAL,"critical" },
92 { G_LOG_LEVEL_WARNING ,G_LOG_LEVEL_WARNING ,"warning" },
93 { G_LOG_LEVEL_MESSAGE ,G_LOG_LEVEL_MESSAGE ,"message" },
94 { G_LOG_LEVEL_INFO ,G_LOG_LEVEL_INFO ,"info" },
95 { G_LOG_LEVEL_DEBUG ,G_LOG_LEVEL_DEBUG ,"debug" },
97 static const struct flag_map {
98 GLogLevelFlags from,to;
101 { G_LOG_FLAG_RECURSION,G_LOG_FLAG_RECURSION,"recursion" },
102 { G_LOG_FLAG_FATAL ,0 ,"fatal" },
104 const struct level_map *levelp;
105 const struct flag_map *flagp;
107 for (levelp=level_map;levelp<level_map+G_N_ELEMENTS(level_map);levelp++) {
108 log_level_use=g_log_message->log_level;
109 if (!(g_log_message->log_level & levelp->from))
112 xmlNode *xml_message=NULL;
114 if (servant->captive_vfs_parent_object->corba_bug_log) {
115 xml_message=xmlNewTextChild(servant->captive_vfs_parent_object->corba_bug_log,NULL,BAD_CAST "message",BAD_CAST g_log_message->message);
116 xmlNewProp(xml_message,BAD_CAST "level",BAD_CAST levelp->name);
119 log_level_use&=~levelp->from;
120 log_level_use|= levelp->to;
121 for (flagp=flag_map;flagp<flag_map+G_N_ELEMENTS(flag_map);flagp++) {
122 if (!(g_log_message->log_level & flagp->from))
124 log_level_use&=~flagp->from;
125 log_level_use|= flagp->to;
127 xmlNewProp(xml_message,BAD_CAST flagp->name,BAD_CAST flagp->name);
130 g_log(G_LOG_DOMAIN,log_level_use,"sandbox: %s%s",
131 (!(g_log_message->log_level & G_LOG_FLAG_FATAL) ? "" : "FATAL: "),
132 g_log_message->message);
137 static void impl_Captive_Vfs_init_g_log_func_log_func
138 (const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,const Captive_GLogFunc obj /* user_data */)
140 CORBA_Environment ev;
141 Captive_GLogMessage g_log_message;
143 CORBA_exception_init(&ev);
144 g_log_message.log_level=log_level;
145 g_log_message.message=(CORBA_string)message;
146 Captive_GLogFunc_g_log_func(obj,&g_log_message,&ev);
147 g_assert(validate_CORBA_Environment(&ev));
148 CORBA_exception_free(&ev);
152 static gboolean impl_Captive_Vfs_init_g_log_func_handled=FALSE;
153 static guint impl_Captive_Vfs_init_g_log_func_handler_id;
154 static Captive_GLogFunc g_log_func_copy;
157 /* We MUST NOT touch 'captive_options' as it may not be initialized yet
159 void impl_Captive_Vfs_init_g_log_func(const Captive_GLogFunc g_log_func,gboolean debug_messages,CORBA_Environment *ev)
161 g_assert(impl_Captive_Vfs_init_g_log_func_handled==FALSE);
163 g_log_func_copy=CORBA_Object_duplicate(g_log_func,ev);
164 if (ev->_major!=CORBA_NO_EXCEPTION)
167 impl_Captive_Vfs_init_g_log_func_handler_id=g_log_set_handler(
168 G_LOG_DOMAIN, /* log_domain; "Captive" */
170 | 0 /* !G_LOG_FLAG_RECURSION */
172 | (G_LOG_LEVEL_MASK & ~(debug_messages ? 0 : 0
173 /* The same mask is in:
174 * libcaptive/sandbox/server-GLogFunc.c
175 * libcaptive/client/init.c
177 | G_LOG_LEVEL_MESSAGE
179 | G_LOG_LEVEL_DEBUG)),
180 (GLogFunc)impl_Captive_Vfs_init_g_log_func_log_func, /* log_func */
181 (gpointer)g_log_func_copy); /* user_data */
183 impl_Captive_Vfs_init_g_log_func_handled=TRUE;
187 /* Called during child shutdown where our CORBA peer is no longer responding. */
188 void impl_Captive_Vfs_init_g_log_func_disable(void)
190 CORBA_Environment ev;
192 if (!impl_Captive_Vfs_init_g_log_func_handled)
195 g_log_remove_handler(
196 G_LOG_DOMAIN, /* log_domain; "Captive" */
197 impl_Captive_Vfs_init_g_log_func_handler_id); /* handler_id */
198 CORBA_exception_init(&ev);
199 CORBA_Object_release(g_log_func_copy,&ev);
200 g_assert(validate_CORBA_Environment(&ev));
201 CORBA_exception_free(&ev);
203 impl_Captive_Vfs_init_g_log_func_handled=FALSE;