hello-world/include/db.h File Reference

#include <glib.h>
#include <libermetadb/ermetadb.h>
Include dependency graph for hello-world/include/db.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  thumbType

Defines

#define IN
#define OUT
#define INOUT

Functions

erMetadb open_database (const char *IN dir)
 Opens metadata database in directory.
void close_database (erMetadb IN db)
 Closes an open metadata database in directory.
gboolean load_file_metadata (erMetadb IN db, const gchar *IN filepath, const gchar *IN filename, GString *OUT title, GString *OUT author, thumbType *OUT small, thumbType *OUT medium)
 Loads the file metadata from database.
gboolean save_file_metadata (erMetadb IN db, const gchar *IN filepath, const gchar *IN filename, GString *IN title, GString *IN author, thumbType *IN small, thumbType *IN medium)
 Saves the file metadata to database.
void pixbuf_draw_rectangle (GdkPixbuf *pixbuf, gint xx, gint yy, gint ww, gint hh, gint color)
 Draw a rectangle border in a pixbuf.
gboolean pixbuf_to_blob (GdkPixbuf *IN pixbuf, gchar **OUT buffer, gsize *OUT buf_size)
 Converts a GdkPixbuf* to a BLOB buffer.

Define Documentation

#define IN

File Name : db.h

Description: Metadb interface functions Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Definition at line 54 of file hello-world/include/db.h.

#define INOUT

Definition at line 56 of file hello-world/include/db.h.

#define OUT

Definition at line 55 of file hello-world/include/db.h.


Function Documentation

void close_database ( erMetadb IN  db  ) 

Closes an open metadata database in directory.

---------------------------------------------------------------------------

Name : close_database

Parameters:
db pointer to a valid erMetadb object
Returns:
--

--------------------------------------------------------------------------

Definition at line 102 of file hello-world/src/db.c.

References ermetadb_close(), and sync().

00103 {
00104     g_assert ( NULL != db );
00105     
00106     ermetadb_close(db);
00107     // explicit sync since ermetadb_close_database does not flush to disk
00108     sync();
00109 }

Here is the call graph for this function:

gboolean load_file_metadata ( erMetadb IN  db,
const gchar *IN  filepath,
const gchar *IN  filename,
GString *OUT  title,
GString *OUT  author,
thumbType *OUT  small,
thumbType *OUT  medium 
)

Loads the file metadata from database.

---------------------------------------------------------------------------

Name : load_file_metadata

Parameters:
db pointer to a valid erMetadb object
filepath filename for which to load metadata
filename filename for which to load metadata
title pointer to GString to store the title NULL -> title should not be retreived
author pointer to GString to store the author NULL -> author should not be retreived
Returns:
FALSE on failure, TRUE on success

--------------------------------------------------------------------------

Definition at line 112 of file hello-world/src/db.c.

References ER_OK, ermetadb_global_get_file(), ERRORPRINTF, FILE_AUTHOR, FILE_TITLE, METADATA_BLOB, METADATA_NULL, metadata_table_add_column(), metadata_table_find_column(), metadata_table_free, metadata_table_get_cell(), metadata_table_new(), METADATA_TEXT, THUMBNAIL_COLUMNS, THUMBNAIL_MEDIUM, THUMBNAIL_SMALL, metadata_cell::type, metadata_cell::v_blob, metadata_cell::v_text, and metadata_cell::value.

Referenced by do_example_db_actions().

