From 99a79f729a85ab0f5f273ff50d843fb2b64d7340 Mon Sep 17 00:00:00 2001 From: Michi Henning Date: Wed, 25 Jul 2007 14:06:50 +1000 Subject: Added life cycle demo for book. --- cpp/demo/book/Makefile | 1 + cpp/demo/book/lifecycle/.depend | 9 + cpp/demo/book/lifecycle/Client.cpp | 47 ++++ cpp/demo/book/lifecycle/Filesystem.ice | 42 +++ cpp/demo/book/lifecycle/FilesystemI.cpp | 312 +++++++++++++++++++++ cpp/demo/book/lifecycle/FilesystemI.h | 83 ++++++ cpp/demo/book/lifecycle/Grammar.y | 142 ++++++++++ cpp/demo/book/lifecycle/Makefile | 50 ++++ cpp/demo/book/lifecycle/Makefile.mak | 69 +++++ cpp/demo/book/lifecycle/Parser.cpp | 482 ++++++++++++++++++++++++++++++++ cpp/demo/book/lifecycle/Parser.h | 96 +++++++ cpp/demo/book/lifecycle/README | 11 + cpp/demo/book/lifecycle/Scanner.l | 284 +++++++++++++++++++ cpp/demo/book/lifecycle/Server.cpp | 55 ++++ 14 files changed, 1683 insertions(+) create mode 100644 cpp/demo/book/lifecycle/.depend create mode 100644 cpp/demo/book/lifecycle/Client.cpp create mode 100644 cpp/demo/book/lifecycle/Filesystem.ice create mode 100644 cpp/demo/book/lifecycle/FilesystemI.cpp create mode 100644 cpp/demo/book/lifecycle/FilesystemI.h create mode 100644 cpp/demo/book/lifecycle/Grammar.y create mode 100644 cpp/demo/book/lifecycle/Makefile create mode 100644 cpp/demo/book/lifecycle/Makefile.mak create mode 100644 cpp/demo/book/lifecycle/Parser.cpp create mode 100644 cpp/demo/book/lifecycle/Parser.h create mode 100644 cpp/demo/book/lifecycle/README create mode 100644 cpp/demo/book/lifecycle/Scanner.l create mode 100644 cpp/demo/book/lifecycle/Server.cpp (limited to 'cpp') diff --git a/cpp/demo/book/Makefile b/cpp/demo/book/Makefile index 9468eac283d..bd282fbaef3 100644 --- a/cpp/demo/book/Makefile +++ b/cpp/demo/book/Makefile @@ -13,6 +13,7 @@ include $(top_srcdir)/config/Make.rules SUBDIRS = printer \ simple_filesystem \ + lifecycle \ freeze_filesystem $(EVERYTHING):: diff --git a/cpp/demo/book/lifecycle/.depend b/cpp/demo/book/lifecycle/.depend new file mode 100644 index 00000000000..b8ff935428a --- /dev/null +++ b/cpp/demo/book/lifecycle/.depend @@ -0,0 +1,9 @@ +Filesystem$(OBJEXT): Filesystem.cpp Filesystem.h ../../../include/Ice/LocalObjectF.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Config.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/StreamF.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/Outgoing.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/Ice/BasicStream.h ../../../include/Ice/InstanceF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/Ice/StringConverter.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/Direct.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/LocalException.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/ObjectFactory.h ../../../include/IceUtil/Iterator.h ../../../include/IceUtil/ScopedArray.h ../../../include/IceUtil/DisableWarnings.h +Grammar$(OBJEXT): Grammar.cpp Parser.h ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Config.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/StringConverter.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ImplicitContextF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/OutgoingAsync.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Process.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Direct.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/IceUtil/Functional.h ../../../include/Ice/Stream.h ../../../include/Ice/ImplicitContext.h ../../../include/Ice/Locator.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/ProcessF.h ../../../include/Ice/Router.h ../../../include/Ice/DispatchInterceptor.h ../../../include/Ice/IconvStringConverter.h Filesystem.h +Scanner$(OBJEXT): Scanner.cpp ../../../include/IceUtil/Config.h Parser.h ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/IceUtil/Shared.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/StringConverter.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ImplicitContextF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/OutgoingAsync.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Process.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Direct.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/IceUtil/Functional.h ../../../include/Ice/Stream.h ../../../include/Ice/ImplicitContext.h ../../../include/Ice/Locator.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/ProcessF.h ../../../include/Ice/Router.h ../../../include/Ice/DispatchInterceptor.h ../../../include/Ice/IconvStringConverter.h Filesystem.h Grammar.h +Parser$(OBJEXT): Parser.cpp ../../../include/IceUtil/DisableWarnings.h Parser.h ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Config.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/StringConverter.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ImplicitContextF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/OutgoingAsync.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Process.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Direct.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/IceUtil/Functional.h ../../../include/Ice/Stream.h ../../../include/Ice/ImplicitContext.h ../../../include/Ice/Locator.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/ProcessF.h ../../../include/Ice/Router.h ../../../include/Ice/DispatchInterceptor.h ../../../include/Ice/IconvStringConverter.h Filesystem.h +Client$(OBJEXT): Client.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Config.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/StringConverter.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ImplicitContextF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/OutgoingAsync.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Process.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Direct.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/IceUtil/Functional.h ../../../include/Ice/Stream.h ../../../include/Ice/ImplicitContext.h ../../../include/Ice/Locator.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/ProcessF.h ../../../include/Ice/Router.h ../../../include/Ice/DispatchInterceptor.h ../../../include/Ice/IconvStringConverter.h Filesystem.h Parser.h +FilesystemI$(OBJEXT): FilesystemI.cpp ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Config.h ../../../include/IceUtil/AbstractMutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/IceUtil/Exception.h ../../../include/IceUtil/Algorithm.h ../../../include/IceUtil/ArgVector.h ../../../include/IceUtil/Base64.h ../../../include/IceUtil/Cache.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/CountDownLatch.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/IceUtil/CtrlCHandler.h ../../../include/IceUtil/Functional.h ../../../include/IceUtil/InputUtil.h ../../../include/IceUtil/Iterator.h ../../../include/IceUtil/MD5.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Options.h ../../../include/IceUtil/RecMutex.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/OutputUtil.h ../../../include/IceUtil/RWRecMutex.h ../../../include/IceUtil/Thread.h ../../../include/IceUtil/Random.h ../../../include/IceUtil/ScopedArray.h ../../../include/IceUtil/StaticMutex.h ../../../include/IceUtil/StringUtil.h ../../../include/IceUtil/UUID.h ../../../include/IceUtil/Unicode.h FilesystemI.h ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/StringConverter.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ImplicitContextF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/OutgoingAsync.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/Ice/Process.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Direct.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/Ice/Stream.h ../../../include/Ice/ImplicitContext.h ../../../include/Ice/Locator.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/ProcessF.h ../../../include/Ice/Router.h ../../../include/Ice/DispatchInterceptor.h ../../../include/Ice/IconvStringConverter.h Filesystem.h +Server$(OBJEXT): Server.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Initialize.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalObjectF.h ../../../include/IceUtil/Shared.h ../../../include/IceUtil/Config.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Exception.h ../../../include/Ice/Config.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ObjectF.h ../../../include/Ice/GCCountMap.h ../../../include/Ice/GCShared.h ../../../include/Ice/Exception.h ../../../include/Ice/LocalObject.h ../../../include/Ice/UndefSysMacros.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/InstanceF.h ../../../include/Ice/LoggerF.h ../../../include/Ice/StreamF.h ../../../include/Ice/StatsF.h ../../../include/Ice/StringConverter.h ../../../include/Ice/BuiltinSequences.h ../../../include/Ice/Proxy.h ../../../include/IceUtil/Mutex.h ../../../include/IceUtil/Lock.h ../../../include/IceUtil/ThreadException.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/ConnectionIF.h ../../../include/Ice/EndpointIF.h ../../../include/Ice/Endpoint.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/OutgoingAsyncF.h ../../../include/Ice/Current.h ../../../include/Ice/ConnectionF.h ../../../include/Ice/Identity.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/LoggerUtil.h ../../../include/Ice/Stats.h ../../../include/Ice/Communicator.h ../../../include/Ice/Object.h ../../../include/Ice/IncomingAsyncF.h ../../../include/Ice/ObjectFactoryF.h ../../../include/Ice/RouterF.h ../../../include/Ice/LocatorF.h ../../../include/Ice/PluginF.h ../../../include/Ice/ImplicitContextF.h ../../../include/Ice/ObjectFactory.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/ServantLocatorF.h ../../../include/Ice/FacetMap.h ../../../include/Ice/ServantLocator.h ../../../include/Ice/OutgoingAsync.h ../../../include/IceUtil/Monitor.h ../../../include/IceUtil/Cond.h ../../../include/IceUtil/Time.h ../../../include/IceUtil/RecMutex.h ../../../include/Ice/IncomingAsync.h ../../../include/Ice/Incoming.h ../../../include/Ice/ServantManagerF.h ../../../include/Ice/BasicStream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Protocol.h ../../../include/IceUtil/Unicode.h ../../../include/Ice/Process.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Direct.h ../../../include/Ice/Application.h ../../../include/Ice/Connection.h ../../../include/Ice/Functional.h ../../../include/IceUtil/Functional.h ../../../include/Ice/Stream.h ../../../include/Ice/ImplicitContext.h ../../../include/Ice/Locator.h ../../../include/Ice/UserExceptionFactory.h ../../../include/Ice/FactoryTable.h ../../../include/Ice/FactoryTableDef.h ../../../include/IceUtil/StaticMutex.h ../../../include/Ice/UserExceptionFactoryF.h ../../../include/Ice/ProcessF.h ../../../include/Ice/Router.h ../../../include/Ice/DispatchInterceptor.h ../../../include/Ice/IconvStringConverter.h FilesystemI.h Filesystem.h +Filesystem.cpp: Filesystem.ice +Filesystem.ice: $(SLICE2CPP) $(SLICEPARSERLIB) diff --git a/cpp/demo/book/lifecycle/Client.cpp b/cpp/demo/book/lifecycle/Client.cpp new file mode 100644 index 00000000000..0e74b129254 --- /dev/null +++ b/cpp/demo/book/lifecycle/Client.cpp @@ -0,0 +1,47 @@ +// ********************************************************************** +// +// 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 +#include +#include + +using namespace std; +using namespace Filesystem; + +class FilesystemClient : virtual public Ice::Application +{ +public: + virtual int run(int, char * []) { + // Terminate cleanly on receipt of a signal + // + shutdownOnInterrupt(); + + // Create a proxy for the root directory + // + Ice::ObjectPrx base = communicator()->stringToProxy("RootDir:default -p 10000"); + if (!base) + throw "Could not create proxy"; + + // Down-cast the proxy to a Directory proxy + // + DirectoryPrx rootDir = DirectoryPrx::checkedCast(base); + if (!rootDir) + throw "Invalid proxy"; + + ParserPtr p = new Parser(rootDir); + return p->parse(); + }; +}; + +int +main(int argc, char* argv[]) +{ + FilesystemClient client; + return client.main(argc, argv); +} diff --git a/cpp/demo/book/lifecycle/Filesystem.ice b/cpp/demo/book/lifecycle/Filesystem.ice new file mode 100644 index 00000000000..195002c8c46 --- /dev/null +++ b/cpp/demo/book/lifecycle/Filesystem.ice @@ -0,0 +1,42 @@ +module Filesystem { + exception GenericError + { + string reason; + }; + exception PermissionDenied extends GenericError {}; + exception NameInUse extends GenericError {}; + exception NoSuchName extends GenericError {}; + + interface Node + { + idempotent string name(); + void destroy() throws PermissionDenied; + }; + + sequence Lines; + + interface File extends Node + { + idempotent Lines read(); + idempotent void write(Lines text) throws GenericError; + }; + + enum NodeType { DirType, FileType }; + + struct NodeDesc + { + string name; + NodeType type; + Node* proxy; + }; + + sequence NodeDescSeq; + + interface Directory extends Node + { + idempotent NodeDescSeq list(); + idempotent NodeDesc find(string name) throws NoSuchName; + File* createFile(string name) throws NameInUse; + Directory* createDirectory(string name) throws NameInUse; + }; +}; diff --git a/cpp/demo/book/lifecycle/FilesystemI.cpp b/cpp/demo/book/lifecycle/FilesystemI.cpp new file mode 100644 index 00000000000..09d10b37f51 --- /dev/null +++ b/cpp/demo/book/lifecycle/FilesystemI.cpp @@ -0,0 +1,312 @@ +// ********************************************************************** +// +// 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 +#include + +using namespace std; +using namespace Ice; +using namespace Filesystem; +using namespace FilesystemI; + +FilesystemI::DirectoryI::ReapMap FilesystemI::DirectoryI::_reapMap; + +// Slice Node::name() operation. + +std::string +FilesystemI::NodeI::name(const Current&) +{ + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + + return _name; +} + +// Return the object identity for this node. + +Identity +FilesystemI::NodeI::id() const +{ + return _id; +} + +FilesystemI::NodeI::NodeI(const string& name, const DirectoryIPtr& parent) + : _name(name), _parent(parent), _destroyed(false) +{ +} + +// Slice File::read() operation. + +Lines +FilesystemI::FileI::read(const Current&) +{ + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + + return _lines; +} + +// Slice File::write() operation. + +void +FilesystemI::FileI::write(const Lines& text, const Current&) +{ + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + + _lines = text; +} + +// Slice File::destroy() operation. + +void +FilesystemI::FileI::destroy(const Current& c) +{ + { + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + _destroyed = true; + } + + IceUtil::Mutex::Lock lock(_parent->_lcMutex); + + c.adapter->remove(id()); + _parent->addReapEntry(_name); +} + +// FileI constructor. + +FilesystemI::FileI::FileI(const ObjectAdapterPtr& a, const string& name, const DirectoryIPtr& parent) + : NodeI(name, parent) +{ + _id.name = IceUtil::generateUUID(); + parent->addChild(name, this); + a->add(this, _id); +} + +// Slice Directory::list() operation. + +NodeDescSeq +FilesystemI::DirectoryI::list(const Current& c) +{ + { + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + } + + IceUtil::Mutex::Lock lock(_lcMutex); + + reap(); + + NodeDescSeq ret; + for(Contents::const_iterator i = _contents.begin(); i != _contents.end(); ++i) + { + NodeDesc d; + d.name = i->first; + d.type = FilePtr::dynamicCast(i->second) ? FileType : DirType; + d.proxy = NodePrx::uncheckedCast(c.adapter->createProxy(i->second->id())); + ret.push_back(d); + } + return ret; +} + +// Slice Directory::find() operation. + +NodeDesc +FilesystemI::DirectoryI::find(const string& name, const Current& c) +{ + { + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + } + + IceUtil::Mutex::Lock lock(_lcMutex); + + reap(); + + Contents::const_iterator pos = _contents.find(name); + if(pos == _contents.end()) + { + throw NoSuchName(name); + } + + NodeIPtr p = pos->second; + NodeDesc d; + d.name = name; + d.type = FilePtr::dynamicCast(p) ? FileType : DirType; + d.proxy = NodePrx::uncheckedCast(c.adapter->createProxy(p->id())); + return d; +} + +// Slice Directory::createFile() operation. + +FilePrx +FilesystemI::DirectoryI::createFile(const string& name, const Current& c) +{ + { + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + } + + IceUtil::Mutex::Lock lock(_lcMutex); + + reap(); + + if(_contents.find(name) != _contents.end()) + { + throw NameInUse(name); + } + + FileIPtr f = new FileI(c.adapter, name, this); + return FilePrx::uncheckedCast(c.adapter->createProxy(f->id())); +} + +// Slice Directory::createDirectory() operation. + +DirectoryPrx +FilesystemI::DirectoryI::createDirectory(const string& name, const Current& c) +{ + { + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + } + + IceUtil::Mutex::Lock lock(_lcMutex); + + reap(); + + if(_contents.find(name) != _contents.end()) + { + throw NameInUse(name); + } + + DirectoryIPtr d = new DirectoryI(c.adapter, name, this); + return DirectoryPrx::uncheckedCast(c.adapter->createProxy(d->id())); +} + +// Slice Directory::destroy() operation. + +void +FilesystemI::DirectoryI::destroy(const Current& c) +{ + if(!_parent) + { + throw PermissionDenied("Cannot destroy root directory"); + } + + { + IceUtil::Mutex::Lock lock(_m); + + if(_destroyed) + { + throw ObjectNotExistException(__FILE__, __LINE__); + } + _destroyed = true; + } + + IceUtil::Mutex::Lock lock(_lcMutex); + + reap(); + + if(!_contents.empty()) + { + throw PermissionDenied("Cannot destroy non-empty directory"); + } + + c.adapter->remove(id()); + _parent->addReapEntry(_name); +} + +// DirectoryI constructor. + +FilesystemI::DirectoryI::DirectoryI(const ObjectAdapterPtr& a, const string& name, const DirectoryIPtr& parent) + : NodeI(name, parent) +{ + if(!parent) + { + _id.name = "RootDir"; + } + else + { + _id.name = IceUtil::generateUUID(); + _parent->addChild(name, this); + } + a->add(this, _id); +} + +void +FilesystemI::DirectoryI::addChild(const string& name, const NodeIPtr& node) +{ + _contents[name] = node; +} + +// Add a directory and the name of a deleted entry in that directory to the reap map. + +void +FilesystemI::DirectoryI::addReapEntry(const string& name) +{ + ReapMap::iterator pos = _reapMap.find(this); + if(pos != _reapMap.end()) + { + pos->second.push_back(name); + } + else + { + vector v; + v.push_back(name); + _reapMap[this] = v; + } +} + +// Remove all names in the reap map from the corresponding directory contents. + +void +FilesystemI::DirectoryI::reap() +{ + for(ReapMap::const_iterator i = _reapMap.begin(); i != _reapMap.end(); ++i) + { + for(vector::const_iterator j = i->second.begin(); j != i->second.end(); ++j) + { + i->first->_contents.erase(*j); + } + } + _reapMap.clear(); +} diff --git a/cpp/demo/book/lifecycle/FilesystemI.h b/cpp/demo/book/lifecycle/FilesystemI.h new file mode 100644 index 00000000000..ae3c42c7d79 --- /dev/null +++ b/cpp/demo/book/lifecycle/FilesystemI.h @@ -0,0 +1,83 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +#ifndef __FilesystemI_h__ +#define __FilesystemI_h__ + +#include +#include +#include +#include + +namespace FilesystemI +{ + class DirectoryI; + typedef IceUtil::Handle DirectoryIPtr; + + class NodeI : virtual public Filesystem::Node + { + public: + virtual std::string name(const Ice::Current&); + Ice::Identity id() const; + + protected: + NodeI(const ::std::string&, const DirectoryIPtr&); + + const ::std::string _name; + const DirectoryIPtr _parent; + bool _destroyed; + Ice::Identity _id; + IceUtil::Mutex _m; + }; + + typedef IceUtil::Handle NodeIPtr; + + class FileI : virtual public Filesystem::File, virtual public NodeI + { + public: + virtual Filesystem::Lines read(const Ice::Current&); + virtual void write(const Filesystem::Lines&, const Ice::Current&); + virtual void destroy(const Ice::Current&); + + FileI(const Ice::ObjectAdapterPtr&, const std::string&, const DirectoryIPtr&); + + private: + Filesystem::Lines _lines; + }; + + typedef IceUtil::Handle FileIPtr; + + class DirectoryI : virtual public NodeI, virtual public Filesystem::Directory + { + public: + virtual Filesystem::NodeDescSeq list(const Ice::Current&); + virtual Filesystem::NodeDesc find(const std::string& name, const Ice::Current&); + Filesystem::FilePrx createFile(const ::std::string&, const Ice::Current&); + Filesystem::DirectoryPrx createDirectory(const ::std::string&, const Ice::Current&); + virtual void destroy(const Ice::Current&); + + DirectoryI(const Ice::ObjectAdapterPtr&, const std::string& = "/", const DirectoryIPtr& = 0); + void addChild(const ::std::string&, const NodeIPtr&); + + void addReapEntry(const ::std::string&); + + IceUtil::Mutex _lcMutex; + + private: + typedef ::std::map< ::std::string, NodeIPtr> Contents; + Contents _contents; + + typedef ::std::map > ReapMap; + static ReapMap _reapMap; + + static void reap(); + }; +} + +#endif diff --git a/cpp/demo/book/lifecycle/Grammar.y b/cpp/demo/book/lifecycle/Grammar.y new file mode 100644 index 00000000000..db4cc27f560 --- /dev/null +++ b/cpp/demo/book/lifecycle/Grammar.y @@ -0,0 +1,142 @@ +%{ + +// ********************************************************************** +// +// 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 + +#ifdef _MSC_VER +// I get these warnings from some bison versions: +// warning C4102: 'yyoverflowlab' : unreferenced label +# pragma warning( disable : 4102 ) +// warning C4065: switch statement contains 'default' but no 'case' labels +# pragma warning( disable : 4065 ) +#endif + +using namespace std; + +void +yyerror(const char* s) +{ + parser->error(s); +} + +%} + +%pure_parser + +%token TOK_HELP +%token TOK_EXIT +%token TOK_STRING +%token TOK_LIST +%token TOK_LIST_RECURSIVE +%token TOK_CREATE_FILE +%token TOK_CREATE_DIR +%token TOK_PWD +%token TOK_CD +%token TOK_CAT +%token TOK_WRITE +%token TOK_RM + +%% + +// ---------------------------------------------------------------------- +start +// ---------------------------------------------------------------------- +: commands +{ +} +| +{ +} +; + +// ---------------------------------------------------------------------- +commands +// ---------------------------------------------------------------------- +: commands command +{ +} +| command +{ +} +; + +// ---------------------------------------------------------------------- +command +// ---------------------------------------------------------------------- +: TOK_HELP ';' +{ + parser->usage(); +} +| TOK_EXIT ';' +{ + return 0; +} +| TOK_LIST +{ + parser->list(false); +} +| TOK_LIST_RECURSIVE +{ + parser->list(true); +} +| TOK_CREATE_FILE strings +{ + parser->createFile($2); +} +| TOK_CREATE_DIR strings +{ + parser->createDir($2); +} +| TOK_PWD +{ + parser->pwd(); +} +| TOK_CD TOK_STRING +{ + parser->cd($2.front()); +} +| TOK_CAT TOK_STRING +{ + parser->cat($2.front()); +} +| TOK_WRITE strings +{ + parser->write($2); +} +| TOK_RM strings +{ + parser->destroy($2); +} +| error ';' +{ + parser->usage(); + yyerrok; +} +| ';' +{ +} +; + +// ---------------------------------------------------------------------- +strings +// ---------------------------------------------------------------------- +: TOK_STRING strings +{ + $$ = $2; + $$.push_front($1.front()); +} +| TOK_STRING +{ + $$ = $1; +} +; + +%% diff --git a/cpp/demo/book/lifecycle/Makefile b/cpp/demo/book/lifecycle/Makefile new file mode 100644 index 00000000000..51cf3e77a1e --- /dev/null +++ b/cpp/demo/book/lifecycle/Makefile @@ -0,0 +1,50 @@ +# ********************************************************************** +# +# 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +CLIENT = client +SERVER = server + +TARGETS = $(CLIENT) $(SERVER) + +OBJS = Filesystem.o + +COBJS = Grammar.o \ + Scanner.o \ + Parser.o \ + Client.o \ + +SOBJS = FilesystemI.o \ + Server.o + +SRCS = $(OBJS:.o=.cpp) \ + $(COBJS:.o=.cpp) \ + $(SOBJS:.o=.cpp) + +SLICE_SRCS = Filesystem.ice + +include $(top_srcdir)/config/Make.rules + +CPPFLAGS := -I. $(READLINE_FLAGS) $(CPPFLAGS) +SLICE2CPPFLAGS := --ice $(SLICE2CPPFLAGS) + +$(CLIENT): $(OBJS) $(COBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(COBJS) $(LIBS) $(READLINE_LIBS) + +$(SERVER): $(OBJS) $(SOBJS) + rm -f $@ + $(CXX) $(LDFLAGS) -o $@ $(OBJS) $(SOBJS) $(DB_RPATH_LINK) $(LIBS) + +clean:: + -rm -f Grammar.cpp Grammar.h + -rm -f Scanner.cpp + +include .depend diff --git a/cpp/demo/book/lifecycle/Makefile.mak b/cpp/demo/book/lifecycle/Makefile.mak new file mode 100644 index 00000000000..aaa777324b4 --- /dev/null +++ b/cpp/demo/book/lifecycle/Makefile.mak @@ -0,0 +1,69 @@ +# ********************************************************************** +# +# 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. +# +# ********************************************************************** + +top_srcdir = ..\..\.. + +CLIENT = client.exe +SERVER = server.exe + +TARGETS = $(CLIENT) $(SERVER) + +OBJS = Filesystem.obj + +COBJS = Scanner.obj \ + Grammar.obj \ + Parser.obj \ + Client.obj + +SOBJS = FilesystemI.obj \ + Server.obj + +SRCS = $(OBJS:.obj=.cpp) \ + $(COBJS:.obj=.cpp) \ + $(SOBJS:.obj=.cpp) + +!include $(top_srcdir)/config/Make.rules.mak + +CPPFLAGS = -I. $(CPPFLAGS) -DWIN32_LEAN_AND_MEAN + +!if "$(CPP_COMPILER)" != "BCC2006" && "$(OPTIMIZE)" != "yes" +CPDBFLAGS = /pdb:$(CLIENT:.exe=.pdb) +SPDBFLAGS = /pdb:$(SERVER:.exe=.pdb) +!endif + +$(CLIENT): $(OBJS) $(COBJS) + $(LINK) $(LD_EXEFLAGS) $(CPDBFLAGS) $(SETARGV) $(OBJS) $(COBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + +$(SERVER): $(OBJS) $(SOBJS) + $(LINK) $(LD_EXEFLAGS) $(SPDBFLAGS) $(SETARGV) $(OBJS) $(SOBJS) $(PREOUT)$@ $(PRELIBS)$(LIBS) + @if exist $@.manifest echo ^ ^ ^ Embedding manifest using $(MT) && \ + $(MT) -nologo -manifest $@.manifest -outputresource:$@;#1 && del /q $@.manifest + +Scanner.cpp: Scanner.l + flex Scanner.l + -del /q $@ + echo #include "IceUtil/Config.h" > Scanner.cpp + type lex.yy.c >> Scanner.cpp + -del /q lex.yy.c + +Grammar.cpp Grammar.h: Grammar.y + -del /q Grammar.h Grammar.cpp + bison -dvt Grammar.y + move Grammar.tab.c Grammar.cpp + move Grammar.tab.h Grammar.h + -del /q Grammar.output + +clean:: + -del /q Filesystem.cpp Filesystem.h + -del /q Scanner.cpp Scanner.h + -del /q Grammar.cpp Grammar.h + +!include .depend diff --git a/cpp/demo/book/lifecycle/Parser.cpp b/cpp/demo/book/lifecycle/Parser.cpp new file mode 100644 index 00000000000..c62b8146ce6 --- /dev/null +++ b/cpp/demo/book/lifecycle/Parser.cpp @@ -0,0 +1,482 @@ +// ********************************************************************** +// +// 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 +#include + +#ifdef HAVE_READLINE +# include +# include +#endif + +using namespace std; +using namespace Filesystem; + +extern FILE* yyin; + +Parser* parser; + +Parser::Parser(const DirectoryPrx& root) +{ + _dirs.push_front(root); +} + +void +Parser::usage() +{ + cout << + "help Print this message.\n" + "pwd Print current directory (/ = root).\n" + "cd DIR Change directory (/ = root, .. = parent).\n" + "ls List current directory.\n" + "lr Recursively list current directory.\n" + "mkdir DIR [DIR...] Create directories DIR in current directory.\n" + "mkfile FILE [FILE...] Create files FILE in current directory.\n" + "rm NAME [NAME...] Delete directory or file NAME (rm * to delete all).\n" + "cat FILE List the contents of FILE.\n" + "write FILE [STRINGS] Write STRINGS into FILE.\n" + "exit, quit Exit this program.\n"; +} + +// Print the contents of directory "dir". If recursive is true, +// print in tree fashion. +// For files, show the contents of each file. The "depth" +// parameter is the current nesting level (for indentation). + +void +Parser::list(bool recursive) +{ + return list(_dirs.front(), recursive, 0); +} + +void +Parser::list(const DirectoryPrx& dir, bool recursive, int depth) +{ + string indent(depth++, '\t'); + + NodeDescSeq contents = dir->list(); + + for(NodeDescSeq::const_iterator i = contents.begin(); i != contents.end(); ++i) + { + DirectoryPrx dir = DirectoryPrx::checkedCast(i->proxy); + FilePrx file = FilePrx::uncheckedCast(i->proxy); + cout << indent << i->name << (dir ? " (directory)" : " (file)"); + if(dir && recursive) + { + if(recursive) + { + cout << ":" << endl; + list(dir, true, depth); + } + } + else + { + cout << endl; + } + } +} + +void +Parser::createFile(const std::list& names) +{ + DirectoryPrx dir = _dirs.front(); + + for(std::list::const_iterator i = names.begin(); i != names.end(); ++i) + { + if(*i == "..") + { + cout << "Cannot create a file named `..'" << endl; + continue; + } + + try + { + dir->createFile(*i); + } + catch(const NameInUse&) + { + cout << "`" << *i << "' exists already" << endl; + } + } +} + +void +Parser::createDir(const std::list& names) +{ + DirectoryPrx dir = _dirs.front(); + + for(std::list::const_iterator i = names.begin(); i != names.end(); ++i) + { + if(*i == "..") + { + cout << "Cannot create a file named `.'" << endl; + continue; + } + + try + { + dir->createDirectory(*i); + } + catch(const NameInUse&) + { + cout << "`" << *i << "' exists already" << endl; + } + } +} + +void +Parser::pwd() +{ + if(_dirs.size() == 1) + { + cout << "/"; + } + else + { + // COMPILERFIX: Should be const_reverse_iterator, but that won't compile with + // gcc because operator!= is missing. + // + std::list::reverse_iterator i = _dirs.rbegin(); + ++i; + while(i != _dirs.rend()) + { + cout << "/" << (*i)->name(); + ++i; + } + } + cout << endl; +} + +void +Parser::cd(const string& name) +{ + if(name == "/") + { + while(_dirs.size() > 1) + { + _dirs.pop_front(); + } + return; + } + + if(name == "..") + { + if(_dirs.size() > 1) + { + _dirs.pop_front(); + } + return; + } + + DirectoryPrx dir = _dirs.front(); + NodeDesc d; + try + { + d = dir->find(name); + } + catch(const NoSuchName&) + { + cout << "`" << name << "': no such directory" << endl; + return; + } + if(d.type == FileType) + { + cout << "`" << name << "': not a directory" << endl; + return; + } + _dirs.push_front(DirectoryPrx::uncheckedCast(d.proxy)); +} + +void +Parser::cat(const string& name) +{ + DirectoryPrx dir = _dirs.front(); + NodeDesc d; + try + { + d = dir->find(name); + } + catch(const NoSuchName&) + { + cout << "`" << name << "': no such file" << endl; + return; + } + if(d.type == DirType) + { + cout << "`" << name << "': not a file" << endl; + return; + } + FilePrx f = FilePrx::uncheckedCast(d.proxy); + Lines l = f->read(); + for(Lines::const_iterator i = l.begin(); i != l.end(); ++i) + { + cout << *i << endl; + } +} + +void +Parser::write(const std::list& args) +{ + DirectoryPrx dir = _dirs.front(); + string name = args.front(); + NodeDesc d; + try + { + d = dir->find(name); + } + catch(const NoSuchName&) + { + cout << "`" << name << "': no such file" << endl; + return; + } + if(d.type == DirType) + { + cout << "`" << name << "': not a file" << endl; + return; + } + FilePrx f = FilePrx::uncheckedCast(d.proxy); + + Lines l; + std::list::const_iterator i = args.begin(); + while(++i != args.end()) + { + l.push_back(*i); + } + f->write(l); +} + +void +Parser::destroy(const std::list& names) +{ + DirectoryPrx dir = _dirs.front(); + + for(std::list::const_iterator i = names.begin(); i != names.end(); ++i) + { + if(*i == "*") + { + NodeDescSeq nodes = dir->list(); + for(NodeDescSeq::iterator j = nodes.begin(); j != nodes.end(); ++j) + { + try + { + j->proxy->destroy(); + } + catch(const PermissionDenied& ex) + { + cout << "cannot remove `" << j->name << "': " << ex.reason << endl; + } + } + return; + } + else + { + NodeDesc d; + try + { + d = dir->find(*i); + } + catch(const NoSuchName&) + { + cout << "`" << *i << "': no such file or directory" << endl; + return; + } + try + { + d.proxy->destroy(); + } + catch(const PermissionDenied& ex) + { + cout << "cannot remove `" << *i << "': " << ex.reason << endl; + } + } + } +} + +void +Parser::getInput(char* buf, int& result, int maxSize) +{ + if(isatty(fileno(yyin))) + { +#ifdef HAVE_READLINE + + const char* prompt = parser->getPrompt(); + char* line = readline(const_cast(prompt)); + 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(getc(yyin)); + if(c == EOF) + { + if(line.size()) + { + line += '\n'; + } + break; + } + + line += c; + + if(c == '\n') + { + break; + } + } + + result = static_cast(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 = static_cast(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; +} + +const char* +Parser::getPrompt() +{ + assert(isatty(fileno(yyin))); + + if(_continue) + { + _continue = false; + return "(cont) "; + } + else + { + return "> "; + } +} + +void +Parser::error(const char* s) +{ + if(!isatty(fileno(yyin))) + { + cerr << _currentFile << ':' << _currentLine << ": " << s << endl; + _errors++; + } + else + { + cerr << "error: " << s << endl; + } +} + +void +Parser::error(const string& s) +{ + error(s.c_str()); +} + +void +Parser::warning(const char* s) +{ + if(!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(bool debug) +{ + extern int yydebug; + yydebug = debug ? 1 : 0; + + assert(!parser); + parser = this; + + _errors = 0; + yyin = stdin; + assert(yyin); + + _currentFile = ""; + _currentLine = 0; + _continue = false; + nextLine(); + + //_foundBooks.clear(); + //_current = _foundBooks.end(); + + int status = yyparse(); + if(_errors) + { + status = EXIT_FAILURE; + } + + parser = 0; + return status; +} diff --git a/cpp/demo/book/lifecycle/Parser.h b/cpp/demo/book/lifecycle/Parser.h new file mode 100644 index 00000000000..06891cd812b --- /dev/null +++ b/cpp/demo/book/lifecycle/Parser.h @@ -0,0 +1,96 @@ +// ********************************************************************** +// +// 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. +// +// ********************************************************************** + +#ifndef PARSER_H +#define PARSER_H + +#include +#include +#include +#include + +#ifdef _WIN32 +# include +# ifdef _MSC_VER +# define isatty _isatty +# define fileno _fileno +// '_isatty' : inconsistent dll linkage. dllexport assumed. +# pragma warning( disable : 4273 ) +# endif +#endif + +// +// Stuff for flex and bison +// + +#define YYSTYPE std::list +#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. + +// +// Newer bison versions allow to disable stack resizing by defining +// yyoverflow. +// +#define yyoverflow(a, b, c, d, e, f) yyerror(a) + +class Parser; +typedef IceUtil::Handle ParserPtr; + +class Parser : public IceUtil::SimpleShared +{ +public: + Parser(const Filesystem::DirectoryPrx&); + + void usage(); + void list(bool); + void list(const Filesystem::DirectoryPrx&, bool, int); + void createFile(const ::std::list< ::std::string>&); + void createDir(const ::std::list< ::std::string>&); + void pwd(); + void cd(const ::std::string&); + void cat(const ::std::string&); + void write(const ::std::list< ::std::string>&); + void destroy(const ::std::list< ::std::string>&); + + void getInput(char*, int&, int); + void nextLine(); + void continueLine(); + const char* getPrompt(); + + void error(const char*); + void error(const std::string&); + + void warning(const char*); + void warning(const std::string&); + + int parse(bool = false); + +private: + ::std::list _dirs; + + bool _continue; + int _errors; + int _currentLine; + std::string _currentFile; +}; + +extern Parser* parser; // The current parser for bison/flex + +#endif diff --git a/cpp/demo/book/lifecycle/README b/cpp/demo/book/lifecycle/README new file mode 100644 index 00000000000..c1cd9ec96f6 --- /dev/null +++ b/cpp/demo/book/lifecycle/README @@ -0,0 +1,11 @@ +This demo implements the file system with life cycle support. + +To run it, start the server in a window: + +$ server + +Then run the client in a separate window: + +$ client + +Type "help" at the client prompt to see a list of commands. diff --git a/cpp/demo/book/lifecycle/Scanner.l b/cpp/demo/book/lifecycle/Scanner.l new file mode 100644 index 00000000000..b3f9524eba5 --- /dev/null +++ b/cpp/demo/book/lifecycle/Scanner.l @@ -0,0 +1,284 @@ +%{ + +// ********************************************************************** +// +// 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 +#include + +#if defined(_MSC_VER) && defined(ICE_64) +// +// 'initializing' : conversion from '__int64' to 'int', possible loss of data +// Puts a pointer-difference into an int +// +# pragma warning( 4 : 4244 ) +#endif + +using namespace std; + +#define YY_INPUT(buf, result, maxSize) parser->getInput(buf, result, maxSize) + +%} + +WS [ \t\v\f\r] +NL [\n] + +%option noyywrap +%option never-interactive + +%% + +"//" { + // 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 TOK_HELP; +} + +"quit"|"exit" { + return TOK_EXIT; +} + +"ls" { + return TOK_LIST; +} + +"lr" { + return TOK_LIST_RECURSIVE; +} + +"mkfile" { + return TOK_CREATE_FILE; +} + +"mkdir" { + return TOK_CREATE_DIR; +} + +"pwd" { + return TOK_PWD; +} + +"cd" { + return TOK_CD; +} + +"cat" { + return TOK_CAT; +} + +"write" { + return TOK_WRITE; +} + +"rm" { + return TOK_RM; +} + +{WS}*(\\{WS}*{NL})? { + size_t len = strlen(yytext); + for(size_t i = 0; i < len; ++i) + { + if(yytext[i] == '\\') + { + parser->continueLine(); + } + else if(yytext[i] == '\n') + { + parser->nextLine(); + } + } +} + +{NL}|; { + size_t len = strlen(yytext); + for(size_t i = 0; i < len; ++i) + { + if(yytext[i] == '\n') + { + parser->nextLine(); + } + } + return ';'; +} + +\" { + // "..."-type strings + string s; + while(true) + { + char c = static_cast(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(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 TOK_STRING; +} + +\' { + // '...'-type strings + string s; + while(true) + { + char c = static_cast(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 TOK_STRING; +} + +. { + // Simple strings + string s; + s += yytext[0]; + while(true) + { + char c = static_cast(yyinput()); + if(c == EOF) + { + break; + } + else if(isspace(c) || c == ';') + { + unput(c); + break; + } + + s += c; + } + yylvalp->clear(); + yylvalp->push_back(s); + return TOK_STRING; +} + +%% diff --git a/cpp/demo/book/lifecycle/Server.cpp b/cpp/demo/book/lifecycle/Server.cpp new file mode 100644 index 00000000000..ec9131ff17c --- /dev/null +++ b/cpp/demo/book/lifecycle/Server.cpp @@ -0,0 +1,55 @@ +// ********************************************************************** +// +// 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 +#include + +using namespace std; +using namespace Filesystem; +using namespace FilesystemI; + +class FilesystemApp : virtual public Ice::Application { +public: + virtual int run(int, char * []) { + // Terminate cleanly on receipt of a signal + // + shutdownOnInterrupt(); + + // Create an object adapter. + // + Ice::ObjectAdapterPtr adapter = + communicator()->createObjectAdapterWithEndpoints( + "SimpleFilesystem", "default -p 10000"); + + // Create the root directory. + // + new DirectoryI(adapter); + + // All objects are created, allow client requests now. + // + adapter->activate(); + + // Wait until we are done + // + communicator()->waitForShutdown(); + if (interrupted()) { + cerr << appName() + << ": received signal, shutting down" << endl; + } + + return 0; + }; +}; + +int +main(int argc, char* argv[]) +{ + FilesystemApp app; + return app.main(argc, argv); +} -- cgit v1.2.3