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
|
<!-- $Id$ -->
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>ACE Tutorial 022</title>
</head>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">
<CENTER><B><FONT SIZE=+2>ACE Tutorial 022</FONT></B></CENTER>
Now, lets implement the Acceptor Service. As the first step, let
us take a look at <I><A HREF="Acceptor_Service.h">Acceptor_Service.h</A></I>.
<P>
<HR WIDTH="100%">
<PRE>
<font color=red>// $Id$</font>
<font color=blue>#ifndef</font> <font color=purple>ACCEPTOR_SERVICE_H</font>
<font color=blue>#define</font> <font color=purple>ACCEPTOR_SERVICE_H</font>
<font color=red>/* The ACE_Acceptor<> template lives in the ace/Acceptor.h header
file. */</font>
<font color=blue>#include</font> "<A HREF="../../../ace/Acceptor.h">ace/Acceptor.h</A>"
<font color=blue>#if !defined</font> (<font color=purple>ACE_LACKS_PRAGMA_ONCE</font>)
<font color=blue># pragma</font> <font color=purple>once</font>
<font color=blue>#endif</font> <font color=red>/* ACE_LACKS_PRAGMA_ONCE */</font>
<font color=red>/* Since we want to work with sockets, we'll need a SOCK_Acceptor to
allow the clients to connect to us. */</font>
<font color=blue>#include</font> "<A HREF="../../../ace/SOCK_Acceptor.h">ace/SOCK_Acceptor.h</A>"
<font color=red>/* The Client_Handler object we develop will be used to handle clients
once they're connected. The ACE_Acceptor<> template's first
parameter requires such an object. In some cases, you can get by
with just a forward declaration on the class, in others you have to
have the whole thing. */</font>
<font color=blue>#include</font> "<font color=green>client_handler.h</font>"
<font color=red>/* In our original simple server, we instantiated a
ACE_Acceptor <Client_Handler, ACE_SOCK_ACCEPTOR> object. We can
make it much simpler and efficient by inheriting our
Acceptor_Service from ACE_Acceptor itself.
Our Acceptor_Service class also needs to inherit from
ACE_Service_Object. ACE_Service_Object is an abstract class which
includes methods called by the Service Configurator framework to
start, remove, suspend or resume our service.
You might have noticed that we didnt explicitly inherit from
ACE_Service_Object here. That is because, ACE_Acceptor derives from
ACE_Service_Object and hence there is no explicitly specify it. */
/* TO Do: Describe what/why ACE_Svc_Export */
We use the ACE_Svc_Export macro to export the symbols from the
library on Win.</font>
class ACE_Svc_Export Acceptor_Service : public ACE_Acceptor <Client_Handler, ACE_SOCK_ACCEPTOR>
{
public:
<font color=red> // Constructor </font>
Acceptor_Service (void);
<font color=red> // Destructor </font>
~Acceptor_Service (void);
<font color=red>/* This method is the one which is called by the Service
Configurator Framework to initialize or start the service. */ </font>
virtual int init (int argc, char *argv[]);
<font color=red>/* Called by the Service Configurator framework to remove this
Service. */ </font>
virtual int fini (void);
<font color=red>/* You could easily guess that this method is called to suspend the
service by the same Service Configurator Framework. When in the
suspend mode, the service is not removed completely and is *still
there*. The difference is that the service is not in a active
state and doesnot accept requests.*/ </font>
virtual int suspend (void);
<font color=red> /* And your guess that this method is called to resume the service
is also right. This call brings the service back to the
active state and the service is all ready to accept requests */ </font>
virtual int resume (void);
};
<font color=red>/* The following macros and similar macros which we
will use in the implementation file later are used to define helper
functions for the Service Configurator. As we can easily guess, these
macros are intended to dynamically load ancd configure services using
the svc.conf file. These macros will also help to dynamically configure
even the statically linked services. */</font>
<font color=red>/* This macro is used to declare a data structure
required to register a statically linked service into the service
configurator. As you can see it has only one argument which is the
name of the class that implements this service... so
Acceptor_Service in our case. */</font>
ACE_STATIC_SVC_DECLARE (Acceptor_Service)
<font color=red>/* Once the service implementation is dynamically loaded, the Service
Configurator uses a factory method to create the object. This
macro declares such a factory function with the proper interface
and export macros. */</font>
ACE_SVC_FACTORY_DECLARE (Acceptor_Service)
#include "ace/post.h"
<font color=blue>#endif</font> <<font color=red> /* ACCEPTOR_SERVICE_H */</font>
</PRE>
<P><HR WIDTH="100%">
<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page04.html">Continue This Tutorial</A>]</CENTER>
<hr>
<address><a href="mailto:pgontla@ece.uci.edu">Priyanka Gontla</a></address>
<!-- Created: Thu Jan 18 17:46:58 PST 2001 -->
<!-- hhmts start -->
Last modified: Fri Jan 19 11:38:39 PST 2001
<!-- hhmts end -->
</body>
</html>
|