WvStreams
monikers.cc
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 *
3 * XPLC - Cross-Platform Lightweight Components
4 * Copyright (C) 2002, Net Integration Technologies, Inc.
5 * Copyright (C) 2002-2003, Pierre Phaneuf
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22
23#include <xplc/core.h>
24#include <xplc/utils.h>
25#include "monikers.h"
26
27#define MONIKER_SEPARATOR_CHAR ':'
28
34
35MonikerService::~MonikerService() {
36 MonikerNode* node;
37 MonikerNode* ptr;
38
39 node = monikers;
40
41 while(node) {
42 ptr = node;
43 node = node->next;
44 delete ptr;
45 }
46
47 monikers = 0;
48}
49
50IObject* MonikerService::resolve(const char* aName) {
51 MonikerNode* node;
52 IServiceManager* servmgr;
53 IObject* obj = 0;
54 IMoniker* moniker;
55 char* name = strdup(aName);
56 char* rest = strchr(name, MONIKER_SEPARATOR_CHAR);
57
58 node = monikers;
59
60 if(rest) {
61 *rest = 0;
62 ++rest;
63 }
64
65 while(node) {
66 if(strcmp(name, node->name) == 0) {
67 servmgr = XPLC_getServiceManager();
68 if(!servmgr)
69 break;
70
71 obj = servmgr->getObject(node->uuid);
72 servmgr->release();
73
74 if(rest) {
75 moniker = mutate<IMoniker>(obj);
76 if(moniker) {
77 obj = moniker->resolve(rest);
78 moniker->release();
79 } else
80 obj = 0;
81 }
82
83 break;
84 }
85
86 node = node->next;
87 }
88
89 free(name);
90
91 return obj;
92}
93
94void MonikerService::registerObject(const char* aName, const UUID& aUuid) {
95 MonikerNode* node;
96
97 /*
98 * FIXME: we should do something about registering a name that
99 * contains the separator character.
100 */
101
102 node = monikers;
103
104 while(node) {
105 if(strcmp(aName, node->name) == 0)
106 break;
107
108 node = node->next;
109 }
110
111 /*
112 * FIXME: maybe add a "replace" bool parameter? Or would this
113 * encourage moniker hijacking too much?
114 */
115 if(node)
116 return;
117
118 node = new MonikerNode(aName, aUuid, monikers);
119 monikers = node;
120}
121
An interface for registering objects so they can be retrieved using a moniker.
An interface for obtaining an IObject given a moniker string.
Definition: IMoniker.h:50
virtual IObject * resolve(const char *moniker)=0
Given a moniker string, return the IObject it refers to, or NULL if no objects match.
The basic interface which is included by all other XPLC interfaces and objects.
Definition: IObject.h:65
virtual unsigned int release()=0
Indicate that you are finished using this object.
virtual IObject * getObject(const UUID &)=0
Get the object corresponding to the given UUID.
The XPLC service manager interface.
virtual IObject * resolve(const char *)
Given a moniker string, return the IObject it refers to, or NULL if no objects match.
Definition: monikers.cc:50
virtual void registerObject(const char *, const UUID &)
Register an object to be retrieved with a moniker.
Definition: monikers.cc:94
The structure underlying UUIDs.
Definition: uuid.h:94
Various utility functions, macros and templates.
#define UUID_MAP_END
Marks the end of an interface map.
Definition: utils.h:80
#define UUID_MAP_BEGIN(component)
Start the interface map for "component".
Definition: utils.h:63
#define UUID_MAP_ENTRY(iface)
Add an entry to an interface map.
Definition: utils.h:68