00119 {
00120     g_assert(db != NULL);
00121     g_assert(filename != NULL);
00122 
00123     metadata_table* name_table = metadata_table_new();
00124     g_return_val_if_fail( NULL != name_table, FALSE);
00125 
00126     // add columns, caller is owner of OUT parameters
00127     if (title   ) { metadata_table_add_column(name_table, FILE_TITLE       ); }
00128     if (author  ) { metadata_table_add_column(name_table, FILE_AUTHOR      ); }
00129     if (small   ) { metadata_table_add_column(name_table, THUMBNAIL_COLUMNS[THUMBNAIL_SMALL]);  }
00130     if (medium  ) { metadata_table_add_column(name_table, THUMBNAIL_COLUMNS[THUMBNAIL_MEDIUM]); }
00131 
00132     // query
00133     metadata_table* results_table = NULL; // must be NULL, created by function below
00134     int rc = ermetadb_global_get_file(db, filepath, filename, name_table, &results_table);
00135 
00136     if (rc != ER_OK)
00137     {
00138         ERRORPRINTF("ermetadb_get_file_metadata() returns [%d]", rc);
00139         metadata_table_free(name_table);
00140         metadata_table_free(results_table);
00141         return FALSE;
00142     }
00143 
00144     if (title) 
00145     {
00146         // Get title.
00147         const char *column = FILE_TITLE;
00148         int index = metadata_table_find_column(results_table, column);
00149         if (index >= 0)
00150         {
00151             const metadata_cell *cell = metadata_table_get_cell(results_table, index);
00152 
00153             if (cell && cell->type == METADATA_TEXT)
00154             {
00155                 g_string_assign(title, cell->value.v_text->str );
00156             }
00157         }
00158         else
00159         {
00160             ERRORPRINTF("Cannot find column %s", column);
00161         }
00162     }
00163 
00164     if (author)
00165     {
00166         // get author
00167         const char* column = FILE_AUTHOR;
00168         int index = metadata_table_find_column(results_table, column);
00169         if (index >= 0)
00170         {
00171             const metadata_cell *cell = metadata_table_get_cell(results_table, index);
00172 
00173             if (cell && cell->type == METADATA_TEXT)
00174             {
00175                 g_string_assign(author, cell->value.v_text->str );
00176             }
00177         }
00178         else
00179         {
00180             ERRORPRINTF("Cannot find column %s", column);
00181         }
00182     }
00183 
00184     if (small)
00185     {
00186         // get file thumbnail (medium)
00187         const char* column = THUMBNAIL_COLUMNS[THUMBNAIL_SMALL];
00188         int index = metadata_table_find_column(results_table, column);
00189         if (index >= 0)
00190         {
00191             const metadata_cell *cell = metadata_table_get_cell(results_table, index);
00192 
00193             if (cell && cell->type != METADATA_BLOB)
00194             {
00195                 if (cell->type != METADATA_NULL) {
00196                     ERRORPRINTF("illegal cell type [%d] for thumbnail", cell->type);
00197                 }
00198                 small->data = NULL ;
00199                 small->size = 0;
00200             }
00201             else {
00202                 small->size = cell->value.v_blob.len;
00203                 memcpy((guchar*) small->data, (guchar*) cell->value.v_blob.data, small->size);
00204             }
00205         }
00206         else
00207         {
00208             ERRORPRINTF("Cannot find column %s", column);
00209         }
00210     }
00211 
00212     if (medium)
00213     {
00214         // get file thumbnail (medium)
00215         const char* column = THUMBNAIL_COLUMNS[THUMBNAIL_MEDIUM];
00216         int index = metadata_table_find_column(results_table, column);
00217         if (index >= 0)
00218         {
00219             const metadata_cell *cell = metadata_table_get_cell(results_table, index);
00220 
00221             if (cell && cell->type != METADATA_BLOB)
00222             {
00223                 if (cell->type != METADATA_NULL) {
00224                     ERRORPRINTF("illegal cell type [%d] for thumbnail", cell->type);
00225                 }
00226                 medium->data = NULL ;
00227                 medium->size = 0;
00228             }
00229             else {
00230                 medium->size = cell->value.v_blob.len;
00231                 memcpy((guchar*) medium->data, (guchar*) cell->value.v_blob.data, medium->size);
00232             }
00233         }
00234         else
00235         {
00236             ERRORPRINTF("Cannot find column %s", column);
00237         }
00238     }
00239 
00240     // clean up
00241     metadata_table_free(name_table);
00242     metadata_table_free(results_table);
00243 
00244     return TRUE;
00245 }

Here is the call graph for this function:

Here is the caller graph for this function:

erMetadb open_database ( const char *IN  dir  ) 

Opens metadata database in directory.

---------------------------------------------------------------------------

