Classes | Public Member Functions

cygnal::LcShm Class Reference

#include <lcshm.h>

Inheritance diagram for cygnal::LcShm:
Inheritance graph
[legend]
Collaboration diagram for cygnal::LcShm:
Collaboration graph
[legend]

List of all members.

Classes

struct  lc_header_t
struct  lc_message_t
struct  lc_object_t

Public Member Functions

 LcShm ()
 Construct an uninitialized shared memory segment.
 ~LcShm ()
 Delete the shared memory segment.
 LcShm (boost::uint8_t *baseaddr)
 Construct an initialized shared memory segment.
 LcShm (key_t key)
 Construct an initialized shared memory segment.
bool connect (const std::string &name)
 Connect to a memory segment.
bool connect (key_t key)
 Connect to a memory segment.
void close (void)
 Close a memory segment. This closes the shared memory segment, but the data remains until the next reboot of the computer.
void send (const std::string &name, const std::string &dataname, std::vector< cygnal::Element * > &data)
 Put data in the memory segment This puts data into the memory segment.
void recv (std::string &name, std::string &dataname, boost::shared_ptr< cygnal::Element > data)
 Read the date from the memory.
std::vector< boost::shared_ptr
< cygnal::Element > > 
parseBody (boost::uint8_t *data)
 Parse the body of a memory segment.
boost::uint8_t * parseHeader (boost::uint8_t *data, boost::uint8_t *tooFar)
 Parse the header of the memory segment.
boost::uint8_t * formatHeader (const std::string &con, const std::string &host, bool domain)
 Format the header for the memory segment.
void addConnectionName (std::string &name)
 Set the name for this connection to the memory segment.
void addHostname (std::string &name)
 Set the hostname used for this connection to the memory segment.
void addObject (boost::shared_ptr< cygnal::Element > el)
 Add an AMF0 Element array of data for this memory segment.
size_t size ()
 Get the number of AMF0 Elements stored in this class.
std::vector< boost::shared_ptr
< cygnal::Element > > 
getElements ()
 Get the array of AMF0 objects stored by this class.
void setBaseAddr (boost::uint8_t *addr)
 Set the base address to be used for the memory segment.
void dump ()
 Dump the internal data of this class in a human readable form.
void setconnected (bool trueorfalse)
bool getconnected ()

Detailed Description

This class is formanipulating the LocalConnection memory segment.


Constructor & Destructor Documentation

cygnal::LcShm::LcShm (  ) 

Construct an uninitialized shared memory segment.

Construct an uninitialized shared memory segment. Open a connection between two SWF movies so they can send each other Flash Objects, but does not initialize the memory segment.

cygnal::LcShm::~LcShm (  ) 

Delete the shared memory segment.

Remarks:
This does not clear the content of the memory segment.
cygnal::LcShm::LcShm ( boost::uint8_t *  addr  ) 

Construct an initialized shared memory segment.

Parameters:
baseaddr The address to use for the memory segment.
addr The address to use for the memory segment.
cygnal::LcShm::LcShm ( key_t  key  ) 

Construct an initialized shared memory segment.

Parameters:
key The SYSV style key to use for the memory segment.

Member Function Documentation

void cygnal::LcShm::addConnectionName ( std::string &  name  ) 

Set the name for this connection to the memory segment.

Parameters:
name The name for this connection.
Returns:
nothing.
void cygnal::LcShm::addHostname ( std::string &  name  ) 

Set the hostname used for this connection to the memory segment.

Parameters:
name The hostname for this connection, often "localhost".
Returns:
nothing.
void cygnal::LcShm::addObject ( boost::shared_ptr< cygnal::Element el  )  [inline]

Add an AMF0 Element array of data for this memory segment.

Returns:
void cygnal::LcShm::close ( void   ) 

Close a memory segment. This closes the shared memory segment, but the data remains until the next reboot of the computer.

Returns:
nothing.
bool cygnal::LcShm::connect ( key_t  key  ) 

Connect to a memory segment.

Parameters:
key The SYSV style key for the shared memory segment, which is the default type used.
Returns:
true if this succeeded. false if it doesn't.

References gnash::SharedMem::begin(), gnash::image::begin(), gnash::SharedMem::end(), parseHeader(), and cygnal::Listener::setBaseAddress().

bool cygnal::LcShm::connect ( const std::string &  name  ) 

Connect to a memory segment.

Parameters:
name The name to use for POSIX shared memory, which is not the default type used.
Returns:
true if this succeeded. false if it doesn't.
void cygnal::LcShm::dump (  ) 

Dump the internal data of this class in a human readable form.

Read the date from the memory.

