--- /dev/null
+#include <cstring>
+#include <cstdio>
+#include <iostream>
+#include <dmlite/cpp/dmlite.h>
+#include <dmlite/cpp/catalog.h>
+#include <dmlite/cpp/poolmanager.h>
+
+#define DMLITE_DEFAULT_CONF "/etc/dmlite.conf"
+
+int main(int argc, char *argv[]) {
+ dmlite::PluginManager manager;
+ std::string conf = DMLITE_DEFAULT_CONF;
+
+ if (argc < 3) {
+ std::cout << "Usage: " << argv[0] << " [ DMLITE_CONFIGFILE [ s | d | h | (r|w|c) [PATH] ] ]" << std::endl;
+ std::cout << " s ... stat" << std::endl;
+ std::cout << " d ... opendir/readdir" << std::endl;
+ std::cout << " r ... read" << std::endl;
+ std::cout << " h ... chdir" << std::endl;
+ std::cout << " w ... whereToWrite" << std::endl;
+ std::cout << " c ... create" << std::endl;
+ }
+
+ if (argc >= 2) conf = argv[1];
+ std::cout << "Config file: " << conf << std::endl;
+
+ try {
+ manager.loadConfiguration(conf);
+ } catch (dmlite::DmException& e) {
+ std::cout << "Could not load the configuration file." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return 1;
+ }
+
+ dmlite::StackInstance stack(&manager);
+
+ // Set security credentials
+
+ dmlite::SecurityCredentials creds;
+
+ creds.clientName = std::string("/C=UG/L=Tropic/O=Utopia/OU=Relaxation/CN=dpmtest");
+ creds.remoteAddress = std::string("127.0.0.1");
+ try {
+ stack.setSecurityCredentials(creds);
+ } catch (dmlite::DmException& e) {
+ std::cout << "Could not set the credentials." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return 1;
+ }
+
+ // Action
+ dmlite::Catalog* catalog = stack.getCatalog();
+ dmlite::PoolManager* poolManager = stack.getPoolManager();
+
+ if (argc < 3) return 0;
+
+ switch (argv[2][0]) {
+ case 's':
+ try {
+ dmlite::ExtendedStat xstat = catalog->extendedStat("pokus");
+ std::cout << "Success!" << std::endl;
+ }
+ catch (dmlite::DmException& e) {
+ std::cout << "Could not stat the file." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return e.code();
+ }
+ break;
+
+ case 'd':
+
+ try {
+ std::string path;
+ dmlite::Directory* dir;
+
+ path="/tmp/pokus";
+ if (argc >= 4) path = argv[3];
+
+ dmlite::ExtendedStat* xstat;
+
+ dir = catalog->openDir(path);
+
+ std::cout << "Content of the directory " << path << std::endl;
+ printf(" %6s %5s %5s %5s %s\n", "Mode", "UID", "GID", "Size", "Name");
+ while ((xstat = catalog->readDirx(dir)) != NULL) {
+ printf(" %06o %5d %5d %5zu %s\n", xstat->stat.st_mode, xstat->stat.st_uid, xstat->stat.st_gid, xstat->stat.st_size, xstat->name.c_str());
+ //std::cout << '\t' << xstat->name << std::endl;
+ }
+
+ catalog->closeDir(dir);
+ std::cout << "Success!" << std::endl;
+#if 0
+ struct dirent *ent;
+
+ dir = catalog->openDir(path);
+
+ std::cout << "Content of the directory " << path << std::endl;
+ while ((ent = catalog->readDir(dir)) != NULL) {
+ std::cout << '\t' << ent->d_name << std::endl;
+ }
+
+ catalog->closeDir(dir);
+ std::cout << "Success!" << std::endl;
+#endif
+ }
+ catch (dmlite::DmException& e) {
+ std::cout << "Could not open the directory." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return e.code();
+ }
+ break;
+
+ case 'h':
+ try {
+ std::string d;
+
+ d = catalog->getWorkingDir();
+ std::cout << "Current directory before: '" << d << "'" << std::endl;
+
+ catalog->changeDir("/tmp");
+
+ d = catalog->getWorkingDir();
+ std::cout << "Current directory after: '" << d << "'" << std::endl;
+ } catch (dmlite::DmException& e) {
+ std::cout << "Error." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return e.code();
+ }
+ break;
+
+ case 'r':
+ try {
+ std::string path;
+ dmlite::Location loc;
+ dmlite::Location::const_iterator i;
+ unsigned n;
+
+ path = "/tmp/pokus";
+ //path = "/dpm/zcu.cz/home/vo.org/pokus/xMaster_Splinters_Door2.jpg";
+ if (argc >= 4) path = argv[3];
+ loc = poolManager->whereToRead(path);
+
+ for (i = loc.begin(), n = 0; i != loc.end(); i++, n++) {
+ std::cout << "Chunk " << n << ": " << i->url.toString() << " (" << i->offset << '-' << i->offset + i->size << ")" << std::endl;
+ }
+ } catch (dmlite::DmException& e) {
+ std::cout << "Could not read." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return e.code();
+ }
+ break;
+
+ case 'w':
+ try {
+ std::string path;
+ dmlite::Location loc;
+ dmlite::Location::const_iterator i;
+ unsigned n;
+
+ path = "/tmp/pokus";
+ //path = "/dpm/zcu.cz/home/vo.org/pokus/xMaster_Splinters_Door2.jpg";
+ if (argc >= 4) path = argv[3];
+ loc = poolManager->whereToWrite(path);
+
+ for (i = loc.begin(), n = 0; i != loc.end(); i++, n++) {
+ std::cout << "Chunk " << n << ": " << i->url.toString() << " (" << i->offset << '-' << i->offset + i->size << ")" << std::endl;
+ }
+ } catch (dmlite::DmException& e) {
+ std::cout << "Could not write." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return e.code();
+ }
+ break;
+
+ case 'c':
+ try {
+ std::string path;
+
+ path = "/tmp/pokus";
+ if (argc >= 4) path = argv[3];
+ catalog->create(path, 0644);
+ } catch (dmlite::DmException& e) {
+ std::cout << "Could not create." << std::endl
+ << "Reason: " << e.what() << std::endl;
+ return e.code();
+ }
+ break;
+ }
+
+// delete catalog;
+// delete poolManager;
+
+ return 0;
+}