#include <string>
#include <list>
#include <map>
+#include <tr1/memory>
#include <vector>
#include "buffer.h"
class Context;
class AioCompletionImpl;
class IoCtxImpl;
+class ObjListCtx;
namespace librados
{
class ObjectIterator : public std::iterator <std::forward_iterator_tag, std::string> {
public:
static const ObjectIterator __EndObjectIterator;
- ObjectIterator(rados_list_ctx_t ctx_);
+ ObjectIterator(ObjListCtx *ctx_);
~ObjectIterator();
bool operator==(const ObjectIterator& rhs) const;
bool operator!=(const ObjectIterator& rhs) const;
const std::string& operator*() const;
ObjectIterator &operator++(); // Preincrement
ObjectIterator operator++(int); // Postincrement
+ friend class IoCtx;
private:
void get_next();
- rados_list_ctx_t ctx;
- bufferlist *bl;
+ std::tr1::shared_ptr < ObjListCtx > ctx;
std::string cur_obj;
};
}
};
+struct ObjListCtx {
+ IoCtxImpl *ctx;
+ Objecter::ListContext *lc;
+
+ ObjListCtx(IoCtxImpl *c, Objecter::ListContext *l) : ctx(c), lc(l) {}
+ ~ObjListCtx() {
+ delete lc;
+ }
+};
+
class RadosClient : public Dispatcher
{
OSDMap osdmap;
int connect();
void shutdown();
- struct ListCtx {
- IoCtxImpl *ctx;
- Objecter::ListContext *lc;
-
- ListCtx(IoCtxImpl *c, Objecter::ListContext *l) : ctx(c), lc(l) {}
- ~ListCtx() {
- delete lc;
- }
- };
-
-
int lookup_pool(const char *name) {
int ret = osdmap.lookup_pg_pool_name(name);
if (ret < 0)
///////////////////////////// ObjectIterator /////////////////////////////
librados::ObjectIterator::
-ObjectIterator(rados_list_ctx_t ctx_)
+ObjectIterator(ObjListCtx *ctx_)
: ctx(ctx_)
{
}
librados::ObjectIterator::
~ObjectIterator()
{
- if (ctx) {
- rados_objects_list_close(ctx);
- ctx = NULL;
- }
+ ctx.reset();
}
bool librados::ObjectIterator::
operator==(const librados::ObjectIterator& rhs) const {
- return (ctx == rhs.ctx);
+ return (ctx.get() == rhs.ctx.get());
}
bool librados::ObjectIterator::
operator!=(const librados::ObjectIterator& rhs) const {
- return (ctx != rhs.ctx);
+ return (ctx.get() != rhs.ctx.get());
}
const std::string& librados::ObjectIterator::
get_next()
{
const char *entry;
- int ret = rados_objects_list_next(ctx, &entry);
+ int ret = rados_objects_list_next(ctx.get(), &entry);
if (ret == -ENOENT) {
- rados_objects_list_close(ctx);
- ctx = NULL;
+ ctx.reset();
*this = __EndObjectIterator;
return;
}
{
rados_list_ctx_t listh;
rados_objects_list_open(io_ctx_impl, &listh);
- return ObjectIterator(listh);
+ ObjectIterator iter((ObjListCtx*)listh);
+ iter.get_next();
+ return iter;
}
const librados::ObjectIterator& librados::IoCtx::
Objecter::ListContext *h = new Objecter::ListContext;
h->pool_id = ctx->poolid;
h->pool_snap_seq = ctx->snap_seq;
- *listh = (void *)new RadosClient::ListCtx(ctx, h);
+ *listh = (void *)new ObjListCtx(ctx, h);
return 0;
}
extern "C" void rados_objects_list_close(rados_list_ctx_t h)
{
- RadosClient::ListCtx *lh = (RadosClient::ListCtx *)h;
+ ObjListCtx *lh = (ObjListCtx *)h;
delete lh;
}
extern "C" int rados_objects_list_next(rados_list_ctx_t listctx, const char **entry)
{
- RadosClient::ListCtx *lh = (RadosClient::ListCtx *)listctx;
+ ObjListCtx *lh = (ObjListCtx *)listctx;
Objecter::ListContext *h = lh->lc;
int ret;
}
};
+void testradospp_milestone(void)
+{
+ cout << "*** press enter to continue ***" << std::endl;
+ getchar();
+}
+
int main(int argc, const char **argv)
{
Rados rados;
}
cout << "rados_initialize completed" << std::endl;
- cout << "*** press enter to continue ***" << std::endl;
- getchar();
+ testradospp_milestone();
time_t tm;
bufferlist bl, bl2, blf;
r = io_ctx.watch(oid, objver, &handle, &wc);
cout << "io_ctx.watch returned " << r << std::endl;
- cout << "*** press enter to continue ***" << std::endl;
- getchar();
+ testradospp_milestone();
io_ctx.set_notify_timeout(7);
r = io_ctx.notify(oid, objver);
cout << "io_ctx.notify returned " << r << std::endl;
- cout << "*** press enter to continue ***" << std::endl;
- getchar();
+ testradospp_milestone();
r = io_ctx.notify(oid, objver);
cout << "io_ctx.notify returned " << r << std::endl;
- cout << "*** press enter to continue ***" << std::endl;
- getchar();
+ testradospp_milestone();
r = io_ctx.unwatch(oid, handle);
cout << "io_ctx.unwatch returned " << r << std::endl;
cout << "*** press enter to continue ***" << std::endl;
- getchar();
+ testradospp_milestone();
r = io_ctx.notify(oid, objver);
cout << "io_ctx.notify returned " << r << std::endl;
cout << "*** press enter to continue ***" << std::endl;
- getchar();
+ testradospp_milestone();
io_ctx.set_assert_version(objver);
r = io_ctx.write(oid, bl, bl.length() - 1, 0);
cout << "io_ctx.write returned " << r << std::endl;
- exit(0);
r = io_ctx.write(oid, bl, bl.length() - 2, 0);
cout << "io_ctx.write returned " << r << std::endl;
r = io_ctx.write(oid, bl, bl.length() - 3, 0);
cout << s << std::endl;
}
+ cout << "iterating over objects..." << std::endl;
+ int num_objs = 0;
for (ObjectIterator iter = io_ctx.objects_begin();
- iter != io_ctx.objects_end(); iter++) {
- cout << *iter << std::endl;
+ iter != io_ctx.objects_end(); ++iter) {
+ num_objs++;
+ cout << "'" << *iter << "'" << std::endl;
}
+ cout << "iterated over " << num_objs << " objects." << std::endl;
map<string, bufferlist> attrset;
io_ctx.getxattrs(oid, attrset);