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

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

<CENTER><B><FONT SIZE=+2>Sharing your Memories with persistence</FONT></B></CENTER>

<P>
<HR WIDTH="100%">
The mmap.h where we define stuff that needs to be shared between the
      apps at compile-time.
<hr>
<HR width=50%><P><center>mmap.h</center><HR width=50%>
<PRE>
<font color=red>// $Id$</font>

<font color=blue>#ifndef</font> <font color=purple>MMAP_H</font>
<font color=blue>#define</font> <font color=purple>MMAP_H</font>

<font color=red>// The expected filename for ACE_Shared_Memory_MM.h</font>
<font color=blue>#include</font> "<A HREF="../../../ace/Shared_Memory_MM.h">ace/Shared_Memory_MM.h</A>"

<font color=red>// Just enough for the alphabet...</font>
<font color=blue>#define</font> <font color=purple>SHMSZ</font> 27

<font color=red>/*
  Here we use a real filename instead of an arbitrary number.  This
  actually will exist in the filesystem.  You can 'cat' it and
  everything!
*/</font>
<font color=blue>#define</font> <font color=purple>SHM_KEY</font> "<font color=green>mmapfile</font>"

<font color=red>/*
  The SV Shared Memory SharedData object returns.  It is identical to
  the one we used in that tutorial.  I didn't even change the name.
 */</font>
class SharedData
{
public:
  SharedData (int initialize = 1);
    
  void set (void);
  void show (void);
  int available (void);
  void available (int not_in_use);
        
protected:
  char buf_[128];
  int available_;
};

<font color=blue>#endif</font> <font color=red>/* MMAP_H */</font>
</PRE>
<HR width=50%><P><center>mmap.cpp</center><HR width=50%>
<PRE>

<font color=red>// $Id$</font>

<font color=blue>#include</font> "<font color=green>mmap.h</font>"

<font color=#008888>SharedData::SharedData</font>(int _initialize)
    : available_(0)
{
    if( _initialize )
    {
        <font color=#008888>ACE_OS::sprintf</font>(buf_,"<font color=green>UNSET\n</font>");
    }
}

void <font color=#008888>SharedData::set</font>(void)
{
    <font color=#008888>ACE_OS::sprintf</font>(buf_,"<font color=green>My PID is (%d)\n</font>",ACE_OS::getpid());
}

void <font color=#008888>SharedData::show</font>(void)
{
    ACE_DEBUG ((LM_INFO, "<font color=green>(%P|%t) Shared Data text is (%s)\n</font>",
                buf_ ));
}

int <font color=#008888>SharedData::available</font>(void)
{
    return available_;
}

void <font color=#008888>SharedData::available</font>(int _available)
{
    available_ = _available;
}
</PRE>
<P><HR WIDTH="100%">
<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page06.html">Continue This Tutorial</A>]</CENTER>