diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IceStorm/.depend | 5 | ||||
-rw-r--r-- | cpp/src/IceStorm/Admin.cpp | 174 | ||||
-rw-r--r-- | cpp/src/IceStorm/Grammar.y | 112 | ||||
-rw-r--r-- | cpp/src/IceStorm/Makefile | 29 | ||||
-rw-r--r-- | cpp/src/IceStorm/Parser.cpp | 429 | ||||
-rw-r--r-- | cpp/src/IceStorm/Parser.h | 101 | ||||
-rw-r--r-- | cpp/src/IceStorm/Scanner.l | 275 | ||||
-rw-r--r-- | cpp/src/IceStorm/TopicI.cpp | 19 | ||||
-rw-r--r-- | cpp/src/IceStorm/TopicManagerI.cpp | 23 |
9 files changed, 1133 insertions, 34 deletions
diff --git a/cpp/src/IceStorm/.depend b/cpp/src/IceStorm/.depend index cc42f506c35..30f44f67ef4 100644 --- a/cpp/src/IceStorm/.depend +++ b/cpp/src/IceStorm/.depend @@ -5,4 +5,7 @@ Subscriber.o: Subscriber.cpp ../../include/Ice/Ice.h ../../include/Ice/Initializ TopicI.o: TopicI.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/Stream.h ../../include/Ice/Communicator.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantLocator.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Functional.h ../../include/IceUtil/Functional.h ../IceStorm/TopicI.h ../../include/IceStorm/IceStorm.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../IceStorm/TopicIF.h ../IceStorm/FlusherF.h ../IceStorm/TraceLevelsF.h ../IceStorm/Flusher.h ../IceStorm/SubscriberF.h ../IceStorm/Subscriber.h ../IceStorm/TraceLevels.h TopicManagerI.o: TopicManagerI.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/Stream.h ../../include/Ice/Communicator.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantLocator.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../IceStorm/TopicManagerI.h ../../include/IceStorm/IceStorm.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../IceStorm/TopicIF.h ../IceStorm/FlusherF.h ../IceStorm/TraceLevelsF.h ../IceStorm/TopicI.h ../IceStorm/Flusher.h ../IceStorm/SubscriberF.h ../IceStorm/TraceLevels.h Server.o: Server.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/Stream.h ../../include/Ice/Communicator.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantLocator.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../IceStorm/TopicManagerI.h ../../include/IceStorm/IceStorm.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../IceStorm/TopicIF.h ../IceStorm/FlusherF.h ../IceStorm/TraceLevelsF.h ../IceStorm/TraceLevels.h -Admin.o: Admin.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/Stream.h ../../include/Ice/Communicator.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantLocator.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../../include/IceStorm/IceStorm.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h +Admin.o: Admin.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/Stream.h ../../include/Ice/Communicator.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantLocator.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../IceStorm/Parser.h ../../include/IceStorm/IceStorm.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h +Grammar.o: Grammar.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/Stream.h ../../include/Ice/Communicator.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantLocator.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../IceStorm/Parser.h ../../include/IceStorm/IceStorm.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h +Scanner.o: Scanner.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/Stream.h ../../include/Ice/Communicator.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantLocator.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../IceStorm/Parser.h ../../include/IceStorm/IceStorm.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../IceStorm/Grammar.h +Parser.o: Parser.cpp ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/Logger.h ../../include/Ice/Stream.h ../../include/Ice/Communicator.h ../../include/Ice/LoggerF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/StreamF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/ServantLocator.h ../../include/Ice/Proxy.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/EmitterF.h ../../include/Ice/ReferenceF.h ../IceStorm/Parser.h ../../include/IceStorm/IceStorm.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h diff --git a/cpp/src/IceStorm/Admin.cpp b/cpp/src/IceStorm/Admin.cpp index 4f4803db9e0..d47f8a7cd8a 100644 --- a/cpp/src/IceStorm/Admin.cpp +++ b/cpp/src/IceStorm/Admin.cpp @@ -9,10 +9,12 @@ // ********************************************************************** #include <Ice/Ice.h> -#include <IceStorm/IceStorm.h> +#include <IceStorm/Parser.h> +#include <fstream> using namespace std; using namespace Ice; +using namespace IceStorm; void usage(const char* n) @@ -22,13 +24,103 @@ usage(const char* n) "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" - "create topic Create the given topic.\n" + "-DNAME Define NAME as 1.\n" + "-DNAME=DEF Define NAME as DEF.\n" + "-UNAME Remove any definition for NAME.\n" + "-IDIR Put DIR in the include file search path.\n" + "-e COMMANDS Execute COMMANDS.\n" + "-d, --debug Print debug messages.\n" ; } int run(int argc, char* argv[], const CommunicatorPtr& communicator) { + string cpp("cpp"); + string commands; + bool debug = false; + + int idx = 1; + while (idx < argc) + { + if (strncmp(argv[idx], "-I", 2) == 0) + { + cpp += ' '; + cpp += argv[idx]; + + for (int i = idx ; i + 1 < argc ; ++i) + { + argv[i] = argv[i + 1]; + } + --argc; + } + else if (strncmp(argv[idx], "-D", 2) == 0 || strncmp(argv[idx], "-U", 2) == 0) + { + cpp += ' '; + cpp += argv[idx]; + + for (int i = idx ; i + 1 < argc ; ++i) + { + argv[i] = argv[i + 1]; + } + --argc; + } + else 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 (strcmp(argv[idx], "-e") == 0) + { + if (idx + 1 >= argc) + { + cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + + commands += argv[idx + 1]; + commands += ';'; + + for (int i = idx ; i + 2 < argc ; ++i) + { + argv[i] = argv[i + 2]; + } + argc -= 2; + } + else if (strcmp(argv[idx], "-d") == 0 || strcmp(argv[idx], "--debug") == 0) + { + debug = true; + for (int i = idx ; i + 1 < argc ; ++i) + { + argv[i] = argv[i + 1]; + } + --argc; + } + else if (argv[idx][0] == '-') + { + cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + else + { + ++idx; + } + } + + if (argc >= 2 && !commands.empty()) + { + cerr << argv[0] << ": `-e' option cannot be used if input files are given" << endl; + usage(argv[0]); + return EXIT_FAILURE; + } + PropertiesPtr properties = communicator->getProperties(); const char* managerProperty = "IceStorm.TopicManager"; string managerRef = properties->getProperty(managerProperty); @@ -45,44 +137,69 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator) cerr << argv[0] << ": `" << managerProperty << "' is not running" << endl; return EXIT_FAILURE; } - - int idx = 1; - while (idx < argc) + + ParserPtr parser = Parser::createParser(communicator, manager); + int status = EXIT_SUCCESS; + + if (argc < 2) // No files given { - if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0) + if (!commands.empty()) // Commands were given { - 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; + int parseStatus = parser->parse(commands, debug); + if (parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } } - else if (argv[idx][0] == '-') + else // No commands, let's use standard input { - cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl; - usage(argv[0]); - return EXIT_FAILURE; + int parseStatus = parser->parse(stdin, debug); + if (parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } } - else if (strcmp(argv[idx], "create") == 0) + } + else // Process files given on the command line + { + for (idx = 1 ; idx < argc ; ++idx) { - ++idx; - if (idx > argc) + ifstream test(argv[idx]); + if (!test) { - usage(argv[0]); + cerr << argv[0] << ": can't open `" << argv[idx] << "' for reading: " << strerror(errno) << endl; return EXIT_FAILURE; } + test.close(); + + string cmd = cpp + " " + argv[idx]; +#ifdef WIN32 + FILE* cppHandle = _popen(cmd.c_str(), "r"); +#else + FILE* cppHandle = popen(cmd.c_str(), "r"); +#endif + if (cppHandle == NULL) + { + cerr << argv[0] << ": can't run C++ preprocessor: " << strerror(errno) << endl; + return EXIT_FAILURE; + } + + int parseStatus = parser->parse(cppHandle, debug); + +#ifdef WIN32 + _pclose(cppHandle); +#else + pclose(cppHandle); +#endif - IceStorm::TopicPrx topic = manager->create(argv[idx]); - cout << "created: " << argv[idx] << endl; - } - else - { - ++idx; + if (parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } } } - return EXIT_SUCCESS; + + return status; } int @@ -117,4 +234,3 @@ main(int argc, char* argv[]) return status; } - diff --git a/cpp/src/IceStorm/Grammar.y b/cpp/src/IceStorm/Grammar.y new file mode 100644 index 00000000000..6d7a1dfba74 --- /dev/null +++ b/cpp/src/IceStorm/Grammar.y @@ -0,0 +1,112 @@ +%{ + +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IceStorm/Parser.h> + +using namespace std; +using namespace Ice; +using namespace IceStorm; + +void +yyerror(const char* s) +{ + parser->error(s); +} + +%} + +%pure_parser + +%token ICE_STORM_HELP +%token ICE_STORM_EXIT +%token ICE_STORM_CREATE +%token ICE_STORM_DESTROY +%token ICE_STORM_LIST +%token ICE_STORM_SHUTDOWN +%token ICE_STORM_STRING + +%% + +// ---------------------------------------------------------------------- +start +// ---------------------------------------------------------------------- +: commands +{ +} +| +{ +} +; + +// ---------------------------------------------------------------------- +commands +// ---------------------------------------------------------------------- +: commands command +{ +} +| command +{ +} +; + +// ---------------------------------------------------------------------- +command +// ---------------------------------------------------------------------- +: ICE_STORM_HELP ';' +{ + parser->usage(); +} +| ICE_STORM_EXIT ';' +{ + return 0; +} +| ICE_STORM_CREATE strings ';' +{ + parser->create($2); +} +| ICE_STORM_DESTROY strings ';' +{ + parser->destroy($2); +} +| ICE_STORM_LIST ';' +{ + parser->listAll(); +} +| ICE_STORM_SHUTDOWN ';' +{ + parser->shutdown(); +} +| error ';' +{ + yyerrok; +} +| ';' +{ +} +; + +// ---------------------------------------------------------------------- +strings +// ---------------------------------------------------------------------- +: ICE_STORM_STRING strings +{ + $$ = $2; + $$.push_front($1.front()); +} +| ICE_STORM_STRING +{ + $$ = $1 +} +; + +%% diff --git a/cpp/src/IceStorm/Makefile b/cpp/src/IceStorm/Makefile index 38f571805b0..e4e10d60f36 100644 --- a/cpp/src/IceStorm/Makefile +++ b/cpp/src/IceStorm/Makefile @@ -22,9 +22,17 @@ TARGETS = $(NAME) $(VERSIONED_NAME) $(SERVER) $(ADMIN) OBJS = IceStorm.o -SOBJS = TraceLevels.o Flusher.o Subscriber.o TopicI.o TopicManagerI.o Server.o - -AOBJS = Admin.o +SOBJS = TraceLevels.o \ + Flusher.o \ + Subscriber.o \ + TopicI.o \ + TopicManagerI.o \ + Server.o + +AOBJS = Admin.o \ + Grammar.o \ + Scanner.o \ + Parser.o SRCS = $(OBJS:.o=.cpp) \ $(SOBJS:.o=.cpp) \ @@ -53,13 +61,26 @@ $(SERVER): $(SOBJS) $(ADMIN): $(AOBJS) rm -f $@ - $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(AOBJS) -lIceStorm $(LIBS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $(AOBJS) -lIceStorm $(LIBS) -lreadline -lcurses + $(HDIR)/IceStorm.h IceStorm.cpp: $(SDIR)/IceStorm.ice $(SLICE2CPP) rm -f $(HDIR)/IceStorm.h IceStorm.cpp $(SLICECMD) $(SDIR)/IceStorm.ice mv IceStorm.h $(HDIR) +Grammar.cpp Grammar.h: Grammar.y + bison -dvt Grammar.y + rm -f Grammar.cpp ; mv Grammar.tab.c Grammar.cpp + rm -f Grammar.h ; mv Grammar.tab.h Grammar.h + +Scanner.cpp: Scanner.l Grammar.h + flex Scanner.l + rm -f Scanner.cpp ; mv lex.yy.c Scanner.cpp + +clean:: + -rm -f Grammar.cpp Grammar.h Grammar.output + -rm -f Scanner.cpp lex.yy.c clean:: rm -f $(HDIR)/Clock.h Clock.cpp diff --git a/cpp/src/IceStorm/Parser.cpp b/cpp/src/IceStorm/Parser.cpp new file mode 100644 index 00000000000..f640e9890e9 --- /dev/null +++ b/cpp/src/IceStorm/Parser.cpp @@ -0,0 +1,429 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IceStorm/Parser.h> + +#include <algorithm> + +#ifdef HAVE_READLINE +# include <readline/readline.h> +# include <readline/history.h> +#endif + +using namespace std; +using namespace Ice; +using namespace IceStorm; + +extern FILE* yyin; + +namespace IceStorm +{ + +Parser* parser; + +} + +ParserPtr +Parser::createParser(const CommunicatorPtr& communicator, const TopicManagerPrx& admin) +{ + return new Parser(communicator, admin); +} + +void +Parser::usage() +{ + cout << + "help Print this message.\n" + "exit, quit Exit this program.\n" + "create TOPICS Add TOPICS.\n" + "destroy TOPICS Remove TOPICS.\n" + "list List all server descriptions.\n" + "shutdown Shut the IceStorm server down.\n"; +} + +#include <IceUtil/Functional.h> +#include <functional> + +void +Parser::create(const list<string>& args) +{ + if (args.empty()) + { + error("`create' requires at least one argument (type `help' for more info)"); + return; + } + + try + { + // + // TODO: How is this supposed to work? + // + //for_each(args.begin(), args.end(), bind1st(IceUtil::memFun1(&TopicManager::create), _admin)); + for (list<string>::const_iterator i = args.begin(); i != args.end() ; ++i) + { + _admin->create(*i); + } + } + catch(const Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void +Parser::destroy(const list<string>& args) +{ + if (args.empty()) + { + error("`destroy' requires exactly one argument (type `help' for more info)"); + return; + } + + try + { + for (list<string>::const_iterator i = args.begin(); i != args.end() ; ++i) + { + TopicPrx topic = _admin->retrieve(*i); + topic->destroy(); + } + } + catch(const Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void +Parser::listAll() +{ + try + { + TopicDict d = _admin->retrieveAll(); + if (!d.empty()) + { + for (TopicDict::iterator i = d.begin(); i != d.end(); ++i) + { + if (i != d.begin()) + { + cout << ", "; + } + cout << i->first; + } + cout << endl; + } + } + catch(const Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void +Parser::shutdown() +{ + try + { + _admin->shutdown(); + } + catch(const Exception& ex) + { + ostringstream s; + s << ex; + error(s.str()); + } +} + +void +Parser::getInput(char* buf, int& result, int maxSize) +{ + if (!_commands.empty()) + { + if (_commands == ";") + { + result = 0; + } + else + { +#if defined(_MSC_VER) && !defined(_STLP_MSVC) + // COMPILERBUG: Stupid Visual C++ defines min and max as macros + result = _MIN(maxSize, static_cast<int>(_commands.length())); +#else + result = min(maxSize, static_cast<int>(_commands.length())); +#endif + strncpy(buf, _commands.c_str(), result); + _commands.erase(0, result); + if (_commands.empty()) + { + _commands = ";"; + } + } + } + else if (isatty(fileno(yyin))) + { +#ifdef HAVE_READLINE + + char* line = readline(parser->getPrompt()); + if (!line) + { + result = 0; + } + else + { + if (*line) + { + add_history(line); + } + + result = strlen(line) + 1; + if (result > maxSize) + { + free(line); + error("input line too long"); + result = 0; + } + else + { + strcpy(buf, line); + strcat(buf, "\n"); + free(line); + } + } + +#else + + cout << parser->getPrompt() << flush; + + string line; + while (true) + { + char c = static_cast<char>(getc(yyin)); + if (c == EOF) + { + if (line.size()) + { + line += '\n'; + } + break; + } + + line += c; + + if (c == '\n') + { + break; + } + } + + result = line.length(); + if (result > maxSize) + { + error("input line too long"); + buf[0] = EOF; + result = 1; + } + else + { + strcpy(buf, line.c_str()); + } + +#endif + } + else + { + if (((result = fread(buf, 1, maxSize, yyin)) == 0) && ferror(yyin)) + { + error("input in flex scanner failed"); + buf[0] = EOF; + result = 1; + } + } +} + +void +Parser::nextLine() +{ + _currentLine++; +} + +void +Parser::continueLine() +{ + _continue = true; +} + +char* +Parser::getPrompt() +{ + assert(_commands.empty() && isatty(fileno(yyin))); + + if (_continue) + { + _continue = false; + return "(cont) "; + } + else + { + return ">>> "; + } +} + +void +Parser::scanPosition(const char* s) +{ + string line(s); + string::size_type idx; + + idx = line.find("line"); + if (idx != string::npos) + { + line.erase(0, idx + 4); + } + + idx = line.find_first_not_of(" \t\r#"); + if (idx != string::npos) + { + line.erase(0, idx); + } + + _currentLine = atoi(line.c_str()) - 1; + + idx = line.find_first_of(" \t\r"); + if (idx != string::npos) + { + line.erase(0, idx); + } + + idx = line.find_first_not_of(" \t\r\""); + if (idx != string::npos) + { + line.erase(0, idx); + + idx = line.find_first_of(" \t\r\""); + if (idx != string::npos) + { + _currentFile = line.substr(0, idx); + line.erase(0, idx + 1); + } + else + { + _currentFile = line; + } + } +} + +void +Parser::error(const char* s) +{ + if (_commands.empty() && !isatty(fileno(yyin))) + { + cerr << _currentFile << ':' << _currentLine << ": " << s << endl; + } + else + { + cerr << "error: " << s << endl; + } + _errors++; +} + +void +Parser::error(const string& s) +{ + error(s.c_str()); +} + +void +Parser::warning(const char* s) +{ + if (_commands.empty() && !isatty(fileno(yyin))) + { + cerr << _currentFile << ':' << _currentLine << ": warning: " << s << endl; + } + else + { + cerr << "warning: " << s << endl; + } +} + +void +Parser::warning(const string& s) +{ + warning(s.c_str()); +} + +int +Parser::parse(FILE* file, bool debug) +{ + extern int yydebug; + yydebug = debug ? 1 : 0; + + assert(!parser); + parser = this; + + _errors = 0; + _commands.empty(); + yyin = file; + assert(yyin); + + _currentFile = ""; + _currentLine = 0; + _continue = false; + nextLine(); + + int status = yyparse(); + if (_errors) + { + status = EXIT_FAILURE; + } + + parser = 0; + return status; +} + +int +Parser::parse(const std::string& commands, bool debug) +{ + extern int yydebug; + yydebug = debug ? 1 : 0; + + assert(!parser); + parser = this; + + _errors = 0; + _commands = commands; + assert(!_commands.empty()); + yyin = 0; + + _currentFile = ""; + _currentLine = 0; + _continue = false; + nextLine(); + + int status = yyparse(); + if (_errors) + { + status = EXIT_FAILURE; + } + + parser = 0; + return status; +} + +Parser::Parser(const CommunicatorPtr& communicator, const TopicManagerPrx& admin) : + _communicator(communicator), + _admin(admin) +{ +} diff --git a/cpp/src/IceStorm/Parser.h b/cpp/src/IceStorm/Parser.h new file mode 100644 index 00000000000..56009b66fe9 --- /dev/null +++ b/cpp/src/IceStorm/Parser.h @@ -0,0 +1,101 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#ifndef ICE_STORM_PARSER_H +#define ICE_STORM_PARSER_H + +#include <IceUtil/Handle.h> +#include <IceStorm/IceStorm.h> +#include <list> + +#ifdef WIN32 +# include <io.h> +# define isatty _isatty +# define fileno _fileno +// '_isatty' : inconsistent dll linkage. dllexport assumed. +# pragma warning( disable : 4273 ) +#endif + +// +// Stuff for flex and bison +// + +#define YYSTYPE std::list<std::string> +#define YY_DECL int yylex(YYSTYPE* yylvalp) +YY_DECL; +int yyparse(); + +// +// I must set the initial stack depth to the maximum stack depth to +// disable bison stack resizing. The bison stack resizing routines use +// simple malloc/alloc/memcpy calls, which do not work for the +// YYSTYPE, since YYSTYPE is a C++ type, with constructor, destructor, +// assignment operator, etc. +// +#define YYMAXDEPTH 20000 // 20000 should suffice. Bison default is 10000 as maximum. +#define YYINITDEPTH YYMAXDEPTH // Initial depth is set to max depth, for the reasons described above. + +namespace IceStorm +{ + +class Parser; +typedef ::IceUtil::Handle<Parser> ParserPtr; + +} + +namespace IceStorm +{ + +class Parser : public ::IceUtil::SimpleShared +{ +public: + + static ParserPtr createParser(const Ice::CommunicatorPtr&, const IceStorm::TopicManagerPrx&); + + void usage(); + + void create(const std::list<std::string>&); + void destroy(const std::list<std::string>&); + void listAll(); + void shutdown(); + + void getInput(char*, int&, int); + void nextLine(); + void continueLine(); + char* getPrompt(); + void scanPosition(const char*); + + void error(const char*); + void error(const std::string&); + + void warning(const char*); + void warning(const std::string&); + + int parse(FILE*, bool); + int parse(const std::string&, bool); + +private: + + Parser(const Ice::CommunicatorPtr&, const IceStorm::TopicManagerPrx&); + + std::string _commands; + Ice::CommunicatorPtr _communicator; + IceStorm::TopicManagerPrx _admin; + bool _continue; + int _errors; + int _currentLine; + std::string _currentFile; +}; + +extern Parser* parser; // The current parser for bison/flex + +} + +#endif diff --git a/cpp/src/IceStorm/Scanner.l b/cpp/src/IceStorm/Scanner.l new file mode 100644 index 00000000000..6beba8e1444 --- /dev/null +++ b/cpp/src/IceStorm/Scanner.l @@ -0,0 +1,275 @@ +%{ + +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <IceStorm/Parser.h> +#include <IceStorm/Grammar.h> + +using namespace std; +using namespace Ice; +using namespace IceStorm; + +#define YY_INPUT(buf, result, maxSize) parser->getInput(buf, result, maxSize) + +%} + +WS [ \t\v\f\r] +NL [\n] + +%option noyywrap + +%% + +^"#"[[:blank:]]*[[:digit:]]+[[:blank:]]*$ { + parser->scanPosition(yytext); +} + +^"#"[[:blank:]]*[[:digit:]]+[[:blank:]]+"\""[^\"]*"\"".*$ { + parser->scanPosition(yytext); +} + +^"#"[[:blank:]]*"line"[[:blank:]]+[[:digit:]]+[[:blank:]]*$ { + parser->scanPosition(yytext); +} + +^"#"[[:blank:]]*"line"[[:blank:]]+[[:digit:]]+[[:blank:]]+"\""[^\"]*"\"".*$ { + parser->scanPosition(yytext); +} + +"//" { + // C++-style comment + int c; + do + { + c = yyinput(); + if (c == '\n') + { + parser->nextLine(); + } + } + while (c != '\n' && c != EOF); +} + +"/*" { + // C-style comment + while (true) + { + int c = yyinput(); + if (c == '\n') + { + parser->nextLine(); + } + else if (c == '*') + { + int next = yyinput(); + if (next == '/') + { + break; + } + else + { + unput(next); + } + } + else if (c == EOF) + { + parser->warning("EOF in comment"); + break; + } + } +} + +"help" { + return ICE_STORM_HELP; +} + +"quit"|"exit" { + return ICE_STORM_EXIT; +} + +"create" { + return ICE_STORM_CREATE; +} + +"destroy" { + return ICE_STORM_DESTROY; +} + +"list" { + return ICE_STORM_LIST; +} + +"shutdown" { + return ICE_STORM_SHUTDOWN; +} + +{WS}*(\\{WS}*{NL})? { + int len = strlen(yytext); + for (int i = 0; i < len; ++i) + { + if (yytext[i] == '\\') + { + parser->continueLine(); + } + else if (yytext[i] == '\n') + { + parser->nextLine(); + } + } +} + +{NL}|; { + int len = strlen(yytext); + for (int i = 0; i < len; ++i) + { + if (yytext[i] == '\n') + { + parser->nextLine(); + } + } + return ';'; +} + +\" { + // "..."-type strings + string s; + while (true) + { + char c = static_cast<char>(yyinput()); + if (c == '"') + { + break; + } + else if (c == EOF) + { + parser->warning("EOF in string"); + break; + } + else if (c == '\n') + { + s += c; + parser->nextLine(); + } + else if (c == '\\') + { + char next = static_cast<char>(yyinput()); + switch (next) + { + case '\\': + case '"': + { + s += next; + break; + } + + case 'n': + { + s += '\n'; + break; + } + + case 'r': + { + s += '\r'; + break; + } + + case 't': + { + s += '\t'; + break; + } + + case 'v': + { + s += '\v'; + break; + } + + case 'f': + { + s += '\f'; + break; + } + + default: + { + s += c; + unput(next); + } + } + } + else + { + s += c; + } + } + yylvalp->clear(); + yylvalp->push_back(s); + return ICE_STORM_STRING; +} + +\' { + // '...'-type strings + string s; + while (true) + { + char c = static_cast<char>(yyinput()); + if (c == '\'') + { + break; + } + else if (c == EOF) + { + parser->warning("EOF in string"); + break; + } + else if (c == '\n') + { + s += c; + parser->nextLine(); + } + else + { + s += c; + } + } + yylvalp->clear(); + yylvalp->push_back(s); + return ICE_STORM_STRING; +} + +. { + // Simple strings + string s; + s += yytext[0]; + while (true) + { + char c = static_cast<char>(yyinput()); + if (c == EOF) + { + break; + } + else if (isspace(c) || c == ';') + { + unput(c); + break; + } + + s += c; + } + yylvalp->clear(); + yylvalp->push_back(s); + return ICE_STORM_STRING; +} + +%% diff --git a/cpp/src/IceStorm/TopicI.cpp b/cpp/src/IceStorm/TopicI.cpp index d95c4d0d000..8b17f4da2f1 100644 --- a/cpp/src/IceStorm/TopicI.cpp +++ b/cpp/src/IceStorm/TopicI.cpp @@ -24,6 +24,10 @@ using namespace std; namespace IceStorm { +// +// The servant has a 1-1 association with a topic. It is used to +// receive events from Publishers. +// class BlobjectI : public Ice::Blobject { public: @@ -42,6 +46,9 @@ public: private: + // + // Set of associated subscribers + // IceStorm::TopicSubscribersPtr _subscribers; }; @@ -186,6 +193,11 @@ TopicI::TopicI(const Ice::ObjectAdapterPtr& adapter, const TraceLevelsPtr& trace { _subscribers = new TopicSubscribers(_traceLevels, _logger, _name, _flusher); + // + // Create a servant per Topic to receive event data. The servants + // object-id is <topic>#publish. Active the object and save a + // reference to give to publishers. + // _publisher = new BlobjectI(_subscribers); string id = name; @@ -216,6 +228,13 @@ void TopicI::destroy() { JTCSyncT<JTCMutex> sync(_destroyedMutex); + if (_traceLevels->topic > 0) + { + ostringstream s; + s << "Destroy " << _name; + _logger->trace(_traceLevels->topicCat, s.str()); + } + _adapter->remove(_name); _destroyed = true; } diff --git a/cpp/src/IceStorm/TopicManagerI.cpp b/cpp/src/IceStorm/TopicManagerI.cpp index 7a282c28baa..49bfe3dbe1e 100644 --- a/cpp/src/IceStorm/TopicManagerI.cpp +++ b/cpp/src/IceStorm/TopicManagerI.cpp @@ -211,5 +211,28 @@ TopicManagerI::shutdown() void TopicManagerI::reap() { + // + // Always Called with mutex locked + // + // JTCSyncT<JTCMutex> sync(*this); + // + TopicIMap::iterator i = _topicIMap.begin(); + while (i != _topicIMap.end()) + { + if (i->second->destroyed()) + { + if (_traceLevels->topicMgr > 0) + { + ostringstream s; + s << "Reaping " << i->first; + _communicator->getLogger()->trace(_traceLevels->topicMgrCat, s.str()); + } + _topicIMap.erase(i++); + } + else + { + ++i; + } + } } |