BaseComponent Class Reference

#include <BaseComponent.h>

Inheritance diagram for BaseComponent:

ArduinoInterface CamVisionInterface CollisionInterface GeneratePI GenerateRandom1 GenerateRandom2 GenerateRandom3 LaserInterface Observer ProjectionInterface ProjectionTest ReadPI RoadSelectInterface RoadSelectTest WaypointInterface

List of all members.


Detailed Description

Base component class; All components should derive from this class and overload the appropriate functions.

Public Member Functions

void Stop ()
void Run ()
int GetDataByteCount (const char *ComponentName, const char *DataType)
int GetData (const char *ComponentName, const char *DataType, void *DataBuffer, unsigned int *SecondsSent=NULL, unsigned int *MillisecondsSent=NULL)
int SendData (const char *DataType, const void *DataBuffer, int BufferByteSize)

Protected Member Functions

 BaseComponent (const char *ComponentName, float AllocatedTime, const char *CentralIP=NULL, int Port=1381)
 ~BaseComponent ()
 Destructor; Releases internal resources and allocations, as well as releases from the main component.
void SetDependency (const char *GivenComponentName)
 Sets a dependency; Tells the underlying communication system to expect input from the given component names.
virtual int Update ()=0
bool LoadInt (const char *Key, int *Data)
bool LoadFloat (const char *Key, float *Data)
bool LoadString (const char *Key, char **Data)

Static Protected Member Functions

static void __Run ()
 A static run handle that is used for complex call backs such as with OpenGL hooks.

Private Member Functions

ComModelBlockGetDataBlock (const char *GivenComponentName, const char *GivenDataType)
 Get the data page block based on the given component name and data type; Returns null on error.
int LoadConfig (const char *FileName)

Private Attributes

char * ConfigTable [CONFIG_TABLE_LENGTH][2]
 The configuration table that is string-name / data pairs.
bool RunLoop
 Infinite looping control variable.
float AllocatedTime
 The internal performance clock (The allocated time per cycle); Set by the constructor.
char * ComponentName
 This component name; Must be unique.
char * CentralIP
 Server name / IP.
int Port
 Server port number.

Constructor & Destructor Documentation

BaseComponent::BaseComponent ( const char *  ComponentName,
float  AllocatedTime,
const char *  CentralIP = NULL,
int  Port = 1381 
) [protected]

Constructor; Takes this component's name and registers itself to the main component The main component is found using a configuration file or a hard-coded IP/port value If central IP is NULL, then config file's IP is used, which if it is not defined, the 'localhost' is used Dependencies should be set by calling the "SetDepandancy" function within the constructor

BaseComponent::~BaseComponent (  )  [protected]

Destructor; Releases internal resources and allocations, as well as releases from the main component.


Member Function Documentation

void BaseComponent::SetDependency ( const char *  GivenComponentName  )  [protected]

Sets a dependency; Tells the underlying communication system to expect input from the given component names.

virtual int BaseComponent::Update (  )  [protected, pure virtual]

The main update function; The end-developer of the target component must overload this function Though no input / output events are required, this is where such transfer would be done The return value can be anything, though a negative value means a failure and will kill the component

Implemented in ArduinoInterface, CamVisionInterface, LaserInterface, GenerateRandom1, GenerateRandom2, GenerateRandom3, Observer, ProjectionInterface, ProjectionTest, RoadSelectInterface, RoadSelectTest, GeneratePI, ReadPI, and WaypointInterface.

bool BaseComponent::LoadInt ( const char *  Key,
int *  Data 
) [protected]

Load an integer from the configuration file Takes the data associated with the given key-string (case insensitive) and posts it to the given data buffer Returns a "true" if the assignment is valid, "false" otherwise. If it fails, no data is changed / set

bool BaseComponent::LoadFloat ( const char *  Key,
float *  Data 
) [protected]

Load an float from the configuration file Takes the data associated with the given key-string (case insensitive) and posts it to the given data buffer Returns a "true" if the assignment is valid, "false" otherwise. If it fails, no data is changed / set

bool BaseComponent::LoadString ( const char *  Key,
char **  Data 
) [protected]

Load a string from the configuration file Takes the data associated with the given key-string (case insensitive) and posts it to the given data buffer The string is not copied, but is set to the internal buffer; Do not write to it (Though you can if you must) Returns a "true" if the assignment is valid, "false" otherwise. If it fails, no data is changed / set

void BaseComponent::__Run (  )  [static, protected]

A static run handle that is used for complex call backs such as with OpenGL hooks.

void BaseComponent::Stop (  ) 

Stop the Run cycle; Does not call destructor but allows the class to release from infinite loop Note that this is a "soft" stop; The run function completes a final cycle and then returns control to the caller

void BaseComponent::Run (  ) 

The main loop function for this class; Call's destructor when killed Note that this function does an infinite loop until the destructor is called

int BaseComponent::GetDataByteCount ( const char *  ComponentName,
const char *  DataType 
)

Get data size Takes the given target component name, as well as the data type, and returns the number of bytes for that page block. Returns a negative value on error

int BaseComponent::GetData ( const char *  ComponentName,
const char *  DataType,
void *  DataBuffer,
unsigned int *  SecondsSent = NULL,
unsigned int *  MillisecondsSent = NULL 
)

Get data (Input) Takes the target component name, as well as the data element queried, and posts into a generic buffer NOTE: The buffer must be pre-allocated! For varying sizes, use the "GetSize" to determine message size Returns a negative value on error, else, returns the byte count written to the given buffer Returns the time this message was posted via reference style; This is purely optional

int BaseComponent::SendData ( const char *  DataType,
const void *  DataBuffer,
int  BufferByteSize 
)

Send data (Output) Sends data into an internal buffer and passes it to the appropriate "listening" components Returns a negative value on error, else, returns the byte-size sent

ComModelBlock * BaseComponent::GetDataBlock ( const char *  GivenComponentName,
const char *  GivenDataType 
) [private]

Get the data page block based on the given component name and data type; Returns null on error.

int BaseComponent::LoadConfig ( const char *  FileName  )  [private]

Load a configuration file of the given config file name Returns a non-zero in case of failure


Member Data Documentation

char* BaseComponent::ConfigTable[CONFIG_TABLE_LENGTH][2] [private]

The configuration table that is string-name / data pairs.

bool BaseComponent::RunLoop [private]

Infinite looping control variable.

The internal performance clock (The allocated time per cycle); Set by the constructor.

This component name; Must be unique.

char* BaseComponent::CentralIP [private]

Server name / IP.

int BaseComponent::Port [private]

Server port number.


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

Generated on Sun Feb 21 00:00:09 2010 for Penn State Robotics Club: Mini Grand Challenge 2010 by  doxygen 1.5.5