Coverage for ion/core/messaging/message_client : 92.73%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#!/usr/bin/env python
@file ion/core/messaging/message_client.py @author David Stuebe @brief Message Client and and Message Instance classes are used to manage message objects in services and processes. They provide a simple interface to create and manage messages.
@ TODO Add methods to access the state of updates which are merging... """
#from ion.core.process import process
""" A class for message client exceptions """
""" @brief This is the base class for a message client. It is a factory for message instances. The message instance provides the interface for working with messages. The client helps create and manage message instances. """
""" Initializes a process client @param proc a IProcess instance as originator of messages @param datastore the name of the datastore service with which you wish to interact with the OOICI. """ #proc = process.Process() raise MessageClientError('Message Client can not be used without a process')
# The message client is backed by a process workbench.
def _check_init(self): """ Called in client methods to ensure that there exists a spawned process to send and receive messages """
### Let someone else worry about whether the process is spawnded...
#Must use a yield to keep the defered interface #yield None 'Process workbench is not initialized'
""" @brief Create an instance of the message type! @param MessageContentTypeID is a type identifier object @param MessageName is a depricated architectural concept. Please do not use it! @retval message is a MInstance object """
# Create a sendable message object
# For now let the message ID be set by the process that created it?
# Add an empty message object of the requested type
# make a local commit
# Create a message instance
""" @brief Reference message creates a data object which can be used as a message or part of a message or added to another data object or message. @param instance is a messageInstance object @param current_state is a boolen argument which determines whether you intend to reference exactly the current state of the message. @retval an Identity Reference object to the message """
return self.workbench.reference_repository(instance.MessageIdentity, current_state)
""" Exception class for Message Instance Object """
raise AttributeError('Can not delete a Message Instance property')
raise AttributeError('Can not set a Message Instance enum object')
raise AttributeError('Can not delete a Message Instance property')
""" Metaclass that automatically generates subclasses of Wrapper with corresponding enums and pass-through properties for each field in the protobuf descriptor.
This approach is generally applicable to wrap data structures. It is extremely powerful! """
# Cache the custom-built classes
# Check that the object we are wrapping is a Google Message object raise MessageInstanceError('MessageInstance init argument must be an instance of a Repository')
raise MessageInstanceError( 'MessageInstance init Repository argument is in an invalid state - checkout first!')
raise MessageInstanceError('MessageInstance init Repository is not a message object!')
else: # Get the class name
# Now setup the properties to map through to the GPB object #print 'Key: %s; Type: %s' % (fieldName, type(message_field))
# Try rewriting using slots - would be more efficient... '''Cant add properties to the ION Message Instance.\n''' '''Unknown property name - "%s"; value - "%s"''' % (k, v))
# Finally allow the instantiation to occur, but slip in our new class type
""" @brief The resoure instance is the vehicle through which a process interacts with a message instance. It hides the git semantics of the data store and deals with message specific properties. """
""" message Instance objects are created by the message client """
def Repository(self):
def Message(self):
raise MessageInstanceError('Can not change the type of a message object!')
""" @brief CreateObject is used to make new locally created objects which can be added to the message's data structure. @param type_id is the type_id of the object to be created @retval the new object which can now be attached to the message """
""" Return a list of the names of the fields which have been set. """
log.warn('HasField is depricated because the name is confusing. Use IsFieldSet') return self.IsFieldSet(field)
return self.MessageObject.ClearField(field)
#@property #def IonResponse(self): # return self.Message.IonResponse # #def _set_message_ion_response(self, value): # """ # Set the name of the message object # """ # self.Message.ion_response = value # #def _get_message_ion_response(self): # """ # """ # return self.Message.ion_response # #MessageIonResponse = property(_get_message_ion_response, _set_message_ion_response)
#@property #def ApplicationResponse(self): # return self.Repository._workspace_root.ApplicationResponse # #def _set_message_application_response(self, value): # """ # Set the name of the message object # """ # self.Message.application_response = value # #def _get_message_application_response(self): # """ # """ # return self.Message.application_response # #MessageApplicationResponse = property(_get_message_application_response, _set_message_application_response)
def ResponseCodes(self):
""" Set the name of the message object """
""" """
""" Set the name of the message object """
""" """
def MessageIdentity(self): """ @brief Return the message identity as a string """
def MessageType(self): """ @brief Returns the message type - A type identifier object - not the wrapped object. """ else:
""" Set the name of the message object """
""" """
@var MessageName is a getter setter property for the name of the message """
|