Browse files

Start to deal with the clusterfuck that is C++

  • Loading branch information...
1 parent c7a0f59 commit 8012501ef25d5d564fc022fb2cecbace89603026 @paulcbetts committed May 1, 2010
Showing with 32 additions and 13 deletions.
  1. +3 −2 src/Makefile.am
  2. +27 −5 src/gridfs_wrapper.cpp
  3. +1 −3 src/gridfs_wrapper.h
  4. +1 −1 src/mongodbfs.h
  5. +0 −2 src/stdafx.h
View
5 src/Makefile.am
@@ -2,15 +2,16 @@
INCLUDES = \
-DFUSE_USE_VERSION=27 \
- -I. -Wall -Werror \
+ -I. -Wall -I/usr/local/include \
$(MONGODBFS_CFLAGS)
bin_PROGRAMS = mongodbfs
AM_CFLAGS = -std=c99 -g -O0
## HACK HACK HACK: We're adding libevent here, without ever actually checking for it!
-mongodbfs_LDADD = $(MONGODBFS_LIBS) -lgthread-2.0 -lpthread \
+mongodbfs_LDADD = $(MONGODBFS_LIBS) -lgthread-2.0 -lpthread -lmongoclient \
+ -lboost_system-mt -lboost_thread-mt -lboost_program_options-mt -lboost_filesystem-mt \
#-levent
mongodbfs_SOURCES = \
View
32 src/gridfs_wrapper.cpp
@@ -21,17 +21,39 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-extern "C" {
#include "stdafx.h"
#include "gridfs_wrapper.h"
-#include "config.h"
-}
-mongo_conn_t mongodb_conn_create(const char* host, int port)
+#include <mongo/client/dbclient.h>
+#include <mongo/client/gridfs.h>
+#include <mongo/client/connpool.h>
+
+using namespace mongo;
+
+struct MongoConnection {
+ DBClientConnection db;
+ auto_ptr<GridFS> fs;
+};
+
+mongo_conn_t mongodb_conn_create(const char* host, int port, const char* db)
{
- return NULL;
+ gchar* conn_str;
+ struct MongoConnection* ret = new MongoConnection();
+ string dontcare;
+
+ conn_str = g_strdup_printf("%s:%d", host, port);
+ if (ret->db.connect( string(conn_str), dontcare)) {
+ g_free(conn_str);
+ delete ret;
+ return NULL;
+ }
+
+ ret->fs = auto_ptr<GridFS>(new GridFS(ret->db, string(db)));
+ g_free(conn_str);
+ return ret;
}
void mongodb_conn_free(mongo_conn_t conn)
{
+ delete conn;
}
View
4 src/gridfs_wrapper.h
@@ -24,9 +24,7 @@
#ifndef _GRIDFS_WRAPPER_H
#define _GRIDFS_WRAPPER_H
-#include "stdafx.h"
-
-typedef void* mongo_conn_t;
+typedef struct MongoConnection* mongo_conn_t;
mongo_conn_t mongodb_conn_create(const char* host, int port);
void mongodb_conn_free(mongo_conn_t conn);
View
2 src/mongodbfs.h
@@ -37,7 +37,7 @@ struct mongodbfs_mount {
/* File descriptor table */
GHashTable* fd_table;
GHashTable* fd_table_byname;
- uint next_fd;
+ gint next_fd_atomic;
GStaticRWLock fd_table_rwlock;
gint quitflag_atomic;
View
2 src/stdafx.h
@@ -39,6 +39,4 @@
#include <glib.h>
-#include "config.h"
-
#endif

0 comments on commit 8012501

Please sign in to comment.