[OSADL-svn-commits] r77 - fapia-trunk/FAPIAController/source
OSADL repository commits
osadl-svn-commits at lists.osadl.org
Tue Oct 2 11:46:15 CEST 2007
Author: tb10rts
Date: Thu Jul 19 07:08:51 2007
New Revision: 77
Log:
Added a folder remotely
Added:
fapia-trunk/FAPIAController/source/
fapia-trunk/FAPIAController/source/FAPIA.cpp
fapia-trunk/FAPIAController/source/FAPIAControllerController.cpp
fapia-trunk/FAPIAController/source/FAPIAControllerController.h
fapia-trunk/FAPIAController/source/FAPIAControllerMethodRequestShutdown.cpp
fapia-trunk/FAPIAController/source/FAPIAControllerMethodRequestShutdown.h
fapia-trunk/FAPIAController/source/FAPIAControllerReplyCommandHandler.cpp
fapia-trunk/FAPIAController/source/FAPIAControllerReplyCommandHandler.h
Added: fapia-trunk/FAPIAController/source/FAPIA.cpp
==============================================================================
--- (empty file)
+++ fapia-trunk/FAPIAController/source/FAPIA.cpp Thu Jul 19 07:08:51 2007
@@ -0,0 +1,270 @@
+// $Id$
+
+
+#include "../../interface/FAPIA.h"
+#include "FAPIAControllerController.h"
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_init (
+ int argc,
+ char* argv[],
+ const char * const name)
+{
+ return FAPIA_CONTROLLER->fapia_init (argc, argv, name);
+}
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_deinit (void)
+{
+ return FAPIA_CONTROLLER->fapia_deinit ();
+}
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_logical_object_names (
+ char*** logical_object_names,
+ unsigned long* number_of_logical_object_names)
+ {
+ return FAPIA_CONTROLLER->fapia_logical_object_names (
+ logical_object_names,
+ number_of_logical_object_names);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_set_callback_for_parameter_read_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAValue *,
+ const FAPIAError *))
+ {
+ return FAPIA_CONTROLLER->fapia_set_callback_for_parameter_read_response_callback (f);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_set_callback_for_parameter_write_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAError *))
+ {
+ return FAPIA_CONTROLLER->fapia_set_callback_for_parameter_write_response_callback (f);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_set_callback_for_parameter_info_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAInfo *,
+ const FAPIAError *))
+ {
+ return FAPIA_CONTROLLER->fapia_set_callback_for_parameter_info_response_callback (f);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_set_callback_for_parameter_read_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *))
+ {
+ return FAPIA_CONTROLLER->fapia_set_callback_for_parameter_read_request_callback (f);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_set_callback_for_parameter_write_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAValue *))
+ {
+ return FAPIA_CONTROLLER->fapia_set_callback_for_parameter_write_request_callback (f);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_set_callback_for_parameter_info_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *))
+ {
+ return FAPIA_CONTROLLER->fapia_set_callback_for_parameter_info_request_callback (f);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_read_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_read_request (
+ fapia_communication,
+ fapia_parameters);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+#if 0
+long fapia_parameter_read_response_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values,
+ const FAPIAError * const fapia_errors)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_read_response_callback (
+ fapia_communication,
+ fapia_parameters,
+ fapia_values,
+ fapia_errors);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_read_request_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_read_request_callback (
+ fapia_communication,
+ fapia_parameters);
+ }
+#endif
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_read_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values,
+ const FAPIAError * const fapia_errors)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_read_response (
+ fapia_communication,
+ fapia_parameters,
+ fapia_values,
+ fapia_errors);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_write_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_write_request (
+ fapia_communication,
+ fapia_parameters,
+ fapia_values);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+#if 0
+long fapia_parameter_write_response_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAError * const fapia_errors)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_write_response_callback (
+ fapia_communication,
+ fapia_parameters,
+ fapia_errors);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_write_request_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_write_request_callback (
+ fapia_communication,
+ fapia_parameters,
+ fapia_values);
+ }
+#endif
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_write_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAError * const fapia_errors)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_write_response (
+ fapia_communication,
+ fapia_parameters,
+ fapia_errors);
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_info_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_info_request (
+ fapia_communication,
+ fapia_parameters);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+#if 0
+long fapia_parameter_info_response_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAInfo * const fapia_infos,
+ const FAPIAError * const fapia_errors)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_info_response_callback (
+ fapia_communication,
+ fapia_parameters,
+ fapia_infos,
+ fapia_errors);
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_info_request_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_info_request_callback (
+ fapia_communication,
+ fapia_parameters);
+ }
+#endif
+
+/* ---------------------------------------------------------------------------*/
+
+long fapia_parameter_info_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAInfo * const fapia_infos,
+ const FAPIAError * const fapia_errors)
+ {
+ return FAPIA_CONTROLLER->fapia_parameter_info_response (
+ fapia_communication,
+ fapia_parameters,
+ fapia_infos,
+ fapia_errors);
+ }
+
+/* ---------------------------------------------------------------------------*/
Added: fapia-trunk/FAPIAController/source/FAPIAControllerController.cpp
==============================================================================
--- (empty file)
+++ fapia-trunk/FAPIAController/source/FAPIAControllerController.cpp Thu Jul 19 07:08:51 2007
@@ -0,0 +1,2731 @@
+// $Id$
+
+
+#include "FAPIAControllerController.h"
+#include "FAPIAControllerReplyCommandHandler.h"
+#include "../../FAPIAConfiguration/interface/FAPIAIConfiguration.h"
+#include "../../FAPIAConfiguration/interface/FAPIAConfiguration.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCIParameter.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterImplementation.h"
+#include "../../FAPIAIPCSynchronize/interface/FAPIAIPCSynchronize.h"
+#include "../../interface/FAPIATrace.h"
+#include /**/ <ace/Arg_Shifter.h>
+
+namespace FAPI
+ {
+ namespace Acyclic
+ {
+ namespace Controller
+ {
+
+/* ---------------------------------------------------------------------------*/
+
+ Controller::Controller (void)
+ {
+ FAPIA_TRACE;
+
+ // Initialize ACE first.
+ ACE::init ();
+ ACE_LOG_MSG->priority_mask (
+ LM_ERROR |
+ LM_CRITICAL |
+ LM_ALERT |
+ LM_EMERGENCY,
+ ACE_Log_Msg::PROCESS);
+
+ // Initialize members.
+ state_ = INITIAL;
+ transaction_id_ = 0;
+ physical_object_name_ = "";
+ number_of_logical_object_names_ = 0;
+ logical_object_names_ = 0;
+ reply_command_handler_ = 0;
+ parameter_read_response_callback_ = 0;
+ parameter_write_response_callback_ = 0;
+ parameter_info_response_callback_ = 0;
+ parameter_read_request_callback_ = 0;
+ parameter_write_request_callback_ = 0;
+ parameter_info_request_callback_ = 0;
+ ipc_parameter_ = 0;
+ ipc_synchronize_ = 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ Controller::~Controller (void)
+ {
+ FAPIA_TRACE;
+
+ state_ = SHUTDOWN;
+
+ // Free members.
+ physical_object_name_ = "";
+
+ if (logical_object_names_ != 0)
+ {
+ unsigned long i = 0;
+ for (i = 0; i < number_of_logical_object_names_; ++i)
+ {
+ delete [] logical_object_names_[i];
+ logical_object_names_[i] = 0;
+ }
+ delete [] logical_object_names_;
+ logical_object_names_ = 0;
+ number_of_logical_object_names_ = 0;
+ }
+
+ logical_physical_object_names_.clear ();
+
+ // Shut down reply command handler.
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ }
+ parameter_read_response_callback_ = 0;
+ parameter_write_response_callback_ = 0;
+ parameter_info_response_callback_ = 0;
+ parameter_read_request_callback_ = 0;
+ parameter_write_request_callback_ = 0;
+ parameter_info_request_callback_ = 0;
+ if (ipc_parameter_)
+ {
+ delete ipc_parameter_;
+ ipc_parameter_ = 0;
+ }
+ if (ipc_synchronize_)
+ {
+ delete ipc_synchronize_;
+ ipc_synchronize_ = 0;
+ }
+
+ // Cleanup ACE.
+ ACE::fini ();
+ state_ = EXITED;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_init (
+ int argc,
+ char* argv[],
+ const char * const name)
+ {
+ FAPIA_TRACE;
+
+ // Check if state is valid.
+ if (state_ == RUNNING)
+ {
+ FAPIA_DEBUG (
+ LM_WARNING,
+ "State is already running.\n");
+ return -1;
+ }
+
+ if (state_ == ABORTED)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "State is aborted.\n");
+ return -1;
+ }
+
+ if (state_ == SHUTDOWN)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Shutdown in progress.\n");
+ return -1;
+ }
+
+
+ // Initialize Logging from argc, argv
+ if (this->process_commandline_arguments (argc, argv) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error processing commandline.\n");
+ state_ = ABORTED;
+ return -1;
+ }
+
+
+ // Initialize own module.
+ this->physical_object_name_ = name;
+
+ ACE_NEW_NORETURN (
+ reply_command_handler_,
+ FAPI::Acyclic::Controller::ReplyCommandHandler (
+ this,
+ &this->receive_queue_));
+ if (reply_command_handler_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::Controller::ReplyCommandHandler.\n");
+ state_ = ABORTED;
+ return -1;
+ }
+
+ // Start up the created thread;
+ if (reply_command_handler_->activate () == -1)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error activating reply_command_handler.\n");
+ delete reply_command_handler_;
+ reply_command_handler_ = 0;
+ state_ = ABORTED;
+ }
+ ACE_Thread::yield ();
+ ACE_OS::sleep(1);
+
+ // Retrieve initialization data from configuration module.
+ FAPI::Acyclic::IConfiguration * configuration = 0;
+ ACE_NEW_NORETURN (
+ configuration,
+ FAPI::Acyclic::Configuration::Configuration ());
+
+ if (configuration == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::Configuration::Configuration.\n");
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ }
+ state_ = ABORTED;
+ return -1;
+ }
+
+ FAPI::Acyclic::Configuration::Init configuration_init;
+ FAPI::Acyclic::Configuration::Error configuration_error;
+
+ configuration_init.physical_object_name_ =
+ this->physical_object_name_;
+
+ if (configuration->init(
+ configuration_init,
+ configuration_error)
+ < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error %d initializing Configuration module. Reason: %C\n",
+ configuration_error.error_code_,
+ configuration_error.reason_.c_str ());
+
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ }
+ delete configuration;
+ configuration = 0;
+ state_ = ABORTED;
+ return -1;
+ }
+
+ // Not needed any more.
+ delete configuration;
+ configuration = 0;
+
+#ifdef WIN32
+ configuration_init.fapia_shared_memory_name_ = "C:\\machine1\\sharedmem\\FAPIA_Shared_Memory.txt";
+#else
+ configuration_init.fapia_shared_memory_name_ = "/sharedmem/FAPIA_Shared_Memory.txt";
+#endif
+
+ ACE_NEW_NORETURN (this->logical_object_names_, char *[configuration_init.logical_physical_objects_.size ()]);
+ if (logical_object_names_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Array for logical objects could not be allocated.\n");
+ state_ = ABORTED;
+ return -1;
+ }
+
+ number_of_logical_object_names_ = configuration_init.logical_physical_objects_.size ();
+
+ // Create the mapping between logical and physical object names.
+ unsigned long i = 0;
+ for (i = 0; i < configuration_init.logical_physical_objects_.size (); ++i)
+ {
+ int rc = this->logical_physical_object_names_.bind (
+ configuration_init.logical_physical_objects_[i].logical_object_name_,
+ configuration_init.logical_physical_objects_[i].physical_object_name_);
+ if (rc == 1)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Logical object %C and physical object %C are already bounded together\n",
+ configuration_init.logical_physical_objects_[i].logical_object_name_.c_str (),
+ configuration_init.logical_physical_objects_[i].physical_object_name_.c_str ());
+ }
+ else if (rc == -1)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Logical object %C and physical object %C could not be bounded together\n",
+ configuration_init.logical_physical_objects_[i].logical_object_name_.c_str (),
+ configuration_init.logical_physical_objects_[i].physical_object_name_.c_str ());
+
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ }
+ state_ = ABORTED;
+ }
+
+ ACE_NEW_NORETURN (this->logical_object_names_[i], char [configuration_init.logical_physical_objects_[i].logical_object_name_.length () + 1]);
+ if (logical_object_names_[i] == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Memory for logical object %C could not be allocated.\n",
+ configuration_init.logical_physical_objects_[i].logical_object_name_.c_str ());
+ state_ = ABORTED;
+ }
+ if (state_ == ABORTED)
+ {
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ if (logical_object_names_ != 0)
+ {
+ delete [] logical_object_names_[j];
+ logical_object_names_[j] = 0;
+ }
+ }
+ delete [] logical_object_names_;
+ logical_object_names_ = 0;
+ number_of_logical_object_names_ = 0;
+ this->logical_physical_object_names_.clear ();
+ return -1;
+ }
+
+ ACE_OS::strcpy (
+ logical_object_names_[i],
+ configuration_init.logical_physical_objects_[i].logical_object_name_.c_str ());
+ }
+
+
+ // Initialize parameter module.
+ ipc_parameter_ = 0;
+ ACE_NEW_NORETURN (ipc_parameter_, FAPI::Acyclic::IPC::Parameter::ParameterImplementation ());
+ if (ipc_parameter_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::IPC::Parameter::Parameter.\n");
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ }
+ state_ = ABORTED;
+ return -1;
+ }
+
+ FAPI::Acyclic::IPC::Parameter::Init ipc_parameter_init;
+ FAPI::Acyclic::IPC::Parameter::Error ipc_parameter_error;
+
+ // Physical object address of this process.
+ ACE_CString physical_object_address;
+
+ ipc_parameter_init.receive_queue_ = &(this->receive_queue_);
+ ipc_parameter_init.send_queue_ = &(this->send_queue_);
+
+ if (ipc_parameter_->init (
+ ipc_parameter_init,
+ physical_object_address,
+ ipc_parameter_error)
+ < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error %d initializing Parameter module. Reason: %C\n",
+ ipc_parameter_error.error_code_,
+ ipc_parameter_error.reason_.c_str ());
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ }
+ delete ipc_parameter_;
+ ipc_parameter_ = 0;
+ state_ = ABORTED;
+ return -1;
+ }
+
+
+
+ // Initialize synchronize module.
+ ipc_synchronize_ = 0;
+ ACE_NEW_NORETURN (ipc_synchronize_, FAPI::Acyclic::IPC::Synchronize::Synchronize ());
+ if (ipc_synchronize_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::IPC::Synchronize::Synchronize.\n");
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ }
+ delete ipc_parameter_;
+ ipc_parameter_ = 0;
+ state_ = ABORTED;
+ return -1;
+ }
+
+ FAPI::Acyclic::IPC::Synchronize::Init ipc_synchronize_init;
+ FAPI::Acyclic::IPC::Synchronize::Error ipc_synchronize_error;
+
+ ipc_synchronize_init.fapia_shared_memory_name_ =
+ configuration_init.fapia_shared_memory_name_;
+
+ ipc_synchronize_init.physical_object_address_ =
+ physical_object_address;
+
+ ipc_synchronize_init.physical_object_name_ =
+ this->physical_object_name_;
+
+ if (ipc_synchronize_->init (
+ ipc_synchronize_init,
+ ipc_synchronize_error)
+ < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error %d initializing Synchronize module. Reason: %C\n",
+ ipc_synchronize_error.error_code_,
+ ipc_synchronize_error.reason_.c_str ());
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ }
+ delete ipc_parameter_;
+ ipc_parameter_ = 0;
+ delete ipc_synchronize_;
+ ipc_synchronize_ = 0;
+ state_ = ABORTED;
+ return -1;
+ }
+
+ state_ = RUNNING;
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_deinit (void)
+ {
+ FAPIA_TRACE;
+
+ state_ = SHUTDOWN;
+
+ // Free members.
+ physical_object_name_ = "";
+ this->logical_physical_object_names_.clear ();
+
+ long rc = 0;
+ if (ipc_parameter_)
+ {
+ if (ipc_parameter_->deinit () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error deinitializing Parameter module.\n");
+ rc = -1;
+ }
+ delete ipc_parameter_;
+ ipc_parameter_ = 0;
+ }
+ if (ipc_synchronize_)
+ {
+ if (ipc_synchronize_->deinit () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error deinitializing Synchronization module.\n");
+ rc = -1;
+ }
+ delete ipc_synchronize_;
+ ipc_synchronize_ = 0;
+ }
+
+ // Shut down reply command handler.
+ if (this->shutdown_reply_command_handler () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error on shutdown of reply command handler.\n");
+ rc = -1;
+ }
+
+ state_ = EXITED;
+ return rc;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_logical_object_names (
+ char*** logical_object_names,
+ unsigned long* number_of_logical_object_names)
+ {
+ if (number_of_logical_object_names_ == 0)
+ {
+ *logical_object_names = 0;
+ *number_of_logical_object_names = 0;
+ return -1;
+ }
+
+ *logical_object_names = logical_object_names_;
+ *number_of_logical_object_names = number_of_logical_object_names_;
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_set_callback_for_parameter_read_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAValue *,
+ const FAPIAError *))
+ {
+ FAPIA_TRACE;
+
+ parameter_read_response_callback_ = f;
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_set_callback_for_parameter_write_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAError *))
+ {
+ FAPIA_TRACE;
+
+ parameter_write_response_callback_ = f;
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_set_callback_for_parameter_info_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAInfo *,
+ const FAPIAError *))
+ {
+ FAPIA_TRACE;
+
+ parameter_info_response_callback_ = f;
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_set_callback_for_parameter_read_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *))
+ {
+ FAPIA_TRACE;
+
+ parameter_read_request_callback_ = f;
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_set_callback_for_parameter_write_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAValue *))
+ {
+ FAPIA_TRACE;
+
+ parameter_write_request_callback_ = f;
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_set_callback_for_parameter_info_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *))
+ {
+ FAPIA_TRACE;
+
+ parameter_info_request_callback_ = f;
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_parameter_read_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters)
+ {
+ FAPIA_TRACE;
+
+
+ // Check if controller can work.
+ if (state_ != RUNNING)
+ {
+ FAPIA_DEBUG (
+ LM_WARNING,
+ "State is not running.\n");
+ return -1;
+ }
+
+ if (this->parameter_read_response_callback_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error: no callback method set, this->parameter_read_response_callback_ not valid.\n");
+ return -1;
+ }
+
+
+ this->increment_and_get_transaction_id (
+ fapia_communication->transaction_id);
+
+ // Create method request.
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest* mr_read_request = 0;
+
+ ACE_NEW_NORETURN (
+ mr_read_request,
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest ());
+
+ if (mr_read_request == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest");
+ return -1;
+ }
+
+ if (this->convert_to_read_request (
+ mr_read_request,
+ fapia_communication,
+ fapia_parameters) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_to_read_request failed.\n");
+ delete mr_read_request;
+ mr_read_request = 0;
+ return -1;
+ }
+
+ this->send_queue_.enqueue (mr_read_request);
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_parameter_read_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values,
+ const FAPIAError * const fapia_errors)
+ {
+ FAPIA_TRACE;
+
+ // Check if controller can work.
+ if (state_ != RUNNING)
+ {
+ FAPIA_DEBUG (
+ LM_WARNING,
+ "State is not running.\n");
+ return -1;
+ }
+
+ // Create method request.
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse* mr_read_response = 0;
+
+ ACE_NEW_NORETURN (
+ mr_read_response,
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse ());
+
+ if (mr_read_response == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse");
+ return -1;
+ }
+
+ if (this->convert_to_read_response (
+ mr_read_response,
+ fapia_communication,
+ fapia_parameters,
+ fapia_values,
+ fapia_errors) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_to_read_response failed.\n");
+ delete mr_read_response;
+ mr_read_response = 0;
+ return -1;
+ }
+
+ this->send_queue_.enqueue (mr_read_response);
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_parameter_write_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values)
+ {
+ FAPIA_TRACE;
+
+ // Check if controller can work.
+ if (state_ != RUNNING)
+ {
+ FAPIA_DEBUG (
+ LM_WARNING,
+ "State is not running.\n");
+ return -1;
+ }
+
+ if (this->parameter_write_response_callback_ == 0 && fapia_communication->send_reply)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error: no callback method set, this->parameter_write_response_callback_ not valid.\n");
+ return -1;
+ }
+
+
+
+ this->increment_and_get_transaction_id (
+ fapia_communication->transaction_id);
+
+ // Create method request.
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest* mr_write_request = 0;
+
+ ACE_NEW_NORETURN (
+ mr_write_request,
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest ());
+
+ if (mr_write_request == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest");
+ return -1;
+ }
+
+ if (this->convert_to_write_request (
+ mr_write_request,
+ fapia_communication,
+ fapia_parameters,
+ fapia_values) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_to_write_request failed.\n");
+ delete mr_write_request;
+ mr_write_request = 0;
+ return -1;
+ }
+
+ this->send_queue_.enqueue (mr_write_request);
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_parameter_write_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAError * const fapia_errors)
+ {
+ FAPIA_TRACE;
+
+ // Check if controller can work.
+ if (state_ != RUNNING)
+ {
+ FAPIA_DEBUG (
+ LM_WARNING,
+ "State is not running.\n");
+ return -1;
+ }
+
+ // Create method request.
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse* mr_write_response = 0;
+
+ ACE_NEW_NORETURN (
+ mr_write_response,
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse ());
+
+ if (mr_write_response == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse");
+ return -1;
+ }
+
+ if (this->convert_to_write_response (
+ mr_write_response,
+ fapia_communication,
+ fapia_parameters,
+ fapia_errors) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_to_write_response failed.\n");
+ delete mr_write_response;
+ mr_write_response = 0;
+ return -1;
+ }
+
+ this->send_queue_.enqueue (mr_write_response);
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_parameter_info_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters)
+ {
+ FAPIA_TRACE;
+
+ // Check if controller can work.
+ if (state_ != RUNNING)
+ {
+ FAPIA_DEBUG (
+ LM_WARNING,
+ "State is not running.\n");
+ return -1;
+ }
+
+ if (this->parameter_info_response_callback_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error: no callback method set, this->parameter_info_response_callback_ not valid.\n");
+ return -1;
+ }
+
+
+
+ this->increment_and_get_transaction_id (
+ fapia_communication->transaction_id);
+
+ // Create method request.
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest* mr_info_request = 0;
+
+ ACE_NEW_NORETURN (
+ mr_info_request,
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest ());
+
+ if (mr_info_request == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest");
+ return -1;
+ }
+
+ if (this->convert_to_info_request (
+ mr_info_request,
+ fapia_communication,
+ fapia_parameters) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_to_info_request failed.\n");
+ delete mr_info_request;
+ mr_info_request = 0;
+ return -1;
+ }
+
+ this->send_queue_.enqueue (mr_info_request);
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::fapia_parameter_info_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAInfo * const fapia_infos,
+ const FAPIAError * const fapia_errors)
+ {
+ FAPIA_TRACE;
+
+ // Check if controller can work.
+ if (state_ != RUNNING)
+ {
+ FAPIA_DEBUG (
+ LM_WARNING,
+ "State is not running.\n");
+ return -1;
+ }
+
+ // Create method request.
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse* mr_info_response = 0;
+
+ ACE_NEW_NORETURN (
+ mr_info_response,
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse ());
+
+ if (mr_info_response == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse");
+ return -1;
+ }
+
+ if (this->convert_to_info_response (
+ mr_info_response,
+ fapia_communication,
+ fapia_parameters,
+ fapia_infos,
+ fapia_errors) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_to_info_response failed.\n");
+ delete mr_info_response;
+ mr_info_response = 0;
+ return -1;
+ }
+
+ this->send_queue_.enqueue (mr_info_response);
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ void Controller::increment_and_get_transaction_id (
+ unsigned long& transaction_id)
+ {
+ FAPIA_TRACE;
+
+ ACE_Guard <ACE_Thread_Mutex> lock (transaction_id_mutex_);
+ ++this->transaction_id_;
+ transaction_id = this->transaction_id_;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_to_read_request (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ mr->communication_,
+ fapia_communication) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_communication to parameter communication.\n");
+ return -1;
+ }
+
+ if (this->convert (
+ mr->parameters_,
+ fapia_parameters,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_parameters to parameter parameters.\n");
+ return -1;
+ }
+
+ mr->priority (fapia_communication->priority);
+
+ // Retrieve physical object address.
+ ACE_CString physical_object_address;
+ FAPI::Acyclic::IPC::Synchronize::Error ipc_synchronize_error;
+ ACE_CString destination_physical_object_name;
+
+
+ int rc = logical_physical_object_names_.find (
+ fapia_communication->logical_object_name,
+ destination_physical_object_name);
+
+ if (rc != 0)
+ {
+ // Maybe the logical_object_name is a physical object.
+ // Just try it.
+ destination_physical_object_name =
+ fapia_communication->logical_object_name;
+ }
+
+
+ if (this->ipc_synchronize_->retrieve_physical_object_address (
+ destination_physical_object_name,
+ physical_object_address,
+ ipc_synchronize_error) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error %d: physical object address could not be retrieved. Reason: %C\n",
+ ipc_synchronize_error.error_code_,
+ ipc_synchronize_error.reason_.c_str ());
+ return -1;
+ }
+
+ mr->destination_physical_object_address_ =
+ physical_object_address;
+
+ return 0;
+ }
+
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_from_read_request (
+ FAPIACommunication * const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest* mr)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ fapia_communication,
+ mr->communication_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter communication to fapia_communication.\n");
+ return -1;
+ }
+
+ fapia_communication->number_of_entries =
+ mr->parameters_.size ();
+ fapia_communication->priority = (FAPIACommunicationPriority)mr->priority ();
+
+ if (this->convert (
+ fapia_parameters,
+ mr->parameters_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter parameters to fapia_parameters.\n");
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_to_read_response (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values,
+ const FAPIAError * const fapia_errors)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ mr->communication_,
+ fapia_communication) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_communication to parameter communication.\n");
+ return -1;
+ }
+
+ // Reset physical object name of source.
+ mr->communication_.source_physical_object_name_ =
+ fapia_communication->source_physical_object_name;
+
+
+ if (this->convert (
+ mr->parameters_,
+ fapia_parameters,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_parameters to parameter parameters.\n");
+ return -1;
+ }
+
+ if (this->convert (
+ mr->values_,
+ fapia_values,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_values to parameter values.\n");
+ return -1;
+ }
+ if (this->convert (
+ mr->errors_,
+ fapia_errors,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_errors to parameter errors.\n");
+ return -1;
+ }
+
+ mr->priority (fapia_communication->priority);
+
+ // Retrieve physical object address.
+ ACE_CString physical_object_address;
+ FAPI::Acyclic::IPC::Synchronize::Error ipc_synchronize_error;
+
+ if (this->ipc_synchronize_->retrieve_physical_object_address (
+ mr->communication_.source_physical_object_name_,
+ physical_object_address,
+ ipc_synchronize_error) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error %d: physical object address could not be retrieved. Reason: %C\n",
+ ipc_synchronize_error.error_code_,
+ ipc_synchronize_error.reason_.c_str ());
+ return -1;
+ }
+
+ mr->destination_physical_object_address_ =
+ physical_object_address;
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_from_read_response (
+ FAPIACommunication * const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ FAPIAValue * const fapia_values,
+ FAPIAError * const fapia_errors,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse* mr)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ fapia_communication,
+ mr->communication_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter communication to fapia_communication.\n");
+ return -1;
+ }
+
+ fapia_communication->number_of_entries =
+ mr->parameters_.size ();
+ fapia_communication->priority = (FAPIACommunicationPriority)mr->priority ();
+
+ if (this->convert (
+ fapia_parameters,
+ mr->parameters_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter parameters to fapia_parameters.\n");
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+ if (this->convert (
+ fapia_values,
+ mr->values_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter values to fapia_values.\n");
+ this->free_memory (fapia_parameters, fapia_communication->number_of_entries);
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+ if (this->convert (
+ fapia_errors,
+ mr->errors_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter errors to fapia_errors.\n");
+ this->free_memory (fapia_values, fapia_communication->number_of_entries);
+ this->free_memory (fapia_parameters, fapia_communication->number_of_entries);
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_to_write_request (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ mr->communication_,
+ fapia_communication) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_communication to parameter communication.\n");
+ return -1;
+ }
+
+ if (this->convert (
+ mr->parameters_,
+ fapia_parameters,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_parameters to parameter parameters.\n");
+ return -1;
+ }
+
+ if (this->convert (
+ mr->values_,
+ fapia_values,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_values to parameter values.\n");
+ return -1;
+ }
+ mr->priority (fapia_communication->priority);
+
+ // Retrieve physical object address.
+ ACE_CString physical_object_address;
+ FAPI::Acyclic::IPC::Synchronize::Error ipc_synchronize_error;
+ ACE_CString destination_physical_object_name;
+
+
+ int rc = logical_physical_object_names_.find (
+ fapia_communication->logical_object_name,
+ destination_physical_object_name);
+
+ if (rc != 0)
+ {
+ // Maybe the logical_object_name is a physical object.
+ // Just try it.
+ destination_physical_object_name =
+ fapia_communication->logical_object_name;
+ }
+
+
+ if (this->ipc_synchronize_->retrieve_physical_object_address (
+ destination_physical_object_name,
+ physical_object_address,
+ ipc_synchronize_error) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error %d: physical object address could not be retrieved. Reason: %C\n",
+ ipc_synchronize_error.error_code_,
+ ipc_synchronize_error.reason_.c_str ());
+ return -1;
+ }
+
+ mr->destination_physical_object_address_ =
+ physical_object_address;
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_from_write_request (
+ FAPIACommunication* const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ FAPIAValue * const fapia_values,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest* mr)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ fapia_communication,
+ mr->communication_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter communication to fapia_communication.\n");
+ return -1;
+ }
+
+ fapia_communication->number_of_entries =
+ mr->parameters_.size ();
+ fapia_communication->priority = (FAPIACommunicationPriority)mr->priority ();
+
+ if (this->convert (
+ fapia_parameters,
+ mr->parameters_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter parameters to fapia_parameters.\n");
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+ if (this->convert (
+ fapia_values,
+ mr->values_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter values to fapia_values.\n");
+ this->free_memory (fapia_parameters, fapia_communication->number_of_entries);
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_to_write_response (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAError * const fapia_errors)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ mr->communication_,
+ fapia_communication) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_communication to parameter communication.\n");
+ return -1;
+ }
+
+ // Reset physical object name of source.
+ mr->communication_.source_physical_object_name_ =
+ fapia_communication->source_physical_object_name;
+
+ if (this->convert (
+ mr->parameters_,
+ fapia_parameters,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_parameters to parameter parameters.\n");
+ return -1;
+ }
+
+ if (this->convert (
+ mr->errors_,
+ fapia_errors,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_errors to parameter errors.\n");
+ return -1;
+ }
+
+ mr->priority (fapia_communication->priority);
+
+ // Retrieve physical object address.
+ ACE_CString physical_object_address;
+ FAPI::Acyclic::IPC::Synchronize::Error ipc_synchronize_error;
+
+ if (this->ipc_synchronize_->retrieve_physical_object_address (
+ fapia_communication->source_physical_object_name,
+ physical_object_address,
+ ipc_synchronize_error) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error %d: physical object address could not be retrieved. Reason: %C\n",
+ ipc_synchronize_error.error_code_,
+ ipc_synchronize_error.reason_.c_str ());
+ return -1;
+ }
+
+ mr->destination_physical_object_address_ =
+ physical_object_address;
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_from_write_response (
+ FAPIACommunication * const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ FAPIAError * const fapia_errors,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse* mr)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ fapia_communication,
+ mr->communication_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter communication to fapia_communication.\n");
+ return -1;
+ }
+
+ fapia_communication->number_of_entries =
+ mr->parameters_.size ();
+ fapia_communication->priority = (FAPIACommunicationPriority)mr->priority ();
+
+ if (this->convert (
+ fapia_parameters,
+ mr->parameters_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter parameters to fapia parameters.\n");
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+ if (this->convert (
+ fapia_errors,
+ mr->errors_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter errors to fapia_errors.\n");
+ this->free_memory (fapia_parameters, fapia_communication->number_of_entries);
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_to_info_request (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ mr->communication_,
+ fapia_communication) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_communication to parameter communication.\n");
+ return -1;
+ }
+
+ if (this->convert (
+ mr->parameters_,
+ fapia_parameters,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_parameters to parameter parameters.\n");
+ return -1;
+ }
+
+ mr->priority (fapia_communication->priority);
+
+ // Retrieve physical object address.
+ ACE_CString physical_object_address;
+ FAPI::Acyclic::IPC::Synchronize::Error ipc_synchronize_error;
+ ACE_CString destination_physical_object_name;
+
+
+ int rc = logical_physical_object_names_.find (
+ fapia_communication->logical_object_name,
+ destination_physical_object_name);
+
+ if (rc != 0)
+ {
+ // Maybe the logical_object_name is a physical object.
+ // Just try it.
+ destination_physical_object_name =
+ fapia_communication->logical_object_name;
+ }
+
+
+ if (this->ipc_synchronize_->retrieve_physical_object_address (
+ destination_physical_object_name,
+ physical_object_address,
+ ipc_synchronize_error) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error %d: physical object address could not be retrieved. Reason: %C\n",
+ ipc_synchronize_error.error_code_,
+ ipc_synchronize_error.reason_.c_str ());
+ return -1;
+ }
+
+ mr->destination_physical_object_address_ =
+ physical_object_address;
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_from_info_request (
+ FAPIACommunication* const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest* mr)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ fapia_communication,
+ mr->communication_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter communication to fapia_communication.\n");
+ return -1;
+ }
+
+ fapia_communication->number_of_entries =
+ mr->parameters_.size ();
+ fapia_communication->priority = (FAPIACommunicationPriority)mr->priority ();
+
+ if (this->convert (
+ fapia_parameters,
+ mr->parameters_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter parameters to fapia_parameters.\n");
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_to_info_response (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAInfo * const fapia_infos,
+ const FAPIAError * const fapia_errors)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ mr->communication_,
+ fapia_communication) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_communication to parameter communication.\n");
+ return -1;
+ }
+
+ // Reset physical object name of source.
+ mr->communication_.source_physical_object_name_ =
+ fapia_communication->source_physical_object_name;
+
+ if (this->convert (
+ mr->parameters_,
+ fapia_parameters,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_parameters to parameter parameters.\n");
+ return -1;
+ }
+
+ if (this->convert (
+ mr->infos_,
+ fapia_infos,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_infos to parameter infos.\n");
+ return -1;
+ }
+
+ if (this->convert (
+ mr->errors_,
+ fapia_errors,
+ fapia_communication->number_of_entries) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting fapia_errors to parameter errors.\n");
+ return -1;
+ }
+
+ mr->priority (fapia_communication->priority);
+
+ // Retrieve physical object address.
+ ACE_CString physical_object_address;
+ FAPI::Acyclic::IPC::Synchronize::Error ipc_synchronize_error;
+
+ if (this->ipc_synchronize_->retrieve_physical_object_address (
+ fapia_communication->source_physical_object_name,
+ physical_object_address,
+ ipc_synchronize_error) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error %d: physical object address could not be retrieved. Reason: %C\n",
+ ipc_synchronize_error.error_code_,
+ ipc_synchronize_error.reason_.c_str ());
+ return -1;
+ }
+
+ mr->destination_physical_object_address_ =
+ physical_object_address;
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert_from_info_response (
+ FAPIACommunication * const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ FAPIAInfo * const fapia_infos,
+ FAPIAError * const fapia_errors,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse* mr)
+ {
+ FAPIA_TRACE;
+
+ // Call the convert functions.
+ if (this->convert (
+ fapia_communication,
+ mr->communication_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter communication to fapia_communication.\n");
+ return -1;
+ }
+
+ fapia_communication->number_of_entries =
+ mr->parameters_.size ();
+ fapia_communication->priority = (FAPIACommunicationPriority)mr->priority ();
+
+ if (this->convert (
+ fapia_parameters,
+ mr->parameters_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter parameters to fapia parameters.\n");
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+ if (this->convert (
+ fapia_infos,
+ mr->infos_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter infos to fapia infos.\n");
+ this->free_memory (fapia_communication);
+ this->free_memory (fapia_parameters, fapia_communication->number_of_entries);
+ return -1;
+ }
+
+ if (this->convert (
+ fapia_errors,
+ mr->errors_) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error converting parameter errors to fapia_errors.\n");
+ this->free_memory (fapia_infos, fapia_communication->number_of_entries);
+ this->free_memory (fapia_parameters, fapia_communication->number_of_entries);
+ this->free_memory (fapia_communication);
+ return -1;
+ }
+
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPIACommunication * const fapia_communication,
+ const FAPI::Acyclic::IPC::Parameter::Communication& ipc_parameter_communication)
+ {
+ FAPIA_TRACE;
+
+ // Set communications.
+ fapia_communication->communication_error.error_code =
+ ipc_parameter_communication.communication_error_.error_code_;
+
+ if (fapia_communication->communication_error.error_code != FAPIA_ERROR_OK)
+ {
+ // Allocate memory for the reason.
+ unsigned long len = ipc_parameter_communication.communication_error_.reason_.length ();
+
+ ACE_NEW_NORETURN (fapia_communication->communication_error.reason, char[len + 1]);
+ if (fapia_communication->communication_error.reason == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_communication->communication_error.reason");
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_communication->communication_error.reason,
+ ipc_parameter_communication.communication_error_.reason_.c_str (),
+ len);
+
+ // Set a trailing zero for strings.
+ fapia_communication->communication_error.reason[len] = '\0';
+ }
+ else
+ {
+ fapia_communication->communication_error.reason = 0;
+ }
+
+ fapia_communication->send_reply =
+ ipc_parameter_communication.send_reply_;
+ fapia_communication->transaction_id =
+ ipc_parameter_communication.transaction_id_;
+
+
+ // Copy logical_object_name.
+
+ // Allocate memory for the logical_object_name.
+ unsigned long len = ipc_parameter_communication.logical_object_name_.length ();
+
+ ACE_NEW_NORETURN (fapia_communication->logical_object_name, char[len + 1]);
+ if (fapia_communication->logical_object_name == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_communication->logical_object_name");
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_communication->logical_object_name,
+ ipc_parameter_communication.logical_object_name_.c_str (),
+ len);
+
+ // Set a trailing zero for strings.
+ fapia_communication->logical_object_name[len] = '\0';
+
+
+
+ // Copy physical_object_name.
+
+ // Allocate memory for the physical_object_name.
+ len = ipc_parameter_communication.source_physical_object_name_.length ();
+
+ ACE_NEW_NORETURN (fapia_communication->source_physical_object_name, char[len + 1]);
+ if (fapia_communication->source_physical_object_name == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_communication->source_physical_object_name");
+
+ delete fapia_communication->logical_object_name;
+ fapia_communication->logical_object_name = 0;
+
+ if (fapia_communication->communication_error.reason != 0)
+ {
+ delete fapia_communication->communication_error.reason;
+ fapia_communication->communication_error.reason = 0;
+ }
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_communication->source_physical_object_name,
+ ipc_parameter_communication.source_physical_object_name_.c_str (),
+ len);
+
+ // Set a trailing zero for strings.
+ fapia_communication->source_physical_object_name[len] = '\0';
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPI::Acyclic::IPC::Parameter::Communication& ipc_parameter_communication,
+ const FAPIACommunication * const fapia_communication)
+ {
+ FAPIA_TRACE;
+
+ // Set communication structure.
+ ipc_parameter_communication.communication_error_.error_code_ =
+ fapia_communication->communication_error.error_code;
+
+ ipc_parameter_communication.communication_error_.reason_ =
+ fapia_communication->communication_error.reason;
+
+ ipc_parameter_communication.send_reply_ =
+ fapia_communication->send_reply == 0 ? false : true;
+
+ ipc_parameter_communication.transaction_id_ =
+ fapia_communication->transaction_id;
+
+ if (fapia_communication->logical_object_name == 0)
+ {
+ FAPIA_DEBUG (
+ LM_WARNING,
+ "Logical object name is a NULL pointer.");
+ return -1;
+ }
+
+ ipc_parameter_communication.logical_object_name_ =
+ fapia_communication->logical_object_name;
+
+ ipc_parameter_communication.source_physical_object_name_ =
+ this->physical_object_name_;
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPIAParameter * const fapia_parameters,
+ const FAPI::Acyclic::IPC::Parameter::Parameters& ipc_parameter_parameters)
+ {
+ FAPIA_TRACE;
+
+ // Set parameters.
+ unsigned long count = ipc_parameter_parameters.size ();
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ // Copy parameter_name.
+
+ // Allocate memory for the parameter_name.
+ unsigned long len = ipc_parameter_parameters[i].parameter_name_.length ();
+
+ ACE_NEW_NORETURN (fapia_parameters[i].parameter_name, char[len + 1]);
+ if (fapia_parameters[i].parameter_name == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_parameters[i].parameter_name");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ delete [] fapia_parameters[j].parameter_name;
+ fapia_parameters[j].parameter_name = 0;
+ }
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_parameters[i].parameter_name,
+ ipc_parameter_parameters[i].parameter_name_.c_str (),
+ len);
+
+ // Set a trailing zero for strings.
+ fapia_parameters[i].parameter_name[len] = '\0';
+
+ }
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPI::Acyclic::IPC::Parameter::Parameters& ipc_parameter_parameters,
+ const FAPIAParameter * const fapia_parameters,
+ unsigned long count)
+ {
+ FAPIA_TRACE;
+
+ // Set parameters.
+ FAPI::Acyclic::IPC::Parameter::Parameter ipc_parameter_parameter;
+ ipc_parameter_parameters.max_size (count);
+
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ ipc_parameter_parameter.parameter_name_ =
+ fapia_parameters[i].parameter_name;
+
+ ipc_parameter_parameters.push_back (
+ ipc_parameter_parameter);
+ }
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPIAValue * const fapia_values,
+ const FAPI::Acyclic::IPC::Parameter::Values& ipc_parameter_values)
+ {
+ FAPIA_TRACE;
+
+ // Set values.
+ unsigned long count = ipc_parameter_values.size ();
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ fapia_values[i].data_length =
+ ipc_parameter_values[i].data_len ();
+ fapia_values[i].data_type =
+ ipc_parameter_values[i].data_type_;
+
+
+ // Copy data value.
+
+ // Allocate memory for the value.
+ // If string then reserve a char for trailing zero.
+ unsigned long len =
+ fapia_values[i].data_type == FAPIA_DATA_TYPE_STRING ?
+ fapia_values[i].data_length + 1 :
+ fapia_values[i].data_length;
+
+ ACE_NEW_NORETURN (fapia_values[i].data_value, char[len]);
+ if (fapia_values[i].data_value == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_values[i].data_value");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ delete [] (char *)fapia_values[j].data_value;
+ fapia_values[j].data_value= 0;
+ }
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_values[i].data_value,
+ ipc_parameter_values[i].data_value (),
+ fapia_values[i].data_length);
+
+ // Set a trailing zero for strings.
+ if (fapia_values[i].data_type == FAPIA_DATA_TYPE_STRING)
+ {
+ ACE_static_cast (
+ char* ,
+ fapia_values[i].data_value)[fapia_values[i].data_length] =
+ '\0';
+ }
+ }
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPI::Acyclic::IPC::Parameter::Values& ipc_parameter_values,
+ const FAPIAValue * const fapia_values,
+ unsigned long count)
+ {
+ FAPIA_TRACE;
+
+ // Set values.
+ FAPI::Acyclic::IPC::Parameter::Value ipc_parameter_value;
+ ipc_parameter_values.max_size (count);
+
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ ipc_parameter_value.data_type_ =
+ fapia_values[i].data_type;
+ if (ipc_parameter_value.data_value (
+ fapia_values[i].data_value,
+ fapia_values[i].data_length) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error setting data_value for parameter failed.\n");
+ return -1;
+ }
+ ipc_parameter_values.push_back (
+ ipc_parameter_value);
+ }
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPIAInfo * const fapia_infos,
+ const FAPI::Acyclic::IPC::Parameter::Infos& ipc_parameter_infos)
+ {
+ FAPIA_TRACE;
+
+ // Set infos.
+ unsigned long count = ipc_parameter_infos.size ();
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ fapia_infos[i].data_length =
+ ipc_parameter_infos[i].data_len_;
+ fapia_infos[i].data_type =
+ ipc_parameter_infos[i].data_type_;
+ fapia_infos[i].access_rights =
+ ipc_parameter_infos[i].access_rights_;
+ fapia_infos[i].exponent =
+ ipc_parameter_infos[i].exponent_;
+ fapia_infos[i].factor =
+ ipc_parameter_infos[i].factor_;
+
+
+
+ // Copy min value.
+
+ if (ipc_parameter_infos[i].min_value_ != 0)
+ {
+ // Allocate memory for the info.
+ // If string then reserve a char for trailing zero.
+ unsigned long len =
+ fapia_infos[i].data_type == FAPIA_DATA_TYPE_STRING ?
+ fapia_infos[i].data_length + 1 :
+ fapia_infos[i].data_length;
+
+ ACE_NEW_NORETURN (fapia_infos[i].min_value, char[len]);
+ if (fapia_infos[i].min_value == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_infos[i].min_value");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ if (fapia_infos[j].min_value)
+ {
+ delete [] (char *)fapia_infos[j].min_value;
+ fapia_infos[j].min_value = 0;
+ }
+ if (fapia_infos[j].max_value)
+ {
+ delete [] (char *)fapia_infos[j].max_value;
+ fapia_infos[j].max_value = 0;
+ }
+ if (fapia_infos[j].unit)
+ {
+ delete [] (char *)fapia_infos[j].unit;
+ fapia_infos[j].unit = 0;
+ }
+ if (fapia_infos[j].description)
+ {
+ delete [] (char *)fapia_infos[j].description;
+ fapia_infos[j].description = 0;
+ }
+ }
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_infos[i].min_value,
+ ipc_parameter_infos[i].min_value_,
+ fapia_infos[i].data_length);
+
+ // Set a trailing zero for strings.
+ if (fapia_infos[i].data_type == FAPIA_DATA_TYPE_STRING)
+ {
+ ACE_static_cast (
+ char* ,
+ fapia_infos[i].min_value)[fapia_infos[i].data_length] =
+ '\0';
+ }
+ }
+ else
+ {
+ fapia_infos[i].min_value = 0;
+ }
+
+ // Copy max value.
+
+ if (ipc_parameter_infos[i].max_value_ != 0)
+ {
+ // Allocate memory for the info.
+ // If string then reserve a char for trailing zero.
+ unsigned long len =
+ fapia_infos[i].data_type == FAPIA_DATA_TYPE_STRING ?
+ fapia_infos[i].data_length + 1 :
+ fapia_infos[i].data_length;
+
+ ACE_NEW_NORETURN (fapia_infos[i].max_value, char[len]);
+ if (fapia_infos[i].max_value == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_infos[i].max_value");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ if (fapia_infos[j].min_value)
+ {
+ delete [] (char *)fapia_infos[j].min_value;
+ fapia_infos[j].min_value = 0;
+ }
+ if (fapia_infos[j].max_value)
+ {
+ delete [] (char *)fapia_infos[j].max_value;
+ fapia_infos[j].max_value = 0;
+ }
+ if (fapia_infos[j].unit)
+ {
+ delete [] (char *)fapia_infos[j].unit;
+ fapia_infos[j].unit = 0;
+ }
+ if (fapia_infos[j].description)
+ {
+ delete [] (char *)fapia_infos[j].description;
+ fapia_infos[j].description = 0;
+ }
+ }
+ if (fapia_infos[i].min_value)
+ {
+ delete [] (char *)fapia_infos[i].min_value;
+ fapia_infos[i].min_value = 0;
+ }
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_infos[i].max_value,
+ ipc_parameter_infos[i].max_value_,
+ fapia_infos[i].data_length);
+
+ // Set a trailing zero for strings.
+ if (fapia_infos[i].data_type == FAPIA_DATA_TYPE_STRING)
+ {
+ ACE_static_cast (
+ char* ,
+ fapia_infos[i].max_value)[fapia_infos[i].data_length] =
+ '\0';
+ }
+ }
+ else
+ {
+ fapia_infos[i].max_value = 0;
+ }
+
+ // Copy unit.
+
+ // Allocate memory for the unit.
+ // If string then reserve a char for trailing zero.
+ unsigned long len = ipc_parameter_infos[i].unit_.length ();
+
+ ACE_NEW_NORETURN (fapia_infos[i].unit, char[len + 1]);
+ if (fapia_infos[i].unit == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_infos[i].unit");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ if (fapia_infos[j].min_value)
+ {
+ delete [] (char *)fapia_infos[j].min_value;
+ fapia_infos[j].min_value = 0;
+ }
+ if (fapia_infos[j].max_value)
+ {
+ delete [] (char *)fapia_infos[j].max_value;
+ fapia_infos[j].max_value = 0;
+ }
+
+ delete [] fapia_infos[j].unit;
+ fapia_infos[j].unit = 0;
+
+ if (fapia_infos[j].description)
+ {
+ delete [] (char *)fapia_infos[j].description;
+ fapia_infos[j].description = 0;
+ }
+ }
+ if (fapia_infos[i].min_value)
+ {
+ delete [] (char *)fapia_infos[i].min_value;
+ fapia_infos[i].min_value = 0;
+ }
+ if (fapia_infos[i].max_value)
+ {
+ delete [] (char *)fapia_infos[i].max_value;
+ fapia_infos[i].max_value = 0;
+ }
+
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_infos[i].unit,
+ ipc_parameter_infos[i].unit_.c_str (),
+ len);
+
+ // Set a trailing zero for strings.
+ fapia_infos[i].unit[len] = '\0';
+
+
+ // Copy description.
+
+ // Allocate memory for the description.
+ // If string then reserve a char for trailing zero.
+ len = ipc_parameter_infos[i].description_.length ();
+
+ ACE_NEW_NORETURN (fapia_infos[i].description, char[len + 1]);
+ if (fapia_infos[i].description == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_infos[i].description");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ if (fapia_infos[j].min_value)
+ {
+ delete [] (char *)fapia_infos[j].min_value;
+ fapia_infos[j].min_value = 0;
+ }
+ if (fapia_infos[j].max_value)
+ {
+ delete [] (char *)fapia_infos[j].max_value;
+ fapia_infos[j].max_value = 0;
+ }
+
+ if (fapia_infos[j].unit)
+ {
+ delete [] fapia_infos[j].unit;
+ fapia_infos[j].unit = 0;
+ }
+
+ if (fapia_infos[j].description)
+ {
+ delete [] (char *)fapia_infos[j].description;
+ fapia_infos[j].description = 0;
+ }
+ }
+ if (fapia_infos[i].min_value)
+ {
+ delete [] (char *)fapia_infos[i].min_value;
+ fapia_infos[i].min_value = 0;
+ }
+ if (fapia_infos[i].max_value)
+ {
+ delete [] (char *)fapia_infos[i].max_value;
+ fapia_infos[i].max_value = 0;
+ }
+
+ if (fapia_infos[i].unit)
+ {
+ delete [] fapia_infos[i].unit;
+ fapia_infos[i].unit = 0;
+ }
+
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_infos[i].description,
+ ipc_parameter_infos[i].description_.c_str (),
+ len);
+
+ // Set a trailing zero for strings.
+ fapia_infos[i].description[len] = '\0';
+
+ }
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPI::Acyclic::IPC::Parameter::Infos& ipc_parameter_infos,
+ const FAPIAInfo * const fapia_infos,
+ unsigned long count)
+ {
+ FAPIA_TRACE;
+
+ // Set infos.
+ FAPI::Acyclic::IPC::Parameter::Info ipc_parameter_info;
+ ipc_parameter_infos.max_size (count);
+
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ ipc_parameter_info.data_type_ =
+ fapia_infos[i].data_type;
+ ipc_parameter_info.data_len_ =
+ fapia_infos[i].data_length;
+ ipc_parameter_info.access_rights_ =
+ fapia_infos[i].access_rights;
+ ipc_parameter_info.unit_ =
+ fapia_infos[i].unit;
+ ipc_parameter_info.exponent_ =
+ fapia_infos[i].exponent;
+ ipc_parameter_info.factor_ =
+ fapia_infos[i].factor;
+ ipc_parameter_info.description_ =
+ fapia_infos[i].description;
+
+ unsigned long len =
+ fapia_infos[i].data_type == FAPIA_DATA_TYPE_STRING ?
+ fapia_infos[i].data_length + 1 :
+ fapia_infos[i].data_length;
+
+ if (fapia_infos[i].min_value)
+ {
+ // allocate memory for the min value.
+ ACE_NEW_NORETURN (ipc_parameter_info.min_value_, char[len]);
+ if (ipc_parameter_info.min_value_ == 0)
+ {
+ FAPIA_DEBUG (LM_ALERT,
+ "Error allocating ipc_parameter_info.min_value_");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ if (ipc_parameter_infos[j].min_value_)
+ {
+ delete [] (char *)ipc_parameter_infos[j].min_value_;
+ ipc_parameter_infos[j].min_value_ = 0;
+ }
+ if (ipc_parameter_infos[j].max_value_)
+ {
+ delete [] (char *)ipc_parameter_infos[j].max_value_;
+ ipc_parameter_infos[j].min_value_ = 0;
+ }
+ }
+ return -1;
+ }
+
+ // copy content
+ ACE_OS::memcpy (
+ ipc_parameter_info.min_value_,
+ fapia_infos[i].min_value,
+ fapia_infos[i].data_length);
+
+ // Set a trailing zero for strings.
+ if (fapia_infos[i].data_type == FAPIA_DATA_TYPE_STRING)
+ {
+ ACE_static_cast (
+ char* ,
+ ipc_parameter_info.min_value_)[fapia_infos[i].data_length] =
+ '\0';
+ }
+ }
+ else
+ {
+ ipc_parameter_info.min_value_ = 0;
+ }
+
+ if (fapia_infos[i].max_value)
+ {
+ // allocate memory for the max value.
+ ACE_NEW_NORETURN (ipc_parameter_info.max_value_, char[len]);
+ if (ipc_parameter_info.max_value_ == 0)
+ {
+ FAPIA_DEBUG (LM_ALERT,
+ "Error allocating ipc_parameter_info.max_value_");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ if (ipc_parameter_infos[j].min_value_)
+ {
+ delete [] (char *)ipc_parameter_infos[j].min_value_;
+ ipc_parameter_infos[j].min_value_ = 0;
+ }
+ if (ipc_parameter_infos[j].max_value_)
+ {
+ delete [] (char *)ipc_parameter_infos[j].max_value_;
+ ipc_parameter_infos[j].min_value_ = 0;
+ }
+ }
+ if (ipc_parameter_infos[i].min_value_)
+ {
+ delete [] (char *)ipc_parameter_infos[i].min_value_;
+ ipc_parameter_infos[i].min_value_ = 0;
+ }
+ return -1;
+ }
+
+ // copy content
+ ACE_OS::memcpy (
+ ipc_parameter_info.max_value_,
+ fapia_infos[i].max_value,
+ fapia_infos[i].data_length);
+
+ // Set a trailing zero for strings.
+ if (fapia_infos[i].data_type == FAPIA_DATA_TYPE_STRING)
+ {
+ ACE_static_cast (
+ char* ,
+ ipc_parameter_info.max_value_)[fapia_infos[i].data_length] =
+ '\0';
+ }
+ }
+ else
+ {
+ ipc_parameter_info.max_value_ = 0;
+ }
+
+
+ ipc_parameter_infos.push_back (
+ ipc_parameter_info);
+ }
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPIAError * const fapia_errors,
+ const FAPI::Acyclic::IPC::Parameter::Errors& ipc_parameter_errors)
+ {
+ FAPIA_TRACE;
+
+ // Set errors.
+ unsigned long count = ipc_parameter_errors.size ();
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ fapia_errors[i].error_code =
+ ipc_parameter_errors[i].error_code_ ;
+
+
+ // Copy reason.
+
+ // Allocate memory for the reason.
+ unsigned long len = ipc_parameter_errors[i].reason_.length ();
+
+ ACE_NEW_NORETURN (fapia_errors[i].reason, char[len + 1]);
+ if (fapia_errors[i].reason == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating fapia_errors[i].reason");
+ unsigned long j = 0;
+ for (j = 0; j < i; ++j)
+ {
+ delete [] fapia_errors[j].reason;
+ fapia_errors[j].reason = 0;
+ }
+ return -1;
+ }
+
+ // Copy content.
+ ACE_OS::memcpy (
+ fapia_errors[i].reason,
+ ipc_parameter_errors[i].reason_.c_str (),
+ len);
+
+ // Set a trailing zero for strings.
+ fapia_errors[i].reason[len] = '\0';
+
+ }
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::convert (
+ FAPI::Acyclic::IPC::Parameter::Errors& ipc_parameter_errors,
+ const FAPIAError * const fapia_errors,
+ unsigned long count)
+ {
+ FAPIA_TRACE;
+
+ // Set errors.
+ FAPI::Acyclic::IPC::Parameter::Error ipc_parameter_error;
+ ipc_parameter_errors.max_size (count);
+
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ ipc_parameter_error.error_code_ =
+ fapia_errors[i].error_code;
+ ipc_parameter_error.reason_ =
+ fapia_errors[i].reason;
+
+ ipc_parameter_errors.push_back (
+ ipc_parameter_error);
+ }
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ void Controller::free_memory (
+ FAPIACommunication * const fapia_communication)
+ {
+ FAPIA_TRACE;
+
+ if (fapia_communication->communication_error.reason)
+ {
+ delete [] fapia_communication->communication_error.reason;
+ fapia_communication->communication_error.reason = 0;
+ }
+
+ if (fapia_communication->logical_object_name)
+ {
+ delete [] fapia_communication->logical_object_name;
+ fapia_communication->logical_object_name = 0;
+ }
+
+ if (fapia_communication->source_physical_object_name)
+ {
+ delete [] fapia_communication->source_physical_object_name;
+ fapia_communication->source_physical_object_name = 0;
+ }
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ void Controller::free_memory (
+ FAPIAParameter * const fapia_parameters,
+ unsigned long count)
+ {
+ FAPIA_TRACE;
+
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ if (fapia_parameters[i].parameter_name)
+ {
+ delete [] fapia_parameters[i].parameter_name;
+ fapia_parameters[i].parameter_name = 0;
+ }
+ }
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ void Controller::free_memory (
+ FAPIAValue * const fapia_values,
+ unsigned long count)
+ {
+ FAPIA_TRACE;
+
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ if (fapia_values[i].data_value)
+ {
+ delete [] (char *)fapia_values[i].data_value;
+ fapia_values[i].data_value = 0;
+ }
+ }
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ void Controller::free_memory (
+ FAPIAInfo * const fapia_infos,
+ unsigned long count)
+ {
+ FAPIA_TRACE;
+
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ if (fapia_infos[i].min_value)
+ {
+ delete [] fapia_infos[i].min_value;
+ fapia_infos[i].min_value = 0;
+ }
+ if (fapia_infos[i].max_value)
+ {
+ delete [] fapia_infos[i].max_value;
+ fapia_infos[i].max_value = 0;
+ }
+ if (fapia_infos[i].unit)
+ {
+ delete [] fapia_infos[i].unit;
+ fapia_infos[i].unit = 0;
+ }
+ if (fapia_infos[i].description)
+ {
+ delete [] fapia_infos[i].description;
+ fapia_infos[i].description = 0;
+ }
+ }
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ void Controller::free_memory (
+ FAPIAError * const fapia_errors,
+ unsigned long count)
+ {
+ FAPIA_TRACE;
+
+ unsigned long i = 0;
+ for (i = 0; i < count; ++i)
+ {
+ if (fapia_errors[i].reason)
+ {
+ delete [] fapia_errors[i].reason;
+ fapia_errors[i].reason = 0;
+ }
+ }
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::process_commandline_arguments (
+ int argc,
+ char* argv[])
+ {
+ FAPIA_TRACE;
+
+ // Set the default debug level
+ unsigned long fapia_debug_level = LM_ERROR | LM_CRITICAL | LM_ALERT | LM_EMERGENCY;
+
+ // Retrieve arguments for FAPIA.
+ ACE_Arg_Shifter arg_shifter (argc, argv);
+ while (arg_shifter.is_anything_left ())
+ {
+ const ACE_TCHAR *current_arg = arg_shifter.get_current ();
+
+ const ACE_TCHAR fapia_debug_levelopt[] = ACE_TEXT("-FAPIADebugLevel");
+ size_t fapia_debug_levellen = ACE_OS::strlen (fapia_debug_levelopt);
+
+ // Handle option FAPIADebugLevel.
+ if (ACE_OS::strcasecmp (current_arg, fapia_debug_levelopt) == 0)
+ {
+ arg_shifter.consume_arg ();
+ if (arg_shifter.is_parameter_next ())
+ {
+ fapia_debug_level = atol (ACE_TEXT_ALWAYS_CHAR(arg_shifter.get_current ()));
+ arg_shifter.consume_arg ();
+ }
+ }
+ else if (ACE_OS::strncasecmp (current_arg, fapia_debug_levelopt, fapia_debug_levellen) == 0)
+ {
+ arg_shifter.consume_arg ();
+ // The rest of the argument is the FAPIA debug level...
+ // but we should skip an optional space...
+ if (current_arg[fapia_debug_levellen] == ' ')
+ fapia_debug_level = atol (ACE_TEXT_ALWAYS_CHAR(current_arg + fapia_debug_levellen + 1));
+ else
+ fapia_debug_level = atol (ACE_TEXT_ALWAYS_CHAR(current_arg + fapia_debug_levellen));
+ }
+ else
+ arg_shifter.ignore_arg ();
+ }
+
+ // Set the logging level.
+ ACE_LOG_MSG->priority_mask (fapia_debug_level, ACE_Log_Msg::PROCESS);
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long Controller::shutdown_reply_command_handler (void)
+ {
+ FAPIA_TRACE;
+
+ if (reply_command_handler_)
+ {
+ if (reply_command_handler_->shutdown () < 0)
+ {
+ FAPIA_DEBUG (
+ LM_ERROR,
+ "Error shutting reply command handler down.\n");
+ return -1;
+ }
+
+ delete reply_command_handler_;
+ reply_command_handler_ = 0;
+ }
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ } /* namespace Controller */
+ } /* namespace Acyclic */
+ } /* namespace FAPI */
Added: fapia-trunk/FAPIAController/source/FAPIAControllerController.h
==============================================================================
--- (empty file)
+++ fapia-trunk/FAPIAController/source/FAPIAControllerController.h Thu Jul 19 07:08:51 2007
@@ -0,0 +1,767 @@
+/* -*- C++ -*- */
+
+//=============================================================================
+/**
+ * @file FAPIAControllerController.h
+ *
+ * $Id$
+ *
+ * @author Thomas Rothfuss <thomas.rothfuss at homag.de>
+ */
+//=============================================================================
+
+#ifndef _FAPI_ACYCLIC_CONTROLLER_CONTROLLER_H_
+#define _FAPI_ACYCLIC_CONTROLLER_CONTROLLER_H_
+
+#include /**/ <ace/SString.h>
+#include /**/ <ace/Singleton.h>
+#include /**/ <ace/Activation_Queue.h>
+#include /**/ <ace/RB_Tree.h>
+#include "../../interface/FAPIA.h"
+#include "FAPIAControllerReplyCommandHandler.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCIParameter.h"
+#include "../../FAPIAIPCSynchronize/interface/FAPIAIPCISynchronize.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestReadRequest.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestReadResponse.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestWriteRequest.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestWriteResponse.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestInfoRequest.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestInfoResponse.h"
+
+
+namespace FAPI
+ {
+ namespace Acyclic
+ {
+ namespace Controller
+ {
+ namespace Test
+ {
+ class ConversionsTest; // Forward declaration.
+ }
+
+ /**
+ * @class Controller
+ *
+ * @brief The Controller class is a singleton and implements the
+ * FAPIA interface.
+ *
+ */
+ class Controller
+ {
+
+ public:
+ friend class FAPI::Acyclic::Controller::ReplyCommandHandler;
+ friend class FAPI::Acyclic::Controller::Test::ConversionsTest;
+
+ /**
+ * @brief Constructor.
+ *
+ */
+ Controller (void);
+
+ /**
+ * @brief Destructor.
+ *
+ */
+ virtual ~Controller (void);
+
+ /**
+ * @brief Initializes the FAPIA. name is the physical_object_name of this
+ * communication node.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_init (
+ int argc,
+ char* argv[],
+ const char * const name);
+
+
+ /**
+ * @brief Deinitializes the FAPIA. FAPIA has to deallocate all allocated memory
+ * and shut down.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_deinit (void);
+
+
+ /**
+ * @brief Retrieves the logical object names from the FAPIA.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_logical_object_names (
+ char*** logical_object_names,
+ unsigned long* number_of_logical_object_names);
+
+
+ /**
+ * @brief Initializing the caller for responses of read requests. FAPIA holds a
+ * reference to the function and calls it when a response is received.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_set_callback_for_parameter_read_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAValue *,
+ const FAPIAError *));
+
+
+ /**
+ * @brief Initializing the caller for responses of write requests. FAPIA holds a
+ * reference to the function and calls it when a response is received.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_set_callback_for_parameter_write_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAError *));
+
+
+ /**
+ * @brief Initializing the caller for responses of info requests. FAPIA holds a
+ * reference to the function and calls it when a response is received.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_set_callback_for_parameter_info_response_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAInfo *,
+ const FAPIAError *));
+
+
+ /**
+ * @brief Initializing the callee for read requests. FAPIA holds a
+ * reference to the function and calls it when a request is received.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_set_callback_for_parameter_read_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *));
+
+
+ /**
+ * @brief Initializing the callee for write requests. FAPIA holds a
+ * reference to the function and calls it when a request is received.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_set_callback_for_parameter_write_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAValue *));
+
+
+ /**
+ * @brief Initializing the callee for info requests. FAPIA holds a
+ * reference to the function and calls it when a request is received.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_set_callback_for_parameter_info_request_callback (
+ long (*f) (const FAPIACommunication *,
+ const FAPIAParameter *));
+
+
+ /**
+ * @brief Sends a read request to the callee. fapia_communication.transaction_id
+ * and fapia_communication.source_physical_object_name are filled out by the
+ * FAPIA.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_read_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters);
+
+#if 0
+ /**
+ * @brief This is the callback response function of the read_request. It is _not_
+ * implemented by FAPIA. This may be done by the caller application. A function
+ * with this signature must be set by function
+ * fapia_set_callback_for_parameter_read_response_callback.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_read_response_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values,
+ const FAPIAError * const fapia_errors);
+
+
+
+ /**
+ * @brief This is the callback request function of the read_request. It is _not_
+ * implemented by FAPIA. This may be done by the callee application. A function
+ * with this signature must be set by function
+ * fapia_set_callback_for_parameter_read_request_callback.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_read_request_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters);
+#endif
+
+ /**
+ * @brief Sends a read response to the caller.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_read_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values,
+ const FAPIAError * const fapia_errors);
+
+
+ /**
+ * @brief Sends a write request to the callee. fapia_communication.transaction_id
+ * and fapia_communication.source_physical_object_name are filled out by the
+ * FAPIA.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_write_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values);
+
+#if 0
+ /**
+ * @brief This is the callback response function of the write_request. It is _not_
+ * implemented by FAPIA. This may be done by the caller application. A function
+ * with this signature must be set by function
+ * fapia_set_callback_for_parameter_write_response_callback.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_write_response_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAError * const fapia_errors);
+
+
+ /**
+ * @brief This is the callback response function of the write_request. It is _not_
+ * implemented by FAPIA. This may be done by the caller application. A function
+ * with this signature must be set by function
+ * fapia_set_callback_for_parameter_write_response_callback.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_write_request_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values);
+#endif
+
+ /**
+ * @brief Sends a write response to the caller.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_write_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAError * const fapia_errors);
+
+ /**
+ * @brief Sends a info request to the callee. fapia_communication.transaction_id
+ * and fapia_communication.source_physical_object_name are filled out by the
+ * FAPIA.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_info_request (
+ FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters);
+
+#if 0
+ /**
+ * @brief This is the callback response function of the info_request. It is _not_
+ * implemented by FAPIA. This may be done by the caller application. A function
+ * with this signature must be set by function
+ * fapia_set_callback_for_parameter_info_response_callback.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_info_response_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAInfo * const fapia_infos,
+ const FAPIAError * const fapia_errors);
+
+
+ /**
+ * @brief This is the callback response function of the info_request. It is _not_
+ * implemented by FAPIA. This may be done by the caller application. A function
+ * with this signature must be set by function
+ * fapia_set_callback_for_parameter_info_response_callback.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_info_request_callback (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters);
+#endif
+
+ /**
+ * @brief Sends a info response to the caller.
+ *
+ * If it returns a negative number there was an error.
+ *
+ */
+ long fapia_parameter_info_response (
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAInfo * const fapia_infos,
+ const FAPIAError * const fapia_errors);
+
+
+ protected:
+
+ /**
+ * @enum State
+ *
+ * @brief State of the controller module.
+ *
+ */
+ enum State
+ {
+ INITIAL = 1,
+ RUNNING = 2,
+ ABORTED = 3,
+ SHUTDOWN = 4,
+ EXITED = 5
+ };
+
+ /// State of the controller module.
+ State state_;
+
+ /// Transaction id is unique related to the physical_object_name_.
+ unsigned long transaction_id_;
+
+ /// Holds the physical object name of this process.
+ ACE_CString physical_object_name_;
+
+ /// Mapping from logical to physical objects
+ /// (<logical_object_name, physical_object_name>).
+ ACE_RB_Tree <ACE_CString, ACE_CString, ACE_Less_Than<ACE_CString> ,ACE_SYNCH_NULL_MUTEX> logical_physical_object_names_;
+
+ /// Array with existing logical object names. This is needed for
+ /// retrieving all logical object names. The number of them
+ /// are stored in number_of_logical_object_names_.
+ char** logical_object_names_;
+
+ /// Number of logical object names in the logical_object_names_
+ /// array.
+ unsigned long number_of_logical_object_names_;
+
+
+ /// Pointer to command handler for replies.
+ FAPI::Acyclic::Controller::ReplyCommandHandler* reply_command_handler_;
+
+ /// Callback function for read responses.
+ long (*parameter_read_response_callback_) (
+ const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAValue *,
+ const FAPIAError *);
+
+
+ /// Callback function for write responses.
+ long (*parameter_write_response_callback_) (
+ const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAError *);
+
+
+ /// Callback function for info responses.
+ long (*parameter_info_response_callback_) (
+ const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAInfo *,
+ const FAPIAError *);
+
+
+ /// Callback function for read requests.
+ long (*parameter_read_request_callback_) (
+ const FAPIACommunication *,
+ const FAPIAParameter *);
+
+
+ /// Callback function for write requests.
+ long (*parameter_write_request_callback_) (
+ const FAPIACommunication *,
+ const FAPIAParameter *,
+ const FAPIAValue *);
+
+ /// Callback function for info requests.
+ long (*parameter_info_request_callback_) (
+ const FAPIACommunication *,
+ const FAPIAParameter *);
+
+ /// Pointer to interface of ipc parameter module.
+ FAPI::Acyclic::IPC::IParameter* ipc_parameter_;
+
+ /// Activation queue for sending message requests to
+ /// IPC::Parameter.
+ ACE_Activation_Queue send_queue_;
+
+ /// Activation queue for receiving message requests from
+ /// IPC::Parameter.
+ ACE_Activation_Queue receive_queue_;
+
+ /// Pointer to interface of ipc parameter synchronize.
+ FAPI::Acyclic::IPC::ISynchronize* ipc_synchronize_;
+
+ /// Mutex to synchronize the incrementation of the
+ /// transaction_id_.
+ ACE_Thread_Mutex transaction_id_mutex_;
+
+ /**
+ * @brief Increments the transaction id and returns the value.
+ *
+ * This method is thread-safe.
+ *
+ */
+ void increment_and_get_transaction_id (
+ unsigned long& transaction_id);
+
+
+ /**
+ * @brief Converts the fapia parameters to a method request.
+ *
+ */
+ long convert_to_read_request (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters);
+
+
+ /**
+ * @brief Converts a method request to the fapia parameters.
+ *
+ */
+ long convert_from_read_request (
+ FAPIACommunication * const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest* mr);
+
+
+ /**
+ * @brief Converts the fapia parameters to a method request.
+ *
+ */
+ long convert_to_read_response (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values,
+ const FAPIAError * const fapia_errors);
+
+
+ /**
+ * @brief Converts a method request to the fapia parameters.
+ *
+ */
+ long convert_from_read_response (
+ FAPIACommunication * const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ FAPIAValue * const fapia_values,
+ FAPIAError * const fapia_errors,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse* mr);
+
+
+ /**
+ * @brief Converts the fapia parameters to a method request.
+ *
+ */
+ long convert_to_write_request (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAValue * const fapia_values);
+
+
+ /**
+ * @brief Converts a method request to the fapia parameters.
+ *
+ */
+ long convert_from_write_request (
+ FAPIACommunication* const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ FAPIAValue * const fapia_values,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest* mr);
+
+
+ /**
+ * @brief Converts the fapia parameters to a method request.
+ *
+ */
+ long convert_to_write_response (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAError * const fapia_errors);
+
+
+ /**
+ * @brief Converts a method request to the fapia parameters.
+ *
+ */
+ long convert_from_write_response (
+ FAPIACommunication * const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ FAPIAError * const fapia_errors,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse* mr);
+
+
+
+ /**
+ * @brief Converts the fapia parameters to a method request.
+ *
+ */
+ long convert_to_info_request (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters);
+
+
+ /**
+ * @brief Converts a method request to the fapia parameters.
+ *
+ */
+ long convert_from_info_request (
+ FAPIACommunication* const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest* mr);
+
+
+ /**
+ * @brief Converts the fapia parameters to a method request.
+ *
+ */
+ long convert_to_info_response (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse* mr,
+ const FAPIACommunication * const fapia_communication,
+ const FAPIAParameter * const fapia_parameters,
+ const FAPIAInfo * const fapia_infos,
+ const FAPIAError * const fapia_errors);
+
+
+ /**
+ * @brief Converts a method request to the fapia parameters.
+ *
+ */
+ long convert_from_info_response (
+ FAPIACommunication * const fapia_communication,
+ FAPIAParameter * const fapia_parameters,
+ FAPIAInfo * const fapia_infos,
+ FAPIAError * const fapia_errors,
+ const FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse* mr);
+
+
+
+ /**
+ * @brief Converts the ipc parameter to the fapia parameter.
+ *
+ */
+ long convert (
+ FAPIACommunication * const fapia_communication,
+ const FAPI::Acyclic::IPC::Parameter::Communication& ipc_parameter_communication);
+
+ /**
+ * @brief Converts the fapia parameter to the ipc parameter.
+ *
+ */
+ long convert (
+ FAPI::Acyclic::IPC::Parameter::Communication& ipc_parameter_communication,
+ const FAPIACommunication * const fapia_communication);
+
+
+
+ /**
+ * @brief Converts the ipc parameter to the fapia parameter.
+ *
+ */
+ long convert (
+ FAPIAParameter * const fapia_parameters,
+ const FAPI::Acyclic::IPC::Parameter::Parameters& ipc_parameter_parameters);
+
+ /**
+ * @brief Converts the fapia parameter to the ipc parameter.
+ *
+ */
+ long convert (
+ FAPI::Acyclic::IPC::Parameter::Parameters& ipc_parameter_parameters,
+ const FAPIAParameter * const fapia_parameters,
+ unsigned long count);
+
+
+
+ /**
+ * @brief Converts the ipc parameter to the fapia parameter.
+ *
+ */
+ long convert (
+ FAPIAValue * const fapia_values,
+ const FAPI::Acyclic::IPC::Parameter::Values& ipc_parameter_values);
+
+ /**
+ * @brief Converts the fapia parameter to the ipc parameter.
+ *
+ */
+ long convert (
+ FAPI::Acyclic::IPC::Parameter::Values& ipc_parameter_values,
+ const FAPIAValue * const fapia_values,
+ unsigned long count);
+
+
+
+ /**
+ * @brief Converts the ipc parameter to the fapia parameter.
+ *
+ */
+ long convert (
+ FAPIAInfo * const fapia_infos,
+ const FAPI::Acyclic::IPC::Parameter::Infos& ipc_parameter_infos);
+
+ /**
+ * @brief Converts the fapia parameter to the ipc parameter.
+ *
+ */
+ long convert (
+ FAPI::Acyclic::IPC::Parameter::Infos& ipc_parameter_infos,
+ const FAPIAInfo * const fapia_infos,
+ unsigned long count);
+
+
+
+ /**
+ * @brief Converts the ipc parameter to the fapia parameter.
+ *
+ */
+ long convert (
+ FAPIAError * const fapia_errors,
+ const FAPI::Acyclic::IPC::Parameter::Errors& ipc_parameter_errors);
+
+ /**
+ * @brief Converts the fapia parameter to the ipc parameter.
+ *
+ */
+ long convert (
+ FAPI::Acyclic::IPC::Parameter::Errors& ipc_parameter_errors,
+ const FAPIAError * const fapia_errors,
+ unsigned long count);
+
+
+ /**
+ * @brief Frees the memory.
+ *
+ */
+ void free_memory (
+ FAPIACommunication * const fapia_communication);
+
+ /**
+ * @brief Frees the memory.
+ *
+ */
+ void free_memory (
+ FAPIAParameter * const fapia_parameters,
+ unsigned long count);
+
+ /**
+ * @brief Frees the memory.
+ *
+ */
+ void free_memory (
+ FAPIAValue * const fapia_values,
+ unsigned long count);
+
+ /**
+ * @brief Frees the memory.
+ *
+ */
+ void free_memory (
+ FAPIAInfo * const fapia_infos,
+ unsigned long count);
+
+ /**
+ * @brief Frees the memory.
+ *
+ */
+ void free_memory (
+ FAPIAError * const fapia_errors,
+ unsigned long count);
+
+ /**
+ * @brief Processes the commandline arguments, e.g sets
+ * the trace level
+ *
+ */
+ long process_commandline_arguments (
+ int argc,
+ char* argv[]);
+
+ /**
+ * @brief Shuts the reply command handler down.
+ *
+ */
+ long shutdown_reply_command_handler (void);
+
+ private:
+
+ /**
+ * Copy Constructor is private, so this object cannot be copied.
+ */
+ Controller (const Controller&);
+
+ /**
+ * Assignment operator is private, so this object cannot be copied.
+ */
+ const Controller& operator= (const Controller&);
+
+
+ }; /* class Controller */
+
+ } /* namespace Controller */
+ } /* namespace Acyclic */
+ } /* namespace FAPI */
+
+/// Typedef for singleton of controller class.
+typedef ACE_Singleton<FAPI::Acyclic::Controller::Controller, ACE_Null_Mutex> FAPIAControllerControllerSingleton;
+
+/// Macro for accessing the controller class.
+#define FAPIA_CONTROLLER FAPIAControllerControllerSingleton::instance ()
+
+
+#endif /* _FAPI_ACYCLIC_CONTROLLER_CONTROLLER_H_ */
Added: fapia-trunk/FAPIAController/source/FAPIAControllerMethodRequestShutdown.cpp
==============================================================================
--- (empty file)
+++ fapia-trunk/FAPIAController/source/FAPIAControllerMethodRequestShutdown.cpp Thu Jul 19 07:08:51 2007
@@ -0,0 +1,36 @@
+// $Id$
+
+
+#include "FAPIAControllerMethodRequestShutdown.h"
+
+namespace FAPI
+ {
+ namespace Acyclic
+ {
+ namespace Controller
+ {
+
+/*---------------------------------------------------------------------------*/
+
+ MethodRequestShutdown::MethodRequestShutdown (void)
+ {
+ }
+
+/*---------------------------------------------------------------------------*/
+
+ MethodRequestShutdown::~MethodRequestShutdown (void)
+ {
+ }
+
+/*---------------------------------------------------------------------------*/
+
+ int MethodRequestShutdown::call (void)
+ {
+ return -1;
+ }
+
+/*---------------------------------------------------------------------------*/
+
+ } /* namespace Controller */
+ } /* namespace Acyclic */
+ } /* namespace FAPI */
Added: fapia-trunk/FAPIAController/source/FAPIAControllerMethodRequestShutdown.h
==============================================================================
--- (empty file)
+++ fapia-trunk/FAPIAController/source/FAPIAControllerMethodRequestShutdown.h Thu Jul 19 07:08:51 2007
@@ -0,0 +1,81 @@
+/* -*- C++ -*- */
+
+//=============================================================================
+/**
+ * @file FAPIAControllerMethodRequestShutdown.h
+ *
+ * $Id$
+ *
+ * @author Thomas Rothfuss <thomas.rothfuss at homag.de>
+ */
+//=============================================================================
+
+#ifndef _FAPI_ACYCLIC_CONTROLLER_METHOD_REQUEST_SHUTDOWN_H_
+#define _FAPI_ACYCLIC_CONTROLLER_METHOD_REQUEST_SHUTDOWN_H_
+
+#include /**/ <ace/Method_Request.h>
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequest.h"
+
+namespace FAPI
+ {
+ namespace Acyclic
+ {
+ namespace Controller
+ {
+ /**
+ * @class MethodRequestShutdown
+ *
+ * @brief The MethodRequestShutdown is the class to shutdown
+ * the reply command handler thread.
+ *
+ */
+ class MethodRequestShutdown : public FAPI::Acyclic::IPC::Parameter::MethodRequest
+ {
+
+ public:
+ /**
+ * @brief Constructor of MethodRequestShutdown.
+ *
+ */
+ MethodRequestShutdown (void);
+
+ /**
+ * @brief Destructor of MethodRequestShutdown.
+ *
+ */
+ virtual ~MethodRequestShutdown (void);
+
+ /**
+ * @brief Invoked when the MethodRequestShutdown is
+ * scheduled to run.
+ *
+ * If it returns -1 the receiving thread of this message
+ * must shut down.
+ *
+ */
+ virtual int call (void);
+
+ protected:
+
+ private:
+ /**
+ * @brief Copy Constructor is private, so this object cannot
+ * be copied.
+ *
+ */
+ MethodRequestShutdown (const MethodRequestShutdown&);
+
+ /**
+ * @brief Assignment operator is private, so this object cannot
+ * be copied.
+ *
+ */
+ const MethodRequestShutdown& operator= (const MethodRequestShutdown&);
+
+ }; /* class MethodRequestShutdown */
+
+ } /* namespace Controller */
+ } /* namespace Acyclic */
+ } /* namespace FAPI */
+
+#endif /* _FAPI_ACYCLIC_CONTROLLER_METHOD_REQUEST_SHUTDOWN_H_ */
Added: fapia-trunk/FAPIAController/source/FAPIAControllerReplyCommandHandler.cpp
==============================================================================
--- (empty file)
+++ fapia-trunk/FAPIAController/source/FAPIAControllerReplyCommandHandler.cpp Thu Jul 19 07:08:51 2007
@@ -0,0 +1,686 @@
+// $Id$
+
+#include "FAPIAControllerReplyCommandHandler.h"
+#include "FAPIAControllerController.h"
+#include "../../interface/FAPIATrace.h"
+#include "FAPIAControllerMethodRequestShutdown.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestReadRequest.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestWriteRequest.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestInfoRequest.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestReadResponse.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestWriteResponse.h"
+#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestInfoResponse.h"
+
+namespace FAPI
+ {
+ namespace Acyclic
+ {
+ namespace Controller
+ {
+
+/* ---------------------------------------------------------------------------*/
+
+ ReplyCommandHandler::ReplyCommandHandler (
+ FAPI::Acyclic::Controller::Controller* fapia_controller,
+ ACE_Activation_Queue* receive_queue
+ ) :
+ fapia_controller_ (fapia_controller),
+ receive_queue_ (receive_queue)
+ {
+ FAPIA_TRACE;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ ReplyCommandHandler::~ReplyCommandHandler (void)
+ {
+ FAPIA_TRACE;
+ this->clear_queue ();
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ int ReplyCommandHandler::perform (ACE_Method_Request * request)
+ {
+ FAPIA_TRACE;
+ return this->receive_queue_->enqueue (request);
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ void ReplyCommandHandler::clear_queue (void)
+ {
+ FAPIA_TRACE;
+ while (!this->receive_queue_->is_empty ())
+ {
+ ACE_Method_Request * request = this->receive_queue_->dequeue ();
+ if (request)
+ {
+ delete request; // Free allocated memory.
+ request = 0;
+ }
+ }
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ int ReplyCommandHandler::process_request (ACE_Method_Request * request)
+ {
+ FAPIA_TRACE;
+
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest*
+ method_request_read_request = 0;
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest*
+ method_request_write_request = 0;
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest*
+ method_request_info_request = 0;
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse*
+ method_request_read_response = 0;
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse*
+ method_request_write_response = 0;
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse*
+ method_request_info_response = 0;
+
+
+ method_request_read_request =
+ ACE_dynamic_cast (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadRequest *,
+ request);
+
+ if (method_request_read_request)
+ {
+ if (fapia_controller_->parameter_read_request_callback_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error callback method parameter_read_request_callback_ not set.\n");
+ return -1;
+ }
+
+ FAPIACommunication fapia_communication;
+ FAPIAParameter* fapia_parameters = 0;
+
+ method_request_read_request->parameters_.size ();
+ ACE_NEW_NORETURN (fapia_parameters, FAPIAParameter[method_request_read_request->parameters_.size ()]);
+ if (fapia_parameters == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAParameter.\n");
+ return -1;
+ }
+
+ if (fapia_controller_->convert_from_read_request (
+ &fapia_communication,
+ fapia_parameters,
+ method_request_read_request) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_from_read_request failed.\n");
+ return -1;
+ }
+
+ if ((*fapia_controller_->parameter_read_request_callback_)
+ (&fapia_communication, fapia_parameters) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error on calling parameter_read_request_callback_.\n");
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ return -1;
+ }
+
+ if (fapia_communication.communication_error.error_code ==
+ FAPIA_ERROR_DESTINATION_NOT_ONLINE)
+ {
+ FAPI::Acyclic::IPC::Synchronize::Error error;
+ fapia_controller_->ipc_synchronize_->disable_physical_object (
+ method_request_read_request->destination_physical_object_address_,
+ error);
+ }
+
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete fapia_parameters;
+ fapia_parameters = 0;
+ return 0;
+ }
+
+
+ method_request_write_request =
+ ACE_dynamic_cast (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteRequest *,
+ request);
+
+ if (method_request_write_request)
+ {
+ if (fapia_controller_->parameter_write_request_callback_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error callback method parameter_write_request_callback_ not set.\n");
+ return -1;
+ }
+
+ FAPIACommunication fapia_communication;
+ FAPIAParameter* fapia_parameters = 0;
+ FAPIAValue* fapia_values = 0;
+
+ ACE_NEW_NORETURN (fapia_parameters, FAPIAParameter[method_request_write_request->parameters_.size ()]);
+ if (fapia_parameters == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAParameter.\n");
+ return -1;
+ }
+
+ ACE_NEW_NORETURN (fapia_values, FAPIAValue[method_request_write_request->values_.size ()]);
+ if (fapia_values == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAValue.\n");
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ return -1;
+ }
+
+ if (fapia_controller_->convert_from_write_request (
+ &fapia_communication,
+ fapia_parameters,
+ fapia_values,
+ method_request_write_request) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_from_write_request failed.\n");
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_values;
+ fapia_values = 0;
+ return -1;
+ }
+
+ if ((*fapia_controller_->parameter_write_request_callback_)
+ (&fapia_communication, fapia_parameters, fapia_values) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error on calling parameter_write_request_callback_.\n");
+ fapia_controller_->free_memory (fapia_values, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_values;
+ fapia_values = 0;
+ return -1;
+ }
+
+ if (fapia_communication.communication_error.error_code ==
+ FAPIA_ERROR_DESTINATION_NOT_ONLINE)
+ {
+ FAPI::Acyclic::IPC::Synchronize::Error error;
+ fapia_controller_->ipc_synchronize_->disable_physical_object (
+ method_request_write_request->destination_physical_object_address_,
+ error);
+ }
+
+ fapia_controller_->free_memory (fapia_values, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_values;
+ fapia_values = 0;
+ return 0;
+ }
+
+
+ method_request_info_request =
+ ACE_dynamic_cast (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoRequest *,
+ request);
+
+ if (method_request_info_request)
+ {
+ if (fapia_controller_->parameter_info_request_callback_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error callback method parameter_info_request_callback_ not set.\n");
+ return -1;
+ }
+
+ FAPIACommunication fapia_communication;
+ FAPIAParameter* fapia_parameters = 0;
+
+ ACE_NEW_NORETURN (fapia_parameters, FAPIAParameter[method_request_info_request->parameters_.size ()]);
+ if (fapia_parameters == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAParameter.\n");
+ return -1;
+ }
+
+ if (fapia_controller_->convert_from_info_request (
+ &fapia_communication,
+ fapia_parameters,
+ method_request_info_request) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_from_info_request failed.\n");
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ return -1;
+ }
+
+ if ((*fapia_controller_->parameter_info_request_callback_)
+ (&fapia_communication, fapia_parameters) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error on calling parameter_info_request_callback_.\n");
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ return -1;
+ }
+
+ if (fapia_communication.communication_error.error_code ==
+ FAPIA_ERROR_DESTINATION_NOT_ONLINE)
+ {
+ FAPI::Acyclic::IPC::Synchronize::Error error;
+ fapia_controller_->ipc_synchronize_->disable_physical_object (
+ method_request_info_request->destination_physical_object_address_,
+ error);
+ }
+
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ return 0;
+ }
+
+
+ method_request_read_response =
+ ACE_dynamic_cast (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestReadResponse *,
+ request);
+ if (method_request_read_response)
+ {
+ if (fapia_controller_->parameter_read_response_callback_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error callback method parameter_read_response_callback_ not set.\n");
+ return -1;
+ }
+
+ FAPIACommunication fapia_communication;
+ FAPIAParameter* fapia_parameters = 0;
+ FAPIAValue* fapia_values = 0;
+ FAPIAError* fapia_errors = 0;
+
+ ACE_NEW_NORETURN (fapia_parameters, FAPIAParameter[method_request_read_response->parameters_.size ()]);
+ if (fapia_parameters == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAParameter.\n");
+ return -1;
+ }
+
+ ACE_NEW_NORETURN (fapia_values, FAPIAValue[method_request_read_response->values_.size ()]);
+ if (fapia_values == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAValue.\n");
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ return -1;
+ }
+
+ ACE_NEW_NORETURN (fapia_errors, FAPIAError[method_request_read_response->errors_.size ()]);
+ if (fapia_errors == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAError.\n");
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_values;
+ fapia_values = 0;
+ return -1;
+ }
+
+ if (fapia_controller_->convert_from_read_response (
+ &fapia_communication,
+ fapia_parameters,
+ fapia_values,
+ fapia_errors,
+ method_request_read_response) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_from_read_response failed.\n");
+ return -1;
+ }
+
+ if ((*fapia_controller_->parameter_read_response_callback_)
+ (&fapia_communication, fapia_parameters, fapia_values, fapia_errors) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error on calling parameter_read_response_callback_.\n");
+ fapia_controller_->free_memory (fapia_errors, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_values, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_values;
+ fapia_values = 0;
+ delete [] fapia_errors;
+ fapia_errors = 0;
+ return -1;
+ }
+
+ if (fapia_communication.communication_error.error_code ==
+ FAPIA_ERROR_DESTINATION_NOT_ONLINE)
+ {
+ FAPI::Acyclic::IPC::Synchronize::Error error;
+ fapia_controller_->ipc_synchronize_->disable_physical_object (
+ method_request_read_response->destination_physical_object_address_,
+ error);
+ }
+
+ fapia_controller_->free_memory (fapia_errors, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_values, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_values;
+ fapia_values = 0;
+ delete [] fapia_errors;
+ fapia_errors = 0;
+ return 0;
+ }
+
+
+ method_request_write_response =
+ ACE_dynamic_cast (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestWriteResponse *,
+ request);
+ if (method_request_write_response)
+ {
+ if (fapia_controller_->parameter_write_response_callback_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error callback method parameter_write_response_callback_ not set.\n");
+ return -1;
+ }
+
+ FAPIACommunication fapia_communication;
+ FAPIAParameter* fapia_parameters = 0;
+ FAPIAError* fapia_errors = 0;
+
+ ACE_NEW_NORETURN (fapia_parameters, FAPIAParameter[method_request_write_response->parameters_.size ()]);
+ if (fapia_parameters == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAParameter.\n");
+ return -1;
+ }
+
+ ACE_NEW_NORETURN (fapia_errors, FAPIAError[method_request_write_response->errors_.size ()]);
+ if (fapia_errors == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAError.\n");
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ return -1;
+ }
+
+
+ if (fapia_controller_->convert_from_write_response (
+ &fapia_communication,
+ fapia_parameters,
+ fapia_errors,
+ method_request_write_response) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_from_write_response failed.\n");
+ return -1;
+ }
+
+ if ((*fapia_controller_->parameter_write_response_callback_)
+ (&fapia_communication, fapia_parameters, fapia_errors) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error on calling parameter_write_response_callback_.\n");
+ fapia_controller_->free_memory (fapia_errors, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_errors;
+ fapia_errors = 0;
+ return -1;
+ }
+
+ if (fapia_communication.communication_error.error_code ==
+ FAPIA_ERROR_DESTINATION_NOT_ONLINE)
+ {
+ FAPI::Acyclic::IPC::Synchronize::Error error;
+ fapia_controller_->ipc_synchronize_->disable_physical_object (
+ method_request_write_response->destination_physical_object_address_,
+ error);
+ }
+
+ fapia_controller_->free_memory (fapia_errors, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_errors;
+ fapia_errors = 0;
+ return 0;
+ }
+
+ method_request_info_response =
+ ACE_dynamic_cast (
+ FAPI::Acyclic::IPC::Parameter::MethodRequestInfoResponse *,
+ request);
+ if (method_request_info_response)
+ {
+ if (fapia_controller_->parameter_info_response_callback_ == 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error callback method parameter_info_response_callback_ not set.\n");
+ return -1;
+ }
+
+ FAPIACommunication fapia_communication;
+ FAPIAParameter* fapia_parameters = 0;
+ FAPIAInfo* fapia_infos = 0;
+ FAPIAError* fapia_errors = 0;
+
+ ACE_NEW_NORETURN (fapia_parameters, FAPIAParameter[method_request_info_response->parameters_.size ()]);
+ if (fapia_parameters == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAParameter.\n");
+ return -1;
+ }
+
+ ACE_NEW_NORETURN (fapia_infos, FAPIAInfo[method_request_info_response->parameters_.size ()]);
+ if (fapia_infos == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAInfo.\n");
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ return -1;
+ }
+
+ ACE_NEW_NORETURN (fapia_errors, FAPIAError[method_request_info_response->errors_.size ()]);
+ if (fapia_errors == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPIAError.\n");
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_infos;
+ fapia_infos = 0;
+ return -1;
+ }
+
+
+ if (fapia_controller_->convert_from_info_response (
+ &fapia_communication,
+ fapia_parameters,
+ fapia_infos,
+ fapia_errors,
+ method_request_info_response) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error convert_from_info_response failed.\n");
+ return -1;
+ }
+
+ if ((*fapia_controller_->parameter_info_response_callback_)
+ (&fapia_communication, fapia_parameters, fapia_infos, fapia_errors) < 0)
+ {
+ FAPIA_DEBUG (
+ LM_CRITICAL,
+ "Error on calling parameter_info_response_callback_.\n");
+ fapia_controller_->free_memory (fapia_errors, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_infos, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_infos;
+ fapia_infos = 0;
+ delete [] fapia_errors;
+ fapia_errors = 0;
+ return -1;
+ }
+
+ if (fapia_communication.communication_error.error_code ==
+ FAPIA_ERROR_DESTINATION_NOT_ONLINE)
+ {
+ FAPI::Acyclic::IPC::Synchronize::Error error;
+ fapia_controller_->ipc_synchronize_->disable_physical_object (
+ method_request_info_response->destination_physical_object_address_,
+ error);
+ }
+
+ fapia_controller_->free_memory (fapia_errors, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_infos, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (fapia_parameters, fapia_communication.number_of_entries);
+ fapia_controller_->free_memory (&fapia_communication);
+ delete [] fapia_parameters;
+ fapia_parameters = 0;
+ delete [] fapia_infos;
+ fapia_infos = 0;
+ delete [] fapia_errors;
+ fapia_errors = 0;
+ return 0;
+ }
+
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ int ReplyCommandHandler::svc (void)
+ {
+ FAPIA_TRACE;
+
+ bool shutdown = false;
+
+ while (!shutdown)
+ {
+ ACE_Method_Request * request = this->receive_queue_->dequeue ();
+ if (request)
+ {
+ this->process_request (request);
+ long result = request->call ();
+ delete request; // Free allocated memory.
+ request = 0;
+ if (result == -1)
+ {
+ shutdown = true; // Exit thread.
+ }
+ }
+ }
+
+ // Clear the queue.
+ clear_queue ();
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ long ReplyCommandHandler::shutdown (void)
+ {
+ // Create shutdown method request.
+ FAPI::Acyclic::Controller::MethodRequestShutdown* mr_shutdown = 0;
+
+ ACE_NEW_NORETURN (
+ mr_shutdown,
+ FAPI::Acyclic::Controller::MethodRequestShutdown ());
+
+ if (mr_shutdown == 0)
+ {
+ FAPIA_DEBUG (
+ LM_ALERT,
+ "Error allocating FAPI::Acyclic::Controller::MethodRequestShutdown\n");
+ return -1;
+ }
+
+ // Enqueue shutdown request into receive queue. Thread will be
+ // woken up and shutdown.
+ this->perform (mr_shutdown);
+ this->wait ();
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ int ReplyCommandHandler::close (u_long flags)
+ {
+ FAPIA_TRACE;
+ ACE_UNUSED_ARG (flags);
+ return 0;
+ }
+
+/* ---------------------------------------------------------------------------*/
+
+ } /* namespace Controller */
+ } /* namespace Acyclic */
+ } /* namespace FAPI */
Added: fapia-trunk/FAPIAController/source/FAPIAControllerReplyCommandHandler.h
==============================================================================
--- (empty file)
+++ fapia-trunk/FAPIAController/source/FAPIAControllerReplyCommandHandler.h Thu Jul 19 07:08:51 2007
@@ -0,0 +1,116 @@
+/* -*- C++ -*- */
+
+//=============================================================================
+/**
+ * @file FAPIAControllerReplyCommandHandler.h
+ *
+ * $Id$
+ *
+ * @author Thomas Rothfuss <thomas.rothfuss at homag.de>
+ */
+//=============================================================================
+
+#ifndef _FAPI_ACYCLIC_CONTROLLER_REPLY_COMMAND_HANDLER_H_
+#define _FAPI_ACYCLIC_CONTROLLER_REPLY_COMMAND_HANDLER_H_
+
+#include /**/ <ace/Task.h>
+#include /**/ <ace/Activation_Queue.h>
+//#include "../../interface/FAPIA.h"
+//#include "../../FAPIAIPCParameter/interface/FAPIAIPCParameterMethodRequestWriteResponse.h"
+
+
+namespace FAPI
+ {
+ namespace Acyclic
+ {
+ namespace Controller
+ {
+ // Forward declaration.
+ class Controller;
+
+ /**
+ * @class ReplyCommandHandler
+ *
+ * @brief This command handler is responsible for the replies of the
+ * callee.
+ *
+ */
+ class ReplyCommandHandler : public ::ACE_Task<ACE_MT_SYNCH>
+
+ {
+
+ public:
+ /**
+ * @brief Constructor.
+ *
+ */
+ ReplyCommandHandler (
+ FAPI::Acyclic::Controller::Controller* fapia_controller,
+ ACE_Activation_Queue* receive_queue);
+
+ /**
+ * @brief Destructor.
+ *
+ */
+ virtual ~ReplyCommandHandler (void);
+
+ /**
+ * Performs a method request.
+ */
+ int perform (ACE_Method_Request* request);
+
+ /**
+ * Clears the queue.
+ */
+ void clear_queue (void);
+
+ /**
+ * Shutdowns the thread.
+ */
+ long shutdown (void);
+
+ /**
+ * Closes the command handler.
+ */
+ virtual int close (u_long flags = 0);
+
+ protected:
+
+ /// Pointer to controller instance.
+ FAPI::Acyclic::Controller::Controller* fapia_controller_;
+
+ /// Activation queue for receiving message requests from
+ /// IPC::Parameter.
+ ACE_Activation_Queue* receive_queue_;
+
+ /**
+ * Virtual function for receiving data.
+ */
+ virtual int svc (void);
+
+ /**
+ * This method processes the requests of the queue.
+ */
+ int process_request (ACE_Method_Request * request);
+
+ private:
+
+ /**
+ * Copy Constructor is private, so this object cannot be copied.
+ */
+ ReplyCommandHandler (const ReplyCommandHandler&);
+
+ /**
+ * Assignment operator is private, so this object cannot be copied.
+ */
+ const ReplyCommandHandler& operator= (const ReplyCommandHandler&);
+
+
+
+ }; /* class ReplyCommandHandler */
+
+ } /* namespace Controller */
+ } /* namespace Acyclic */
+ } /* namespace FAPI */
+
+#endif /* _FAPI_ACYCLIC_CONTROLLER_REPLY_COMMAND_HANDLER_H_ */
More information about the OSADL-svn-commits
mailing list