From cd49ce3b34c324450792e6c41e75a420ad298bf7 Mon Sep 17 00:00:00 2001 From: spaunov Date: Mon, 27 Jun 2005 03:59:21 +0000 Subject: Sun Jun 26 23:53:23 EDT 2005 Stoyan Paunov --- TAO/CIAO/DAnCE/new_RepositoryManager/Options.h | 15 +--- TAO/CIAO/DAnCE/new_RepositoryManager/README.txt | 28 ++++++- TAO/CIAO/DAnCE/new_RepositoryManager/RMadmin.cpp | 20 +++-- .../new_RepositoryManager/RepositoryManager.cpp | 88 ++++++++++++++++++++-- .../DAnCE/new_RepositoryManager/ZIP_Wrapper.cpp | 10 +++ .../new_RepositoryManager.mpc | 11 +-- .../new_RepositoryManager_Impl.cpp | 79 ++++++++++++++----- .../new_RepositoryManager_Impl.h | 37 +++++++-- 8 files changed, 226 insertions(+), 62 deletions(-) diff --git a/TAO/CIAO/DAnCE/new_RepositoryManager/Options.h b/TAO/CIAO/DAnCE/new_RepositoryManager/Options.h index 0b6acf62d76..f9439579846 100644 --- a/TAO/CIAO/DAnCE/new_RepositoryManager/Options.h +++ b/TAO/CIAO/DAnCE/new_RepositoryManager/Options.h @@ -19,18 +19,11 @@ // //============================================================================ -#ifndef HTTP_OPTIONS_H -#define HTTP_OPTIONS_H +#ifndef RM_OPTIONS_H +#define RM_OPTIONS_H #include "ace/Get_Opt.h" -#include "ace/String_Base.h" -#include "ace/OS_NS_string.h" //for ACE_CString - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include "ace/ARGV.h" +#include "ace/SString.h" //for ACE_CString class Options { @@ -72,4 +65,4 @@ protected: void usage (void); }; -#endif /* HTTP_OPTIONS_H */ +#endif /* RM_OPTIONS_H */ diff --git a/TAO/CIAO/DAnCE/new_RepositoryManager/README.txt b/TAO/CIAO/DAnCE/new_RepositoryManager/README.txt index b9f0fcbf883..08b6847023b 100644 --- a/TAO/CIAO/DAnCE/new_RepositoryManager/README.txt +++ b/TAO/CIAO/DAnCE/new_RepositoryManager/README.txt @@ -1,4 +1,30 @@ -to compile with tao_idl use: +This is the README file for the Repository Manager (RM). + +In order to be able to compile the RM you need to have ZZIP lib because the RM +uses it to read the contents of CCM packages. ZZIP itself is a C++ wrapper +around ZLIB, thus you will also need ZLIB. In order to compile the RM successfully +you will need to do the following: + +1. Download ZLIB and ZZIP-LIB +2. Compile the multi-threaded versions of these libraries +3. create a separate directory for each library and create an include and a lib +subdirectory within them. Then copy the libraries files in the library subdirectory. +Copy zlib.h in the zlib_path/include and copy zziplib.h, zzip-conf.h and zzip-msvc.h +(for Windows platforms; Linux might have its own file!!!). This step might be easier if +you find a binary package of the libraries and just install it. +4. Set $ZLIB_ROOT and $ZZIP_ROOT to point to the directories where you placed the +libraries and the include files. +5. Turn on ZIP_Wrappers in the default.features or the global.features for MPC. +6. MPC will handle the rest. + + +Things to watch out for: +On Windows make sure that you are linking the right ZIP libraries +together with the rest of the libraries, i.e. if you are building the debug version of ACE, +TAO and CIAO, then use the debug version of the ZIP libraries. Otherwise the RM will compile +but it will not work properly. + +to compile the idl with the tao_idl compiler: tao_idl -GI new_RepositoryManager.idl -I%TAO_ROOT% -I%TAO_ROOT%\tao -I%TAO_ROOT%\orbsvcs -I%CIAO_ROOT%\DAnCE\ciao diff --git a/TAO/CIAO/DAnCE/new_RepositoryManager/RMadmin.cpp b/TAO/CIAO/DAnCE/new_RepositoryManager/RMadmin.cpp index d7a758176da..eb7b50a9952 100644 --- a/TAO/CIAO/DAnCE/new_RepositoryManager/RMadmin.cpp +++ b/TAO/CIAO/DAnCE/new_RepositoryManager/RMadmin.cpp @@ -1,10 +1,10 @@ // $Id$ -/** +/*** * @file RMClient.cpp * - * @auther Stoyan + **/ #include "new_RepositoryManagerC.h" #include "Options.h" @@ -22,7 +22,7 @@ using namespace std; const char * ior = "file://RepositoryManagerDeamon.ior"; -//=============================COUPLE OF HELPER METHORS================================== +///=============================COUPLE OF HELPER METHORS================================== CORBA::Octet* read_from_disk ( const char* full_path, size_t &length @@ -33,20 +33,18 @@ int write_to_disk ( const CORBA::Octet* buffer, size_t length ); -//======================================================================================== +///======================================================================================== +///main function that provides a sample interface for RM clients -int -ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_TRY_NEW_ENV { // Initialize orb - CORBA::ORB_var orb = CORBA::ORB_init (argc, - argv, - "" - ACE_ENV_ARG_PARAMETER); + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, + ""ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; diff --git a/TAO/CIAO/DAnCE/new_RepositoryManager/RepositoryManager.cpp b/TAO/CIAO/DAnCE/new_RepositoryManager/RepositoryManager.cpp index 400c3ba1f53..c13f42e31ca 100644 --- a/TAO/CIAO/DAnCE/new_RepositoryManager/RepositoryManager.cpp +++ b/TAO/CIAO/DAnCE/new_RepositoryManager/RepositoryManager.cpp @@ -1,22 +1,58 @@ // $Id$ -//RepositoryManager.cpp, v2.0 Stoyan +/*** + * @file RepositoryManager.cpp + * + * @author Stoyan Paunov + **/ + #include "new_RepositoryManager_Impl.h" #include "ace/OS_NS_stdio.h" #include "ace/streams.h" #include "ace/Auto_Ptr.h" +#include "ace/Task.h" using namespace std; +namespace +{ +///name of the file holding the IOR of the RM const char * rm_ior = "RepositoryManagerDeamon.ior"; +///default number of worker threads to run in the multi-threaded RM +const unsigned int nthreads = 3; +} -int -ACE_TMAIN (int argc, ACE_TCHAR *argv[]) + +///Class that implements the service routine of the worker threads +///of the repository manager + +class Worker : public ACE_Task_Base { + // = TITLE + // Run a server thread + // + // = DESCRIPTION + // Use the ACE_Task_Base class to run server threads + // +public: + Worker (CORBA::ORB_ptr orb); + // ctor + + virtual int svc (void); + // The thread entry point. - //check the previous implementation for stuff to reuse! +private: + CORBA::ORB_var orb_; + // The orb +}; + +///Main function + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ try { //init the ORB @@ -38,7 +74,7 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) //trasfer ownership to the POA PortableServer::ServantBase_var distributor_owner_transfer(repo); - //register servant + //register and implicitly activate servant CIAO::new_RepositoryManagerDaemon_var RepositoryManagerDeamon = repo->_this (); //convert the IOR to string @@ -56,6 +92,20 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) ACE_OS::fprintf (ior_out, "%s", ior.in ()); ACE_OS::fclose (ior_out); + Worker worker (orb.in ()); + if (worker.activate (THR_NEW_LWP | THR_JOINABLE, + nthreads) != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot activate client threads\n"), + 1); + + worker.thr_mgr ()->wait (); + + ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); + + //done + return 0; + //Start accepting requests orb->run (); @@ -77,3 +127,31 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) return 0; } + + +// **************************************************************** + +///Constuctor for the worker class +Worker::Worker (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +///implementation of the service routine inherited from ACE::Task_Base + +int Worker::svc (void) +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + } + ACE_ENDTRY; + return 0; +} + + diff --git a/TAO/CIAO/DAnCE/new_RepositoryManager/ZIP_Wrapper.cpp b/TAO/CIAO/DAnCE/new_RepositoryManager/ZIP_Wrapper.cpp index 61c1a21fe7c..1177a615700 100644 --- a/TAO/CIAO/DAnCE/new_RepositoryManager/ZIP_Wrapper.cpp +++ b/TAO/CIAO/DAnCE/new_RepositoryManager/ZIP_Wrapper.cpp @@ -1,5 +1,15 @@ // $Id$ +///==================================================================== +//@filename: ZIP_Wrapper.cpp +//@Author: Stoyan Paunov spaunov@isis.vanderbilt.edu +// +//@Purpose: to provide a wrapper around ZZIPlib for easy handling of +// ZIP archives. This wrapper can me used as an auxiliary +// class that allows a program to become ZIP-aware + + + #include "ace/Containers_T.h" //for ACE_Double_Linked_List #include "ace/Message_Block.h" //for ACE_Message_Block diff --git a/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager.mpc b/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager.mpc index de872f8b4cb..cd19972bd7b 100644 --- a/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager.mpc +++ b/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager.mpc @@ -1,20 +1,13 @@ // $Id$ -project (new_RepositoryManager) : ciao_server_dnc,ciao_deployment_svnt, ciao_deployment_stub, taoexe, xerces, exceptions { +project (new_RepositoryManager) : ciao_server_dnc,ciao_deployment_svnt, ciao_deployment_stub, taoexe, xerces, exceptions, ZIP_Wrapper { exename = RepositoryManagerDeamon after += XSC_Config_Handlers libs += XSC_Config_Handlers libs += CIAO_DnC_Server - - includes += $(ZZIP_ROOT)/zziplib $(ZLIB_ROOT) - libpaths += $(ZLIB_ROOT)/lib $(ZZIP_ROOT)/lib - libs += zlib zziplib - - //requires += zlib - //lit_libs += zlib //stupid MPC does not add ZLIB by default, only its wrapper ZZIP ?!?!?! - //requires += zzip + requires += ZIP_Wrapper IDL_Files { new_RepositoryManager.idl diff --git a/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager_Impl.cpp b/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager_Impl.cpp index 47ec43b3972..20b56256d1c 100644 --- a/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager_Impl.cpp +++ b/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager_Impl.cpp @@ -30,6 +30,14 @@ // TAO_IDL - Generated from // .\be\be_codegen.cpp:939 + +///==================================================================== +//@filename: new_RepositoryManager_Impl.cpp +//@Author: Stoyan Paunov spaunov@isis.vanderbilt.edu +// + + + #include "new_RepositoryManager_Impl.h" #include "ace/OS_NS_fcntl.h" //for open @@ -77,6 +85,8 @@ CIAO_new_RepositoryManagerDaemon_i::~CIAO_new_RepositoryManagerDaemon_i (void) this->packages_.unbind_all (); } + +//shutdown method to shut down the orb gracefully void CIAO_new_RepositoryManagerDaemon_i::shutdown ( ) @@ -88,11 +98,11 @@ void CIAO_new_RepositoryManagerDaemon_i::shutdown ( this->packages_.unbind_all (); - this->the_orb_->shutdown (1); - - ACE_OS::exit (0); + this->the_orb_->shutdown (0); } +//This method allow you to install a package into the RM + void CIAO_new_RepositoryManagerDaemon_i::installPackage ( const char * installationName, const ::Deployment::Package & the_package, @@ -125,11 +135,17 @@ void CIAO_new_RepositoryManagerDaemon_i::installPackage ( this->packages_.bind (ACE_CString (installationName), path); } +//This method parse the depoyment plan in a package and return the +//corresponding structure. You need to provide the name of the +//package whose deployment plan you want to get . If no plan is +//found in the package, an exception is thrown + ::Deployment::DeploymentPlan * CIAO_new_RepositoryManagerDaemon_i::retrievePlan ( const char * packageName ) ACE_THROW_SPEC (( - CORBA::SystemException + CORBA::SystemException, + ::Deployment::NoPlan )) { // Add your implementation here @@ -171,19 +187,18 @@ void CIAO_new_RepositoryManagerDaemon_i::installPackage ( //there is not deployment plan in the package if (!found) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("[RM::retrievePlan] no DeploymentPlan in package!\n")), - 0); + { + ACE_TEXT ("[RM::retrievePlan] no DeploymentPlan in package!\n"); + ACE_THROW (Deployment::NoPlan ()); + } //read the Deployment plan from the package ACE_Message_Block file (0,0); if (!zip.get_file( const_cast (path.c_str ()), const_cast (plan_name.c_str ()), file)) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("[RM::retrievePlan] Unable to retrieve file!\n")), - 0); - + { + ACE_TEXT ("[RM::retrievePlan] Unable to retrieve file!\n"); + ACE_THROW (CORBA::INTERNAL ()); + } //if file is 0 length XERCESC Fails!!! @@ -200,17 +215,20 @@ void CIAO_new_RepositoryManagerDaemon_i::installPackage ( //write the file to disk if(!this->write_to_disk (const_cast (local_file.c_str ()), file)) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("%p\n"), - ACE_TEXT ("[RM::retrievePlan] DeploymentPlan preparation failule!\n")), - 0); + { + ACE_TEXT ("[RM::retrievePlan] DeploymentPlan preparation failule!\n"); + ACE_THROW (CORBA::INTERNAL ()); + } //parse the Deployment plan and return the resulting data structure CIAO::Config_Handlers::XML_Helper the_helper; xercesc::DOMDocument *doc; if (!(doc = the_helper.create_dom (local_file.c_str ()))) - return 0; + { + ACE_TEXT ("[RM::retrievePlan] XML_Helper failed us!\n"); + ACE_THROW (CORBA::INTERNAL ()); + } CIAO::Config_Handlers::DeploymentPlan dp = CIAO::Config_Handlers::deploymentPlan (doc); CIAO::Config_Handlers::DP_Handler dp_handler (dp); @@ -223,6 +241,10 @@ void CIAO_new_RepositoryManagerDaemon_i::installPackage ( return dp_handler.plan (); } + +//find a package and return it if installed in the RM +//else throw an exception + ::Deployment::Package * CIAO_new_RepositoryManagerDaemon_i::findPackageByName ( const char * name ) @@ -255,6 +277,11 @@ void CIAO_new_RepositoryManagerDaemon_i::installPackage ( return package; } + +//find an implementation (.dll, .so) by its name and return it if installed in the RM +//else throw an exception. You need to specify the package in which the RM +//is to look for the implementation + ::Deployment::Implementation * CIAO_new_RepositoryManagerDaemon_i::findImplementationByName ( const char * implementation_name, const char * package_name @@ -314,6 +341,7 @@ void CIAO_new_RepositoryManagerDaemon_i::installPackage ( return impl; } + ::Deployment::Package * CIAO_new_RepositoryManagerDaemon_i::findPackageByUUID ( const char * UUID ) @@ -338,6 +366,8 @@ void CIAO_new_RepositoryManagerDaemon_i::installPackage ( ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0); } +//get the names of all packages currently installed in the RM + ::CORBA::StringSeq * CIAO_new_RepositoryManagerDaemon_i::getAllPackageNames ( ) @@ -393,6 +423,12 @@ void CIAO_new_RepositoryManagerDaemon_i::deletePackage ( remove (path.c_str ()); } +//==========================================HELPER METHODS======================================================== + + +//This function attempts to write a sequence of bytes to +//a specified location. A -1 is returned in the case of an error +//and a 1 upon success int CIAO_new_RepositoryManagerDaemon_i::write_to_disk ( const char* full_path, @@ -423,6 +459,10 @@ int CIAO_new_RepositoryManagerDaemon_i::write_to_disk ( } +//This function attempts to read a sequence of bytes into an +//ACE_Message_Block from a specified location. A -1 is returned +//in the case of an error and a 1 upon success + int CIAO_new_RepositoryManagerDaemon_i::write_to_disk (const char* full_path, ACE_Message_Block& mb, @@ -457,6 +497,9 @@ int CIAO_new_RepositoryManagerDaemon_i::write_to_disk return 1; } +//This function attempts to read a sequence of bytes from a specified +//location and returns an octet sequence. A -1 is returned +//in the case of an error and a 1 upon success CORBA::Octet* CIAO_new_RepositoryManagerDaemon_i::read_from_disk ( const char* full_path, diff --git a/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager_Impl.h b/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager_Impl.h index f544aa6e63d..37343fb9864 100644 --- a/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager_Impl.h +++ b/TAO/CIAO/DAnCE/new_RepositoryManager/new_RepositoryManager_Impl.h @@ -47,6 +47,7 @@ #include "ace/Hash_Map_Manager.h" //for the ACE_Hash_Map_Manager #include "ace/Null_Mutex.h" //for ACE_Null_Mutex +#include "ace/RW_Mutex.h" //for ACE_RW_Mutex #include "ace/OS_NS_string.h" //for ACE_CString #include "ace/SString.h" @@ -55,21 +56,24 @@ #pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ - +namespace +{ ///DIRECTORY WHERE THE PACKAGES WILL BE STORED LOCALLY const static char* RM_STORAGE_PATH = "./RepositoryDir"; - +} class CIAO_new_RepositoryManagerDaemon_i : public virtual POA_CIAO::new_RepositoryManagerDaemon, public virtual PortableServer::RefCountServantBase { public: - //Constructor + /// Constructor CIAO_new_RepositoryManagerDaemon_i (CORBA::ORB_ptr the_orb); - //Destructor + /// Destructor virtual ~CIAO_new_RepositoryManagerDaemon_i (void); + + /// shutdown method to shut down the orb gracefully virtual void shutdown ( @@ -78,6 +82,7 @@ public: CORBA::SystemException )); + /// This method allow you to install a package into the RM virtual void installPackage ( const char * installationName, @@ -89,15 +94,22 @@ public: ::Deployment::NameExists, ::Deployment::PackageError )); - + + /// This method parse the depoyment plan in a package and return the + /// corresponding structure. You need to provide the name of the + /// package whose deployment plan you want to get . If no plan is + /// found in the package, an exception is thrown virtual ::Deployment::DeploymentPlan * retrievePlan ( const char * packageName ) ACE_THROW_SPEC (( - CORBA::SystemException + CORBA::SystemException, + ::Deployment::NoPlan )); + /// find a package and return it if installed in the RM + /// else throw an exception virtual ::Deployment::Package * findPackageByName ( const char * name @@ -107,6 +119,9 @@ public: ::Deployment::NoSuchName )); + /// find an implementation (.dll, .so) by its name and return it if installed in the RM + /// else throw an exception. You need to specify the package in which the RM + /// is to look for the implementation virtual ::Deployment::Implementation * findImplementationByName ( const char * implementation_name, @@ -117,6 +132,7 @@ public: ::Deployment::NoSuchName )); + /// not implemented virtual ::Deployment::Package * findPackageByUUID ( const char * UUID @@ -126,6 +142,7 @@ public: ::Deployment::NoSuchName )); + ///not implemented virtual ::Deployment::Implementation * findImplementationByUUID ( const char * UUID @@ -135,6 +152,7 @@ public: ::Deployment::NoSuchName )); + /// get the names of all packages currently installed in the RM virtual ::CORBA::StringSeq * getAllPackageNames ( @@ -143,6 +161,8 @@ public: CORBA::SystemException )); + /// Find out if the package was installed in the repository, + /// delete it if found or throw and exception otherwise virtual void deletePackage ( const char * installationName @@ -188,11 +208,14 @@ public: /// Key: Package name of CString type or /// Value: The location of the local copy of the package + ///Based on the synchronization needed we can parametrize this with either + ///ACE_Null_Mutex or ACE_RW_Mutex + typedef ACE_Hash_Map_Manager_Ex, ACE_Equal_To, - ACE_Null_Mutex> RepositoryDatabase; + ACE_RW_Mutex> RepositoryDatabase; typedef RepositoryDatabase::iterator RepositoryDatabase_Iterator; -- cgit v1.2.1