summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2002-04-04 01:14:48 +0000
committerMarc Laukien <marc@zeroc.com>2002-04-04 01:14:48 +0000
commit19c25b1c91eca6009439f7d8b2f9b81ea47444e0 (patch)
treeac5f2dda561f2e475c2f2528b8f78be1571d390d /cpp/src
parentmore IcePatch stuff (diff)
downloadice-19c25b1c91eca6009439f7d8b2f9b81ea47444e0.tar.bz2
ice-19c25b1c91eca6009439f7d8b2f9b81ea47444e0.tar.xz
ice-19c25b1c91eca6009439f7d8b2f9b81ea47444e0.zip
more IcePatch stuff
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IcePatch/Client.cpp56
-rw-r--r--cpp/src/IcePatch/NodeI.cpp84
2 files changed, 88 insertions, 52 deletions
diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp
index 4fb7e347a67..1adc3b93fe4 100644
--- a/cpp/src/IcePatch/Client.cpp
+++ b/cpp/src/IcePatch/Client.cpp
@@ -24,8 +24,7 @@ public:
void usage();
virtual int run(int, char*[]);
- void printNode(const NodePrx&);
- void printNodes(const Nodes&, const string&);
+ void printNodeDescSeq(const NodeDescSeq&, const string&);
};
};
@@ -96,49 +95,44 @@ IcePatch::Client::run(int argc, char* argv[])
//
ObjectPrx topObj = communicator()->stringToProxy("IcePatch/.:" + endpoints);
NodePrx top = NodePrx::checkedCast(topObj);
- printNode(top);
+ NodeDescPtr nodeDesc = top->describe();
+ NodeDescSeq nodeDescSeq;
+ nodeDescSeq.push_back(nodeDesc);
+ printNodeDescSeq(nodeDescSeq, "");
return EXIT_SUCCESS;
}
void
-IcePatch::Client::printNode(const NodePrx& node)
+IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& indent)
{
- string name = node->ice_getIdentity().name;
- string::size_type pos = name.rfind('/');
- if (pos != string::npos)
+ for (unsigned int i = 0; i < nodeDescSeq.size(); ++i)
{
- name.erase(0, pos + 1);
- }
-
- cout << name << endl;
-
- DirectoryPrx directory = DirectoryPrx::checkedCast(node);
- if (directory)
- {
- printNodes(directory->getNodes(), "");
- }
-}
-
-void
-IcePatch::Client::printNodes(const Nodes& nodes, const string& indent)
-{
- for (unsigned int i = 0; i < nodes.size(); ++i)
- {
- string name = nodes[i]->ice_getIdentity().name;
+ string name;
+ DirectoryDescPtr directoryDesc = DirectoryDescPtr::dynamicCast(nodeDescSeq[i]);
+ if (directoryDesc)
+ {
+ name = directoryDesc->directory->ice_getIdentity().name;
+ }
+ else
+ {
+ FileDescPtr fileDesc = FileDescPtr::dynamicCast(nodeDescSeq[i]);
+ assert(fileDesc);
+ name = fileDesc->file->ice_getIdentity().name;
+ }
+
string::size_type pos = name.rfind('/');
if (pos != string::npos)
{
name.erase(0, pos + 1);
}
-
- cout << indent << "+-" << name << endl;
- DirectoryPrx directory = DirectoryPrx::checkedCast(nodes[i]);
- if (directory)
+ cout << "+-" << name << endl;
+
+ if (directoryDesc)
{
string newIndent;
- if (i < nodes.size() - 1)
+ if (i < nodeDescSeq.size() - 1)
{
newIndent = indent + "| ";
}
@@ -147,7 +141,7 @@ IcePatch::Client::printNodes(const Nodes& nodes, const string& indent)
newIndent = indent + " ";
}
- printNodes(directory->getNodes(), newIndent);
+ printNodeDescSeq(directoryDesc->directory->getContents(), newIndent);
}
}
}
diff --git a/cpp/src/IcePatch/NodeI.cpp b/cpp/src/IcePatch/NodeI.cpp
index 77deba89b7a..4a3c0ed1b7e 100644
--- a/cpp/src/IcePatch/NodeI.cpp
+++ b/cpp/src/IcePatch/NodeI.cpp
@@ -9,6 +9,9 @@
// **********************************************************************
#include <IcePatch/NodeI.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <dirent.h>
using namespace std;
@@ -55,14 +58,17 @@ IcePatch::DirectoryI::DirectoryI(const ObjectAdapterPtr& adapter) :
{
}
-Nodes
-IcePatch::DirectoryI::getNodes(const Ice::Current& current)
+NodeDescPtr
+IcePatch::DirectoryI::describe(const Ice::Current& current)
{
- //
- // No synchronization necessary, this servant is completely
- // stateless.
- //
+ DirectoryDescPtr desc = new DirectoryDesc;
+ desc->directory = DirectoryPrx::uncheckedCast(_adapter->createProxy(current.identity));
+ return desc;
+}
+NodeDescSeq
+IcePatch::DirectoryI::getContents(const Ice::Current& current)
+{
string path = normalizePath(current.identity.name);
struct dirent **namelist;
@@ -74,23 +80,56 @@ IcePatch::DirectoryI::getNodes(const Ice::Current& current)
throw ex;
}
- Nodes result;
+ NodeDescSeq result;
result.reserve(n - 2);
- Identity identity;
- identity.category = "IcePatch";
+ int i;
- while(n--)
+ try
{
- if (strcmp(namelist[n]->d_name, "..") != 0 && strcmp(namelist[n]->d_name, ".") != 0)
+ Identity identity;
+ identity.category = "IcePatch";
+
+ for (i = 0; i < n; ++i)
+ {
+ string name = namelist[i]->d_name;
+
+ if (name != ".." && name != ".")
+ {
+ identity.name = path + '/' + name;
+ NodePrx node = NodePrx::uncheckedCast(_adapter->createProxy(identity));
+ try
+ {
+ result.push_back(node->describe());
+ }
+ catch (const ObjectNotExistException&)
+ {
+ //
+ // Ignore. This can for example happen if the node
+ // locator cannot call stat() on the file.
+ //
+ }
+ }
+ }
+
+ for (i = 0; i < n; ++i)
{
- identity.name = path + '/' + namelist[n]->d_name;
- result.push_back(NodePrx::uncheckedCast(_adapter->createProxy(identity)));
+ free(namelist[i]);
}
- free(namelist[n]);
+ free(namelist);
+
}
- free(namelist);
+ catch (...)
+ {
+ for (i = 0; i < n; ++i)
+ {
+ free(namelist[i]);
+ }
+ free(namelist);
+ throw;
+ }
+
return result;
}
@@ -98,15 +137,18 @@ IcePatch::FileI::FileI(const ObjectAdapterPtr& adapter) :
NodeI(adapter)
{
}
+
+NodeDescPtr
+IcePatch::FileI::describe(const Ice::Current& current)
+{
+ FileDescPtr desc = new FileDesc;
+ desc->file = FilePrx::uncheckedCast(_adapter->createProxy(current.identity));
+ return desc;
+}
+
ByteSeq
IcePatch::FileI::getBytes(Int startPos, Int howMuch, const Ice::Current& current)
{
- //
- // No synchronization necessary, this servant is completely
- // stateless.
- //
-
string path = normalizePath(current.identity.name);
-
return ByteSeq();
}