/*! \brief Sets the message type context to the named message type. \param[in] Name String containing name of desired message type context. \param[in] context Pointer to runtime context. \return Returns dmz::True if the named message type context is found. */ dmz::Boolean dmz::Message::set_type (const String &Name, RuntimeContext *context) { Definitions defs (context); return defs.lookup_message (Name, *this); }
/*! \brief Sets the message type context to the type specified by the unique handle. \param[in] TypeHandle Unique handle of a message type context. \param[in] context Pointer to the runtime context. \return Returns dmz::True if the message type context is found. */ dmz::Boolean dmz::Message::set_type (const Handle TypeHandle, RuntimeContext *context) { Definitions defs (context); return defs.lookup_message (TypeHandle, *this); }
/*! \brief Converts Config to Message. \details Defined in dmzRuntimeMessaging.h. This function converts the named attribute to a dmz::Message. It is assumed that the last part of the \a Name variable specifies the attribute name. If the String "type.name" is passed in as \a Name, it will try to find a config context called "type" and the attribute "name" stored in the "type" config context. \code dmz::Message type = dmz::config_to_message ("dmz.type.name", global, get_plugin_runtime_context (), &_log); \endcode \param[in] Name String containing name of the attribute in the config context to convert. \param[in] Source Config containing config context to convert. \param[in] context Pointer to the runtime context. \param[in] log Pointer to the dmz::Log to use for log reporting. \return Returns dmz::Message containing the message type. Returns an empty dmz::Message if the message type is not found. */ dmz::Message dmz::config_to_message ( const String &Name, const Config &Source, RuntimeContext *context, Log *log) { Message result; String messageTypeName; if (Source.lookup_attribute (Name, messageTypeName)) { Definitions defs (context); if (!defs.lookup_message (messageTypeName, result)) { if (log) { log->warn << "Message type: " << messageTypeName << " not found" << endl; } } else if (log && !result) { log->warn << "Message type: " << messageTypeName << " look up returned null type" << endl; } } else if (log) { log->warn << "Message type config: " << Source.get_name () << " does not contain attribute: " << Name << endl; } return result; }
int main (int argc, char *argv[]) { Test test ("dmzRuntimeMessageTest", argc, argv); RuntimeContext *context (test.rt.get_context ()); Config config; if (test.validate ( "Looking up runtime table", test.config.lookup_config ("dmz.runtime", config))) { runtime_init (config, test.rt.get_context (), &(test.log)); } const String TestTypeName ("testType"); const String RootTypeName ("rootType"); Message type; Definitions defs (context, &(test.log)); test.validate ( "Looking up Message: testType", defs.lookup_message (TestTypeName, type)); test.validate ( "Message name is set to: testType", type.get_name () == TestTypeName); test.validate ( "Message handle is non-zero", type.get_handle () != 0); Message parent (type.get_parent ()); test.validate ( "Fetching parent message type", parent); test.validate ( "Message parent name is set to: rootType", parent.get_name () == RootTypeName); test.validate ( "Message parent handle is non-zero", parent.get_handle () != 0); // null constructor Message nullMessage; test.validate ( "Default constructor", !nullMessage.get_message_context ()); // standard constructors Message testMessageName ("testType", context); test.validate ( "Constructor with \"Name\" and \"RuntimeContext\" supplied.", testMessageName.get_message_context () && !(strcmp (testMessageName.get_name ().get_buffer (), "testType"))); Message testMessageHandle (testMessageName.get_handle (), context); test.validate ( "Constructor with \"Handle\" and \"RuntimeContext\" supplied.", testMessageHandle.get_message_context () && !(strcmp (testMessageHandle.get_name ().get_buffer (), "testType")) && (testMessageHandle == testMessageName)); Message testMessage (testMessageHandle.get_message_context ()); test.validate ( "Constructor with \"MessageContext\" supplied.", testMessage.get_message_context () && !(strcmp (testMessage.get_name ().get_buffer (), "testType")) && (testMessage == testMessageName) && (testMessage == testMessageHandle)); // copy constructor Message copyOfTestMessage (testMessage); test.validate ( "Copy Constructor.", copyOfTestMessage.get_message_context () && !(strcmp (copyOfTestMessage.get_name ().get_buffer (), "testType")) && (copyOfTestMessage == testMessage) && (copyOfTestMessage == testMessageName) && (copyOfTestMessage == testMessageHandle)); // operators Message sameType (testMessage); Message differentType ("rootType", context); // == operator test.validate ( "== operator", (testMessage == sameType) && !(testMessage == differentType)); // != operator test.validate ( "!= operator", !(testMessage != sameType) && (testMessage != differentType)); // ! operator Message anotherType; test.validate ( "! operator", (!anotherType) && !(!testMessage)); // = operator anotherType = testMessage; test.validate ( "Assignment operator", (testMessage == anotherType)); // validate set_type anotherType = differentType; test.validate ( "set_type", (testMessage != anotherType) && anotherType.set_type (testMessage.get_handle (), context) && (testMessage == anotherType)); // is_of_type and is_of_exact_type Message testMessageRoot ("rootType", context); Message testMessageTest ("testType", context); test.validate ( "is_of_type", testMessageRoot.is_of_type (testMessageRoot) && !testMessageRoot.is_of_type (testMessageTest) && testMessageTest.is_of_type (testMessageRoot) && testMessageTest.is_of_type (testMessageTest)); test.validate ( "is_of_exact_type", testMessageRoot.is_of_exact_type (testMessageRoot) && !testMessageRoot.is_of_exact_type (testMessageTest) && !testMessageTest.is_of_exact_type (testMessageRoot) && testMessageTest.is_of_exact_type (testMessageTest)); // get and set functions test.validate ( "get_name", !strcmp (testMessageRoot.get_name ().get_buffer (), "rootType") && !strcmp (testMessageTest.get_name ().get_buffer (), "testType")); test.validate ( "get_handle", !nullMessage.get_handle () && testMessage.get_handle ()); testMessage = testMessageTest.get_parent (); test.validate ( "get_parent", (testMessage == testMessageRoot)); testMessage = testMessageTest; test.validate ( "become_parent", (testMessage != testMessageRoot) && testMessage.become_parent () && (testMessage == testMessageRoot)); return test.result (); }
// Plugin Interface void dmz::QtPluginAppUpdater::update_plugin_state ( const PluginStateEnum State, const UInt32 Level) { if (State == PluginStateInit) { } else if (State == PluginStateStart) { RuntimeContext *context (get_plugin_runtime_context ()); Definitions defs (context, &_log); Message message; if (defs.lookup_message (_updateMessageName, message)) { const Data *data (message.get_monostate ()); if (data) { data->lookup_boolean (_valueAttrHandle, 0, _updateFlag); } } if (defs.lookup_message (_channelMessageName, message)) { const Data *data (message.get_monostate ()); if (data) { data->lookup_string (_valueAttrHandle, 0, _releaseChannel); } } if (_forceUpdate || _updateFlag) { if (!_netManager) { _netManager = new QNetworkAccessManager (this); } if (_netManager) { if (_mainWindowModule && !_updateDialog) { _updateDialog = new QDialog ( _mainWindowModule ? _mainWindowModule->get_qt_main_window () : 0); _ui.setupUi (_updateDialog); connect ( _ui.downloadButton, SIGNAL (clicked ()), this, SLOT (_slot_download_start ())); connect ( _ui.laterButton, SIGNAL (clicked ()), this, SLOT (_slot_download_cancel ())); connect ( _ui.finishedButton, SIGNAL (clicked ()), this, SLOT (_slot_handle_downloaded_file ())); } _check_for_update (); } } } else if (State == PluginStateStop) { } else if (State == PluginStateShutdown) { } }