ICE 3.4.2
[php5-ice-freebsdport.git] / cpp / demo / book / simple_filesystem / FilesystemI.cpp
blob3e5526adac0cb6810676724aad5ba092da580b1e
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 #include <IceUtil/IceUtil.h>
11 #include <FilesystemI.h>
13 using namespace std;
15 // Slice Node::name() operation
17 std::string
18 Filesystem::NodeI::name(const Ice::Current&)
20 return _name;
23 // NodeI constructor
25 Filesystem::NodeI::NodeI(const Ice::CommunicatorPtr& communicator, const string& name, const DirectoryIPtr& parent) :
26 _name(name), _parent(parent)
28 // Create an identity. The root directory has the fixed identity "RootDir"
29 if(parent)
31 _id.name = IceUtil::generateUUID();
33 else
35 _id.name = "RootDir";
39 // NodeI activate() member function
41 void
42 Filesystem::NodeI::activate(const Ice::ObjectAdapterPtr& a)
44 NodePrx thisNode = NodePrx::uncheckedCast(a->add(this, _id));
45 if(_parent)
47 _parent->addChild(thisNode);
51 // Slice File::read() operation
53 Filesystem::Lines
54 Filesystem::FileI::read(const Ice::Current&)
56 return _lines;
59 // Slice File::write() operation
61 void
62 Filesystem::FileI::write(const Filesystem::Lines& text, const Ice::Current&)
64 _lines = text;
67 // FileI constructor
69 Filesystem::FileI::FileI(const Ice::CommunicatorPtr& communicator, const string& name, const DirectoryIPtr& parent) :
70 NodeI(communicator, name, parent)
74 // Slice Directory::list() operation
76 Filesystem::NodeSeq
77 Filesystem::DirectoryI::list(const Ice::Current& c)
79 return _contents;
82 // DirectoryI constructor
84 Filesystem::DirectoryI::DirectoryI(const Ice::CommunicatorPtr& communicator, const string& name,
85 const DirectoryIPtr& parent) :
86 NodeI(communicator, name, parent)
90 // addChild is called by the child in order to add
91 // itself to the _contents member of the parent
93 void
94 Filesystem::DirectoryI::addChild(const NodePrx& child)
96 _contents.push_back(child);