Classes | Defines | Functions | Variables

C:/Documents and Settings/gw/My Documents/Other projects/flightos/Core/sockets.h File Reference

#include "common.h"
#include "module.h"

Go to the source code of this file.

Classes

class  Socket
 Class that exposes data to other modules. More...
class  SocketT< T >
 Sockets of various types. More...
class  Socket16
class  Socket32
class  SocketF
class  ParameterT< T >
 Parameters of various types. More...
class  Parameter16
class  Parameter32
class  ParameterF
class  PlugT< T >
 Plugs of various types. More...
class  Plug16
class  Plug32
class  PlugF
class  Splice8
class  Splice16
class  Splice32
class  SpliceF

Defines

#define DEFINE_SOCKET(C, T, P, D)
#define DEFINE_PARAMETER(C, T, D, P)
#define DEFINE_PLUG(C, T, D)
#define DEFINE_SPLICE(C, T, D)

Functions

 operator byte () const
byte * GetPointer ()
const byte & operator= (const byte value)
const byte & operator+= (const byte value)
const byte & operator-= (const byte value)
const byte & operator*= (const byte value)
const byte & operator/= (const byte value)
virtual const char * GetType ()
virtual void Print (class Print &dest)
virtual void * GetPayload (int &size)
virtual bool IsParameter ()
virtual bool Parse (const char *string)
void operator= (const Plug8 &ptr)
bool IsConnected ()
bool Connect (const char *name)
void Invalidate ()

Variables

SocketT C
 Sockets of various types.
SocketT T
SocketT P
SocketT m_data
ParameterT D
class PlugT m_socket

Define Documentation

#define DEFINE_PARAMETER (   C,
  T,
  D,
  P 
)
Value:
class C : public D\
  {\
  public:\
    inline operator T() const {return (m_data);}\
    inline const T& operator = (const T value){m_data = value; return m_data;}\
    inline const T& operator += (const T value){m_data += value; return m_data;}\
    inline const T& operator -= (const T value){m_data -= value; return m_data;}\
    inline const T& operator *= (const T value){m_data *= value; return m_data;}\
    inline const T& operator /= (const T value){m_data /= value; return m_data;}\
    virtual bool IsParameter(){return (true);}\
    virtual bool Parse(const char * string){m_data = P(string);}\
  };\
#define DEFINE_PLUG (   C,
  T,
  D 
)
Value:
class C\
  {\
  public:\
    C(){m_socket = NULL;}\
    inline operator D() const {return (*m_socket);}\
    inline void operator = (const C& ptr){if(m_socket)*m_socket = *ptr.m_socket;}\
    inline void operator = (const D value){if(m_socket)*m_socket = value;}\
    inline const T& operator += (const D value){*m_socket += value; return *m_socket;}\
    inline const T& operator -= (const D value){*m_socket -= value; return *m_socket;}\
    inline const T& operator *= (const D value){*m_socket *= value; return *m_socket;}\
    inline const T& operator /= (const D value){*m_socket /= value; return *m_socket;}\
    inline D * GetPointer(){return (m_socket->GetPointer());}\
    inline bool IsConnected(){return(m_socket != NULL);}\
    bool Connect(const char * name){\
      m_socket = (T*)g_moduleManager.GetSocket(name,#T);\
      return(IsConnected());\
    }\
    void Invalidate(){m_socket = NULL;}\
  private:\
    T * m_socket;\
  };
#define DEFINE_SOCKET (   C,
  T,
  P,
  D 
)
Value:
class C : public Socket\
  {\
  public:\
    C(){m_data = 0;}\
    inline operator T() const {return (m_data);}\
    inline T* GetPointer(){return(&m_data);}\
    inline const T& operator = (const T value){m_data = value; return m_data;}\
    inline const T& operator += (const T value){m_data += value; return m_data;}\
    inline const T& operator -= (const T value){m_data -= value; return m_data;}\
    inline const T& operator *= (const T value){m_data *= value; return m_data;}\
    inline const T& operator /= (const T value){m_data /= value; return m_data;}\
    virtual const char * GetType(){return(#C);}\
    virtual void Print(class Print& dest){dest.print((P)m_data,D);}\
    virtual void * GetPayload(int& size){size = sizeof(T);return(&m_data);}\
  protected:\
    T m_data;\
  };
#define DEFINE_SPLICE (   C,
  T,
  D 
)
Value:
class C : public T\
  {\
  public:\
    C(){m_data = 0;\
        m_socket = NULL;\
    }\
    inline operator D() const {return (*m_socket);}\
    inline void operator = (const D value){m_data = value;}\
    inline const D& operator += (const D value){m_data = *m_socket + value; return m_data;}\
    inline const D& operator -= (const D value){m_data = *m_socket - value; return m_data;}\
    inline const D& operator *= (const D value){m_data = *m_socket * value; return m_data;}\
    inline const D& operator /= (const D value){m_data = *m_socket / value; return m_data;}\
    inline void PassThrough(){m_data = *m_socket;}\
    inline bool IsConnected(){return(m_socket != NULL);}\
    bool Connect(const char * name){\
      m_socket = (T*)g_moduleManager.GetSocket(name,#T);\
      if(m_socket) g_moduleManager.ReplaceSocket(m_socket,this);\
      return(IsConnected());\
    }\
    void Invalidate(){m_socket = NULL;}\
  private:\
    T * m_socket;\
  };

Function Documentation

bool Connect ( const char *  name  )  [protected]
virtual void* GetPayload ( int &  size  )  [virtual]
byte * GetPointer (  )  [inline]
virtual const char* GetType (  )  [virtual]
void Invalidate (  )  [protected]
bool IsConnected (  )  [inline, protected]
virtual bool IsParameter (  )  [protected, virtual]
operator byte (  )  const [inline]
const Socket8 & operator*= ( const byte  value  )  [inline]
const Socket8 & operator+= ( const byte  value  )  [inline]
const Socket8 & operator-= ( const byte  value  )  [inline]
const Socket8 & operator/= ( const byte  value  )  [inline]
void operator= ( const Plug8 &  ptr  )  [inline, protected]
void operator= ( const byte  value  )  [inline]
virtual bool Parse ( const char *  string  )  [protected, virtual]
virtual void Print ( class Print &  dest  )  [virtual]

Variable Documentation

class PlugT C

Sockets of various types.

Plugs of various types.

Parameters of various types.

Currently defined are:

Parameters are like non-volatile sockets. They are stored in EEPROM They can be read by other modules. Writing to them is a special case and has to be done via ModuleManager. Have look at the serial module for an example.

Currently defined are:

Plugs encapsulate acquiring and using sockets exposed by other modules. They can be read just like their data type. To connect a Plug to another module's socket use this syntax in your module's Init() function:

 FooPlug.Connect("socket name");

To access the data, simply read it like any normal variable. Say you have a PlugF called FooPlug, this code would work fine:

float f = FooPlug;

NOTE: It is a very good idea to check IsValid() after connecting. The socket may not exist or may be of the wrong data type!

 FooPlug.Connect("socket name");
 if(!FooPlug.IsValid())
 {
   Show an error message or reduce functionality so you don't need this value.
 }

If you read a Plug that is not valid the returned value is indeterminate.

Writing to a plug that is not valid has no effect

Plugs are type safe so for examaple a PlugF will only connect to a SocketF or ParameterF.

Currently defined are:

  • Plug8 (8 bit unsigned)
  • Plug16 (16 bit signed)
  • Plug32 (32 bit signed)
  • PlugF (Floating point)
Socket8 * m_socket
class PlugT T
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Defines