WvStreams
|
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 00002 * 00003 * XPLC - Cross-Platform Lightweight Components 00004 * Copyright (C) 2000-2003, Pierre Phaneuf 00005 * Copyright (C) 2002, Net Integration Technologies, Inc. 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00020 * USA 00021 */ 00022 00023 #include <stdlib.h> 00024 #include <xplc/utils.h> 00025 #include <xplc/uuidops.h> 00026 #include "statichandler.h" 00027 00028 UUID_MAP_BEGIN(StaticServiceHandler) 00029 UUID_MAP_ENTRY(IObject) 00030 UUID_MAP_ENTRY(IServiceHandler) 00031 UUID_MAP_ENTRY(IStaticServiceHandler) 00032 UUID_MAP_END 00033 00034 StaticServiceHandler::~StaticServiceHandler() { 00035 ObjectNode* node; 00036 ObjectNode* ptr; 00037 00038 node = objects; 00039 00040 while(node) { 00041 ptr = node; 00042 node = node->next; 00043 delete ptr; 00044 } 00045 00046 objects = 0; 00047 } 00048 00049 IObject* StaticServiceHandler::getObject(const UUID& aUuid) { 00050 ObjectNode* node; 00051 00052 node = objects; 00053 00054 while(node) { 00055 if(node->uuid == aUuid) { 00056 node->obj->addRef(); 00057 return node->obj; 00058 } 00059 00060 node = node->next; 00061 } 00062 00063 /* 00064 * No match was found, we return empty-handed. 00065 */ 00066 return 0; 00067 } 00068 00069 void StaticServiceHandler::addObject(const UUID& aUuid, IObject* aObj) { 00070 ObjectNode* node; 00071 00072 /* No object given? */ 00073 if(!aObj) 00074 return; 00075 00076 node = objects; 00077 00078 while(node) { 00079 if(node->uuid == aUuid) 00080 break; 00081 00082 node = node->next; 00083 } 00084 00085 /* 00086 * FIXME: maybe add a "replace" bool parameter? Or would this 00087 * encourage UUID hijacking too much? 00088 */ 00089 if(node) 00090 return; 00091 00092 node = new ObjectNode(aUuid, aObj, objects); 00093 objects = node; 00094 } 00095 00096 void StaticServiceHandler::removeObject(const UUID& aUuid) { 00097 ObjectNode* node; 00098 ObjectNode** ptr; 00099 00100 node = objects; 00101 ptr = &objects; 00102 00103 while(node) { 00104 if(node->uuid == aUuid) { 00105 *ptr = node->next; 00106 delete node; 00107 break; 00108 } 00109 00110 ptr = &node->next; 00111 node = *ptr; 00112 } 00113 }