WvStreams
statichandler.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) 2000-2003, Pierre Phaneuf
5  * Copyright (C) 2002, Net Integration Technologies, Inc.
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 <stdlib.h>
24 #include <xplc/utils.h>
25 #include <xplc/uuidops.h>
26 #include "statichandler.h"
27 
33 
34 StaticServiceHandler::~StaticServiceHandler() {
35  ObjectNode* node;
36  ObjectNode* ptr;
37 
38  node = objects;
39 
40  while(node) {
41  ptr = node;
42  node = node->next;
43  delete ptr;
44  }
45 
46  objects = 0;
47 }
48 
50  ObjectNode* node;
51 
52  node = objects;
53 
54  while(node) {
55  if(node->uuid == aUuid) {
56  node->obj->addRef();
57  return node->obj;
58  }
59 
60  node = node->next;
61  }
62 
63  /*
64  * No match was found, we return empty-handed.
65  */
66  return 0;
67 }
68 
69 void StaticServiceHandler::addObject(const UUID& aUuid, IObject* aObj) {
70  ObjectNode* node;
71 
72  /* No object given? */
73  if(!aObj)
74  return;
75 
76  node = objects;
77 
78  while(node) {
79  if(node->uuid == aUuid)
80  break;
81 
82  node = node->next;
83  }
84 
85  /*
86  * FIXME: maybe add a "replace" bool parameter? Or would this
87  * encourage UUID hijacking too much?
88  */
89  if(node)
90  return;
91 
92  node = new ObjectNode(aUuid, aObj, objects);
93  objects = node;
94 }
95 
97  ObjectNode* node;
98  ObjectNode** ptr;
99 
100  node = objects;
101  ptr = &objects;
102 
103  while(node) {
104  if(node->uuid == aUuid) {
105  *ptr = node->next;
106  delete node;
107  break;
108  }
109 
110  ptr = &node->next;
111  node = *ptr;
112  }
113 }
IStaticServiceHandler
Service handler for statically linked components.
Definition: IStaticServiceHandler.h:36
UUID_MAP_ENTRY
#define UUID_MAP_ENTRY(iface)
Add an entry to an interface map.
Definition: utils.h:68
UUID_MAP_BEGIN
#define UUID_MAP_BEGIN(component)
Start the interface map for "component".
Definition: utils.h:63
IServiceHandler
Definition: IServiceHandler.h:43
utils.h
StaticServiceHandler::addObject
virtual void addObject(const UUID &, IObject *)
Adds an object to the static service handler.
Definition: statichandler.cc:69
UUID_MAP_END
#define UUID_MAP_END
Marks the end of an interface map.
Definition: utils.h:80
IObject
Definition: IObject.h:65
StaticServiceHandler::getObject
virtual IObject * getObject(const UUID &)
Get the object corresponding to the given UUID.
Definition: statichandler.cc:49
StaticServiceHandler
Definition: statichandler.h:28
StaticServiceHandler::removeObject
virtual void removeObject(const UUID &)
Removes an object from the static service handler.
Definition: statichandler.cc:96
_GUID
The structure underlying UUIDs.
Definition: uuid.h:94
IObject::addRef
virtual unsigned int addRef()=0
Indicate you are using this object.
ObjectNode
Definition: objectnode.h:27