dd68980ced561cadc105143df89b9a2f4e7e27aa
[captive.git] / src / libcaptive / sandbox / server-GlibLogFunc.c
1 /* $Id$
2  * CORBA/ORBit server side of GlibLogFunc object, ran by sandbox_parent()
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
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
8  * 
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.
13  * 
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
17  */
18
19
20 #include "config.h"
21
22 #include "server-GlibLogFunc.h" /* self */
23 #include "sandbox.h"
24 #include "split.h"
25 #include <glib/gmessages.h>
26 #include "captive/macros.h"
27
28
29 typedef struct {
30         POA_Captive_GlibLogFunc servant;
31         PortableServer_POA poa;
32         } impl_POA_Captive_GlibLogFunc;
33
34 static void impl_Captive_GlibLogFunc_glibLogFunc
35                 (impl_POA_Captive_GlibLogFunc *servant,const Captive_GlibLogMessage *glib_log_message,CORBA_Environment *ev);
36
37 static PortableServer_ServantBase__epv impl_Captive_GlibLogFunc_base_epv={
38         NULL,   /* _private data */
39         NULL,   /* finalize routine */
40         NULL,   /* default_POA routine */
41         };
42 static POA_Captive_GlibLogFunc__epv impl_Captive_GlibLogFunc_epv={
43         NULL,   /* _private */
44         (gpointer)&impl_Captive_GlibLogFunc_glibLogFunc,
45         };
46 static POA_Captive_GlibLogFunc__vepv impl_Captive_GlibLogFunc_vepv={
47         &impl_Captive_GlibLogFunc_base_epv,
48         &impl_Captive_GlibLogFunc_epv,
49         };
50
51
52 Captive_GlibLogFunc impl_Captive_GlibLogFunc__create(PortableServer_POA poa,CORBA_Environment *ev)
53 {
54 Captive_GlibLogFunc retval;
55 impl_POA_Captive_GlibLogFunc *newservant;
56 PortableServer_ObjectId *objid;
57
58         captive_new0(newservant);       /* FIXME: leak */
59         newservant->servant.vepv=&impl_Captive_GlibLogFunc_vepv;
60         newservant->poa=poa;
61         POA_Captive_GlibLogFunc__init((PortableServer_Servant)newservant,ev);
62         objid=PortableServer_POA_activate_object(poa,newservant,ev);
63         CORBA_free(objid);
64         retval=PortableServer_POA_servant_to_reference(poa,newservant,ev);
65
66         return retval;
67 }
68
69
70 static void impl_Captive_GlibLogFunc_glibLogFunc
71                 (impl_POA_Captive_GlibLogFunc *servant,const Captive_GlibLogMessage *glib_log_message,CORBA_Environment *ev)
72 {
73         g_log(G_LOG_DOMAIN,glib_log_message->log_level,"%s",glib_log_message->message);
74 }
75
76
77 static void impl_Captive_Vfs_registerGlibLogFunc_log_func
78                 (const gchar *log_domain,GLogLevelFlags log_level,const gchar *message,const Captive_GlibLogFunc obj /* user_data */)
79 {
80 CORBA_Environment ev;
81 Captive_GlibLogMessage glib_log_message;
82
83         /* Init 'ev' */
84         CORBA_exception_init(&ev);
85
86         glib_log_message.log_level=log_level;
87         glib_log_message.message=(CORBA_string)message;
88         Captive_GlibLogFunc_glibLogFunc(obj,&glib_log_message,&ev);
89         g_assert(validate_CORBA_Environment(&ev));
90
91         /* Shutdown 'ev' */
92         CORBA_exception_free(&ev);
93 }
94
95
96 void impl_Captive_Vfs_registerGlibLogFunc
97                 (impl_POA_Captive_Vfs *servant,const Captive_GlibLogFunc glib_log_func,CORBA_Environment *ev)
98 {
99         g_log_set_handler(
100                         G_LOG_DOMAIN,   /* log_domain; "Captive" */
101                         0       /* log_levels */
102                                         | 0 /* !G_LOG_FLAG_RECURSION */
103                                         | G_LOG_FLAG_FATAL
104                                         | G_LOG_LEVEL_MASK,
105                         (GLogFunc)impl_Captive_Vfs_registerGlibLogFunc_log_func,        /* log_func */
106                         (gpointer)glib_log_func);       /* user_data */
107 }