summaryrefslogtreecommitdiff
path: root/docs/tutorials/012/page02.html
blob: 9647dd84a836ff583d2e5c2ea1e73d95bbfb8cec (plain)
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
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="James CE Johnson">
   <TITLE>ACE Tutorial 012</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">

<CENTER><B><FONT SIZE=+2>ACE Tutorial 012</FONT></B></CENTER>

<CENTER><B><FONT SIZE=+2>Passing classes through ACE_Message_Queue</FONT></B></CENTER>


<P>
<HR WIDTH="100%">
<P>
We normally start by looking at main() and work our way out from
there.  This time, I want to start by showing you the ACE_Message_Block
derivative but before that, I have to introduce you to the Work object 
and it's baseclass Unit_Of_Work
<P>
<HR WIDTH="100%">
<PRE>

/*
  We'll start by defining a basic unit of work that can be put into
  the message queue.  The threads in the pool will expect to find one
  of these in each message block and will invoke a method or two.
*/
class Unit_Of_Work
{
public:
    Unit_Of_Work (void)
        {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) Unit_Of_Work ctor 0x%x\n", (void *) this));
        }
    virtual ~ Unit_Of_Work (void)
        {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) Unit_Of_Work dtor 0x%x\n", (void *) this));
        }

    void who_am_i (void)
        {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) Unit_Of_Work instance 0x%x\n", (void *) this));
        }

    virtual void what_am_i (void)
        {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) I am a Unit_Of_Work object\n"));
        }

};

/*
  Now, we specialize the Unit_Of_Work object to do something
  different.  By overriding the virtual method, we can do whatever
  "real work" is needed but the thread pool doesn't have to know the specifics.
*/
class Work : public Unit_Of_Work
{
public:
    Work (void)
            : message_ (-1)
        {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) Work ctor 0x%x\n", (void *) this));
        }

    Work (int message)
            : message_ (message)
        {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) Work ctor 0x%x for message %d\n", (void *) this, message_));
        }
    virtual ~ Work (void)
        {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) Work dtor 0x%x\n", (void *) this));
        }

    void what_am_i (void)
        {
            ACE_DEBUG ((LM_DEBUG, "(%P|%t) I am a Work object for message %d\n", message_));
        }

protected:
    int message_;

};
</PRE>
<HR WIDTH="100%">
<P>
This is basically the same as the <i>DataBase</i> in the previous
tutorial but I've changed the name to be more generic.  The feeling is 
that a <i>Data</i> object would be a C struct but an <i>Work</i>
object would be a class with methods.
<P>
Now that you know what we'll be putting into the queue, lets go to the 
next page where I specialize the ACE_Message_Block.
<P>
<HR WIDTH="100%">
<P>
<CENTER>[<A HREF="..">Tutorial Index</A>] [<A HREF="page03.html">Continue
This Tutorial</A>]</CENTER>

</BODY>
</HTML>