Name : open_database

Parameters:
dir directory where the database resides. This is the same place as where the files are stored.
Returns:
pointer to a valid erMedadb object on success, NULL on failure

--------------------------------------------------------------------------

Definition at line 90 of file hello-world/src/db.c.

References ermetadb_global_open(), and ERRORPRINTF.

Referenced by do_example_db_actions().

00091 {
00092     g_assert(dir != NULL);
00093 
00094     erMetadb db = ermetadb_global_open(dir, FALSE);
00095     if ( NULL == db) {
00096         ERRORPRINTF("Could not open database %s", dir );
00097     } 
00098     return db;
00099 }

Here is the call graph for this function:

Here is the caller graph for this function:

void pixbuf_draw_rectangle ( GdkPixbuf *  pixbuf,
gint  xx,
gint  yy,
gint  ww,
gint  hh,
gint  color 
)

Draw a rectangle border in a pixbuf.

---------------------------------------------------------------------------

Name : pixbuf_draw_rectangle

Parameters:
pixbuf pointer to GdkPixbuf to be converted to BLOB
xx x position offset
yy y position offset
ww width in pixels
hh height pixels
color RGB color
Returns:
--

--------------------------------------------------------------------------

Definition at line 399 of file hello-world/src/db.c.

References set_pixel_value().

Referenced by do_example_db_actions().

