📄 phonebooki.cpp
字号:
// **********************************************************************//// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.//// This copy of Ice is licensed to you under the terms described in the// ICE_LICENSE file included in this distribution.//// **********************************************************************#include <PhoneBookI.h>#include <IceUtil/UUID.h>using namespace std;using namespace Demo;ContactI::ContactI(const ContactFactoryPtr& contactFactory) : _factory(contactFactory){}stringContactI::getName(const Ice::Current&) const{ IceUtil::Mutex::Lock lock(*this); return name;}voidContactI::setName(const string& newName, const Ice::Current&){ IceUtil::Mutex::Lock lock(*this); name = newName;}stringContactI::getAddress(const Ice::Current&) const{ IceUtil::Mutex::Lock lock(*this); return address;}voidContactI::setAddress(const string& newAddress, const Ice::Current&){ IceUtil::Mutex::Lock lock(*this); address = newAddress;}stringContactI::getPhone(const Ice::Current&) const{ IceUtil::Mutex::Lock lock(*this); return phone;}voidContactI::setPhone(const string& newPhone, const Ice::Current&){ IceUtil::Mutex::Lock lock(*this); phone = newPhone;}voidContactI::destroy(const Ice::Current& c){ try { _factory->getEvictor()->remove(c.id); } catch(const Freeze::DatabaseException& ex) { DatabaseException e; e.message = ex.message; throw e; }}PhoneBookI::PhoneBookI(const Freeze::EvictorPtr& evictor, const ContactFactoryPtr& contactFactory, const NameIndexPtr& index) : _evictor(evictor), _contactFactory(contactFactory), _index(index){}class IdentityToContact{public: IdentityToContact(const Ice::ObjectAdapterPtr& adapter) : _adapter(adapter) { } ContactPrx operator()(const Ice::Identity& ident) { return ContactPrx::uncheckedCast(_adapter->createProxy(ident)); }private: const Ice::ObjectAdapterPtr _adapter;};ContactPrxPhoneBookI::createContact(const Ice::Current& c){ // // Get a new unique identity. // Ice::Identity ident; ident.name = IceUtil::generateUUID(); ident.category = "contact"; // // Create a new Contact Servant. // ContactIPtr contact = new ContactI(_contactFactory); // // Create a new Ice Object in the evictor, using the new identity // and the new Servant. // _evictor->add(contact, ident); // // Turn the identity into a Proxy and return the Proxy to the // caller. // return IdentityToContact(c.adapter)(ident);}ContactsPhoneBookI::findContacts(const string& name, const Ice::Current& c) const{ try { vector<Ice::Identity> identities = _index->find(name); Contacts contacts; contacts.reserve(identities.size()); transform(identities.begin(), identities.end(), back_inserter(contacts), IdentityToContact(c.adapter)); return contacts; } catch(const Freeze::DatabaseException& ex) { DatabaseException e; e.message = ex.message; throw e; }}voidPhoneBookI::setEvictorSize(Ice::Int size, const Ice::Current&){ _evictor->setSize(size);}voidPhoneBookI::shutdown(const Ice::Current& c) const{ c.adapter->getCommunicator()->shutdown();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -