diff options
author | Ossama Othman <ossama-othman@users.noreply.github.com> | 2000-06-20 02:31:06 +0000 |
---|---|---|
committer | Ossama Othman <ossama-othman@users.noreply.github.com> | 2000-06-20 02:31:06 +0000 |
commit | 3eae6f5abfcb8a7a7eb7e3a392ef17d6b2f96dfa (patch) | |
tree | b51c7a0d9d9c7e9203adb86b3552f2b9ceec3e93 | |
parent | 00cee9caaa814685d352584815a2859c8c9b4bbd (diff) | |
download | ATCD-3eae6f5abfcb8a7a7eb7e3a392ef17d6b2f96dfa.tar.gz |
ChangeLogTag:Mon Jun 19 19:26:14 2000 Ossama Othman <ossama@uci.edu>
18 files changed, 315 insertions, 224 deletions
diff --git a/TAO/examples/Content_Server/AMI_Iterator/Content_Iterator_i.cpp b/TAO/examples/Content_Server/AMI_Iterator/Content_Iterator_i.cpp index d100cc0584d..5aefbf685b8 100644 --- a/TAO/examples/Content_Server/AMI_Iterator/Content_Iterator_i.cpp +++ b/TAO/examples/Content_Server/AMI_Iterator/Content_Iterator_i.cpp @@ -13,8 +13,7 @@ Content_Iterator_i::Content_Iterator_i (const char *pathname, : file_ (pathname), file_io_ (), file_size_ (file_size), - chunk_index_ (1), - initialized_ (0) + chunk_index_ (1) { // Nothing else } @@ -44,8 +43,8 @@ Content_Iterator_i::next_chunk (CORBA::ULong offset, if (real_offset == (off_t) -1) // Invalid supplied offset? ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "Error during lseek"), + ACE_TEXT ("%p\n"), + ACE_TEXT ("Error during lseek")), 0); else if (offset != ACE_static_cast (CORBA::ULong, real_offset)) { @@ -58,15 +57,23 @@ Content_Iterator_i::next_chunk (CORBA::ULong offset, (void) ACE_OS::lseek (this->file_io_.get_handle (), real_offset, SEEK_SET); - ACE_DEBUG ((LM_ERROR, - "Unable to reposition to desired offset.\n")); - return 0; + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Unable to reposition to desired ") + ACE_TEXT ("offset.\n")), + 0); } // Allocate a buffer for the file being read. CORBA::Octet *buf = Web_Server::Chunk_Type::allocbuf (BUFSIZ); + if (buf == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Could not allocate chunk buffer\n")), + 0); + } + ssize_t bytes_read = this->file_io_.recv (buf, BUFSIZ); if (bytes_read == -1) @@ -74,13 +81,13 @@ Content_Iterator_i::next_chunk (CORBA::ULong offset, Web_Server::Chunk_Type::freebuf (buf); ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "Error during read"), + ACE_TEXT ("%p\n"), + ACE_TEXT ("Error during read")), 0); } ACE_DEBUG ((LM_DEBUG, - "Sending chunk %d at offset <%u> of size <%u>\n", + ACE_TEXT ("Sending chunk %d at offset <%u> of size <%u>\n"), this->chunk_index_, offset, bytes_read)); @@ -103,8 +110,6 @@ Content_Iterator_i::destroy (CORBA::Environment &ACE_TRY_ENV) { (void) this->file_io_.close (); - this->initialized_ = 0; - // Get the POA used when activating the Content_Iterator object. PortableServer::POA_var poa = this->_default_POA (ACE_TRY_ENV); @@ -141,6 +146,5 @@ Content_Iterator_i::init (void) this->file_.get_path_name ()), -1); - this->initialized_ = 1; return 0; } diff --git a/TAO/examples/Content_Server/AMI_Iterator/Content_Iterator_i.h b/TAO/examples/Content_Server/AMI_Iterator/Content_Iterator_i.h index 40f44c4c731..607ee9a9d5f 100644 --- a/TAO/examples/Content_Server/AMI_Iterator/Content_Iterator_i.h +++ b/TAO/examples/Content_Server/AMI_Iterator/Content_Iterator_i.h @@ -74,10 +74,6 @@ private: CORBA::ULong chunk_index_; // The number of the current chunk of data being sent. (Used only // for debugging purposes.) - - int initialized_; - // Flag that denotes that the Content Iterator has not been - // initialized. }; #endif /* CONTENT_ITERATOR_I_H */ diff --git a/TAO/examples/Content_Server/AMI_Iterator/Iterator_Factory_i.cpp b/TAO/examples/Content_Server/AMI_Iterator/Iterator_Factory_i.cpp index 56c60df8a4e..32e2c07d1ba 100644 --- a/TAO/examples/Content_Server/AMI_Iterator/Iterator_Factory_i.cpp +++ b/TAO/examples/Content_Server/AMI_Iterator/Iterator_Factory_i.cpp @@ -18,7 +18,7 @@ Iterator_Factory_i::get_iterator (const char *pathname, // Based on code available in H&V. ACE_DEBUG ((LM_DEBUG, - "Received request for file: <%s>\n", + ACE_TEXT ("Received request for file: <%s>\n"), pathname)); struct stat file_status; @@ -144,9 +144,9 @@ Iterator_Factory_i::content_type (const char *filename, { metadata->content_type = CORBA::string_dup ("text/html"); ACE_ERROR ((LM_WARNING, - "\n " - "Unknown file type. " - "Using \"text/html\" content type.\n")); + ACE_TEXT ("\n ") + ACE_TEXT ("Unknown file type. ") + ACE_TEXT ("Using \"text/html\" content type.\n"))); } return 0; diff --git a/TAO/examples/Content_Server/AMI_Iterator/Iterator_Handler.cpp b/TAO/examples/Content_Server/AMI_Iterator/Iterator_Handler.cpp index 8937832db00..163c53efcfa 100644 --- a/TAO/examples/Content_Server/AMI_Iterator/Iterator_Handler.cpp +++ b/TAO/examples/Content_Server/AMI_Iterator/Iterator_Handler.cpp @@ -11,7 +11,7 @@ ACE_RCSID(AMI_Iterator, Iterator_Handler, "$Id$") Iterator_Handler::Iterator_Handler (void) - : file_ ((const ACE_FILE_Addr &) ACE_Addr::sap_any), + : file_ (ACE_sap_any_cast (const ACE_FILE_Addr &)), file_io_ (), contents_ (), metadata_ (), @@ -97,7 +97,7 @@ Iterator_Handler::run (int *request_count, this->request_count_ = request_count; else // @@ Application code shouldn't throw system exceptions. - ACE_THROW (CORBA::BAD_PARAM ()); + ACE_THROW (CORBA::BAD_PARAM ()); // Initialize the Content Iterator this->initialize_content_iterator (pathname, factory, @@ -116,7 +116,7 @@ Iterator_Handler::run (int *request_count, } void -Iterator_Handler::initialize_content_iterator +Iterator_Handler::initialize_content_iterator (const char *pathname, Web_Server::Iterator_Factory_ptr factory, CORBA::Environment &ACE_TRY_ENV) @@ -227,7 +227,7 @@ Iterator_Handler::get_viewer (char *viewer, } else ACE_ERROR_RETURN ((LM_ERROR, - "Unsupported MIME type: <%s>\n", + ACE_TEXT ("Unsupported MIME type: <%s>\n"), content_type), -1); @@ -237,9 +237,7 @@ Iterator_Handler::get_viewer (char *viewer, int Iterator_Handler::spawn_viewer (void) { - // It is highly unlikey, a mime type will ever be larger than 80 - // bytes. - char viewer[80]; + char viewer[BUFSIZ]; if (this->get_viewer (viewer, sizeof viewer) != 0) @@ -272,7 +270,7 @@ Iterator_Handler::spawn_viewer (void) default: // Parent ACE_DEBUG ((LM_INFO, - "Spawned viewer <%s> with PID <%d>.\n", + ACE_TEXT ("Spawned viewer <%s> with PID <%d>.\n"), viewer, result)); break; diff --git a/TAO/examples/Content_Server/AMI_Iterator/Iterator_Handler.h b/TAO/examples/Content_Server/AMI_Iterator/Iterator_Handler.h index 4123670e648..4b653122a89 100644 --- a/TAO/examples/Content_Server/AMI_Iterator/Iterator_Handler.h +++ b/TAO/examples/Content_Server/AMI_Iterator/Iterator_Handler.h @@ -120,10 +120,11 @@ private: Web_Server::AMI_Content_IteratorHandler_var ami_handler_; // Reference to this Reply Handler's self. - int *request_count_; // Pointer to external status monitoring -variable. The contents (not // the pointer itself) of the -<pending_data> parameter will be // decremented when file retrieval -has completed. }; + int *request_count_; + // Pointer to external status monitoring variable. The contents (not + // the pointer itself) of the<pending_data> parameter will be + // decremented when file retrieval has completed. +}; #include "ace/post.h" diff --git a/TAO/examples/Content_Server/AMI_Iterator/client.cpp b/TAO/examples/Content_Server/AMI_Iterator/client.cpp index d070b16b028..4b6e1a461d9 100644 --- a/TAO/examples/Content_Server/AMI_Iterator/client.cpp +++ b/TAO/examples/Content_Server/AMI_Iterator/client.cpp @@ -10,6 +10,18 @@ ACE_RCSID(AMI_Iterator, client, "$Id") +// Obtain reference to Iterator_Factory +Web_Server::Iterator_Factory_ptr +get_iterator (CORBA::ORB_ptr orb, + CORBA::Environment &ACE_TRY_ENV); + +// Perform file requests +void invoke_requests (int argc, + char *argv[], + int *request_count, + Web_Server::Iterator_Factory_ptr f, + CORBA::Environment &ACE_TRY_ENV); + int main (int argc, char *argv[]) { @@ -18,7 +30,8 @@ main (int argc, char *argv[]) { if (argc < 2) ACE_ERROR_RETURN ((LM_ERROR, - "Usage: client filename [filename ...]\n"), + ACE_TEXT ("Usage: client filename ") + ACE_TEXT ("[filename ...]\n")), -1); // Initialize the ORB. CORBA::ORB_var orb = CORBA::ORB_init (argc, @@ -42,66 +55,34 @@ main (int argc, char *argv[]) mgr->activate (ACE_TRY_ENV); ACE_TRY_CHECK; - // Get a reference to the Name Service. - obj = orb->resolve_initial_references ("NameService", - ACE_TRY_ENV); - ACE_TRY_CHECK; - - // Narrow to a Naming Context - CosNaming::NamingContext_var nc; - nc = CosNaming::NamingContext::_narrow (obj.in (), ACE_TRY_ENV); - ACE_TRY_CHECK; - - if (CORBA::is_nil (obj.in ())) - ACE_ERROR_RETURN ((LM_ERROR, - "Nil reference to Name Service\n"), - -1); - // Create a name. - CosNaming::Name name; - name.length (1); - name[0].id = CORBA::string_dup ("Iterator_Factory"); - name[0].kind = CORBA::string_dup (""); - - obj = nc->resolve (name, ACE_TRY_ENV); - ACE_TRY_CHECK; - // Now narrow to an Iterator_Factory reference. Web_Server::Iterator_Factory_var factory = - Web_Server::Iterator_Factory::_narrow (obj.in ()); + ::get_iterator (orb.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + if (CORBA::is_nil (factory.in ())) ACE_ERROR_RETURN ((LM_ERROR, - "Object pointed to by:\n %s\n" - "is not an Iterator_Factory object.\n", + ACE_TEXT ("Object pointed to by:\n %s\n") + ACE_TEXT ("is not an Iterator_Factory object.\n"), argv[1]), -1); - // Variable used to keep track of when file retrieval has - // completed. - int request_count = 0; - - // Activate and run the reply handlers. - for (int i = 0; - i < argc - 1; // Don't include the program name. - ++i) - { - Iterator_Handler * handler = 0; - ACE_NEW_RETURN (handler, - Iterator_Handler, - -1); - - // Transfer ownership to the POA. - PortableServer::ServantBase_var tmp (handler); - - handler->run (&request_count, - argv[i + 1], - factory.in (), - ACE_TRY_ENV); - ACE_TRY_CHECK; - } // 1 millisecond delay to reduce "busy waiting" in ORB event // loop. (simulating "work") ACE_Time_Value tv (0, 1000); + // Variable used to keep track of when file retrieval has + // completed. + int request_count = 0; + + ::invoke_requests (argc, + argv, + &request_count, + factory.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + // Run the ORB event loop. while (request_count > 0) if (orb->work_pending (ACE_TRY_ENV)) @@ -123,14 +104,15 @@ main (int argc, char *argv[]) ACE_CATCH (Web_Server::Error_Result, exc) { ACE_ERROR_RETURN ((LM_ERROR, - "Caught Web Server exception with status %d\n", + ACE_TEXT ("Caught Web Server exception with ") + ACE_TEXT ("status %d\n"), exc.status), -1); } ACE_CATCHANY { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Caught unexpected exception:"); + ACE_TEXT ("Caught unexpected exception:")); return -1; } @@ -141,3 +123,74 @@ main (int argc, char *argv[]) return 0; } + +Web_Server::Iterator_Factory_ptr +get_iterator (CORBA::ORB_ptr o, + CORBA::Environment &ACE_TRY_ENV) +{ + CORBA::ORB_var orb = CORBA::ORB::_duplicate (o); + + // Get a reference to the Name Service. + CORBA::Object_var obj = + orb->resolve_initial_references ("NameService", + ACE_TRY_ENV); + ACE_CHECK_RETURN (Web_Server::Iterator_Factory::_nil ()); + + // Narrow to a Naming Context + CosNaming::NamingContext_var nc; + nc = CosNaming::NamingContext::_narrow (obj.in (), ACE_TRY_ENV); + ACE_CHECK_RETURN (Web_Server::Iterator_Factory::_nil ()); + + if (CORBA::is_nil (obj.in ())) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Nil reference to Name Service\n"))); + return Web_Server::Iterator_Factory::_nil (); + } + + // Create a name. + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("Iterator_Factory"); + name[0].kind = CORBA::string_dup (""); + + obj = nc->resolve (name, ACE_TRY_ENV); + ACE_CHECK_RETURN (Web_Server::Iterator_Factory::_nil ()); + + Web_Server::Iterator_Factory_ptr factory = + Web_Server::Iterator_Factory::_narrow (obj.in ()); + + return factory; +} + +void invoke_requests (int argc, + char *argv[], + int *request_count, + Web_Server::Iterator_Factory_ptr f, + CORBA::Environment &ACE_TRY_ENV) +{ + Web_Server::Iterator_Factory_var factory = + Web_Server::Iterator_Factory::_duplicate (f); + + // Activate and run the reply handlers. + for (int i = 0; + i < argc - 1; // Don't include the program name. + ++i) + { + Iterator_Handler *handler = 0; + ACE_NEW_THROW_EX (handler, + Iterator_Handler, + CORBA::NO_MEMORY ()); + ACE_CHECK; + + // Transfer ownership to the POA. + PortableServer::ServantBase_var tmp (handler); + + // This ends up being an AMI call, so it won't block. + handler->run (request_count, + argv[i + 1], + factory.in (), + ACE_TRY_ENV); + ACE_CHECK; + } +} diff --git a/TAO/examples/Content_Server/AMI_Iterator/server.cpp b/TAO/examples/Content_Server/AMI_Iterator/server.cpp index 3d9ed921508..d4446720fae 100644 --- a/TAO/examples/Content_Server/AMI_Iterator/server.cpp +++ b/TAO/examples/Content_Server/AMI_Iterator/server.cpp @@ -69,12 +69,12 @@ main (int argc, char *argv[]) ACE_TRY_ENV); ACE_TRY_CHECK; ACE_DEBUG ((LM_DEBUG, - "Bound <%s> to <%s> in Name Service.\n", + ACE_TEXT ("Bound <%s> to <%s> in Name Service.\n"), name[0].id.in (), IOR.in ())); ACE_DEBUG ((LM_INFO, - "Accepting requests.\n")); + ACE_TEXT ("Accepting requests.\n"))); // Accept requests. orb->run (ACE_TRY_ENV); @@ -83,7 +83,7 @@ main (int argc, char *argv[]) ACE_CATCHANY { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Caught unexpected exception:"); + ACE_TEXT ("Caught unexpected exception:")); return -1; } diff --git a/TAO/examples/Content_Server/AMI_Observer/Callback.cpp b/TAO/examples/Content_Server/AMI_Observer/Callback.cpp index 5792f5e4025..5878f97f525 100644 --- a/TAO/examples/Content_Server/AMI_Observer/Callback.cpp +++ b/TAO/examples/Content_Server/AMI_Observer/Callback.cpp @@ -43,37 +43,12 @@ Callback_i::Callback_i (int * request_count) Callback_i::~Callback_i (void) { (void) this->file_io_.close (); - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - // Get the POA used when activating the Reply Handler object. - PortableServer::POA_var poa = this->_default_POA (ACE_TRY_ENV); - ACE_TRY_CHECK; - - // Get the object ID associated with this servant. - PortableServer::ObjectId_var oid = - poa->servant_to_id (this, - ACE_TRY_ENV); - ACE_TRY_CHECK; - - // Now deactivate the iterator object. - poa->deactivate_object (oid.in (), ACE_TRY_ENV); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - ACE_TEXT ("Caught unexpected exception ") - ACE_TEXT ("in ~Callback_i():")); - } - ACE_ENDTRY; } void Callback_i::next_chunk (const Web_Server::Chunk_Type & chunk_data, CORBA::Boolean last_chunk, - CORBA::Environment &) + CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { if (!last_chunk) @@ -118,32 +93,54 @@ Callback_i::next_chunk (const Web_Server::Chunk_Type & chunk_data, // If the entire metadata has been received, then spawn an // external viewer to display the received file. if (this->metadata_received ()) - (void) this->spawn_viewer (); + { + (void) this->file_io_.close (); + this->deactivate (ACE_TRY_ENV); + ACE_CHECK; + + (void) this->spawn_viewer (); + } } } void Callback_i::metadata (const Web_Server::Metadata_Type & metadata) { - { - ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, - guard, - this->lock_)); - this->metadata_ = metadata; - } - - ACE_DEBUG ((LM_INFO, - ACE_TEXT ("Retrieved file has the following ") - ACE_TEXT ("characteristics:\n") - ACE_TEXT (" Modification Date: %s\n") - ACE_TEXT (" Content Type: %s\n"), - this->metadata_.modification_date.in (), - this->metadata_.content_type.in ())); - - // If the entire content of the data has been received, then spawn - // an external viewer to display it. - if (this->content_received ()) - (void) this->spawn_viewer (); + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + { + ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, + guard, + this->lock_)); + this->metadata_ = metadata; + } + + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("Retrieved file has the following ") + ACE_TEXT ("characteristics:\n") + ACE_TEXT (" Modification Date: %s\n") + ACE_TEXT (" Content Type: %s\n"), + this->metadata_.modification_date.in (), + this->metadata_.content_type.in ())); + + // If the entire content of the data has been received, then spawn + // an external viewer to display it. + if (this->content_received ()) + { + this->deactivate (ACE_TRY_ENV); + ACE_TRY_CHECK; + + (void) this->spawn_viewer (); + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + ACE_TEXT ("Caught unexpected exception ") + ACE_TEXT ("in Callback_i::metdata(...):")); + } + ACE_ENDTRY; } int @@ -279,3 +276,21 @@ Callback_i::spawn_viewer (void) return 0; } + +void +Callback_i::deactivate (CORBA::Environment &ACE_TRY_ENV) +{ + // Get the POA used when activating the Reply Handler object. + PortableServer::POA_var poa = this->_default_POA (ACE_TRY_ENV); + ACE_CHECK; + + // Get the object ID associated with this servant. + PortableServer::ObjectId_var oid = + poa->servant_to_id (this, + ACE_TRY_ENV); + ACE_CHECK; + + // Now deactivate the iterator object. + poa->deactivate_object (oid.in (), ACE_TRY_ENV); + ACE_CHECK; +} diff --git a/TAO/examples/Content_Server/AMI_Observer/Callback.h b/TAO/examples/Content_Server/AMI_Observer/Callback.h index 08c279de2e9..3b3ba50007c 100644 --- a/TAO/examples/Content_Server/AMI_Observer/Callback.h +++ b/TAO/examples/Content_Server/AMI_Observer/Callback.h @@ -73,6 +73,11 @@ private: private: + void deactivate (CORBA::Environment &ACE_TRY_ENV); + // Deactivate this Callback servant. + +private: + ACE_FILE_Addr file_; // The Addr corresponding to the retrieved file. diff --git a/TAO/examples/Content_Server/AMI_Observer/Callback_i.cpp b/TAO/examples/Content_Server/AMI_Observer/Callback_i.cpp index 5792f5e4025..5878f97f525 100644 --- a/TAO/examples/Content_Server/AMI_Observer/Callback_i.cpp +++ b/TAO/examples/Content_Server/AMI_Observer/Callback_i.cpp @@ -43,37 +43,12 @@ Callback_i::Callback_i (int * request_count) Callback_i::~Callback_i (void) { (void) this->file_io_.close (); - - ACE_DECLARE_NEW_CORBA_ENV; - ACE_TRY - { - // Get the POA used when activating the Reply Handler object. - PortableServer::POA_var poa = this->_default_POA (ACE_TRY_ENV); - ACE_TRY_CHECK; - - // Get the object ID associated with this servant. - PortableServer::ObjectId_var oid = - poa->servant_to_id (this, - ACE_TRY_ENV); - ACE_TRY_CHECK; - - // Now deactivate the iterator object. - poa->deactivate_object (oid.in (), ACE_TRY_ENV); - ACE_TRY_CHECK; - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - ACE_TEXT ("Caught unexpected exception ") - ACE_TEXT ("in ~Callback_i():")); - } - ACE_ENDTRY; } void Callback_i::next_chunk (const Web_Server::Chunk_Type & chunk_data, CORBA::Boolean last_chunk, - CORBA::Environment &) + CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { if (!last_chunk) @@ -118,32 +93,54 @@ Callback_i::next_chunk (const Web_Server::Chunk_Type & chunk_data, // If the entire metadata has been received, then spawn an // external viewer to display the received file. if (this->metadata_received ()) - (void) this->spawn_viewer (); + { + (void) this->file_io_.close (); + this->deactivate (ACE_TRY_ENV); + ACE_CHECK; + + (void) this->spawn_viewer (); + } } } void Callback_i::metadata (const Web_Server::Metadata_Type & metadata) { - { - ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, - guard, - this->lock_)); - this->metadata_ = metadata; - } - - ACE_DEBUG ((LM_INFO, - ACE_TEXT ("Retrieved file has the following ") - ACE_TEXT ("characteristics:\n") - ACE_TEXT (" Modification Date: %s\n") - ACE_TEXT (" Content Type: %s\n"), - this->metadata_.modification_date.in (), - this->metadata_.content_type.in ())); - - // If the entire content of the data has been received, then spawn - // an external viewer to display it. - if (this->content_received ()) - (void) this->spawn_viewer (); + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + { + ACE_MT (ACE_GUARD (ACE_SYNCH_MUTEX, + guard, + this->lock_)); + this->metadata_ = metadata; + } + + ACE_DEBUG ((LM_INFO, + ACE_TEXT ("Retrieved file has the following ") + ACE_TEXT ("characteristics:\n") + ACE_TEXT (" Modification Date: %s\n") + ACE_TEXT (" Content Type: %s\n"), + this->metadata_.modification_date.in (), + this->metadata_.content_type.in ())); + + // If the entire content of the data has been received, then spawn + // an external viewer to display it. + if (this->content_received ()) + { + this->deactivate (ACE_TRY_ENV); + ACE_TRY_CHECK; + + (void) this->spawn_viewer (); + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + ACE_TEXT ("Caught unexpected exception ") + ACE_TEXT ("in Callback_i::metdata(...):")); + } + ACE_ENDTRY; } int @@ -279,3 +276,21 @@ Callback_i::spawn_viewer (void) return 0; } + +void +Callback_i::deactivate (CORBA::Environment &ACE_TRY_ENV) +{ + // Get the POA used when activating the Reply Handler object. + PortableServer::POA_var poa = this->_default_POA (ACE_TRY_ENV); + ACE_CHECK; + + // Get the object ID associated with this servant. + PortableServer::ObjectId_var oid = + poa->servant_to_id (this, + ACE_TRY_ENV); + ACE_CHECK; + + // Now deactivate the iterator object. + poa->deactivate_object (oid.in (), ACE_TRY_ENV); + ACE_CHECK; +} diff --git a/TAO/examples/Content_Server/AMI_Observer/Callback_i.h b/TAO/examples/Content_Server/AMI_Observer/Callback_i.h index 08c279de2e9..3b3ba50007c 100644 --- a/TAO/examples/Content_Server/AMI_Observer/Callback_i.h +++ b/TAO/examples/Content_Server/AMI_Observer/Callback_i.h @@ -73,6 +73,11 @@ private: private: + void deactivate (CORBA::Environment &ACE_TRY_ENV); + // Deactivate this Callback servant. + +private: + ACE_FILE_Addr file_; // The Addr corresponding to the retrieved file. diff --git a/TAO/examples/Content_Server/Makefile b/TAO/examples/Content_Server/Makefile index a747fd49f49..5d9e5b322d4 100644 --- a/TAO/examples/Content_Server/Makefile +++ b/TAO/examples/Content_Server/Makefile @@ -12,7 +12,7 @@ DIRS = SMI_Iterator -ifneq ($(ami),) +ifneq ($(ami),0) DIRS += \ AMI_Iterator \ AMI_Observer diff --git a/TAO/examples/Content_Server/SMI_Iterator/Content_Iterator_i.cpp b/TAO/examples/Content_Server/SMI_Iterator/Content_Iterator_i.cpp index a86878af831..e82359ff97a 100644 --- a/TAO/examples/Content_Server/SMI_Iterator/Content_Iterator_i.cpp +++ b/TAO/examples/Content_Server/SMI_Iterator/Content_Iterator_i.cpp @@ -9,13 +9,12 @@ ACE_RCSID(SMI_Iterator, Content_Iterator_i, "$Id$") -Content_Iterator_i::Content_Iterator_i (const char * pathname, +Content_Iterator_i::Content_Iterator_i (const char *pathname, CORBA::ULong file_size) : file_ (pathname), file_io_ (), - file_size_ (file_size), - chunk_index_ (1), - initialized_ (0) + file_size_ (file_size), + chunk_index_ (1) { // Nothing else } @@ -47,8 +46,8 @@ Content_Iterator_i::next_chunk (CORBA::ULong offset, // Invalid supplied offset? ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "Error during lseek"), + ACE_TEXT ("%p\n"), + ACE_TEXT ("Error during lseek")), 0); } else if (offset != ACE_static_cast (CORBA::ULong, real_offset)) @@ -63,16 +62,23 @@ Content_Iterator_i::next_chunk (CORBA::ULong offset, real_offset, SEEK_SET); - ACE_DEBUG ((LM_ERROR, - "Unable to reposition to desired offset.\n")); - - return 0; + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Unable to reposition to desired ") + ACE_TEXT ("offset.\n")), + 0); } // Allocate a buffer for the file being read. CORBA::Octet * buf = Web_Server::Chunk_Type::allocbuf (BUFSIZ); + if (buf == 0) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Could not allocate chunk buffer\n")), + 0); + } + ssize_t bytes_read = this->file_io_.recv (buf, BUFSIZ); @@ -81,13 +87,13 @@ Content_Iterator_i::next_chunk (CORBA::ULong offset, Web_Server::Chunk_Type::freebuf (buf); ACE_ERROR_RETURN ((LM_ERROR, - "%p\n", - "Error during read"), + ACE_TEXT ("%p\n"), + ACE_TEXT ("Error during read")), 0); } ACE_DEBUG ((LM_DEBUG, - "Sending chunk %d at offset <%u> of size <%u>\n", + ACE_TEXT ("Sending chunk %d at offset <%u> of size <%u>\n"), this->chunk_index_, offset, bytes_read)); @@ -111,8 +117,6 @@ Content_Iterator_i::destroy (CORBA::Environment &ACE_TRY_ENV) (void) this->file_io_.close (); - this->initialized_ = 0; - // Get the POA used when activating the Content_Iterator object. PortableServer::POA_var poa = this->_default_POA (ACE_TRY_ENV); ACE_CHECK; @@ -150,8 +154,5 @@ Content_Iterator_i::init (void) -1); } - - this->initialized_ = 1; - return 0; } diff --git a/TAO/examples/Content_Server/SMI_Iterator/Content_Iterator_i.h b/TAO/examples/Content_Server/SMI_Iterator/Content_Iterator_i.h index cb231cec71d..2295cbb59f7 100644 --- a/TAO/examples/Content_Server/SMI_Iterator/Content_Iterator_i.h +++ b/TAO/examples/Content_Server/SMI_Iterator/Content_Iterator_i.h @@ -73,10 +73,6 @@ private: CORBA::ULong chunk_index_; // The number of the current chunk of data being sent. (Used only // for debugging purposes.) - - int initialized_; - // Flag that denotes that the Content Iterator has not been - // initialized. }; diff --git a/TAO/examples/Content_Server/SMI_Iterator/Iterator_Factory_i.cpp b/TAO/examples/Content_Server/SMI_Iterator/Iterator_Factory_i.cpp index 0572d38d9db..3adf63f4e66 100644 --- a/TAO/examples/Content_Server/SMI_Iterator/Iterator_Factory_i.cpp +++ b/TAO/examples/Content_Server/SMI_Iterator/Iterator_Factory_i.cpp @@ -9,7 +9,7 @@ ACE_RCSID(SMI_Iterator, Iterator_Factory_i, "$Id$") void -Iterator_Factory_i::get_iterator (const char * pathname, +Iterator_Factory_i::get_iterator (const char *pathname, Web_Server::Content_Iterator_out contents, Web_Server::Metadata_Type_out metadata, CORBA::Environment &ACE_TRY_ENV) @@ -18,7 +18,7 @@ Iterator_Factory_i::get_iterator (const char * pathname, // Based on code available in H&V. ACE_DEBUG ((LM_DEBUG, - "Received request for file: <%s>\n", + ACE_TEXT ("Received request for file: <%s>\n"), pathname)); struct stat file_status; @@ -28,8 +28,12 @@ Iterator_Factory_i::get_iterator (const char * pathname, // HTTP 1.1 "Internal Server Error" } - Content_Iterator_i * iterator_servant = - new Content_Iterator_i (pathname, file_status.st_size); + Content_Iterator_i *iterator_servant = 0; + ACE_NEW_THROW_EX (iterator_servant, + Content_Iterator_i (pathname, + file_status.st_size), + CORBA::NO_MEMORY ()); + ACE_CHECK; if (iterator_servant->init () != 0) { @@ -71,7 +75,7 @@ Iterator_Factory_i::get_iterator (const char * pathname, } int -Iterator_Factory_i::modification_date (struct stat * file_status, +Iterator_Factory_i::modification_date (struct stat *file_status, Web_Server::Metadata_Type_out metadata) { // Get the modification time from the file status structure/ @@ -94,7 +98,7 @@ Iterator_Factory_i::modification_date (struct stat * file_status, } int -Iterator_Factory_i::content_type (const char * filename, +Iterator_Factory_i::content_type (const char *filename, Web_Server::Metadata_Type_out metadata) { if (filename == 0) @@ -171,9 +175,9 @@ Iterator_Factory_i::content_type (const char * filename, { metadata->content_type = CORBA::string_dup ("text/html"); ACE_ERROR ((LM_WARNING, - "\n " - "Unknown file type. " - "Using \"text/html\" content type.\n")); + ACE_TEXT ("\n ") + ACE_TEXT ("Unknown file type. ") + ACE_TEXT ("Using \"text/html\" content type.\n"))); } return 0; diff --git a/TAO/examples/Content_Server/SMI_Iterator/Iterator_Factory_i.h b/TAO/examples/Content_Server/SMI_Iterator/Iterator_Factory_i.h index 7f6757d63ac..c78465eabd3 100644 --- a/TAO/examples/Content_Server/SMI_Iterator/Iterator_Factory_i.h +++ b/TAO/examples/Content_Server/SMI_Iterator/Iterator_Factory_i.h @@ -41,7 +41,7 @@ public: // to read the <contents> associated with <pathname> one ``chunk'' // at a time. The <metadata> reports information about the // <contents>. - virtual void get_iterator (const char * pathname, + virtual void get_iterator (const char *pathname, Web_Server::Content_Iterator_out contents, Web_Server::Metadata_Type_out metadata, CORBA::Environment &ACE_TRY_ENV) @@ -49,11 +49,11 @@ public: Web_Server::Error_Result)); // Set the file modification date in the metadata structure. - int modification_date (struct stat * file_status, + int modification_date (struct stat *file_status, Web_Server::Metadata_Type_out metadata); // Set the type of file content in the metadata structure. - int content_type (const char * filename, + int content_type (const char *filename, Web_Server::Metadata_Type_out metadata); }; diff --git a/TAO/examples/Content_Server/SMI_Iterator/client.cpp b/TAO/examples/Content_Server/SMI_Iterator/client.cpp index abb6a7841f9..19c9343132a 100644 --- a/TAO/examples/Content_Server/SMI_Iterator/client.cpp +++ b/TAO/examples/Content_Server/SMI_Iterator/client.cpp @@ -59,7 +59,7 @@ main (int argc, char *argv[]) { ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Nil reference to ") - ACE_TEXT ("Name Service\n")), + ACE_TEXT ("Name Service\n")), -1); } @@ -273,12 +273,10 @@ int external_viewer (const char *content_type, } int -spawn_viewer (const char * content_type, - const char * filename) +spawn_viewer (const char *content_type, + const char *filename) { - // It is highly unlikey, a mime type will ever be larger than 80 - // bytes. - char viewer[80]; + char viewer[BUFSIZ]; if (::external_viewer (content_type, viewer, diff --git a/TAO/examples/Content_Server/SMI_Iterator/server.cpp b/TAO/examples/Content_Server/SMI_Iterator/server.cpp index 80afac994c1..63ec2db16cf 100644 --- a/TAO/examples/Content_Server/SMI_Iterator/server.cpp +++ b/TAO/examples/Content_Server/SMI_Iterator/server.cpp @@ -69,12 +69,12 @@ main (int argc, char *argv[]) ACE_TRY_ENV); ACE_TRY_CHECK; ACE_DEBUG ((LM_DEBUG, - "Bound <%s> to <%s> in Name Service.\n", + ACE_TEXT ("Bound <%s> to <%s> in Name Service.\n"), name[0].id.in (), IOR.in ())); ACE_DEBUG ((LM_INFO, - "Accepting requests.\n")); + ACE_TEXT ("Accepting requests.\n"))); // Accept requests. orb->run (ACE_TRY_ENV); @@ -83,7 +83,7 @@ main (int argc, char *argv[]) ACE_CATCHANY { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "Caught unexpected exception:"); + ACE_TEXT ("Caught unexpected exception:")); return -1; } |