- rcf-09c.zip
- RCF-0.9c
- demo
- vs2003
- RCF
- include
- RCF
- SF
- license.txt
- src
- RCF
- SF
- test
- rcf-04.zip
- RCF-0.4
- demo
- vs2003
- RCF
- doc
- html
- latex
- include
- RCF
- SF
- license.txt
- src
- RCF
- SF
- test
- vs2003
- RCF
- RCF.sln
- RCF
- RCF.vcproj
- RCFTest
- client.pem
- RCFTest.vcproj
- server.pem
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>RCF: RcfServer.hpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.5 -->
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li id="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="dirs.html"><span>Directories</span></a></li>
</ul></div>
<div class="nav">
<a class="el" href="dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2F.html">include</a> » <a class="el" href="dir_G_3A_2FDevelopment_2Fbuild_2Fscripts_2Fwin_2FBuildRcf2_5FOutput_2FRCF_2D0_2E4_2Finclude_2FRCF_2F.html">RCF</a></div>
<h1>RcfServer.hpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="comment">//*****************************************************************************</span>
<a name="l00003"></a>00003 <span class="comment">// RCF - Remote Call Framework</span>
<a name="l00004"></a>00004 <span class="comment">// Copyright (c) 2005. All rights reserved.</span>
<a name="l00005"></a>00005 <span class="comment">// Developed by Jarl Lindrud.</span>
<a name="l00006"></a>00006 <span class="comment">// Contact: jlindrud@hotmail.com .</span>
<a name="l00007"></a>00007 <span class="comment">//*****************************************************************************</span>
<a name="l00008"></a>00008
<a name="l00009"></a>00009 <span class="preprocessor">#ifndef INCLUDE_RCF_RCFSERVER_HPP</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span><span class="preprocessor">#define INCLUDE_RCF_RCFSERVER_HPP</span>
<a name="l00011"></a>00011 <span class="preprocessor"></span>
<a name="l00012"></a>00012 <span class="preprocessor">#include <deque></span>
<a name="l00013"></a>00013 <span class="preprocessor">#include <map></span>
<a name="l00014"></a>00014 <span class="preprocessor">#include <memory></span>
<a name="l00015"></a>00015 <span class="preprocessor">#include <string></span>
<a name="l00016"></a>00016 <span class="preprocessor">#include <vector></span>
<a name="l00017"></a>00017
<a name="l00018"></a>00018 <span class="preprocessor">#include <boost/bind.hpp></span>
<a name="l00019"></a>00019 <span class="preprocessor">#include <boost/function.hpp></span>
<a name="l00020"></a>00020 <span class="preprocessor">#include <boost/noncopyable.hpp></span>
<a name="l00021"></a>00021 <span class="preprocessor">#include <boost/shared_ptr.hpp></span>
<a name="l00022"></a>00022 <span class="preprocessor">#include <boost/weak_ptr.hpp></span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="preprocessor">#include <RCF/CheckRtti.hpp></span>
<a name="l00025"></a>00025 <span class="preprocessor">#include <RCF/GetInterfaceName.hpp></span>
<a name="l00026"></a>00026 <span class="preprocessor">#include <RCF/ServerTransport.hpp></span>
<a name="l00027"></a>00027 <span class="preprocessor">#include <RCF/ThreadLibrary.hpp></span>
<a name="l00028"></a>00028
<a name="l00029"></a>00029 <span class="keyword">namespace </span>RCF {
<a name="l00030"></a>00030
<a name="l00031"></a>00031 <span class="keyword">class </span>I_ServerTransport;
<a name="l00032"></a>00032 <span class="keyword">class </span>StubEntry;
<a name="l00033"></a>00033 <span class="keyword">class </span>I_Service;
<a name="l00034"></a>00034 <span class="keyword">class </span>I_Session;
<a name="l00035"></a>00035 <span class="keyword">class </span>Session;
<a name="l00036"></a>00036 <span class="keyword">class </span>I_Endpoint;
<a name="l00037"></a>00037 <span class="keyword">class </span>I_StubEntryLookupProvider;
<a name="l00038"></a>00038 <span class="keyword">class </span>I_FilterFactoryLookupProvider;
<a name="l00039"></a>00039 <span class="keyword">class </span>I_RcfClient;
<a name="l00040"></a>00040
<a name="l00041"></a>00041 <span class="keyword">typedef</span> boost::shared_ptr<I_ServerTransport> ServerTransportPtr;
<a name="l00042"></a>00042 <span class="keyword">typedef</span> boost::shared_ptr<I_Proactor> ProactorPtr;
<a name="l00043"></a>00043 <span class="keyword">typedef</span> boost::shared_ptr<StubEntry> StubEntryPtr;
<a name="l00044"></a>00044 <span class="keyword">typedef</span> boost::shared_ptr<I_Service> ServicePtr;
<a name="l00045"></a>00045 <span class="keyword">typedef</span> boost::shared_ptr<Session> SessionPtr;
<a name="l00046"></a>00046 <span class="keyword">typedef</span> boost::shared_ptr<I_StubEntryLookupProvider> StubEntryLookupProviderPtr;
<a name="l00047"></a>00047 <span class="keyword">typedef</span> boost::shared_ptr<I_FilterFactoryLookupProvider> FilterFactoryLookupProviderPtr;
<a name="l00048"></a>00048 <span class="keyword">typedef</span> boost::shared_ptr<I_RcfClient> RcfClientPtr;
<a name="l00049"></a>00049
<a name="l00050"></a>00050 <span class="keyword">typedef</span> std::deque<SessionPtr> SessionQueue;
<a name="l00051"></a>00051
<a name="l00052"></a>00052 <span class="keyword">typedef</span> boost::shared_ptr<SessionQueue> SessionQueuePtr;
<a name="l00053"></a>00053
<a name="l00055"></a><a class="code" href="class_r_c_f_1_1_rcf_server.html">00055</a> <span class="keyword">class </span><a class="code" href="class_r_c_f_1_1_rcf_server.html">RcfServer</a> : boost::noncopyable, <span class="keyword">public</span> <span class="keyword">virtual</span> <a class="code" href="class_r_c_f_1_1_i___session_manager.html">I_SessionManager</a>
<a name="l00056"></a>00056 {
<a name="l00057"></a>00057 <span class="keyword">public</span>:
<a name="l00058"></a>00058
<a name="l00059"></a>00059 <span class="comment">//*************************************</span>
<a name="l00060"></a>00060 <span class="comment">// public interface</span>
<a name="l00061"></a>00061
<a name="l00064"></a>00064 <a class="code" href="class_r_c_f_1_1_rcf_server.html#30dccd4586556317befa986411eb7908">RcfServer</a>(<span class="keyword">const</span> <a class="code" href="class_r_c_f_1_1_i___endpoint.html">I_Endpoint</a> &endpoint);
<a name="l00065"></a>00065
<a name="l00068"></a>00068 <a class="code" href="class_r_c_f_1_1_rcf_server.html#30dccd4586556317befa986411eb7908">RcfServer</a>(ServicePtr servicePtr);
<a name="l00069"></a>00069
<a name="l00072"></a>00072 <a class="code" href="class_r_c_f_1_1_rcf_server.html#30dccd4586556317befa986411eb7908">RcfServer</a>(ServerTransportPtr serverTransportPtr);
<a name="l00073"></a>00073
<a name="l00075"></a>00075 <a class="code" href="class_r_c_f_1_1_rcf_server.html#0a78239b3654810132ab27c1c8b91e05">~RcfServer</a>();
<a name="l00076"></a>00076
<a name="l00080"></a>00080 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#98e104395628f6854b419f163676588d">start</a>(<span class="keywordtype">bool</span> spawnThreads = <span class="keyword">true</span>);
<a name="l00081"></a>00081
<a name="l00082"></a>00082 <span class="keyword">typedef</span> boost::function0<void> JoinFunctor;
<a name="l00083"></a>00083
<a name="l00086"></a>00086 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#810f898e957abbc4c469139a4fb5565e">addJoinFunctor</a>(JoinFunctor joinFunctor);
<a name="l00087"></a>00087
<a name="l00090"></a>00090 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#3247d4f82a31b7281f0ad9afb6efba65">startInThisThread</a>();
<a name="l00091"></a>00091
<a name="l00095"></a>00095 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#3247d4f82a31b7281f0ad9afb6efba65">startInThisThread</a>(JoinFunctor joinFunctor);
<a name="l00096"></a>00096
<a name="l00100"></a>00100 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#993d42d38cd846e81c3b04ac119078ee">stop</a>(<span class="keywordtype">bool</span> wait = <span class="keyword">true</span>);
<a name="l00101"></a>00101
<a name="l00105"></a>00105 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#1df12cd9c50a0a2b9b5c34faefa8cece">cycle</a>(<span class="keywordtype">int</span> timeoutMs = 0);
<a name="l00106"></a>00106
<a name="l00110"></a>00110 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#b57706df5e0a6ed3ecff290eb14f31ba">cycleSessions</a>(<span class="keywordtype">int</span> timeoutMs, <span class="keyword">const</span> <span class="keyword">volatile</span> <span class="keywordtype">bool</span> &stopFlag);
<a name="l00111"></a>00111
<a name="l00113"></a>00113 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#bc236d7592f97be4031af3df84fa602a">open</a>();
<a name="l00114"></a>00114
<a name="l00116"></a>00116 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#188bb2749480028e2c32415766917412">close</a>();
<a name="l00117"></a>00117
<a name="l00120"></a>00120 <a class="code" href="class_r_c_f_1_1_i___server_transport.html">I_ServerTransport</a> &<a class="code" href="class_r_c_f_1_1_rcf_server.html#f8dd420bf0f38b002557b6e0159bf9df">getServerTransport</a>();
<a name="l00121"></a>00121
<a name="l00124"></a>00124 boost::shared_ptr<I_ServerTransport> <a class="code" href="class_r_c_f_1_1_rcf_server.html#89e9512cfa798dd5106eb41023090be9">getServerTransportPtr</a>();
<a name="l00125"></a>00125
<a name="l00130"></a>00130 <span class="keyword">template</span><<span class="keyword">typename</span> InterfaceT, <span class="keyword">typename</span> ImplementationT>
<a name="l00131"></a>00131 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#5d606416d4505fe8691e7f57d46a2d61">bind</a>(ImplementationT &x, <span class="keyword">const</span> std::string &name = <span class="stringliteral">""</span>);
<a name="l00132"></a>00132
<a name="l00137"></a>00137 <span class="keyword">template</span><<span class="keyword">typename</span> InterfaceT, <span class="keyword">typename</span> ImplementationT>
<a name="l00138"></a>00138 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#5d606416d4505fe8691e7f57d46a2d61">bind</a>(boost::shared_ptr<ImplementationT> px, <span class="keyword">const</span> std::string &name = <span class="stringliteral">""</span>);
<a name="l00139"></a>00139
<a name="l00144"></a>00144 <span class="keyword">template</span><<span class="keyword">typename</span> InterfaceT, <span class="keyword">typename</span> ImplementationT>
<a name="l00145"></a>00145 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#5d606416d4505fe8691e7f57d46a2d61">bind</a>(boost::weak_ptr<ImplementationT> px, <span class="keyword">const</span> std::string &name = <span class="stringliteral">""</span>);
<a name="l00146"></a>00146
<a name="l00151"></a>00151 <span class="keyword">template</span><<span class="keyword">typename</span> InterfaceT, <span class="keyword">typename</span> ImplementationT>
<a name="l00152"></a>00152 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#5d606416d4505fe8691e7f57d46a2d61">bind</a>(std::auto_ptr<ImplementationT> px, <span class="keyword">const</span> std::string &name = <span class="stringliteral">""</span>);
<a name="l00153"></a>00153
<a name="l00157"></a>00157 <span class="keyword">template</span><<span class="keyword">typename</span> InterfaceT>
<a name="l00158"></a>00158 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#6fb3c713e3d877413a0e150fa01e7d51">unbind</a>(<span class="keyword">const</span> std::string &name = <span class="stringliteral">""</span><span class="comment">/*getInterfaceName<InterfaceT>()*/</span>);
<a name="l00159"></a>00159
<a name="l00163"></a>00163 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#92d8f1e4cffe32eeb16cfcd5d5fdf30d">addService</a>(ServicePtr servicePtr);
<a name="l00164"></a>00164
<a name="l00168"></a>00168 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#140f6cffd2b2c5b67fde6365972e8b08">removeService</a>(ServicePtr servicePtr);
<a name="l00169"></a>00169
<a name="l00170"></a>00170 <span class="comment">// preferred form</span>
<a name="l00171"></a>00171 <span class="comment">//typedef boost::function<void(RcfServer&)> StartCallback;</span>
<a name="l00172"></a>00172
<a name="l00173"></a>00173 <span class="comment">// compatible form, needed for Borland C++ 5.5.1</span>
<a name="l00174"></a>00174 <span class="keyword">typedef</span> boost::function1<void, RcfServer&> StartCallback;
<a name="l00175"></a>00175
<a name="l00177"></a>00177 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#05e5beac138dc9b23f563f36ccd8c604">setStartCallback</a>(StartCallback startCallback);
<a name="l00178"></a>00178 <span class="comment">//{</span>
<a name="l00179"></a>00179 <span class="comment">// startCallback_ = startCallback;</span>
<a name="l00180"></a>00180 <span class="comment">//}</span>
<a name="l00181"></a>00181
<a name="l00183"></a><a class="code" href="class_r_c_f_1_1_rcf_server.html#a86a45528ea16cbeb9c77aee081ba3c1">00183</a> <span class="keyword">template</span><<span class="keyword">typename</span> T> <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#05e5beac138dc9b23f563f36ccd8c604">setStartCallback</a>(<span class="keywordtype">void</span> (T::*pfn)(<a class="code" href="class_r_c_f_1_1_rcf_server.html">RcfServer</a> &), T &t)
<a name="l00184"></a>00184 {
<a name="l00185"></a>00185 <span class="comment">// this function is implemented here (rather than in RcfServer.inl), because of borland c++ idiosyncracies</span>
<a name="l00186"></a>00186 <a class="code" href="class_r_c_f_1_1_rcf_server.html#05e5beac138dc9b23f563f36ccd8c604">setStartCallback</a>( boost::bind(pfn, &t, _1) );
<a name="l00187"></a>00187 }
<a name="l00188"></a>00188 <span class="keyword">private</span>:
<a name="l00189"></a>00189 <span class="keywordtype">void</span> invokeStartCallback();
<a name="l00190"></a>00190
<a name="l00191"></a>00191 <span class="keyword">private</span>:
<a name="l00192"></a>00192 <span class="keywordtype">bool</span> bindShared(<span class="keyword">const</span> std::string &name, RcfClientPtr rcfClientPtr);
<a name="l00193"></a>00193
<a name="l00194"></a>00194 <span class="comment">//*************************************</span>
<a name="l00195"></a>00195 <span class="comment">// async io transport interface</span>
<a name="l00196"></a>00196
<a name="l00197"></a>00197 <span class="keyword">private</span>:
<a name="l00198"></a>00198 <span class="keyword">typedef</span> RCF::Session Session;
<a name="l00199"></a>00199 boost::shared_ptr<I_Session> createSession();
<a name="l00200"></a>00200 <span class="keywordtype">void</span> onReadCompleted(boost::shared_ptr<I_Session> sessionPtr);
<a name="l00201"></a>00201 <span class="keywordtype">void</span> onWriteCompleted(boost::shared_ptr<I_Session> sessionPtr);
<a name="l00202"></a>00202
<a name="l00203"></a>00203 <span class="keywordtype">void</span> handleSession(SessionPtr sessionPtr);
<a name="l00204"></a>00204 <span class="keywordtype">void</span> serializeSessionExceptionResponse(SessionPtr sessionPtr);
<a name="l00205"></a>00205 <span class="keywordtype">void</span> sendSessionResponse(SessionPtr sessionPtr);
<a name="l00206"></a>00206 <span class="keywordtype">void</span> closeSession(SessionPtr sessionPtr);
<a name="l00207"></a>00207
<a name="l00208"></a>00208 <span class="comment">//*************************************</span>
<a name="l00209"></a>00209 <span class="comment">// transports, queues and threads</span>
<a name="l00210"></a>00210
<a name="l00211"></a>00211 <span class="keyword">private</span>:
<a name="l00212"></a>00212 SessionQueue &getSessionQueue(Session &session);
<a name="l00213"></a>00213 <span class="keyword">typedef</span> ThreadSpecificPtr<SessionQueue>::Val ThreadSpecificSessionQueuePtr;
<a name="l00214"></a>00214 ThreadSpecificSessionQueuePtr mThreadSpecificSessionQueuePtr;
<a name="l00215"></a>00215 <span class="comment">// eventually other specialized session queues...</span>
<a name="l00216"></a>00216
<a name="l00217"></a>00217 <span class="keyword">volatile</span> <span class="keywordtype">bool</span> mServerThreadsStopFlag;
<a name="l00218"></a>00218 Mutex mOpenedMutex;
<a name="l00219"></a>00219 <span class="keywordtype">bool</span> mOpened;
<a name="l00220"></a>00220
<a name="l00221"></a>00221 Mutex mStartedMutex;
<a name="l00222"></a>00222 <span class="keywordtype">bool</span> mStarted;
<a name="l00223"></a>00223
<a name="l00224"></a>00224 <span class="keyword">public</span>:
<a name="l00225"></a>00225
<a name="l00227"></a>00227 <span class="keywordtype">bool</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#d5175de05a5001b81d03447a5994f3a1">getStopFlag</a>();
<a name="l00228"></a>00228
<a name="l00229"></a>00229 <span class="comment">//*************************************</span>
<a name="l00230"></a>00230 <span class="comment">// stub management</span>
<a name="l00231"></a>00231
<a name="l00232"></a>00232 <span class="keyword">private</span>:
<a name="l00233"></a>00233 ReadWriteMutex mStubMapMutex;
<a name="l00234"></a>00234 <span class="keyword">typedef</span> std::map<std::string, StubEntryPtr> StubMap;
<a name="l00235"></a>00235 StubMap mStubMap;
<a name="l00236"></a>00236
<a name="l00237"></a>00237 <span class="comment">//*************************************</span>
<a name="l00238"></a>00238 <span class="comment">// service management</span>
<a name="l00239"></a>00239
<a name="l00240"></a>00240 <span class="keyword">private</span>:
<a name="l00241"></a>00241 ReadWriteMutex mServicesMutex;
<a name="l00242"></a>00242 std::vector<ServicePtr> mServices;
<a name="l00243"></a>00243 std::vector<StubEntryLookupProviderPtr> mStubEntryLookupProviders;
<a name="l00244"></a>00244 std::vector<FilterFactoryLookupProviderPtr> mFilterFactoryLookupProviders;
<a name="l00245"></a>00245 std::vector<ServerTransportPtr> mServerTransports;
<a name="l00246"></a>00246
<a name="l00247"></a>00247 std::vector<JoinFunctor> mJoinFunctors;
<a name="l00248"></a>00248
<a name="l00249"></a>00249 <span class="keywordtype">void</span> startService(ServicePtr servicePtr);
<a name="l00250"></a>00250 <span class="keywordtype">void</span> stopService(ServicePtr servicePtr, <span class="keywordtype">bool</span> wait = <span class="keyword">true</span>);
<a name="l00251"></a>00251
<a name="l00252"></a>00252 FilterPtr createFilter(<span class="keywordtype">int</span> filterId);
<a name="l00253"></a>00253
<a name="l00254"></a>00254 <span class="keyword">private</span>:
<a name="l00255"></a>00255 <span class="comment">// start callback</span>
<a name="l00256"></a>00256 StartCallback startCallback_;
<a name="l00257"></a>00257
<a name="l00258"></a>00258 <span class="comment">// start functionality</span>
<a name="l00259"></a>00259 <span class="comment">//Mutex mStartMutex;</span>
<a name="l00260"></a>00260 Platform::Threads::condition mStartEvent;
<a name="l00261"></a>00261
<a name="l00262"></a>00262 <span class="comment">// stop functionality</span>
<a name="l00263"></a>00263 <span class="comment">//Mutex mStopMutex;</span>
<a name="l00264"></a>00264 Platform::Threads::condition mStopEvent;
<a name="l00265"></a>00265
<a name="l00266"></a>00266 <span class="keyword">public</span>:
<a name="l00267"></a>00267
<a name="l00269"></a>00269 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#cafe176e066105d7d5a5b65c50b94c24">waitForStopEvent</a>();
<a name="l00270"></a>00270
<a name="l00272"></a>00272 <span class="keywordtype">void</span> <a class="code" href="class_r_c_f_1_1_rcf_server.html#839331111f9f4acf7b1b6c5a9364743f">waitForStartEvent</a>();
<a name="l00273"></a>00273
<a name="l00274"></a>00274 };
<a name="l00275"></a>00275
<a name="l00276"></a>00276 } <span class="comment">// namespace RCF</span>
<a name="l00277"></a>00277
<a name="l00278"></a>00278 <span class="preprocessor">#include <RCF/RcfServer.inl></span>
<a name="l00279"></a>00279
<a name="l00280"></a>00280 <span class="preprocessor">#endif // ! INCLUDE_RCF_RCFSERVER_HPP</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Tue Sep 19 19:02:37 2006 for RCF by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.5 </small></address>
</body>
</html>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Software developer, from Sweden and now living in Canberra, Australia, working on distributed C++ applications. When he is not programming, Jarl enjoys skiing and playing table tennis. He derives immense satisfaction from referring to himself in third person.