C12Adapter Opensource C++ Interface
MCOMFactory Class Reference

Factory that is capable of creating MCOM objects. More...

Inheritance diagram for MCOMFactory:

Static Public Member Functions

static MChannelCreateChannel (const MStdString &channelSource)
 Create a new channel with the channel source given as a parameter. More...
 
static MProtocolCreateProtocol (const MVariant &channelObjectOrSource, const MStdString &protocolSource)
 Create protocol from channel object or source string, and the protocol source string. More...
 
static MProtocolCreateProtocolWithoutChannel (const MStdString &protocolSource)
 Create protocol with null channel from the protocol source string. More...
 
static MProtocolCreateProtocolByName (MChannel *channel, const MStdString &protocolName)
 Create the protocol by the known name, all known names start with "PROTOCOL_". More...
 
static MChannelCreateChannelByName (const MStdString &channelName)
 Create the channel by the known name, all known names start with "CHANNEL_". More...
 
static MStdStringVector GetAllAvailableChannels ()
 Get the channel names available for creation. More...
 
static MStdStringVector GetAllAvailableProtocols ()
 Get the protocol names available for creation. More...
 
static MStdStringVector GetIdentifyStrings (const MStdString &complexIdentify)
 Get identify strings, that are in the given, possibly complex identify string. More...
 
- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 

Additional Inherited Members

- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Factory that is capable of creating MCOM objects.

This is a singleton class. No instances are required, the services are available through static reference syntax.

Member Function Documentation

static MChannel* MCOMFactory::CreateChannel ( const MStdString channelSource)
static

Create a new channel with the channel source given as a parameter.

Parameters
channelSource

The channel name and if desired, additional property values, separated by semi-colons.

The string can be in the form "PROPERTY1=VALUE1;PROPERTY2=VALUE2;..." where the TYPE=channelname property is required and the channelname is a known channel name, such as CHANNEL_OPTICAL_PROBE. The list of possible channel names can be gotten with GetAllAvailableChannels. The properties that can be supplied depend on the particular channel and their values must be correct. If a property is mentioned more than once, the one which is mentioned last is in effect. For properties that are not given, the channel is created with their default values. Here is an example:

// MChannelOpticalProbe is created with all its properties at their default value
channel = MCOMFactory::CreateChannel("TYPE=CHANNEL_OPTICAL_PROBE");
// MChannelOpticalProbe is created with PORT_NAME initialized as COM4, and
// all other properties at their default value.
channel = MCOMFactory::CreateChannel("TYPE=CHANNEL_OPTICAL_PROBE;PORT_NAME=COM4");

Property values that are of type string can be optionally surrounded by double quotes, so both PORT_NAME="COM2" and PORT_NAME=COM2 work. Not requiring the double quotes is convenient as to include them usually requires some special handling, like using escape sequences. For example, C++ code looks like:

PORT_NAME=\"COM2\"

There are rare cases where the double quotes are part of the property value, such as a Bluetooth probe we encountered that actually called itself "BluetoothProbe", instead of BluetoothProbe. This results in a string that has a quoted string, that has a quoted string. You can't just have

PORT_NAME=\"BluetoothProbe\"

because MeteringSDK will take the name as BluetoothProbe. You can't pass it as

PORT_NAME=\"\"BluetoothProbe\"\"

either because MeteringSDK assumes that the 2nd escaped quote (the one before the B) is the end of the value (it thinks that PORT_NAME = ""). What you have to do is escape the backslashes used to escape the quotes that are part of the probe name, like

PORT_NAME=\"\\\"BluetoothProbe\\\"\"
Returns
MChannel. Note that null object is never returned.
See also
CreateChannelByName creates channel from known name, such as "CHANNEL_OPTICAL_PROBE".
GetAllAvailableChannels returns the list of available channel names, such as "CHANNEL_OPTICAL_PROBE".
static MChannel* MCOMFactory::CreateChannelByName ( const MStdString channelName)
static

Create the channel by the known name, all known names start with "CHANNEL_".

The list of possible channel names can be gotten with GetAllAvailableChannels.

Parameters
channelNameThe known channel name, such as "CHANNEL_OPTICAL_PROBE". The channel with such name should exist in the Factory, otherwise an exception is thrown.
Returns
MChannel. Note that null object is never returned.
See also
CreateChannel creates channel from source string.
GetAllAvailableChannels returns the list of available channel names, such as "CHANNEL_OPTICAL_PROBE".
static MProtocol* MCOMFactory::CreateProtocol ( const MVariant channelObjectOrSource,
const MStdString protocolSource 
)
static

Create protocol from channel object or source string, and the protocol source string.

Parameters
channelObjectOrSource

An empty variant (no channel), the channel object, or a string that describes the channel.

