📄 publisher.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 <Ice/Ice.h>#include <IceUtil/Options.h>#include <IceStorm/IceStorm.h>#include <Event.h>using namespace std;using namespace Ice;using namespace IceStorm;using namespace Test;intrun(int argc, char* argv[], const CommunicatorPtr& communicator){ IceUtil::Options opts; opts.addOpt("", "events", IceUtil::Options::NeedArg); opts.addOpt("", "oneway"); try { opts.parse(argc, (const char**)argv); } catch(const IceUtil::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } int events = 1000; string s = opts.optArg("events"); if(!s.empty()) { events = atoi(s.c_str()); } if(events <= 0) { cerr << argv[0] << ": events must be > 0." << endl; return EXIT_FAILURE; } bool oneway = opts.isSet("oneway"); PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStorm.TopicManager.Proxy"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( communicator->stringToProxy(managerProxy)); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } TopicPrx topic; try { topic = manager->retrieve("fed1"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } EventPrx twowayProxy = EventPrx::uncheckedCast(topic->getPublisher()->ice_twoway()); EventPrx proxy; if(oneway) { proxy = EventPrx::uncheckedCast(twowayProxy->ice_oneway()); } else { proxy = twowayProxy; } for(int i = 0; i < events; ++i) { proxy->pub(i); } if(oneway) { // // Before we exit, we ping all proxies as twoway, to make sure // that all oneways are delivered. // twowayProxy->ice_ping(); } return EXIT_SUCCESS;}intmain(int argc, char* argv[]){ int status; CommunicatorPtr communicator; try { communicator = initialize(argc, argv); status = run(argc, argv, communicator); } catch(const Exception& ex) { cerr << ex << endl; status = EXIT_FAILURE; } if(communicator) { try { communicator->destroy(); } catch(const Exception& ex) { cerr << ex << endl; status = EXIT_FAILURE; } } return status;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -