WvStreams
xplc.cc
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * XPLC - Cross-Platform Lightweight Components
00004  * Copyright (C) 2002-2004, Net Integration Technologies, Inc.
00005  * Copyright (C) 2003-2004, Pierre Phaneuf
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  * As a special exception, you may use this file as part of a free
00023  * software library without restriction.  Specifically, if other files
00024  * instantiate templates or use macros or inline functions from this
00025  * file, or you compile this file and link it with other files to
00026  * produce an executable, this file does not by itself cause the
00027  * resulting executable to be covered by the GNU Lesser General Public
00028  * License.  This exception does not however invalidate any other
00029  * reasons why the executable file might be covered by the GNU Lesser
00030  * General Public License.
00031  */
00032 
00033 #include <xplc/IMoniker.h>
00034 #include <xplc/IFactory.h>
00035 #include <xplc/IModuleManagerFactory.h>
00036 #include <xplc/xplc.h>
00037 #include <xplc/ptr.h>
00038 
00039 void XPLC::addModuleDirectory(const char* directory) {
00040   xplc_ptr<IModuleManagerFactory> factory(get<IModuleManagerFactory>(XPLC_moduleManagerFactory));
00041 
00042   if(!factory)
00043     return;
00044 
00045   xplc_ptr<IServiceHandler> modulemgr(factory->createModuleManager(directory));
00046 
00047   if(!modulemgr)
00048     return;
00049 
00050   servmgr->addHandler(modulemgr);
00051 }
00052 
00053 IObject* XPLC::create(const UUID& cid) {
00054   if(!servmgr)
00055     return 0;
00056 
00057   xplc_ptr<IFactory> factory(mutate<IFactory>(servmgr->getObject(cid)));
00058 
00059   if(!factory)
00060     return 0;
00061 
00062   return factory->createObject();
00063 }
00064 
00065 IObject* XPLC::create(const char* aMoniker) {
00066   if(!servmgr)
00067     return 0;
00068 
00069   xplc_ptr<IMoniker> moniker(mutate<IMoniker>(servmgr->getObject(XPLC_monikers)));
00070   if(!moniker)
00071     return 0;
00072 
00073   xplc_ptr<IFactory> factory(mutate<IFactory>(moniker->resolve(aMoniker)));
00074   if(!factory)
00075     return 0;
00076 
00077   return factory->createObject();
00078 }
00079 
00080