• Main Page
  • Classes
  • Files
  • File List
  • File Members

gridfs.h

Go to the documentation of this file.
00001 
00005 /*--------------------------------------------------------------------*/
00006 /* gridfs.h                                                           */
00007 /* Author: Christopher Triolo                                         */
00008 /*--------------------------------------------------------------------*/
00009 
00010 #include "mongo.h"
00011 #include "bson.h"
00012 #include "platform_hacks.h"
00013 #include <stdio.h>
00014 #ifndef GRIDFS_INCLUDED
00015 #define GRIDFS_INCLUDED
00016 
00017 enum {DEFAULT_CHUNK_SIZE = 256 * 1024};
00018 
00019 typedef uint64_t gridfs_offset;
00020 
00021 /* A GridFS contains a db connection, a root database name, and an
00022    optional prefix */
00023 typedef struct {
00024   /* The client to db-connection. */
00025   mongo_connection* client;
00026   /* The root database name */
00027   const char* dbname;
00028   /* The prefix of the GridFS's collections, default is NULL */
00029   const char* prefix;
00030   /* The namespace where the file's metadata is stored */
00031   const char* files_ns;
00032   /* The namespace where the files's data is stored in chunks */
00033   const char* chunks_ns;
00034 
00035 } gridfs;
00036 
00037 /* The state of a gridfile. This is used for incrementally writing buffers
00038  * to a single GridFS file.
00039  */
00040 
00041 /* A GridFile contains the GridFS it is located in and the file
00042    metadata */
00043 typedef struct {
00044   /* The GridFS where the GridFile is located */
00045   gridfs* gfs;
00046   /* The GridFile's bson object where all its metadata is located */
00047   bson* meta;
00048   /* The position is the offset in the file */
00049   gridfs_offset pos;
00050   /* The files_id of the gridfile */
00051   bson_oid_t id;
00052   /* The name of the gridfile as a string */
00053   const char* remote_name;
00054   /* The gridfile's content type */
00055   const char* content_type;
00056   /* The length of this gridfile */
00057   gridfs_offset length;
00058   /* The number of the current chunk being written to */
00059   int chunk_num;
00060   /* A buffer storing data still to be written to chunks */
00061   char* pending_data;
00062   /* Length of pending data */
00063   int pending_len;
00064 
00065 } gridfile;
00066 
00067 /*--------------------------------------------------------------------*/
00068 
00076 int gridfs_init(mongo_connection* client, const char* dbname,
00077   const char* prefix, gridfs* gfs);
00078 
00081 void gridfs_destroy( gridfs* gfs );
00082 
00089 void gridfile_writer_init( gridfile* gfile, gridfs* gfs, const char* remote_name,
00090     const char* content_type );
00091 
00098 void gridfile_write_buffer( gridfile* gfile, const char* data,
00099     gridfs_offset length );
00100 
00107 bson gridfile_writer_done( gridfile* gfile );
00108 
00117 bson gridfs_store_buffer(gridfs* gfs, const char* data, gridfs_offset length,
00118     const char* remotename,
00119     const char * contenttype);
00120 
00128 bson gridfs_store_file(gridfs* gfs, const char* filename,
00129          const char* remotename, const char* contenttype);
00130 
00135 void gridfs_remove_filename(gridfs* gfs, const char* filename);
00136 
00143 int gridfs_find_query(gridfs* gfs, bson* query, gridfile* gfile );
00144 
00152 int gridfs_find_filename(gridfs* gfs, const char *filename,
00153          gridfile* gfile);
00154 
00155 /*--------------------------------------------------------------------*/
00156 
00157 
00164 int gridfile_init(gridfs* gfs, bson* meta, gridfile* gfile);
00165 
00169 void gridfile_destroy(gridfile* gfile);
00170 
00174 int gridfile_exists(gridfile* gfile);
00175 
00180 const char * gridfile_get_filename(gridfile* gfile);
00181 
00186 int gridfile_get_chunksize(gridfile* gfile);
00187 
00192 gridfs_offset gridfile_get_contentlength(gridfile* gfile);
00193 
00199 const char* gridfile_get_contenttype(gridfile* gfile);
00200 
00205 bson_date_t gridfile_get_uploaddate(gridfile* gfile);
00206 
00211 const char* gridfile_get_md5(gridfile* gfile);
00212 
00219 const char *gridfile_get_field(gridfile* gfile,
00220                                  const char* name);
00221 
00228 bson_bool_t gridfile_get_boolean(gridfile* gfile,
00229                                  const char* name);
00230 
00236 bson gridfile_get_metadata(gridfile* gfile);
00237 
00242 int gridfile_get_numchunks(gridfile* gfile);
00243 
00248 bson gridfile_get_chunk(gridfile* gfile, int n);
00249 
00256 mongo_cursor* gridfile_get_chunks(gridfile* gfile, int start, int size);
00257 
00262 gridfs_offset gridfile_write_file(gridfile* gfile, FILE* stream);
00263 
00273 gridfs_offset gridfile_read(gridfile* gfile, gridfs_offset size, char* buf);
00274 
00282 gridfs_offset gridfile_seek(gridfile* gfile, gridfs_offset offset);
00283 
00284 #endif

Generated on Wed May 18 2011 11:22:49 for MongoDBCDriver by  doxygen 1.7.1