• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.server
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 2598 for trunk/components/tools/OmeroCpp/src/omero/client.cpp

Show
Ignore:
Timestamp:
07/05/08 22:16:07 (5 months ago)
Author:
jmoore
Message:

ticket:1018 - Propagating changes to OmeroJava and OmeroCpp

Also add environment methods which have been in OmeroPy for
some time.

Files:
1 modified

  • trunk/components/tools/OmeroCpp/src/omero/client.cpp (modified) (6 diffs)

Legend:

Unmodified
Added
Removed
  • trunk/components/tools/OmeroCpp/src/omero/client.cpp

    r2256 r2598  
    1717      throw omero::ClientError(__FILE__,__LINE__,"Improper initialization."); 
    1818    } 
     19    // Register Object Factory 
    1920    ObjectFactoryPtr of = new ObjectFactory(); 
    2021    of->registerObjectFactory(ic); 
     22    // Define our unique identifier (used during close/detach) 
     23    ic->getImplicitContext()->put(omero::constants::CLIENTUUID, IceUtil::generateUUID()); 
    2124  } 
    2225 
    2326  client::client(const Ice::InitializationData& id) { 
    2427    ic = Ice::initialize(id); 
    25     close_on_destroy = false; 
    2628    init(ic); 
    2729  } 
    … …  
    3032                 const Ice::InitializationData& id) { 
    3133    ic = Ice::initialize(argc, argv, id); 
    32     close_on_destroy = false; 
    3334    init(ic); 
    3435  } 
    3536 
    3637  client::~client(){ 
    37       if (close_on_destroy && sf) { 
     38      try { 
    3839          closeSession(); 
    39       } 
    40       if (ic) { 
    41           try { 
    42               ic->destroy(); 
    43           } catch (const Ice::Exception& ex) { 
    44               cerr << "Caught Ice exception while destroying communicator." << endl; 
    45               cerr << ex << endl; 
    46           } 
    47           ic = Ice::CommunicatorPtr(); 
     40      } catch (...) { 
     41          std::cout << "Ignoring error in ~client"<< std::endl; 
    4842      } 
    4943  } 
    … …  
    5145  omero::api::ServiceFactoryPrx client::createSession(const std::string& _username, const std::string& _password) { 
    5246 
     47      // Check the required properties 
    5348    std::string username, password; 
    5449    if (_username.empty()) { 
    … …  
    7065    } 
    7166 
     67    // Acquire router and get the proxy 
     68    // For whatever reason, we have to se the context 
     69    // on the router context here as well. 
    7270    Ice::RouterPrx prx = ic->getDefaultRouter(); 
    7371    if (!prx) { 
    7472        throw omero::ClientError(__FILE__,__LINE__,"No default router found."); 
    7573    } 
     74    prx = Ice::RouterPrx::uncheckedCast(prx->ice_context(ic->getImplicitContext()->getContext())); 
    7675    Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(prx); 
    7776    if (!router) { 
    … …  
    8180    Glacier2::SessionPrx session; 
    8281    session = router->createSession(username, password); 
     82    if (!session) { 
     83        throw omero::ClientError(__FILE__,__LINE__,"Obtained null object proxy"); 
     84    } 
     85 
     86    // Check type 
    8387    sf = omero::api::ServiceFactoryPrx::checkedCast(session); 
    8488    if (!sf) { 
    85       throw omero::ClientError(__FILE__,__LINE__,"No session obtained."); 
     89      throw omero::ClientError(__FILE__,__LINE__,"Obtained object proxy is not a ServiceFactory."); 
    8690    } 
    8791    return sf; 
    … …  
    8993 
    9094  void client::closeSession() { 
    91     if (sf) { 
    92       try { 
    93         sf->close(); 
    94       } catch (const Ice::Exception& ex) { 
    95         // ok 
     95 
     96      omero::api::ServiceFactoryPrx old = sf; 
     97      sf = omero::api::ServiceFactoryPrx(); 
     98 
     99      if (!ic && old) { 
     100          ic = old->ice_getCommunicator(); 
    96101      } 
    97       sf = omero::api::ServiceFactoryPrx(); 
    98     } 
    99     Ice::RouterPrx prx = ic->getDefaultRouter(); 
    100     Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(prx); 
    101     try { 
    102         router->destroySession(); 
    103     } catch (const Ice::ConnectionLostException& cle) { 
    104         // ok. Always thrown. 
    105     } 
     102 
     103      if (ic) { 
     104 
     105          Ice::RouterPrx prx = ic->getDefaultRouter(); 
     106          Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(prx); 
     107          if (router) { 
     108              try { 
     109                  router->destroySession(); 
     110              } catch (const Ice::ConnectionLostException& cle) { 
     111                  // ok. Always thrown. 
     112              } // TODO what about SNEE 
     113          } 
     114 
     115          try { 
     116              ic->destroy(); 
     117          } catch (const Ice::Exception& ex) { 
     118              cerr << "Caught Ice exception while destroying communicator." << endl; 
     119              cerr << ex << endl; 
     120          } 
     121          ic = Ice::CommunicatorPtr(); 
     122      } 
     123 
    106124  } 
    107125 
     126    // Environment methods 
     127    // ====================================================================== 
     128    omero::RTypePtr client::getInput(const string& key) { 
     129        return env()->getInput(sess(), key); 
     130    } 
     131    omero::RTypePtr client::getOutput(const string& key) { 
     132        return env()->getOutput(sess(), key); 
     133    } 
     134    void client::setInput(const string& key, omero::RTypePtr value) { 
     135        env()->setInput(sess(), key, value); 
     136    } 
     137    void client::setOutput(const string& key, omero::RTypePtr value) { 
     138        env()->setOutput(sess(), key, value); 
     139    } 
     140    vector<string> client::getInputKeys() { 
     141        env()->getInputKeys(sess()); 
     142    } 
     143    vector<string> client::getOutputKeys() { 
     144        env()->getOutputKeys(sess()); 
     145    } 
     146    omero::api::ISessionPrx client::env() { 
     147        return sf->getSessionService(); 
     148    } 
     149    const std::string client::sess() { 
     150        return sf->getAdminService()->getEventContext()->sessionUuid; 
     151    } 
    108152} 
    109153 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/