Remarks:
This should only be used for debugging purposes.
Parameters:
dataname The name of the data to read.
data A vector of smart pointers to the AMF0 Elements in this memory segment.
Returns:
nothing. We may only need a connection name for the receive function. void recv(std::string &name, std::string &dataname, boost::shared_ptr<cygnal::Element> data) log_debug(_(" ***** The recv function is called *****") ); TODO: This function should at do the following work: 1: Lock the shared memory boost::mutex::scoped_lock lock(_localconnection_mutex); 2: Check if the current object is the listener if findListener() Make sure the object is the listener for certain connection name 2: Parse the header boost::uint8_t *parseHeader(boost::uint8_t *data, boost::uint8_t* tooFar); This should be easy if parseHeader function has been finished. 3: Parse the body of the shared memory std::vector<boost::shared_ptr<cygnal::Element> > parseBody(boost::uint8_t *data); This should be easy if parseHeader function has been finished. 4: The listened should implement these commands somehow automatically . Handler? return; Dump the internal data of this class in a human readable form.
Remarks:
This should only be used for debugging purposes.

References _object, and cygnal::Listener::listListeners().

boost::uint8_t * cygnal::LcShm::formatHeader ( const std::string &  con,
const std::string &  host,
bool  domain 
)

Format the header for the memory segment.

Parameters:
con The name of the connection.
host The bostname of the connection, often "localhost"
domain The domain the hostname is in.
Returns:
A real pointer to a header for a memory segment.
Parameters:
con The name of the connection.
host The hostname of the connection, often "localhost"
domain The domain the hostname is in.
Returns:
A real pointer to a header for a memory segment.

References cygnal::AMF::encodeString(), cygnal::Listener::getBaseAddress(), cygnal::LC_HEADER_SIZE, and size().

bool cygnal::LcShm::getconnected (  )  [inline]
std::vector<boost::shared_ptr<cygnal::Element> > cygnal::LcShm::getElements (  )  [inline]

Get the array of AMF0 objects stored by this class.

Returns:
A vector of smart pointers to AMF0 Elements.
std::vector<boost::shared_ptr<cygnal::Element> > cygnal::LcShm::parseBody ( boost::uint8_t *  data  ) 

Parse the body of a memory segment.

Parameters:
data The real pointer to the address to start parsing from.
Returns:
A vector of smart pointers to the AMF0 Elements in this memopry segment.
boost::uint8_t * cygnal::LcShm::parseHeader ( boost::uint8_t *  data,
boost::uint8_t *  tooFar 
)

Parse the header of the memory segment.

Parameters:
data real pointer to start parsing from.
tooFar A pointer to one-byte-past the last valid memory address within the buffer.
Returns:
A real pointer to the data after the headers has been parsed.
Remarks:
May throw a ParserException
Note:
From what I can tell by exaimining the memory segment, after the raw 16 bytes is a LocalConnection object. This appears to have the following data types: String - This appears to the connection name, and looks like "localhost:lc_replay" String - This appears to be the hostname of the connection, and at least in my tests, has always been "localhost". Boolean - In all the files I've looked at, this has always been TRUE. I assume this is the domain security flag. Si: This value could be false. Number - No idea what this number represents. Number - No idea what this number represents. NULL terminator AMF objects - this is followed by the AMF objects that have been added to the LocalConnection. This can be up to 40k long. While other web sites have claimed there is a length field in the initial shared memory segment header, I've never seen one in my tests.
Parameters:
data real pointer to start parsing from.
tooFar A pointer to one-byte-past the last valid memory address within the buffer.
Returns:
A real pointer to the data after the headers has been parsed.
Remarks:
May throw a ParserException

References cygnal::LcShm::lc_object_t::connection_name, ENSUREBYTES, cygnal::AMF::extractAMF(), cygnal::LcShm::lc_object_t::hostname, and cygnal::LC_HEADER_SIZE.

Referenced by connect().

void cygnal::LcShm::recv ( std::string &  name,
std::string &  dataname,
boost::shared_ptr< cygnal::Element data 
)

Read the date from the memory.

Parameters:
dataname The name of the data to read.
data A vector of smart pointers to the AMF0 Elements in this memory segment.
Returns:
nothing. We may only need a connection name for the receive function.
void cygnal::LcShm::send ( const std::string &  name,
const std::string &  dataname,
std::vector< cygnal::Element * > &  data 
)

Put data in the memory segment This puts data into the memory segment.

Parameters:
name The connection name for this connection
dataname The name of the data to send.
data A vector of smart pointers to the AMF0 Elements containing the data for this memory segment.
Returns:
nothing.
void cygnal::LcShm::setBaseAddr ( boost::uint8_t *  addr  )  [inline]

Set the base address to be used for the memory segment.

Parameters:
addr The address to use for opening the memory segment.
Returns:
nothing.
void cygnal::LcShm::setconnected ( bool  trueorfalse  )  [inline]
size_t cygnal::LcShm::size (  )  [inline]

Get the number of AMF0 Elements stored in this class.

Returns:
The number of AMF0 Elements stored in this class.

Referenced by formatHeader().


The documentation for this class was generated from the following files: