Changeset 2598 for trunk/components/tools/OmeroCpp/src/omero/client.cpp
- Timestamp:
- 07/05/08 22:16:07 (5 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/components/tools/OmeroCpp/src/omero/client.cpp
r2256 r2598 17 17 throw omero::ClientError(__FILE__,__LINE__,"Improper initialization."); 18 18 } 19 // Register Object Factory 19 20 ObjectFactoryPtr of = new ObjectFactory(); 20 21 of->registerObjectFactory(ic); 22 // Define our unique identifier (used during close/detach) 23 ic->getImplicitContext()->put(omero::constants::CLIENTUUID, IceUtil::generateUUID()); 21 24 } 22 25 23 26 client::client(const Ice::InitializationData& id) { 24 27 ic = Ice::initialize(id); 25 close_on_destroy = false;26 28 init(ic); 27 29 } … … 30 32 const Ice::InitializationData& id) { 31 33 ic = Ice::initialize(argc, argv, id); 32 close_on_destroy = false;33 34 init(ic); 34 35 } 35 36 36 37 client::~client(){ 37 if (close_on_destroy && sf){38 try { 38 39 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; 48 42 } 49 43 } … … 51 45 omero::api::ServiceFactoryPrx client::createSession(const std::string& _username, const std::string& _password) { 52 46 47 // Check the required properties 53 48 std::string username, password; 54 49 if (_username.empty()) { … … 70 65 } 71 66 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. 72 70 Ice::RouterPrx prx = ic->getDefaultRouter(); 73 71 if (!prx) { 74 72 throw omero::ClientError(__FILE__,__LINE__,"No default router found."); 75 73 } 74 prx = Ice::RouterPrx::uncheckedCast(prx->ice_context(ic->getImplicitContext()->getContext())); 76 75 Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(prx); 77 76 if (!router) { … … 81 80 Glacier2::SessionPrx session; 82 81 session = router->createSession(username, password); 82 if (!session) { 83 throw omero::ClientError(__FILE__,__LINE__,"Obtained null object proxy"); 84 } 85 86 // Check type 83 87 sf = omero::api::ServiceFactoryPrx::checkedCast(session); 84 88 if (!sf) { 85 throw omero::ClientError(__FILE__,__LINE__," No session obtained.");89 throw omero::ClientError(__FILE__,__LINE__,"Obtained object proxy is not a ServiceFactory."); 86 90 } 87 91 return sf; … … 89 93 90 94 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(); 96 101 } 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 106 124 } 107 125 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 } 108 152 } 109 153
