WvStreams
Main Page
Modules
Classes
Files
File List
File Members
xplc
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
28
UUID_MAP_BEGIN
(
StaticServiceHandler
)
29
UUID_MAP_ENTRY
(
IObject
)
30
UUID_MAP_ENTRY
(
IServiceHandler
)
31
UUID_MAP_ENTRY
(
IStaticServiceHandler
)
32
UUID_MAP_END
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
49
IObject
*
StaticServiceHandler::getObject
(
const
UUID
& aUuid) {
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
96
void
StaticServiceHandler::removeObject
(
const
UUID
& aUuid) {
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
}
Generated on Wed Aug 28 2019 23:57:14 for WvStreams by
1.8.3.1