ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From di...@apache.org
Subject cvs commit: ws-axis/c/src/engine/client Call.cpp
Date Fri, 18 Mar 2005 15:47:35 GMT
dicka       2005/03/18 07:47:35

  Modified:    c/include/axis AxisException.hpp
               c/include/axis/client Call.hpp
               c/src/engine Axis.cpp AxisEngineException.cpp
               c/src/engine/client Call.cpp
  Log:
  Reference count calls to initialize/terminate calls.
  Tested on Windows, Linux (RH AS 3.0) and AIX.
  
  PR: AXISCPP-557
  Submitted by: Tim Bartley
  Reviewed by: Adrian Dick
  
  Revision  Changes    Path
  1.6       +6 -5      ws-axis/c/include/axis/AxisException.hpp
  
  Index: AxisException.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/include/axis/AxisException.hpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AxisException.hpp	7 Jan 2005 12:05:40 -0000	1.5
  +++ AxisException.hpp	18 Mar 2005 15:47:34 -0000	1.6
  @@ -142,21 +142,22 @@
   /*65*/    SERVER_PARSE_TRANSPORT_FAILED,
   /*66*/    SERVER_TEST_EXCEPTION,
   /*67*/    SERVER_UNKNOWN_ERROR,
  +/*68*/    SERVER_CLIENT_ENGINE_MISMATCH,
   
       /* AXIS C faults */
       /*Following exceptions are not releated to soap faults
        */
  -/*68*/    AXISC_SERVICE_THROWN_EXCEPTION,
  -/*69*/    AXISC_UNKNOWN_ELEMENT_EXCEPTION,
  -/*70*/    AXISC_NODE_VALUE_MISMATCH_EXCEPTION,
  -/*71*/    AXISC_READ_CONF_EXCEPTION,
  +/*60*/    AXISC_SERVICE_THROWN_EXCEPTION,
  +/*70*/    AXISC_UNKNOWN_ELEMENT_EXCEPTION,
  +/*71*/    AXISC_NODE_VALUE_MISMATCH_EXCEPTION,
  +/*72*/    AXISC_READ_CONF_EXCEPTION,
   
       /*
        * This FAULT_LAST is not used as a fault code, but instead is used 
        * internaly in the code. Developers should not use this as a fault 
        * code.
        */
  -/*72*/    FAULT_LAST 
  +/*73*/    FAULT_LAST 
   } AXISC_EXCEPTIONS;
   
   /**
  
  
  
  1.25      +0 -7      ws-axis/c/include/axis/client/Call.hpp
  
  Index: Call.hpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/include/axis/client/Call.hpp,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Call.hpp	16 Mar 2005 17:34:41 -0000	1.24
  +++ Call.hpp	18 Mar 2005 15:47:34 -0000	1.25
  @@ -489,13 +489,6 @@
       * Use Proxy or not?
       */
       bool m_bUseProxy;
  -    
  -  /**
  -    * If this object calls initialize_module, this will be set to true.
  -    * Helps keep track of whether to call uninitialize_module in destructor.
  -    * It is possible that initialize_module could have been called already.
  -    */
  -    bool m_bModuleInitialized;
   
     /**
       * To track if the initialize was called/matched with an uninitialize
  
  
  
  1.92      +174 -95   ws-axis/c/src/engine/Axis.cpp
  
  Index: Axis.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/engine/Axis.cpp,v
  retrieving revision 1.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- Axis.cpp	19 Feb 2005 22:22:20 -0000	1.91
  +++ Axis.cpp	18 Mar 2005 15:47:34 -0000	1.92
  @@ -86,8 +86,9 @@
   WSDDDeployment* g_pWSDDDeployment;
   AxisConfig* g_pConfig;
   
  -//Keeps track of whether initialize_module/uninitialize_module was called
  -bool g_bModuleInitialize = false;
  +//Keeps track of how many times initialize_module/uninitialize_module was called
  +static volatile long g_uModuleInitialize = 0;
  +
   
   void ModuleInitialize ()
   {    
  @@ -290,121 +291,199 @@
   
   #endif
   
  -extern "C" {
  -STORAGE_CLASS_INFO
  -int initialize_module (int bServer)
  +#ifdef WIN32
  +
  +static volatile long g_uModuleInitializing = 0;
  +static void start_initializing()
   {
  -    g_bModuleInitialize = true;
  -    int status = 0;
  -    // order of these initialization method invocation should not be changed
  -    AxisEngine::m_bServer = bServer;
  -    AxisUtils::initialize ();
  -    WSDDKeywords::initialize ();
  -    SoapKeywordMapping::initialize ();
  -    TypeMapping::initialize ();
  -    URIMapping::initialize ();
  -    SoapFault::initialize ();
  -    ModuleInitialize ();
  -    if (bServer) // no client side wsdd processing at the moment
  -    {
  -		/* Read from the configuration file */
  -        status = g_pConfig->readConfFile (); 
  -        if (status == AXIS_SUCCESS)
  -        {
  -			XMLParserFactory::initialize();
  -            SOAPTransportFactory::initialize();
  -			char *pWsddPath = g_pConfig->getAxisConfProperty(AXCONF_WSDDFILEPATH);
  +    long exchange = 1;
  +    long comperand = 0;
  +    while (InterlockedCompareExchange(((void **)&g_uModuleInitializing), (void *)&exchange,
(void *) &comperand));
  +}
  +static void done_initializing()
  +{
  +    g_uModuleInitializing = 0;
  +}
   
  -#if defined(ENABLE_AXISTRACE)
  +#else
  +
  +#include <pthread.h>
  +static pthread_mutex_t initializingMutex = PTHREAD_MUTEX_INITIALIZER;
  +
  +static void start_initializing()
  +{
  +    pthread_mutex_lock(&initializingMutex);
  +}
  +
  +static void done_initializing()
  +{
  +    pthread_mutex_unlock(&initializingMutex);
  +}
   
  -            status = AxisTrace::openFile ();
  -            if (status == AXIS_FAIL)
  -            {
  -                // Samisa - make sure that we start service, even if we cannot open log
file
  -                //return AXIS_FAIL;
  -            }
   #endif
  -            try
  -            {            
  -                if (AXIS_SUCCESS != g_pWSDDDeployment->loadWSDD (pWsddPath))
  -                    return AXIS_FAIL;
  -            }
  -            catch (exception& e)
  -            {
  -                cout<< e.what();
  -                cout<< "\n";
  -                cout<< "Axis c++: An exception occured while loading the wsdd\n";
  -                exit(1);
  -            }
  + 
   
  -        }
  -        else
  -        {
  -            return AXIS_FAIL;
  -        }
   
  -    }
  -    else if (bServer == 0)      // client side module initialization
  +extern "C" {
  +STORAGE_CLASS_INFO
  +int initialize_module (int bServer)
  +{
  +    start_initializing();
  +    
  +    int status = AXIS_SUCCESS;
  +
  +    try
       {
  -        status = g_pConfig->readConfFile (); /* Read from the configuration
  -						  * file 
  -						  */
  -        if (status == AXIS_SUCCESS)
  +        if (g_uModuleInitialize == 0)
           {
  -#if defined(ENABLE_AXISTRACE)
  -            status = AxisTrace::openFileByClient ();
  -            /* //Samisa: 01/09/2004
  -               //Fix for AXISCPP-127
  -               //Do not stop here merely because log file location ClientLogPath is incorrect
  -            if (status == AXIS_FAIL)
  +            // order of these initialization method invocation should not be changed
  +            AxisEngine::m_bServer = bServer;
  +            AxisUtils::initialize ();
  +            WSDDKeywords::initialize ();
  +            SoapKeywordMapping::initialize ();
  +            TypeMapping::initialize ();
  +            URIMapping::initialize ();
  +            SoapFault::initialize ();
  +            ModuleInitialize ();
  +            if (bServer) // no client side wsdd processing at the moment
               {
  -                return AXIS_FAIL;
  -            }
  -            */
  +    		    /* Read from the configuration file */
  +                status = g_pConfig->readConfFile (); 
  +                if (status == AXIS_SUCCESS)
  +                {
  +                    XMLParserFactory::initialize();
  +                    SOAPTransportFactory::initialize();
  +                    char *pWsddPath = g_pConfig->getAxisConfProperty(AXCONF_WSDDFILEPATH);
  +#if defined(ENABLE_AXISTRACE)
  +                    status = AxisTrace::openFile ();
  +                    if (status == AXIS_FAIL)
  +                    {
  +                        // Samisa - make sure that we start service, even if we cannot
open log file
  +                        //return AXIS_FAIL;
  +                    }
   #endif
  -		XMLParserFactory::initialize();
  -            SOAPTransportFactory::initialize();
  -		char *pClientWsddPath = 
  -		g_pConfig->getAxisConfProperty(AXCONF_CLIENTWSDDFILEPATH);
  -
  -            /* May be there is no client side handlers configured. So may not 
  -	     * have CLIENTWSDDFILEPATH entry in axiscpp.conf 
  -	     */
  -            if (!pClientWsddPath)
  -                return status;
  -            if (AXIS_SUCCESS != g_pWSDDDeployment->loadWSDD (pClientWsddPath))
  -                return AXIS_FAIL;
  -        }
  -        else
  -        {
  -            AXISTRACE3("Reading from the configuration file failed. \
  -                Check for error in the configuration file. \n\
  -				Handlers and logging are not working");
  -            /* TODO:Improve the AxisTrace so that it will log these kind of 
  -	     * messages into a log file according to the critical level 
  -	     * specified.
  -             */
  -        }
  +                    try
  +                    {            
  +                        if (AXIS_SUCCESS != g_pWSDDDeployment->loadWSDD (pWsddPath))
  +                        {
  +                            status = AXIS_FAIL;
  +                        }
  +                    }
  +                    catch (exception& e)
  +                    {
  +                        throw AxisEngineException(&e);
  +                    }
  +    
  +                }
  +                else
  +                {
  +                    status = AXIS_FAIL;
  +                }
  +           }
  +           else if (bServer == 0)      // client side module initialization
  +           {
  +                status = g_pConfig->readConfFile (); /* Read from the configuration
  +                               * file 
  +                                 */
  +                if (status == AXIS_SUCCESS)
  +                {
  +#if defined(ENABLE_AXISTRACE)
  +                    status = AxisTrace::openFileByClient ();
  +                    /*  //Samisa: 01/09/2004
  +                        //Fix for AXISCPP-127
  +                        //Do not stop here merely because log file location ClientLogPath
is incorrect
  +                        if (status == AXIS_FAIL)
  +                        {
  +                            return AXIS_FAIL;
  +                        }
  +                   */
  +#endif
  +                   XMLParserFactory::initialize();
  +                   SOAPTransportFactory::initialize();
  +                   char *pClientWsddPath =
  +                   g_pConfig->getAxisConfProperty(AXCONF_CLIENTWSDDFILEPATH);
  +    
  +                   /* May be there is no client side handlers configured. So may not 
  +                    * have CLIENTWSDDFILEPATH entry in axiscpp.conf 
  +                    */
  +                   if (pClientWsddPath)
  +                   {
  +                       if (AXIS_SUCCESS != g_pWSDDDeployment->loadWSDD (pClientWsddPath))
  +                       {
  +                           status = AXIS_FAIL;
  +                       }
  +                   }
  +                }
  +                else
  +                {
  +                    AXISTRACE3("Reading from the configuration file failed. \
  +                    Check for error in the configuration file. \n\
  +                 Handlers and logging are not working");
  +                    /* TODO:Improve the AxisTrace so that it will log these kind of 
  +                     * messages into a log file according to the critical level 
  +                     * specified.
  +                     */
  +                }
  +           }
  +           else
  +           {
  +               /* Ok if we can't read config file */
  +               status = AXIS_SUCCESS;
  +           }
  +       }
  +       else if (AxisEngine::m_bServer != bServer)
  +       {
  +           throw AxisEngineException(SERVER_ENGINE_EXCEPTION);
  +       }
       }
  -    return AXIS_SUCCESS;
  +    catch (...)
  +    {
  +        done_initializing();
  +        throw;
  +    }
  +
  +    ++g_uModuleInitialize;
  +    done_initializing();
  +
  +    return status;
   }
   }
   
  +
   extern "C" {
   STORAGE_CLASS_INFO
   int uninitialize_module ()
   {
  -    g_bModuleInitialize = false;
  -	TypeMapping::uninitialize();
  -	URIMapping::uninitialize();
  -    SOAPTransportFactory::uninitialize();
  -    ModuleUnInitialize();
  -    SoapKeywordMapping::uninitialize();
  -    XMLParserFactory::uninitialize();
  +    start_initializing();
  +
  +    try
  +    {
  +        if (g_uModuleInitialize > 0)
  +        {
  +            if (--g_uModuleInitialize == 0)
  +            {
  +                TypeMapping::uninitialize();
  +                URIMapping::uninitialize();
  +                SOAPTransportFactory::uninitialize();
  +                ModuleUnInitialize();
  +                SoapKeywordMapping::uninitialize();
  +                XMLParserFactory::uninitialize();
  +            }
  +        }
  +    }
  +    catch (...)
  +    {
  +        done_initializing();
  +        throw;
  +    }
  +
  +    done_initializing();
  +
       return AXIS_SUCCESS;
   }
   }
   
  +
   void Ax_Sleep (int nTime)
   {
   #ifdef WIN32
  
  
  
  1.17      +3 -0      ws-axis/c/src/engine/AxisEngineException.cpp
  
  Index: AxisEngineException.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/engine/AxisEngineException.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AxisEngineException.cpp	18 Oct 2004 09:40:27 -0000	1.16
  +++ AxisEngineException.cpp	18 Mar 2005 15:47:34 -0000	1.17
  @@ -138,6 +138,9 @@
           case SERVER_ENGINE_WRONG_HANDLER_TYPE:
               m_sMessage = "AxisEngineException:Wrong handler type";
               break;
  +        case SERVER_CLIENT_ENGINE_MISMATCH:
  +            m_sMessage = "AxisEngineException:Engine cannot be initialized as both client
and server";
  +            break;
           default:
               m_sMessage = "AxisEngineException:Unknown Axis C++ Engine Exception";
       }
  
  
  
  1.105     +5 -12     ws-axis/c/src/engine/client/Call.cpp
  
  Index: Call.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/engine/client/Call.cpp,v
  retrieving revision 1.104
  retrieving revision 1.105
  diff -u -r1.104 -r1.105
  --- Call.cpp	18 Mar 2005 10:52:19 -0000	1.104
  +++ Call.cpp	18 Mar 2005 15:47:34 -0000	1.105
  @@ -49,24 +49,18 @@
   extern "C" int initialize_module (int bServer);
   extern "C" int uninitialize_module ();
   
  -extern bool g_bModuleInitialize;
  -
   AXIS_CPP_NAMESPACE_USE
   
   bool CallBase::bInitialized = false;
   
   Call::Call ()
  -:m_pcEndPointUri(NULL), m_strProxyHost(""), m_uiProxyPort(0), m_bUseProxy(false), m_bModuleInitialized(false),
  +:m_pcEndPointUri(NULL), m_strProxyHost(""), m_uiProxyPort(0), m_bUseProxy(false),
   m_bCallInitialized(false)
   {
       m_pAxisEngine = NULL;
       m_pIWSSZ = NULL;
       m_pIWSDZ = NULL;
  -    if (!g_bModuleInitialize)
  -    {
  -        initialize_module (0);
  -        m_bModuleInitialized = true;
  -    }
  +    initialize_module (0);
       
       m_pTransport = NULL;
       m_nTransportType = APTHTTP1_1;
  @@ -86,10 +80,9 @@
       // in generated code
        if (m_bCallInitialized) 
           unInitialize();
  -	 SOAPTransportFactory::destroyTransportObject(m_pTransport);
  -		m_pTransport = NULL;
  -    if (m_bModuleInitialized)
  -        uninitialize_module();
  +	SOAPTransportFactory::destroyTransportObject(m_pTransport);
  +	m_pTransport = NULL;
  +    uninitialize_module();
       if (m_pcEndPointUri)
           delete [] m_pcEndPointUri;  
   	m_pcEndPointUri = NULL;
  
  
  

Mime
View raw message