diff options
author | sumedh <sumedh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-04-29 04:16:43 +0000 |
---|---|---|
committer | sumedh <sumedh@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-04-29 04:16:43 +0000 |
commit | 79c1a27e743691fa0dc5647bedf71f55f42dd269 (patch) | |
tree | 73a08e737329da29be16736b9ae96a0cc649849b /TAO | |
parent | 829f0a6d26e943b2a1fe9199736f340f09106a82 (diff) | |
download | ATCD-79c1a27e743691fa0dc5647bedf71f55f42dd269.tar.gz |
CVS:
CVS:
Diffstat (limited to 'TAO')
-rw-r--r-- | TAO/orbsvcs/orbsvcs/AV/AVStreams_i.cpp | 311 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/AV/AVStreams_i.h | 65 |
2 files changed, 375 insertions, 1 deletions
diff --git a/TAO/orbsvcs/orbsvcs/AV/AVStreams_i.cpp b/TAO/orbsvcs/orbsvcs/AV/AVStreams_i.cpp index 149497571ad..4f480ca8ef5 100644 --- a/TAO/orbsvcs/orbsvcs/AV/AVStreams_i.cpp +++ b/TAO/orbsvcs/orbsvcs/AV/AVStreams_i.cpp @@ -614,6 +614,317 @@ TAO_VDev::~TAO_VDev (void) // ---------------------------------------------------------------------- +int +TAO_Endpoint_Strategy::create_B (AVStreams::StreamEndPoint_B_ptr stream_endpoint, + AVStreams::VDev_ptr vdev, + CORBA::Environment &env) +{ + if (this->activate () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) TAO_Endpoint_Strategy: Error in activate ()\n"), + -1); + + stream_endpoint = this->stream_endpoint_b_; + vdev = this->vdev_; + return 0; + +} + +int +TAO_Endpoint_Process_Strategy::activate (void) +{ + ACE_Process process; + + pid_t pid = process.spawn (*this->process_options_); + if (pid == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) ACE_Process:: spawn failed: %p\n", + "spawn"), + -1); + + char sem_str [BUFSIZ]; + char host [MAXHOSTNAMELEN]; + ACE_OS::hostname (host, + sizeof host); + + // create a unique semaphore name + ::sprintf (sem_str, + "%s:%s:%d", + "TAO_AV_Process_Semaphore", + host, + pid); + + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) semaphore is %s\n", + sem_str)); + // Create the semaphore + ACE_Process_Semaphore semaphore (0, // 0 means that the + // semaphore is locked initially + sem_str); + + // %% wait until the child finishes booting + while (1) + { + if (semaphore.acquire () == -1) + { + // See if my child process is still alive -- if not, return an error + if (ACE_OS::kill (pid, + 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Process_Strategy: Process being created died unexpectedly.\n"), + -1); + // if we were not interrupted due to a EINTR, break + if (errno != EINTR) + break; + } + else + break; + } + + if (semaphore.remove () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) semaphore remove failed: %p\n", + "remove"), + -1); + + return this->get_object_references (); +} + +int +TAO_Endpoint_Process_Strategy::get_object_references (void) +{ + TAO_TRY + { + CORBA::Object_var naming_obj = + TAO_ORB_Core_instance ()->orb ()->resolve_initial_references ("NameService"); + if (CORBA::is_nil (naming_obj.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to resolve the Name Service.\n"), + -1); + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow (naming_obj.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + + CosNaming::Name Stream_Endpoint_B_Name (1); + + Stream_Endpoint_B_Name.length (1); + Stream_Endpoint_B_Name [0].id = CORBA::string_dup + ("Stream_Endpoint_B"); + + CORBA::Object_var stream_endpoint_b = + naming_context->resolve (Stream_Endpoint_B_Name, + TAO_TRY_ENV); + TAO_CHECK_ENV; + + this->stream_endpoint_b_ = + AVStreams::StreamEndPoint_B::_narrow (stream_endpoint_b.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + + if (CORBA::is_nil (this->stream_endpoint_b_)) + ACE_ERROR_RETURN ((LM_ERROR, + " could not resolve Stream_Endpoint_B in Naming service <%s>\n"), + -1); + + // ---------------------------------------------------------------------- + CosNaming::Name VDev_Name (1); + VDev_Name.length (1); + VDev_Name [0].id = CORBA::string_dup + ("VDev"); + + CORBA::Object_var vdev = + naming_context->resolve (VDev_Name, + TAO_TRY_ENV); + TAO_CHECK_ENV; + + this->vdev_ = + AVStreams::VDev::_narrow (vdev.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + + if (CORBA::is_nil (this->vdev_)) + ACE_ERROR_RETURN ((LM_ERROR, + " could not resolve Stream_Endpoint_B in Naming service <%s>\n"), + -1); + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("TAO_Endpoint_Process_Strategy::get_object_references"); + return -1; + } + TAO_ENDTRY; + return 0; +} + +template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl> +TAO_Child_Process <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::TAO_Child_Process () +{ +} + +template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl> +int +TAO_Child_Process <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::init (int argc, char **argv) +{ + TAO_TRY + { + this->activate_objects (argc, + argv, + TAO_TRY_ENV); + TAO_CHECK_ENV; + + this->register_with_naming_service (TAO_TRY_ENV); + TAO_CHECK_ENV; + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("TAO_Child_Process"); + return -1; + } + TAO_ENDTRY; + + if (this->release_semaphore () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Error releasing semaphores\n"), + -1); + + return 0; +} + +template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl> +int +TAO_Child_Process <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::activate_objects (int argc, + char **argv, + CORBA::Environment &env) +{ + this->orb_manager_.init (argc, + argv, + env); + TAO_CHECK_ENV_RETURN (env, -1); + + this->orb_manager_.activate ("Stream_Endpoint_B", + this->stream_endpoint_b_, + env); + TAO_CHECK_ENV_RETURN (env, -1); + + + this->orb_manager_.activate ("VDev", + this->vdev_, + env); + TAO_CHECK_ENV_RETURN (env, -1); + + return 0; + +} + +template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl> +int +TAO_Child_Process <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::register_with_naming_service (CORBA::Environment &env) +{ + CORBA::Object_var naming_obj = + this->orb_manager_.orb ()->resolve_initial_references ("NameService"); + if (CORBA::is_nil (naming_obj.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to resolve the Name Service.\n"), + -1); + // ACE_DEBUG ((LM_DEBUG, "(%P|%t) %s:%d\n", __FILE__, __LINE__)); + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow (naming_obj.in (), + env); + TAO_CHECK_ENV_RETURN (env, + -1); + + // ACE_DEBUG ((LM_DEBUG, "(%P|%t) %s:%d\n", __FILE__, __LINE__)); + // Create a name for the video control object + CosNaming::Name Stream_Endpoint_B_Name (1); + + Stream_Endpoint_B_Name.length (1); + Stream_Endpoint_B_Name [0].id = CORBA::string_dup + ("Stream_Endpoint_B"); + + // Register the stream endpoint object with the naming server. + naming_context->bind (Stream_Endpoint_B_Name, + this->stream_endpoint_b_._this (env), + env); + + if (env.exception () != 0) + { + env.clear (); + naming_context->rebind (Stream_Endpoint_B_Name, + this->stream_endpoint_b_._this (env), + env); + TAO_CHECK_ENV_RETURN (env, -1); + } + + CosNaming::Name vdev_name (1); + vdev_name.length (1); + vdev_name [0].id = CORBA::string_dup ("VDev"); + + // Register the vdev with the naming server. + naming_context->bind (vdev_name, + this->vdev_._this (env), + env); + + if (env.exception () != 0) + { + env.clear (); + naming_context->rebind (vdev_name, + this->vdev_._this (env), + env); + TAO_CHECK_ENV_RETURN (env, -1); + } + + + return 0; +} + +template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl> +int +TAO_Child_Process <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::run (ACE_Time_Value &tv) +{ + return this->orb_manager_.run (tv); +} + +template <class T_StreamEndpoint_B, class T_VDev , class T_MediaCtrl> +int +TAO_Child_Process <T_StreamEndpoint_B, T_VDev, T_MediaCtrl>::release_semaphore () +{ + char sem_str [BUFSIZ]; + char host [MAXHOSTNAMELEN]; + pid_t pid; + + if ((pid = ACE_OS::getpid ()) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Unable to get my pid!\n"), + -1); + + ACE_OS::hostname (host, + sizeof host); + + sprintf (sem_str, + "%s:%s:%d", + "TAO_AV_Process_Semaphore", + host, + pid); + + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) semaphore is %s\n", + sem_str)); + + // Release the lock on which the server is waiting + ACE_Process_Semaphore semaphore (0, // 0 means that the semaphore is + // initially locked + sem_str); + + if (semaphore.release () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) Error releasing semaphore %s: %p\n", + sem_str, + "semaphore.release ()"), + -1); + + return 0; +} TAO_MMDevice::TAO_MMDevice () { diff --git a/TAO/orbsvcs/orbsvcs/AV/AVStreams_i.h b/TAO/orbsvcs/orbsvcs/AV/AVStreams_i.h index 72c8b529023..702cb93ac59 100644 --- a/TAO/orbsvcs/orbsvcs/AV/AVStreams_i.h +++ b/TAO/orbsvcs/orbsvcs/AV/AVStreams_i.h @@ -23,6 +23,8 @@ #include "orbsvcs/CosPropertyServiceS.h" #include "orbsvcs/AVStreamsS.h" #include "orbsvcs/Property/CosPropertyService_i.h" +#include "ace/Process.h" +#include "orbsvcs/CosNamingC.h" class TAO_ORBSVCS_Export TAO_Basic_StreamCtrl : public virtual POA_AVStreams::Basic_StreamCtrl @@ -39,7 +41,6 @@ class TAO_ORBSVCS_Export TAO_Basic_StreamCtrl // Stop the transfer of data of the stream // Empty the_spec means apply operation to all flows - virtual void start (const AVStreams::flowSpec &the_spec, CORBA::Environment &env); // Start the transfer of data in the stream. @@ -400,6 +401,68 @@ class TAO_ORBSVCS_Export TAO_VDev CORBA::ORB_ptr orb_; }; +class TAO_ORBSVCS_Export TAO_Endpoint_Strategy +// = DESCRIPTION +// Base class to define various strategies +// used by the MMDevice to create the Endpoint and Vdev +{ +public: + TAO_Endpoint_Strategy (void); + + virtual int create_B (AVStreams::StreamEndPoint_B_ptr stream_endpoint, + AVStreams::VDev_ptr vdev, + CORBA::Environment &env); + + virtual int activate (void) = 0; + + protected: + // TAO_Endpoint_Factory *endpoint_factory_; + AVStreams::StreamEndPoint_B_ptr stream_endpoint_b_; + AVStreams::VDev_ptr vdev_; +}; + +class TAO_ORBSVCS_Export TAO_Endpoint_Process_Strategy + : public virtual TAO_Endpoint_Strategy +// = DESCRIPTION +// Process-based strategy +{ + public: + TAO_Endpoint_Process_Strategy (ACE_Process_Options *process_options); + + virtual int activate (void); + + private: + int get_object_references (void); + ACE_Process_Options *process_options_; + +}; + +template <class T_StreamEndpoint_B, class T_Vdev , class T_MediaCtrl> +class TAO_ORBSVCS_Export TAO_Child_Process +// = DESCRIPTION +// Helper class for the child process created in TAO_Endpoint_Process_Strategy +{ +public: + TAO_Child_Process (); + int init (int argc, char **argv); + int run (ACE_Time_Value &tv = 0); + + private: + + int activate_objects (int argc, + char **argv, + CORBA::Environment &env); + + int register_with_naming_service (CORBA::Environment &env); + int run (ACE_Time_Value &tv); + int release_semaphore (); + + TAO_ORB_Manager orb_manager_; + T_StreamEndpoint stream_endpoint_b_; + T_Vdev vdev_; + T_MediaCtrl media_control_; +}; + class TAO_ORBSVCS_Export TAO_MMDevice : public virtual TAO_PropertySet, public virtual POA_AVStreams::MMDevice |