PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llservice.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 111 lines | 66 code | 10 blank | 35 comment | 8 complexity | 5fd966ca7ffd95ee60d8c3e240e3d7da MD5 | raw file
  1/** 
  2 * @file llservice.cpp
  3 * @author Phoenix
  4 * @date 2005-04-20
  5 *
  6 * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#include "linden_common.h"
 29#include "llservice.h"
 30
 31LLService::creators_t LLService::sCreatorFunctors;
 32
 33LLService::LLService()
 34{
 35}
 36
 37LLService::~LLService()
 38{
 39}
 40
 41// static
 42bool LLService::registerCreator(const std::string& name, creator_t fn)
 43{
 44	llinfos << "LLService::registerCreator(" << name << ")" << llendl;
 45	if(name.empty())
 46	{
 47		return false;
 48	}
 49
 50	creators_t::value_type vt(name, fn);
 51	std::pair<creators_t::iterator, bool> rv = sCreatorFunctors.insert(vt);
 52	return rv.second;
 53
 54	// alternately...
 55	//std::string name_str(name);
 56	//sCreatorFunctors[name_str] = fn;
 57}
 58
 59// static
 60LLIOPipe* LLService::activate(
 61	const std::string& name,
 62	LLPumpIO::chain_t& chain,
 63	LLSD context)
 64{
 65	if(name.empty())
 66	{
 67		llinfos << "LLService::activate - no service specified." << llendl;
 68		return NULL;
 69	}
 70	creators_t::iterator it = sCreatorFunctors.find(name);
 71	LLIOPipe* rv = NULL;
 72	if(it != sCreatorFunctors.end())
 73	{
 74		if((*it).second->build(chain, context))
 75		{
 76			rv = chain[0].get();
 77		}
 78		else
 79		{
 80			// empty out the chain, because failed service creation
 81			// should just discard this stuff.
 82			llwarns << "LLService::activate - unable to build chain: " << name
 83					<< llendl;
 84			chain.clear();
 85		}
 86	}
 87	else
 88	{
 89		llwarns << "LLService::activate - unable find factory: " << name
 90				<< llendl;
 91	}
 92	return rv;
 93}
 94
 95// static
 96bool LLService::discard(const std::string& name)
 97{
 98	if(name.empty())
 99	{
100		return false;
101	}
102	creators_t::iterator it = sCreatorFunctors.find(name);
103	if(it != sCreatorFunctors.end())
104	{
105		//(*it).second->discard();
106		sCreatorFunctors.erase(it);
107		return true;
108	}
109	return false;
110}
111