An empty variant or an object with null value, can be given, in this case the channel associated with the protocol is a null object.

A channel object, such as MChannelOpticalProbe, can be given, and it will be assigned to and owned by the protocol. The channel can be given while in any state - it can be connected or not, etc.

A string that represents the channel type and its property values. CreateChannel describes in detail what the string can be. The result channel is owned by the protocol.

Parameters
protocolSource

The protocol name and if desired, additional property values, separated by semi-colons.

The string can be in the form "PROPERTY1=VALUE1;PROPERTY2=VALUE2;..." where the TYPE=protocolname property is required and the protocolname is a known protocol name, such as PROTOCOL_ANSI_C12_18. The list of possible protocol names can be gotten with GetAllAvailableProtocols. The properties that can be supplied depend on the particular protocol and their values must be correct. If a property is mentioned more than once, the one which is mentioned last is in effect. For properties that are not given, the protocol is created with their default values. Here is an example:

// MProtocolC1218 is created with all its properties at their default value.
protocol = MCOMFactory::CreateProtocol(channel, "TYPE=PROTOCOL_ANSI_C12_18");
// MProtocolC1218 is created with SESSION_BAUD initialized to 28800, and
// all other properties at their default value.
protocol = MCOMFactory::CreateProtocol(channel,
"TYPE=PROTOCOL_ANSI_C12_18;SESSION_BAUD=28800");

Returns
MProtocol. Note that null object is never returned.
See also
CreateProtocolWithoutChannel creates protocol with NULL channel.
CreateProtocolByName creates protocol from known name, such as "PROTOCOL_ANSI_C12_18".
GetAllAvailableChannels returns the list of available channel names, such as "CHANNEL_OPTICAL_PROBE".
GetAllAvailableProtocols returns the list of available protocol names, such as "PROTOCOL_ANSI_C12_18".
static MProtocol* MCOMFactory::CreateProtocolByName ( MChannel channel,
const MStdString protocolName 
)
static

Create the protocol by the known name, all known names start with "PROTOCOL_".

The list of possible protocol names can be gotten with GetAllAvailableProtocols.

Parameters
channelThe channel to be assigned to the resulting protocol object, can be null.
protocolNameThe known protocol name, such as "PROTOCOL_ANSI_C12_18". The protocol with such name should exist in the Factory, otherwise an exception is thrown.
Returns
MProtocol. Note that null object is never returned.
See also
CreateProtocol creates protocol object with a channel.
CreateProtocolWithoutChannel creates protocol with NULL channel.
GetAllAvailableProtocols returns the list of available protocol names, such as "PROTOCOL_ANSI_C12_18".
static MProtocol* MCOMFactory::CreateProtocolWithoutChannel ( const MStdString protocolSource)
static

Create protocol with null channel from the protocol source string.

Parameters
protocolSource

The protocol name and if desired, additional property values, separated by semi-colons.

The string can be in the form "PROPERTY1=VALUE1;PROPERTY2=VALUE2;..." where the TYPE=protocolname property is required and the protocolname is a known protocol name, such as PROTOCOL_ANSI_C12_18. The list of possible protocol names can be gotten with GetAllAvailableProtocols. The properties that can be supplied depend on the particular protocol and their values must be correct. If a property is mentioned more than once, the one which is mentioned last is in effect. For properties that are not given, the protocol is created with their default values. Here is an example:

// MProtocolC1218 is created with all its properties at their default value.
protocol = MCOMFactory::CreateProtocolWithoutChannel("TYPE=PROTOCOL_ANSI_C12_18");
// MProtocolC1218 is created with SESSION_BAUD initialized to 28800, and
// all other properties at their default value.
protocol = MCOMFactory::CreateProtocolWithoutChannel("TYPE=PROTOCOL_ANSI_C12_18;SESSION_BAUD=28800");

Returns
MProtocol. Note that null object is never returned.
See also
CreateProtocol creates protocol object with a channel.
CreateProtocolByName creates protocol from known name, such as "PROTOCOL_ANSI_C12_18".
GetAllAvailableProtocols returns the list of available protocol names, such as "PROTOCOL_ANSI_C12_18".
static MStdStringVector MCOMFactory::GetAllAvailableChannels ( )
static

Get the channel names available for creation.

All channel names start with "CHANNEL_".

static MStdStringVector MCOMFactory::GetAllAvailableProtocols ( )
static

Get the protocol names available for creation.

All protocol names start with "PROTOCOL_".

static MStdStringVector MCOMFactory::GetIdentifyStrings ( const MStdString complexIdentify)
static

Get identify strings, that are in the given, possibly complex identify string.

Precondition
The given identify string is a valid one, possibly consisting of multiple individual identify strings. Otherwise the behavior is undefined.