diff options
Diffstat (limited to 'cpp/src/IceStorm/Admin.cpp')
-rw-r--r-- | cpp/src/IceStorm/Admin.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/cpp/src/IceStorm/Admin.cpp b/cpp/src/IceStorm/Admin.cpp new file mode 100644 index 00000000000..4f4803db9e0 --- /dev/null +++ b/cpp/src/IceStorm/Admin.cpp @@ -0,0 +1,120 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IceStorm/IceStorm.h> + +using namespace std; +using namespace Ice; + +void +usage(const char* n) +{ + cerr << "Usage: " << n << " [options] [file...]\n"; + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display the Ice version.\n" + "create topic Create the given topic.\n" + ; +} + +int +run(int argc, char* argv[], const CommunicatorPtr& communicator) +{ + PropertiesPtr properties = communicator->getProperties(); + const char* managerProperty = "IceStorm.TopicManager"; + string managerRef = properties->getProperty(managerProperty); + if (managerRef.empty()) + { + cerr << argv[0] << ": " << managerProperty << " is not set" << endl; + return EXIT_FAILURE; + } + + ObjectPrx base = communicator->stringToProxy(managerRef); + IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); + if (!manager) + { + cerr << argv[0] << ": `" << managerProperty << "' is not running" << endl; + return EXIT_FAILURE; + } + + int idx = 1; + while (idx < argc) + { + if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) + { + usage(argv[0]); + return EXIT_SUCCESS; + } + else if (strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0) + { + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; + } + else if (argv[idx][0] == '-') + { + cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + else if (strcmp(argv[idx], "create") == 0) + { + ++idx; + if (idx > argc) + { + usage(argv[0]); + return EXIT_FAILURE; + } + + IceStorm::TopicPrx topic = manager->create(argv[idx]); + cout << "created: " << argv[idx] << endl; + } + else + { + ++idx; + } + } + return EXIT_SUCCESS; +} + +int +main(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; +} + |