source: trunk/third/evolution/wombat/wombat-moniker.c @ 18142

Revision 18142, 4.0 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18141, which included commits to RCS files with non-trunk default branches.
Line 
1#include <config.h>
2
3#include <bonobo/bonobo-moniker-simple.h>
4#include <bonobo/bonobo-moniker-util.h>
5#include <bonobo/bonobo-exception.h>
6#include <bonobo/bonobo-storage.h>
7
8#include "wombat-moniker.h"
9
10#include "wombat-interface-check.h"
11
12#define DEFAULT_DB_URL "xmldb:" EVOLUTION_DATADIR "/evolution/config.xmldb"
13#define USER_DB_URL "xmldb:~/evolution/config.xmldb"
14
15#define DB_URL (DEFAULT_DB_URL "#" USER_DB_URL)
16
17static Bonobo_Storage
18wombat_root_storage (CORBA_Environment *ev)
19{
20        static BonoboStorage *root = NULL;
21        char *path;
22
23        if (!root) {
24                path = g_strconcat (g_get_home_dir (), "/evolution/config",
25                                    NULL);
26
27                root = bonobo_storage_open_full (BONOBO_IO_DRIVER_FS, path,
28                                                 Bonobo_Storage_CREATE, 0664,
29                                                 ev);
30               
31                g_free (path);
32
33                if (BONOBO_EX (ev) || !root)
34                        return CORBA_OBJECT_NIL;
35        }
36
37        return BONOBO_OBJREF (root);
38}
39
40static Bonobo_Storage
41wombat_lookup_storage (const char        *name,
42                       CORBA_Environment *ev)
43{
44        Bonobo_Storage root;
45
46        if ((root = wombat_root_storage (ev)) == CORBA_OBJECT_NIL)
47                return CORBA_OBJECT_NIL;               
48       
49        if (!strcmp (name, ""))
50                return bonobo_object_dup_ref (root, ev);
51
52        return Bonobo_Storage_openStorage (root, name, Bonobo_Storage_CREATE,
53                                           ev);
54}
55
56static Bonobo_Storage
57wombat_lookup_stream (const char        *name,
58                      CORBA_Environment *ev)
59{
60        Bonobo_Storage root;
61
62        if (!strcmp (name, "")) {
63                bonobo_exception_set (ev, ex_Bonobo_Storage_NotFound);
64                return CORBA_OBJECT_NIL;
65        }
66
67        if ((root = wombat_root_storage (ev)) == CORBA_OBJECT_NIL)
68                return CORBA_OBJECT_NIL;               
69       
70
71        return Bonobo_Storage_openStream (root, name, Bonobo_Storage_CREATE,
72                                          ev);
73}
74
75static CORBA_Object
76wombat_lookup_db (CORBA_Environment *ev)
77{
78        static CORBA_Object db = CORBA_OBJECT_NIL;
79
80        if (db == CORBA_OBJECT_NIL)
81                db = bonobo_get_object (DB_URL,
82                                        "IDL:Bonobo/ConfigDatabase:1.0", ev);
83
84        bonobo_object_dup_ref (db, ev);
85
86        return db;
87}
88
89static CORBA_Object
90wombat_lookup_interface_check (void)
91{
92        static WombatInterfaceCheck *object = NULL;
93        CORBA_Environment ev;
94        CORBA_Object corba_objref;
95
96        if (object == NULL)
97                object = wombat_interface_check_new ();
98
99        bonobo_object_ref (BONOBO_OBJECT (object));
100
101        CORBA_exception_init (&ev);
102        corba_objref = CORBA_Object_duplicate (BONOBO_OBJREF (object), &ev);
103        CORBA_exception_free (&ev);
104
105        return corba_objref;
106}
107
108static Bonobo_Unknown
109wombat_moniker_resolve (BonoboMoniker               *moniker,
110                        const Bonobo_ResolveOptions *options,
111                        const CORBA_char            *interface,
112                        CORBA_Environment           *ev)
113{
114        CORBA_Object    db;
115        Bonobo_Moniker  parent;
116        const gchar    *name;
117        Bonobo_Storage  storage;
118        Bonobo_Stream   stream;
119
120        parent = bonobo_moniker_get_parent (moniker, ev);
121        if (BONOBO_EX (ev))
122                return CORBA_OBJECT_NIL;
123
124        name = bonobo_moniker_get_name (moniker);
125
126        if (parent != CORBA_OBJECT_NIL) {
127               
128                g_warning ("wombat: parent moniker are not supproted");
129               
130                bonobo_object_release_unref (parent, ev);
131
132                bonobo_exception_set (ev, ex_Bonobo_Moniker_InterfaceNotFound);
133
134                return CORBA_OBJECT_NIL;
135        }
136       
137        if (!strcmp (interface, "IDL:Bonobo/Storage:1.0")) {
138
139                storage = wombat_lookup_storage (name, ev);
140               
141                return storage;
142        }
143
144        if (!strcmp (interface, "IDL:Bonobo/Stream:1.0")) {
145               
146                stream = wombat_lookup_stream (name, ev);
147               
148                return stream;
149        }
150
151        if (!strcmp (interface, "IDL:Bonobo/ConfigDatabase:1.0")) {
152
153                if (strcmp (name, ""))
154                        g_warning ("wombat: unused moniker name");
155
156                if ((db = wombat_lookup_db (ev)) != CORBA_OBJECT_NIL)
157                        return db;
158        }
159
160        if (!strcmp (interface, "IDL:GNOME/Evolution/WombatInterfaceCheck:1.0"))
161                return wombat_lookup_interface_check ();
162
163        bonobo_exception_set (ev, ex_Bonobo_Moniker_InterfaceNotFound);
164        return CORBA_OBJECT_NIL;
165}
166
167BonoboObject *
168wombat_moniker_factory (BonoboGenericFactory *this,
169                        const char           *object_id,
170                        void                 *data)
171{
172        g_return_val_if_fail (object_id != NULL, NULL);
173
174        if (!strcmp (object_id, "OAFIID:Bonobo_Moniker_wombat"))
175
176                return BONOBO_OBJECT (bonobo_moniker_simple_new (
177                        "wombat:", wombat_moniker_resolve));
178
179        else
180                g_warning ("Failing to manufacture a '%s'", object_id);
181
182        return NULL;   
183}
184
Note: See TracBrowser for help on using the repository browser.