PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmessage/llservice.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 185 lines | 68 code | 18 blank | 99 comment | 3 complexity | c0d97d335a32c6ee6df0f7e6a26cf915 MD5 | raw file
  1/** 
  2 * @file llservice.h
  3 * @author Phoenix
  4 * @date 2004-11-21
  5 * @brief Declaration file for LLService and related classes.
  6 *
  7 * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  8 * Second Life Viewer Source Code
  9 * Copyright (C) 2010, Linden Research, Inc.
 10 * 
 11 * This library is free software; you can redistribute it and/or
 12 * modify it under the terms of the GNU Lesser General Public
 13 * License as published by the Free Software Foundation;
 14 * version 2.1 of the License only.
 15 * 
 16 * This library is distributed in the hope that it will be useful,
 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 19 * Lesser General Public License for more details.
 20 * 
 21 * You should have received a copy of the GNU Lesser General Public
 22 * License along with this library; if not, write to the Free Software
 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 24 * 
 25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 26 * $/LicenseInfo$
 27 */
 28
 29#ifndef LL_LLSERVICE_H
 30#define LL_LLSERVICE_H
 31
 32#include <string>
 33#include <map>
 34//#include <boost/intrusive_ptr.hpp>
 35//#include <boost/shared_ptr.hpp>
 36
 37//#include "llframetimer.h"
 38#include "lliopipe.h"
 39#include "llchainio.h"
 40
 41#if 0
 42class LLServiceCreator;
 43/**
 44 * intrusive pointer support
 45 */
 46namespace boost
 47{
 48	void intrusive_ptr_add_ref(LLServiceCreator* p);
 49	void intrusive_ptr_release(LLServiceCreator* p);
 50};
 51#endif
 52
 53/** 
 54 * @class LLServiceCreator
 55 * @brief This class is an abstract base class for classes which create
 56 * new <code>LLService</code> instances.
 57 *
 58 * Derive classes from this class which appropriately implement the
 59 * <code>operator()</code> and destructor.
 60 * @see LLService
 61 */
 62#if 0
 63class LLServiceCreator
 64{
 65public:
 66	typedef boost::intrusive_ptr<LLService> service_t;
 67	virtual ~LLServiceCreator() {}
 68	virtual service_t activate() = 0;
 69	virtual void discard() = 0;
 70
 71protected:
 72	LLServiceCreator() : mReferenceCount(0)
 73	{
 74	}
 75
 76private:
 77	friend void boost::intrusive_ptr_add_ref(LLServiceCreator* p);
 78	friend void boost::intrusive_ptr_release(LLServiceCreator* p);
 79	U32 mReferenceCount;
 80};
 81#endif
 82
 83#if 0
 84namespace boost
 85{
 86	inline void intrusive_ptr_add_ref(LLServiceCreator* p)
 87	{
 88		++p->mReferenceCount;
 89	}
 90	inline void intrusive_ptr_release(LLServiceCreator* p)
 91	{
 92		if(p && 0 == --p->mReferenceCount)
 93		{
 94			delete p;
 95		}
 96	}
 97};
 98#endif
 99
100/** 
101 * @class LLService
102 * @brief This class is the base class for the service classes.
103 * @see LLIOPipe
104 *
105 * The services map a string to a chain factory with a known interface
106 * at the front of the chain. So, to activate a service, call
107 * <code>activate()</code> with the name of the service needed which
108 * will call the associated factory, and return a pointer to the
109 * known interface.
110 * <b>NOTE:</b> If you are implementing a service factory, it is
111 * vitally important that the service pipe is at the front of the
112 * chain.
113 */
114class LLService : public LLIOPipe
115{
116public:
117	//typedef boost::intrusive_ptr<LLServiceCreator> creator_t;
118	//typedef boost::intrusive_ptr<LLService> service_t;
119	typedef boost::shared_ptr<LLChainIOFactory> creator_t;
120
121	/** 
122	 * @brief This method is used to register a protocol name with a
123	 * a functor that creates the service.
124	 *
125	 * THOROUGH_DESCRIPTION
126	 * @param aParameter A brief description of aParameter.
127	 * @return Returns true if a service was successfully registered.
128	 */
129	static bool registerCreator(const std::string& name, creator_t fn);
130
131	/** 
132	 * @brief This method connects to a service by name.
133	 *
134	 * @param name The name of the service to connect to.
135	 * @param chain The constructed chain including the service instance.
136	 * @param context Context for the activation.
137	 * @return An instance of the service for use or NULL on failure.
138	 */
139	static LLIOPipe* activate(
140		const std::string& name,
141		LLPumpIO::chain_t& chain,
142		LLSD context);
143
144	/** 
145	 * @brief 
146	 *
147	 * @param name The name of the service to discard.
148	 * @return true if service creator was found and discarded.
149	 */
150	static bool discard(const std::string& name);
151
152protected:
153	// The creation factory static data.
154	typedef std::map<std::string, creator_t> creators_t;
155	static creators_t sCreatorFunctors;
156
157protected:
158	// construction & destruction. since this class is an abstract
159	// base class, it is up to Service implementations to actually
160	// deal with construction and not a public method. How that
161	// construction takes place will be handled by the service
162	// creators.
163	LLService();
164	virtual ~LLService();
165
166protected:
167	// This frame timer records how long this service has
168	// existed. Useful for derived services to give themselves a
169	// lifetime and expiration.
170	// *NOTE: Phoenix - This functionaity has been moved to the
171	// pump. 2005-12-13
172	//LLFrameTimer mTimer;
173
174	// Since services are designed in an 'ask now, respond later'
175	// idiom which probably crosses thread boundaries, almost all
176	// services will need a handle to a response pipe. It will usually
177	// be the job of the service author to derive a useful
178	// implementation of response, and up to the service subscriber to
179	// further derive that class to do something useful when the
180	// response comes in.
181	LLIOPipe::ptr_t mResponse;
182};
183
184
185#endif // LL_LLSERVICE_H