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
    00052      // Allocate receive buffer
    00053      antEnvCreateSharedBufferMsg receiveBufferMsg(sharedReceiveBufferSize);
    00054      receiveBufferMsg.Call(ipStackRef, sizeof(receiveBufferMsg));
    00055
    00056      if (receiveBufferMsg.error != ANT_SUCCESS)
    00057      {
    00058        cout << "IPEndpoint: ANT Error creating receive buffer \n";
    00059      }
    00060
    00061      receiveBuffer = receiveBufferMsg.buffer;
    00062      receiveBuffer.Map();
    00063      sharedReceiveBuffer = static_cast<byte*>(receiveBuffer.GetAddress());
    00064
    00065      cout << "IPEndpoint(): created sendBuffer with " << sharedSendBufferSize
    00066        << " and receiveBuffer with " << sharedReceiveBufferSize << " bytes \n";
    00067 }
    00068
    00069 IPEndpoint::~IPEndpoint()
    00070 {
    00071     sendBuffer.UnMap();
    00072     receiveBuffer.UnMap();
    00073
    00074     // From InternetProtocolVersion4.pdf
    00075     // antError UnMap();
    00076     // Description
    00077     // Removes a shared memory buffer from an object’s address space.
    00078     // This operation is required before the shared buffer can be destroyed.
    00079 }
    00080
    00081 Out& operator<<(Out& stream, const IPAddress& ipAddress)
    00082 {
    00083     unsigned int address = ipAddress.Address();
    00084
    00085     stream << (address >> 24) << "."
    00086            << (address >> 16 & 255) << "."
    00087            << (address >> 8 & 255) << "."
    00088            << (address & 255);
    00089
    00090     return(stream);
    00091 }
    00092