Sophie

Sophie

distrib > Mandriva > 10.0-com > i586 > by-pkgid > 21280410b6ea906d791d7a12afae2579 > files > 354

libace5-doc-5.4-2mdk.i586.rpm

<!-- page05.html,v 1.7 2000/11/27 17:56:44 othman Exp -->
<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>// page05.html,v 1.7 2000/11/27 17:56:44 othman Exp</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>// page05.html,v 1.7 2000/11/27 17:56:44 othman Exp</font>

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

<font color=blue>#include</font> "<A HREF="../../../ace/Log_Msg.h">ace/Log_Msg.h</A>"

<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>