Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Platform/Aperios1.3.2/IPEndpoint.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file  Platform/Aperios1.3.2/IPEndpoint.cpp
00003 *
00004 * Implementation for IP Communication Classes
00005 * @attention this is the Aperios implementation
00006 *
00007 * @author <A href=mailto:robocup@m-wachter.de>Michael Wachter</A>
00008 * 
00009 */
00010 
00011 #include "IPEndpoint.h"
00012 #include <stdio.h>
00013 #include <iostream.h>
00014 
00015 /*
00016  * Constructor for an enpoint - creates shared memory buffers
00017  * and gets pointers for entry-points
00018  */
00019 
00020 IPEndpoint::IPEndpoint(int sbs, int rbs) :
00021     sharedSendBufferSize(sbs),
00022     sharedReceiveBufferSize(rbs)
00023 {
00024      ipStackRef = antStackRef("IPStack");
00025 
00026      // Get the OID of the process because we need it to send the 
00027      // messages
00028      myOID_ = ProcessBase::theInstance->getOID();
00029 
00030      // Get selectors of the entrypoints to send messages
00031      // (passed as pointers because they change if the endpoint
00032      // is created in the constructor of the process)
00033      ProcessBase::theInstance->
00034            getAntInformation(listenContSelector, 
00035                  sendContSelector, receiveContSelector,
00036                  closeContSelector, connectContSelector);
00037          
00038      // Allocate send buffer
00039      antEnvCreateSharedBufferMsg sendBufferMsg(sharedSendBufferSize);
00040      sendBufferMsg.Call(ipStackRef, sizeof(sendBufferMsg));
00041 
00042      if (sendBufferMsg.error != ANT_SUCCESS) 
00043      {
00044        cout << "IPEndpoint: ANT Error creating send buffer \n";
00045      }
00046 
00047      sendBuffer = sendBufferMsg.buffer;
00048      sendBuffer.Map();
00049      sharedSendBuffer = static_cast<byte*>(sendBuffer.GetAddress());
00050 
00051      // Allocate receive buffer
00052      antEnvCreateSharedBufferMsg receiveBufferMsg(sharedReceiveBufferSize);
00053      receiveBufferMsg.Call(ipStackRef, sizeof(receiveBufferMsg));
00054 
00055      if (receiveBufferMsg.error != ANT_SUCCESS)
00056      {
00057        cout << "IPEndpoint: ANT Error creating receive buffer \n";
00058      }
00059 
00060      receiveBuffer = receiveBufferMsg.buffer;
00061      receiveBuffer.Map();
00062      sharedReceiveBuffer = static_cast<byte*>(receiveBuffer.GetAddress());
00063 
00064      cout << "IPEndpoint(): created sendBuffer with " << sharedSendBufferSize 
00065           << " and receiveBuffer with " << sharedReceiveBufferSize << " bytes \n";
00066 }
00067 
00068 IPEndpoint::~IPEndpoint()
00069 {
00070     sendBuffer.UnMap();
00071     receiveBuffer.UnMap();
00072 
00073     // From InternetProtocolVersion4.pdf
00074     // antError UnMap();
00075     // Description
00076     // Removes a shared memory buffer from an object’s address space.
00077     // This operation is required before the shared buffer can be destroyed.
00078 }
00079 
00080 Out& operator<<(Out& stream, const IPAddress& ipAddress)
00081 {
00082     unsigned int address = ipAddress.Address();
00083 
00084     stream << (address >> 24) << "." 
00085            << (address >> 16 & 255) << "." 
00086            << (address >> 8 & 255) << "."
00087            << (address & 255);
00088 
00089     return(stream);
00090 }
00091 
00092 /*
00093  * Change log :
00094  * 
00095  * $Log: IPEndpoint.cpp,v $
00096  * Revision 1.2  2004/09/12 20:10:47  wachter
00097  * Documentation-fixes
00098  *
00099  * Revision 1.1.1.1  2004/05/22 17:23:25  cvsadm
00100  * created new repository GT2004_WM
00101  *
00102  * Revision 1.8  2004/01/26 13:44:07  wachter
00103  * shared-memory-buffers now have variable sizes
00104  *
00105  * Revision 1.7  2004/01/16 16:23:58  wachter
00106  * Bugfixes
00107  *
00108  * Revision 1.6  2004/01/09 13:57:23  wachter
00109  * Addes streaming-operator for Open-R IPAddress
00110  *
00111  * Revision 1.5  2004/01/03 16:18:24  wachter
00112  * debug-communication mostly working now
00113  *
00114  * Revision 1.4  2003/12/11 15:02:37  wachter
00115  * Low-level TCP and UDP functions for aperios now working.
00116  *
00117  * Revision 1.3  2003/12/03 14:21:52  wachter
00118  * Splitted IPEndpoint.*
00119  *
00120  * Revision 1.2  2003/12/02 20:52:41  wachter
00121  * Added IP-networking to aperios process-framework.
00122  *
00123  * Revision 1.1  2003/11/29 23:01:06  wachter
00124  * idea of an ip-implementation in the process-framework
00125  *
00126  * 
00127  */
00128 

Generated on Thu Sep 23 19:57:34 2004 for GT2004 by doxygen 1.3.6