00400 {
00401     if (pixbuf == NULL)
00402     {
00403         return;
00404     }
00405 
00406     gint w = gdk_pixbuf_get_width (pixbuf);
00407     gint h = gdk_pixbuf_get_height (pixbuf);
00408 
00409     gint i, j, x, y;
00410     
00411     // draw top, buttom line
00412     for (i = 0; i < 2; ++i)
00413     {
00414         if (i == 0)
00415         {
00416             y = yy;
00417         }
00418         else
00419         {
00420             y = yy + hh - 1;
00421         }
00422 
00423         x = xx;
00424         for (j = 0; j < ww; ++j)
00425         {
00426             if ((x + j) < w && y < h)
00427                 set_pixel_value(pixbuf, x + j, y, color);
00428         }
00429     }
00430 
00431     // draw left, right line
00432     for (i = 0; i < 2; ++i)
00433     {
00434         if (i == 0)
00435         {
00436             x = xx;
00437         }
00438         else
00439         {
00440             x = xx + ww -1;
00441         }
00442 
00443         y = yy;
00444         for (j = 0; j < hh; ++j)
00445         {
00446             if (x < w && (y + j) < h)
00447             {
00448                 set_pixel_value(pixbuf, x, y + j, color);
00449             }
00450         }
00451     }
00452 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean pixbuf_to_blob ( GdkPixbuf *IN  pixbuf,
gchar **OUT  buffer,
gsize *OUT  buf_size 
)

Converts a GdkPixbuf* to a BLOB buffer.

---------------------------------------------------------------------------

Name : pixbuf_to_blob

Parameters:
pixbuf pointer to GdkPixbuf to be converted to BLOB
buffer buffer in where the data of the BLOB is stored
buf_size size of the buffer after conversion
Returns:
FALSE on failure, TRUE on success

--------------------------------------------------------------------------

Referenced by do_example_db_actions().

Here is the caller graph for this function:

gboolean save_file_metadata ( erMetadb IN  db,
const gchar *IN  filepath,
const gchar *IN  filename,
GString *IN  title,
GString *IN  author,
thumbType *IN  small,
thumbType *IN  medium 
)

Saves the file metadata to database.

---------------------------------------------------------------------------

Name : save_file_metadata

Parameters:
db pointer to a valid erMetadb object
filepath filepath for which to save metadata
filename filename for which to save metadata
title pointer to GString to store the title NULL -> title should not be stored
author pointer to GString to store the author NULL -> author should not be stored
Returns:
FALSE on failure, TRUE on success

--------------------------------------------------------------------------

Definition at line 248 of file hello-world/src/db.c.

References ER_FAIL, ER_OK, ermetadb_global_change_file(), ERRORPRINTF, FILE_AUTHOR, FILE_TITLE, metadata_table_add_column(), metadata_table_free, metadata_table_new(), metadata_table_set_blob(), metadata_table_set_text(), THUMBNAIL_COLUMNS, THUMBNAIL_MEDIUM, and THUMBNAIL_SMALL.

Referenced by do_example_db_actions().

00255 {
00256     g_assert(db != NULL);
00257     g_assert(filename != NULL);
00258 
00259     // create table
00260     metadata_table *value_table = metadata_table_new();
00261     g_return_val_if_fail( NULL != value_table, FALSE);
00262 
00263     int value_index = -1;
00264 
00265     int rc = ER_FAIL;
00266     gboolean save_needed = FALSE;
00267 
00268     // NOTE: This could be optimized; right now all information that is present is
00269     //       always written to the metadata library, even if nothing has changed
00270     if (title)
00271     {
00272         // set title
00273         gchar* tmp_title =   g_strdup(title->str);
00274         // get rid of some special characters
00275         g_strdelimit(tmp_title, "\t\n\r", ' ');
00276         // trim the heading and tailing spaces
00277         g_strstrip(tmp_title);
00278 
00279         metadata_table_add_column(value_table, FILE_TITLE);
00280         value_index++;
00281         rc = metadata_table_set_text(value_table, value_index, tmp_title);
00282         if (rc == ER_OK)
00283         {
00284             save_needed = TRUE;
00285         }
00286         else
00287         {
00288             ERRORPRINTF("Cannot write value %s to table.", tmp_title);
00289         }
00290         g_free(tmp_title);
00291     }
00292 
00293     // set author
00294     if (author)
00295     {
00296         gchar * tmp =   g_strdup(author->str);
00297         // get rid of some special characters
00298         g_strdelimit(tmp, "\t\n\r", ' ');
00299         // trim the heading and tailing spaces
00300         g_strstrip(tmp);
00301 
00302         metadata_table_add_column(value_table, FILE_AUTHOR);
00303         value_index++;
00304         rc = metadata_table_set_text(value_table, value_index, tmp);
00305         if (rc == ER_OK)
00306         {
00307             save_needed = TRUE;
00308         }
00309         else
00310         {
00311             ERRORPRINTF("Cannot write value %s to table.", tmp);
00312         }
00313 
00314         g_free(tmp);
00315     }
00316 
00317     if ( small )
00318     {
00319         gchar* blob = (gchar*) small->data;
00320         gsize  blob_size = small->size;
00321 
00322         // add column according to the size
00323         metadata_table_add_column(value_table, THUMBNAIL_COLUMNS[THUMBNAIL_SMALL]);
00324         value_index++;
00325         rc = metadata_table_set_blob(value_table, value_index, blob, blob_size);
00326         if (rc== ER_OK)
00327         {
00328             save_needed = TRUE;
00329         }
00330         else
00331         {
00332             ERRORPRINTF("Cannot write thumbnail %s to table.", "small");
00333         }
00334     }
00335 
00336     if ( medium )
00337     {
00338         gchar* blob = (gchar*) medium->data;
00339         gsize  blob_size = medium->size;
00340 
00341         // add column according to the size
00342         metadata_table_add_column(value_table, THUMBNAIL_COLUMNS[THUMBNAIL_MEDIUM]);
00343         value_index++;
00344         rc = metadata_table_set_blob(value_table, value_index, blob, blob_size);
00345         if (rc== ER_OK)
00346         {
00347             save_needed = TRUE;
00348         }
00349         else
00350         {
00351             ERRORPRINTF("Cannot write thumbnail %s to table.", "medium");
00352         }
00353     }
00354 
00355     // write values to database
00356     if (save_needed)
00357     {
00358         rc = ermetadb_global_change_file(db, filepath, filename, value_table);
00359     }
00360     else
00361     {
00362         ERRORPRINTF("No metadata saved, options empty?");
00363     }
00364 
00365     // clean up
00366     metadata_table_free(value_table);
00367 
00368     if (rc != ER_OK)  { return FALSE; }
00369     
00370     return TRUE;
00371 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208