1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
|
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
<TITLE>nevrax.org : docs</TITLE>
<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">
<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF='/'><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF='/'><b>nevrax.com</B></FONT></A> </TD>
</TR>
</TABLE>
<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%>
<TR><TD BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>
<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%>
<TR>
<TD WIDTH=16><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
<TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!------ Begin Box ------>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF>
<TABLE cellspacing=0 cellpadding=1 border=0>
<tr><td ALIGN=middle><a class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
<tr><td ALIGN=middle><a class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
</TABLE>
</TD></TR></TABLE></TD></TR></TABLE>
<!------ End Box ------>
</TD>
<TD WIDTH=15><IMG SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
<TD ALIGN=left valign=top><IMG SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">
<!-- title -->
<TABLE background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
<!-- block -->
<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
<TD><B>Documentation</B></TD>
<TD ALIGN=RIGHT> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>naming_client.cpp</h1><a href="naming__client_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00008 <font class="comment">/* Copyright, 2000 Nevrax Ltd.</font>
00009 <font class="comment"> *</font>
00010 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00011 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00012 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00013 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00014 <font class="comment"> * any later version.</font>
00015 <font class="comment"></font>
00016 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00017 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00018 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00019 <font class="comment"> * General Public License for more details.</font>
00020 <font class="comment"></font>
00021 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00022 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00023 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00024 <font class="comment"> * MA 02111-1307, USA.</font>
00025 <font class="comment"> */</font>
00026
00027 <font class="comment">//</font>
00028 <font class="comment">// Includes</font>
00029 <font class="comment">//</font>
00030
00031 <font class="preprocessor">#include "<a class="code" href="stdnet_8h.html">stdnet.h</a>"</font>
00032
00033 <font class="preprocessor">#include "<a class="code" href="naming__client_8h.html">nel/net/naming_client.h</a>"</font>
00034 <font class="preprocessor">#include "<a class="code" href="callback__client_8h.html">nel/net/callback_client.h</a>"</font>
00035 <font class="preprocessor">#include "<a class="code" href="service_8h.html">nel/net/service.h</a>"</font>
00036
00037
00038 <font class="comment">//</font>
00039 <font class="comment">// Namespaces</font>
00040 <font class="comment">//</font>
00041
00042 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00043 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC;
00044
00045
00046 <font class="keyword">namespace </font>NLNET {
00047
00048 <font class="comment">//</font>
00049 <font class="comment">// Variables</font>
00050 <font class="comment">//</font>
00051
<a name="l00052"></a><a class="code" href="classNLNET_1_1CNamingClient.html#r0">00052</a> CCallbackClient *CNamingClient::_Connection = NULL;
<a name="l00053"></a><a class="code" href="classNLNET_1_1CNamingClient.html#r2">00053</a> CNamingClient::TRegServices CNamingClient::_RegisteredServices;
00054
00055 <font class="keyword">static</font> <a class="code" href="namespaceNLNET.html#a20">TBroadcastCallback</a> <a class="code" href="namespaceNLNET.html#a45">_RegistrationBroadcastCallback</a> = NULL;
00056 <font class="keyword">static</font> <a class="code" href="namespaceNLNET.html#a20">TBroadcastCallback</a> <a class="code" href="namespaceNLNET.html#a46">_UnregistrationBroadcastCallback</a> = NULL;
00057
<a name="l00058"></a><a class="code" href="classNLNET_1_1CNamingClient.html#q0">00058</a> uint CNamingClient::_ThreadId = 0xFFFFFFFF;
00059
<a name="l00060"></a><a class="code" href="classNLNET_1_1CNamingClient.html#r1">00060</a> <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> CNamingClient::_MySId = 0;
00061
00062
<a name="l00063"></a><a class="code" href="classNLNET_1_1CNamingClient.html#r3">00063</a> <a class="code" href="classstd_1_1list.html">std::list<CNamingClient::CServiceEntry></a> CNamingClient::RegisteredServices;
00064 NLMISC::CMutex CNamingClient::RegisteredServicesMutex(<font class="stringliteral">"CNamingClient::RegisteredServicesMutex"</font>);
00065
<a name="l00066"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d17">00066</a> <font class="keywordtype">void</font> CNamingClient::setRegistrationBroadcastCallback (<a class="code" href="namespaceNLNET.html#a20">TBroadcastCallback</a> cb)
00067 {
00068 <a class="code" href="namespaceNLNET.html#a45">_RegistrationBroadcastCallback</a> = cb;
00069 }
00070
<a name="l00071"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d18">00071</a> <font class="keywordtype">void</font> CNamingClient::setUnregistrationBroadcastCallback (<a class="code" href="namespaceNLNET.html#a20">TBroadcastCallback</a> cb)
00072 {
00073 <a class="code" href="namespaceNLNET.html#a46">_UnregistrationBroadcastCallback</a> = cb;
00074 }
00075
00076 <font class="comment">//</font>
00077
00078 <font class="comment">//</font>
00079
00080 <font class="keyword">static</font> <font class="keywordtype">bool</font> <a class="code" href="namespaceNLNET.html#a47">Registered</a>;
00081 <font class="keyword">static</font> <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> <a class="code" href="namespaceNLNET.html#a48">RegisteredSuccess</a>;
00082 <font class="keyword">static</font> <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> *<a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a> = NULL;
00083
00084 <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNLNET.html#a107">cbRegister</a> (CMessage &msgin, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> from, CCallbackNetBase &netbase)
00085 {
00086 <a class="code" href="debug_8h.html#a6">nlassert</a>(<a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a> != NULL);
00087
00088 msgin.serial (<a class="code" href="namespaceNLNET.html#a48">RegisteredSuccess</a>);
00089 <font class="keywordflow">if</font> (RegisteredSuccess)
00090 {
00091 msgin.serial (*<a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a>);
00092
00093 <font class="comment">// decode the registered services at the register process</font>
00094 <a class="code" href="namespaceNLNET.html#a109">cbRegisterBroadcast</a> (msgin, from, netbase);
00095 }
00096 <a class="code" href="namespaceNLNET.html#a47">Registered</a> = <font class="keyword">true</font>;
00097 }
00098
00099 <font class="comment">//</font>
00100
00101 <font class="keyword">static</font> <font class="keywordtype">bool</font> <a class="code" href="namespaceNLNET.html#a50">QueryPort</a>;
00102 <font class="keyword">static</font> uint16 <a class="code" href="namespaceNLNET.html#a51">QueryPortPort</a>;
00103
00104 <font class="keyword">static</font> <font class="keywordtype">void</font> <a class="code" href="namespaceNLNET.html#a108">cbQueryPort</a> (CMessage &msgin, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> from, CCallbackNetBase &netbase)
00105 {
00106 msgin.serial (<a class="code" href="namespaceNLNET.html#a51">QueryPortPort</a>);
00107 <a class="code" href="namespaceNLNET.html#a50">QueryPort</a> = <font class="keyword">true</font>;
00108 }
00109
00110 <font class="comment">//</font>
00111
00112 <font class="comment">//static bool FirstRegisteredBroadcast;</font>
00113
<a name="l00114"></a><a class="code" href="classNLNET_1_1CNamingClient.html#a109">00114</a> <font class="keywordtype">void</font> <a class="code" href="namespaceNLNET.html#a109">cbRegisterBroadcast</a> (CMessage &msgin, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> from, CCallbackNetBase &netbase)
00115 {
00116 <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> size;
00117 string name;
00118 <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> sid;
00119 vector<CInetAddress> <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>;
00120
00121 msgin.serial (size);
00122
00123 <font class="keywordflow">for</font> (<a class="code" href="namespaceNLNET.html#a19">TServiceId</a> i = 0; i < size; i++)
00124 {
00125 msgin.serial (name);
00126 msgin.serial (sid);
00127 msgin.serialCont (<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>);
00128
00129 <font class="comment">// add it in the list</font>
00130
00131 std::vector<CInetAddress> addrs;
00132 CNamingClient::find (sid, addrs);
00133
00134 <font class="keywordflow">if</font> (addrs.size() == 0)
00135 {
00136 CNamingClient::RegisteredServicesMutex.enter ();
00137 CNamingClient::RegisteredServices.push_back (CNamingClient::CServiceEntry (name, sid, <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>));
00138 CNamingClient::RegisteredServicesMutex.leave ();
00139
00140 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"NC: Registration Broadcast of the service %s-%hu '%s'"</font>, name.c_str(), (uint16)sid, <a class="code" href="namespaceNLNET.html#a82">vectorCInetAddressToString</a>(addr).c_str());
00141
00142 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLNET.html#a45">_RegistrationBroadcastCallback</a> != NULL)
00143 <a class="code" href="namespaceNLNET.html#a45">_RegistrationBroadcastCallback</a> (name, sid, <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>);
00144 }
00145 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (addrs.size() == 1)
00146 {
00147 CNamingClient::RegisteredServicesMutex.enter ();
00148 <font class="keywordflow">for</font> (<a class="code" href="classstd_1_1list.html">std::list<CNamingClient::CServiceEntry></a>::iterator it = CNamingClient::RegisteredServices.begin(); it != CNamingClient::RegisteredServices.end (); it++)
00149 {
00150 <font class="keywordflow">if</font> (sid == (*it).SId)
00151 {
00152 (*it).Name = name;
00153 (*it).Addr = <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>;
00154 <font class="keywordflow">break</font>;
00155 }
00156 }
00157 CNamingClient::RegisteredServicesMutex.leave ();
00158 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"NC: Registration Broadcast (update) of the service %s-%hu '%s'"</font>, name.c_str(), (uint16)sid, <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>[0].asString().c_str());
00159 }
00160 <font class="keywordflow">else</font>
00161 {
00162 <a class="code" href="debug_8h.html#a12">nlstop</a>;
00163 }
00164 }
00165
00166 <font class="comment">// FirstRegisteredBroadcast = true;</font>
00167
00168 <font class="comment">//CNamingClient::displayRegisteredServices ();</font>
00169 }
00170
00171 <font class="comment">//</font>
00172
<a name="l00173"></a><a class="code" href="classNLNET_1_1CNamingClient.html#a110">00173</a> <font class="keywordtype">void</font> <a class="code" href="namespaceNLNET.html#a110">cbUnregisterBroadcast</a> (CMessage &msgin, <a class="code" href="namespaceNLNET.html#a0">TSockId</a> from, CCallbackNetBase &netbase)
00174 {
00175 string name;
00176 <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> sid;
00177 vector<CInetAddress> addrs;
00178
00179 msgin.serial (name);
00180 msgin.serial (sid);
00181
00182 <font class="comment">// remove it in the list, if the service is not found, ignore it</font>
00183
00184 CNamingClient::RegisteredServicesMutex.enter ();
00185 <font class="keywordflow">for</font> (<a class="code" href="classstd_1_1list.html">std::list<CNamingClient::CServiceEntry></a>::iterator it = CNamingClient::RegisteredServices.begin(); it != CNamingClient::RegisteredServices.end (); it++)
00186 {
00187 <font class="keywordflow">if</font> ((*it).SId == sid)
00188 {
00189 <font class="comment">// check the structure</font>
00190 <a class="code" href="debug_8h.html#a8">nlassertex</a> ((*it).Name == name, (<font class="stringliteral">"%s %s"</font>,(*it).Name.c_str(), name.c_str()));
00191
00192 addrs = (*it).Addr;
00193
00194 CNamingClient::RegisteredServices.erase (it);
00195 <font class="keywordflow">break</font>;
00196 }
00197 }
00198 CNamingClient::RegisteredServicesMutex.leave ();
00199
00200 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"NC: Unregistration Broadcast of the service %s-%hu"</font>, name.c_str(), (uint16)sid);
00201
00202 <font class="comment">// send the ACK to the NS</font>
00203
00204 CMessage msgout (CNamingClient::_Connection->getSIDA(), <font class="stringliteral">"ACK_UNI"</font>);
00205 msgout.serial (sid);
00206 CNamingClient::_Connection->send (msgout);
00207
00208 <font class="comment">// oh my god, it s my sid! but i m alive, why this f*cking naming service want to kill me? ok, i leave it alone!</font>
00209 <font class="keywordflow">if</font>(CNamingClient::_MySId == sid)
00210 {
00211 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Naming Service asked me to leave, I leave!"</font>);
00212 IService::getInstance()->exit();
00213 <font class="keywordflow">return</font>;
00214 }
00215
00216 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLNET.html#a46">_UnregistrationBroadcastCallback</a> != NULL)
00217 <a class="code" href="namespaceNLNET.html#a46">_UnregistrationBroadcastCallback</a> (name, sid, addrs);
00218
00219 <font class="comment">//CNamingClient::displayRegisteredServices ();</font>
00220 }
00221
00222 <font class="comment">//</font>
00223
00224 <font class="keyword">static</font> TCallbackItem <a class="code" href="namespaceNLNET.html#a52">NamingClientCallbackArray</a>[] =
00225 {
00226 { <font class="stringliteral">"RG"</font>, <a class="code" href="namespaceNLNET.html#a107">cbRegister</a> },
00227 { <font class="stringliteral">"QP"</font>, <a class="code" href="namespaceNLNET.html#a108">cbQueryPort</a> },
00228
00229 { <font class="stringliteral">"RGB"</font>, <a class="code" href="namespaceNLNET.html#a109">cbRegisterBroadcast</a> },
00230 { <font class="stringliteral">"UNB"</font>, <a class="code" href="namespaceNLNET.html#a110">cbUnregisterBroadcast</a> },
00231 };
00232
00233 <font class="keywordtype">void</font> CNamingClient::connect( <font class="keyword">const</font> CInetAddress &<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>, CCallbackNetBase::TRecordingState rec, <font class="keyword">const</font> vector<CInetAddress> &addresses )
00234 {
00235 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> == NULL || <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && !<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00236 <a class="code" href="classNLNET_1_1CNamingClient.html#q0">_ThreadId</a> = <a class="code" href="namespaceNLMISC.html#a237">getThreadId</a> ();
00237
00238 <font class="keywordflow">if</font> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> == NULL)
00239 {
00240 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> = <font class="keyword">new</font> CCallbackClient( rec, <font class="stringliteral">"naming_client.nmr"</font> );
00241 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->addCallbackArray (<a class="code" href="namespaceNLNET.html#a52">NamingClientCallbackArray</a>, <font class="keyword">sizeof</font> (<a class="code" href="namespaceNLNET.html#a52">NamingClientCallbackArray</a>) / <font class="keyword">sizeof</font> (<a class="code" href="namespaceNLNET.html#a52">NamingClientCallbackArray</a>[0]));
00242 }
00243
00244 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connect (<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>);
00245
00246 <font class="comment">/* // send the available addresses</font>
00247 <font class="comment"> CMessage msgout (_Connection->getSIDA(), "RS");</font>
00248 <font class="comment"> msgout.serialCont (const_cast<vector<CInetAddress>&>(addresses));</font>
00249 <font class="comment"> _Connection->send (msgout);</font>
00250 <font class="comment"> </font>
00251 <font class="comment"> // wait the message that contains all already connected services</font>
00252 <font class="comment"> FirstRegisteredBroadcast = false;</font>
00253 <font class="comment"> while (!FirstRegisteredBroadcast && _Connection->connected ())</font>
00254 <font class="comment"> {</font>
00255 <font class="comment"> _Connection->update (-1);</font>
00256 <font class="comment"> nlSleep (1);</font>
00257 <font class="comment"> }</font>
00258 <font class="comment">*/</font>}
00259
00260
<a name="l00261"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d2">00261</a> <font class="keywordtype">void</font> CNamingClient::disconnect ()
00262 {
00263 <a class="code" href="classNLNET_1_1CNamingClient.html#e0">checkThreadId</a> ();
00264
00265 <font class="keywordflow">if</font> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL)
00266 {
00267 <font class="keywordflow">if</font> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ())
00268 {
00269 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->disconnect ();
00270 }
00271 <font class="keyword">delete</font> <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>;
00272 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> = NULL;
00273 }
00274
00275 <font class="comment">// we don't call unregisterAllServices because when the naming service will see the disconnection,</font>
00276 <font class="comment">// it'll automatically unregister all services registered by this client.</font>
00277 }
00278
<a name="l00279"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d3">00279</a> string CNamingClient::info ()
00280 {
00281 string <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00282
00283 <font class="keywordflow">if</font> (<a class="code" href="classNLNET_1_1CNamingClient.html#d1">connected</a> ())
00284 {
00285 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <font class="stringliteral">"connected to "</font>;
00286 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> += <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->remoteAddress().asString();
00287 }
00288 <font class="keywordflow">else</font>
00289 {
00290 <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a> = <font class="stringliteral">"Not connected"</font>;
00291 }
00292
00293 <font class="keywordflow">return</font> <a class="code" href="driver__opengl__extension__def_8h.html#a400">res</a>;
00294 }
00295
<a name="l00296"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d4">00296</a> <font class="keywordtype">bool</font> CNamingClient::registerService (<font class="keyword">const</font> std::string &name, <font class="keyword">const</font> std::vector<CInetAddress> &<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>, <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> &sid)
00297 {
00298 <a class="code" href="classNLNET_1_1CNamingClient.html#e0">checkThreadId</a> ();
00299 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00300
00301 CMessage msgout (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->getSIDA(), <font class="stringliteral">"RG"</font>);
00302 msgout.serial (const_cast<std::string&>(name));
00303 msgout.serialCont (<font class="keyword">const_cast</font><vector<CInetAddress>&>(<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>));
00304 sid = 0;
00305 msgout.serial (sid);
00306 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->send (msgout);
00307
00308 <font class="comment">// wait the answer of the naming service "RG"</font>
00309 <a class="code" href="namespaceNLNET.html#a47">Registered</a> = <font class="keyword">false</font>;
00310 <a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a> = &sid;
00311 <font class="keywordflow">while</font> (!<a class="code" href="namespaceNLNET.html#a47">Registered</a>)
00312 {
00313 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->update (-1);
00314 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (1);
00315 }
00316 <font class="keywordflow">if</font> (RegisteredSuccess)
00317 {
00318 <a class="code" href="classNLNET_1_1CNamingClient.html#r1">_MySId</a> = sid;
00319 <a class="code" href="classNLNET_1_1CNamingClient.html#r2">_RegisteredServices</a>.insert (make_pair (*<a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a>, name));
00320 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"NC: Registered service %s-%hu at %s"</font>, name.c_str(), (uint16)sid, <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>[0].asString().c_str());
00321 }
00322 <font class="keywordflow">else</font>
00323 {
00324 <a class="code" href="debug_8h.html#a3">nlerror</a> (<font class="stringliteral">"NC: Naming service refused to register service %s at %s"</font>, name.c_str(), <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>[0].asString().c_str());
00325 }
00326
00327 <a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a> = NULL;
00328
00329 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a48">RegisteredSuccess</a> == 1;
00330 }
00331
<a name="l00332"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d5">00332</a> <font class="keywordtype">bool</font> CNamingClient::registerServiceWithSId (<font class="keyword">const</font> std::string &name, <font class="keyword">const</font> std::vector<CInetAddress> &<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>, <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> sid)
00333 {
00334 <a class="code" href="classNLNET_1_1CNamingClient.html#e0">checkThreadId</a> ();
00335 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00336
00337 CMessage msgout (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->getSIDA(), <font class="stringliteral">"RG"</font>);
00338 msgout.serial (const_cast<std::string&>(name));
00339 msgout.serialCont (<font class="keyword">const_cast</font><vector<CInetAddress>&>(<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>));
00340 msgout.serial (sid);
00341 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->send (msgout);
00342
00343 <font class="comment">// wait the answer of the naming service "RGI"</font>
00344 <a class="code" href="namespaceNLNET.html#a47">Registered</a> = <font class="keyword">false</font>;
00345 <a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a> = &sid;
00346 <font class="keywordflow">while</font> (!<a class="code" href="namespaceNLNET.html#a47">Registered</a>)
00347 {
00348 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->update (-1);
00349 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (1);
00350 }
00351 <font class="keywordflow">if</font> (RegisteredSuccess)
00352 {
00353 <a class="code" href="classNLNET_1_1CNamingClient.html#r1">_MySId</a> = sid;
00354 <a class="code" href="classNLNET_1_1CNamingClient.html#r2">_RegisteredServices</a>.insert (make_pair (*<a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a>, name));
00355 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"NC: Registered service with sid %s-%hu at %s"</font>, name.c_str(), (uint16)<a class="code" href="namespaceNLNET.html#a49">RegisteredSID</a>, <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>[0].asString().c_str());
00356 }
00357 <font class="keywordflow">else</font>
00358 {
00359 <a class="code" href="debug_8h.html#a3">nlerror</a> (<font class="stringliteral">"NC: Naming service refused to register service with sid %s at %s"</font>, name.c_str(), <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>[0].asString().c_str());
00360 }
00361
00362 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a48">RegisteredSuccess</a> == 1;
00363 }
00364
<a name="l00365"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d6">00365</a> <font class="keywordtype">void</font> CNamingClient::resendRegisteration (<font class="keyword">const</font> std::string &name, <font class="keyword">const</font> std::vector<CInetAddress> &<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>, <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> sid)
00366 {
00367 <a class="code" href="classNLNET_1_1CNamingClient.html#e0">checkThreadId</a> ();
00368 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00369
00370 CMessage msgout (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->getSIDA(), <font class="stringliteral">"RRG"</font>);
00371 msgout.serial (const_cast<std::string&>(name));
00372 msgout.serialCont (<font class="keyword">const_cast</font><vector<CInetAddress>&>(<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>));
00373 msgout.serial (sid);
00374 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->send (msgout);
00375 }
00376
<a name="l00377"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d7">00377</a> <font class="keywordtype">void</font> CNamingClient::unregisterService (<a class="code" href="namespaceNLNET.html#a19">TServiceId</a> sid)
00378 {
00379 <a class="code" href="classNLNET_1_1CNamingClient.html#e0">checkThreadId</a> ();
00380 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00381
00382 CMessage msgout (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->getSIDA(), <font class="stringliteral">"UNI"</font>);
00383 msgout.serial (sid);
00384 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->send (msgout);
00385
00386 <a class="code" href="debug_8h.html#a0">nldebug</a> (<font class="stringliteral">"NC: Unregistering service %s-%hu"</font>, <a class="code" href="classNLNET_1_1CNamingClient.html#r2">_RegisteredServices</a>[sid].c_str(), sid);
00387 <a class="code" href="classNLNET_1_1CNamingClient.html#r2">_RegisteredServices</a>.erase (sid);
00388 }
00389
<a name="l00390"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d8">00390</a> <font class="keywordtype">void</font> CNamingClient::unregisterAllServices ()
00391 {
00392 <a class="code" href="classNLNET_1_1CNamingClient.html#e0">checkThreadId</a> ();
00393 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00394
00395 <font class="keywordflow">while</font> (!<a class="code" href="classNLNET_1_1CNamingClient.html#r2">_RegisteredServices</a>.empty())
00396 {
00397 TRegServices::iterator irs = <a class="code" href="classNLNET_1_1CNamingClient.html#r2">_RegisteredServices</a>.begin();
00398 <a class="code" href="namespaceNLNET.html#a19">TServiceId</a> sid = (*irs).first;
00399 <a class="code" href="classNLNET_1_1CNamingClient.html#d7">unregisterService</a> (sid);
00400 }
00401 }
00402
<a name="l00403"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d9">00403</a> uint16 CNamingClient::queryServicePort ()
00404 {
00405 <a class="code" href="classNLNET_1_1CNamingClient.html#e0">checkThreadId</a> ();
00406 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00407
00408 CMessage msgout (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->getSIDA(), <font class="stringliteral">"QP"</font>);
00409 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->send (msgout);
00410
00411 <font class="comment">// wait the answer of the naming service "QP"</font>
00412 <a class="code" href="namespaceNLNET.html#a50">QueryPort</a> = <font class="keyword">false</font>;
00413 <font class="keywordflow">while</font> (!<a class="code" href="namespaceNLNET.html#a50">QueryPort</a>)
00414 {
00415 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->update (-1);
00416 <a class="code" href="namespaceNLMISC.html#a236">nlSleep</a> (1);
00417 }
00418
00419 <a class="code" href="debug_8h.html#a1">nlinfo</a> (<font class="stringliteral">"NC: Received the answer of the query port (%hu)"</font>, <a class="code" href="namespaceNLNET.html#a51">QueryPortPort</a>);
00420
00421 <font class="keywordflow">return</font> <a class="code" href="namespaceNLNET.html#a51">QueryPortPort</a>;
00422 }
00423
<a name="l00424"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d10">00424</a> <font class="keywordtype">bool</font> CNamingClient::lookup (<font class="keyword">const</font> std::string &name, CInetAddress &<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>)
00425 {
00426 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00427
00428 vector<CInetAddress> addrs;
00429 <a class="code" href="classNLNET_1_1CNamingClient.html#f1">find</a> (name, addrs);
00430
00431 <font class="keywordflow">if</font> (addrs.size()==0)
00432 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00433
00434 <a class="code" href="debug_8h.html#a6">nlassert</a> (addrs.size()==1);
00435 <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a> = addrs[0];
00436
00437 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00438 }
00439
<a name="l00440"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d11">00440</a> <font class="keywordtype">bool</font> CNamingClient::lookup (<a class="code" href="namespaceNLNET.html#a19">TServiceId</a> sid, CInetAddress &<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>)
00441 {
00442 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00443
00444 vector<CInetAddress> addrs;
00445 <a class="code" href="classNLNET_1_1CNamingClient.html#f1">find</a> (sid, addrs);
00446
00447 <font class="keywordflow">if</font> (addrs.size()==0)
00448 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00449
00450 <a class="code" href="debug_8h.html#a6">nlassert</a> (addrs.size()==1);
00451 <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a> = addrs[0];
00452
00453 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00454 }
00455
<a name="l00457"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d12">00457</a> <font class="keywordtype">bool</font> CNamingClient::lookupAlternate (<font class="keyword">const</font> std::string &name, CInetAddress &<a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>)
00458 {
00459 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00460
00461 <font class="comment">// remove it from his local list</font>
00462
00463 <a class="code" href="classNLNET_1_1CNamingClient.html#r4">RegisteredServicesMutex</a>.enter ();
00464 <font class="keywordflow">for</font> (<a class="code" href="classstd_1_1list.html">std::list<CServiceEntry></a>::iterator it = <a class="code" href="classNLNET_1_1CNamingClient.html#r3">RegisteredServices</a>.begin(); it != <a class="code" href="classNLNET_1_1CNamingClient.html#r3">RegisteredServices</a>.end (); it++)
00465 {
00466 <font class="keywordflow">if</font> ((*it).Addr[0] == <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a>)
00467 {
00468 <a class="code" href="classNLNET_1_1CNamingClient.html#r3">RegisteredServices</a>.erase (it);
00469 <font class="keywordflow">break</font>;
00470 }
00471 }
00472 <a class="code" href="classNLNET_1_1CNamingClient.html#r4">RegisteredServicesMutex</a>.leave ();
00473
00474 vector<CInetAddress> addrs;
00475 <a class="code" href="classNLNET_1_1CNamingClient.html#f1">find</a> (name, addrs);
00476
00477 <font class="keywordflow">if</font> (addrs.size()==0)
00478 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00479
00480 <a class="code" href="debug_8h.html#a6">nlassert</a> (addrs.size()==1);
00481 <a class="code" href="driver__opengl__extension__def_8h.html#a414">addr</a> = addrs[0];
00482
00483 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00484 }
00485
<a name="l00486"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d13">00486</a> <font class="keywordtype">void</font> CNamingClient::lookupAll (<font class="keyword">const</font> std::string &name, std::vector<CInetAddress> &addrs)
00487 {
00488 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00489
00490 <a class="code" href="classNLNET_1_1CNamingClient.html#f1">find</a> (name, addrs);
00491 }
00492
<a name="l00493"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d15">00493</a> <font class="keywordtype">bool</font> CNamingClient::lookupAndConnect (<font class="keyword">const</font> std::string &name, CCallbackClient &sock)
00494 {
00495 <a class="code" href="debug_8h.html#a6">nlassert</a> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ());
00496
00497 <font class="comment">// look up for service</font>
00498 CInetAddress servaddr;
00499
00500 <font class="comment">// if service not found, return false</font>
00501 <font class="keywordflow">if</font> (!CNamingClient::lookup (name, servaddr))
00502 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00503
00504 <font class="keywordflow">do</font>
00505 {
00506 <font class="keywordflow">try</font>
00507 {
00508 <font class="comment">// try to connect to the server</font>
00509 sock.connect (servaddr);
00510
00511 <font class="comment">// connection succeeded</font>
00512 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00513 }
00514 <font class="keywordflow">catch</font> (ESocketConnectionFailed &e)
00515 {
00516 <a class="code" href="debug_8h.html#a0">nldebug</a>( <font class="stringliteral">"Connection to %s failed: %s, tring another service if available"</font>, servaddr.asString().c_str(), e.what() );
00517
00518 <font class="comment">// try another server and if service is not found, return false</font>
00519 <font class="keywordflow">if</font> (!CNamingClient::lookupAlternate (name, servaddr))
00520 <font class="keywordflow">return</font> <font class="keyword">false</font>;
00521 }
00522 }
00523 <font class="keywordflow">while</font> (true);
00524 }
00525
00526
00527
<a name="l00528"></a><a class="code" href="classNLNET_1_1CNamingClient.html#d16">00528</a> <font class="keywordtype">void</font> CNamingClient::update ()
00529 {
00530 <a class="code" href="classNLNET_1_1CNamingClient.html#e0">checkThreadId</a> ();
00531 <font class="comment">// get message for naming service (new registration for example)</font>
00532 <font class="keywordflow">if</font> (<a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a> != NULL && <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->connected ())
00533 <a class="code" href="classNLNET_1_1CNamingClient.html#r0">_Connection</a>->update ();
00534 }
00535
<a name="l00536"></a><a class="code" href="classNLNET_1_1CNamingClient.html#e0">00536</a> <font class="keywordtype">void</font> CNamingClient::checkThreadId ()
00537 {
00538 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a237">getThreadId</a> () != <a class="code" href="classNLNET_1_1CNamingClient.html#q0">_ThreadId</a>)
00539 {
00540 <a class="code" href="debug_8h.html#a3">nlerror</a> (<font class="stringliteral">"You try to access to the CNamingClient with 2 differents thread (%d and %d)"</font>, <a class="code" href="classNLNET_1_1CNamingClient.html#q0">_ThreadId</a>, <a class="code" href="namespaceNLMISC.html#a237">getThreadId</a>());
00541 }
00542 }
00543
00544
00545 <font class="comment">//</font>
00546 <font class="comment">// Commands</font>
00547 <font class="comment">//</font>
00548
00549 <a class="code" href="namespaceNLNET.html#a111">NLMISC_COMMAND</a>(services, <font class="stringliteral">"displays registered services"</font>, <font class="stringliteral">""</font>)
00550 {
00551 <font class="keywordflow">if</font>(args.size() != 0) <font class="keywordflow">return</font> <font class="keyword">false</font>;
00552
00553 CNamingClient::displayRegisteredServices (&log);
00554
00555 <font class="keywordflow">return</font> <font class="keyword">true</font>;
00556 }
00557
00558 } <font class="comment">// NLNET</font>
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|