scbdoc.h File Reference

#include <libermetadb/ermetadb.h>
#include "scbpath.h"
#include "scbpages.h"
Include dependency graph for scbdoc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _ScbTBSItem
struct  _ScbDocContext
struct  _ScbVersion
struct  _ScbDocVersion
struct  _ScbScreen
struct  _ScbDoc

Typedefs

typedef enum _ScbTBState ScbTBState
typedef struct _ScbTBSItem ScbTBSItem
typedef ScbTBSItemScbTBSItemPtr
typedef struct _ScbDocContext ScbDocContext
typedef struct _ScbVersion ScbVersion
typedef struct _ScbDocVersion ScbDocVersion
typedef struct _ScbScreen ScbScreen
typedef struct _ScbDoc ScbDoc
typedef ScbDocScbDocPtr

Enumerations

enum  _ScbTBState {
  ERSCRIBBLE_TBS_NONE, ERSCRIBBLE_TBS_SCRIBBLE, ERSCRIBBLE_TBS_SELECT_PEN_SIZE, ERSCRIBBLE_TBS_SELECT_LINE_COLOR,
  ERSCRIBBLE_TBS_ERASE, ERSCRIBBLE_TBS_INVALID
}

Functions

ScbDocPtr erscribble_doc_new (const ScbPathPtr target_doc_path)
ScbDocPtr erscribble_doc_new_with_database (const char *target_file_name, erMetadb metadata_db)
void erscribble_doc_free (ScbDocPtr doc)
void erscribble_doc_free_without_database (ScbDocPtr doc)
ScbDocPtr erscribble_doc_open (const ScbPathPtr target_doc_path)
ScbDocPtr erscribble_doc_open_with_database (const char *target_file_name, erMetadb metadata_db)
gboolean erscribble_doc_save_page (ScbDocPtr doc, ScbPagePtr page)
ScbPagePtr erscribble_doc_get_page (ScbDocPtr doc, const ScbPageIdPtr id)
ScbPagesPtr erscribble_doc_get_pages (ScbDocPtr doc)
ScbStrokeAttributesPtr erscribble_doc_get_current_stroke_attributes (ScbDocPtr doc)
gboolean erscribble_doc_add_page (ScbDocPtr doc, ScbPagePtr page)
gboolean erscribble_doc_insert_page (ScbDocPtr doc, ScbPagePtr page)
gboolean erscribble_doc_delete_page (ScbDocPtr doc, ScbPageIdPtr pid)
void erscribble_doc_add_map_item (ScbDocPtr doc, const ScbTBSItemPtr ptr)
gboolean erscribble_state_is_scribble (ScbDocPtr doc)
gboolean erscribble_state_is_erase (ScbDocPtr doc)
void erscribble_doc_dump (ScbDocPtr ptr)
void erscribble_doc_disable_autodelete (gboolean do_disable)

Typedef Documentation

typedef struct _ScbDoc ScbDoc
typedef struct _ScbDocContext ScbDocContext
typedef ScbDoc* ScbDocPtr

Definition at line 138 of file scbdoc.h.

typedef struct _ScbDocVersion ScbDocVersion
typedef struct _ScbScreen ScbScreen
typedef struct _ScbTBSItem ScbTBSItem

Definition at line 92 of file scbdoc.h.

typedef enum _ScbTBState ScbTBState

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

typedef struct _ScbVersion ScbVersion

Enumeration Type Documentation

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Enumerator:
ERSCRIBBLE_TBS_NONE 
ERSCRIBBLE_TBS_SCRIBBLE 
ERSCRIBBLE_TBS_SELECT_PEN_SIZE 
ERSCRIBBLE_TBS_SELECT_LINE_COLOR 
ERSCRIBBLE_TBS_ERASE 
ERSCRIBBLE_TBS_INVALID 

Definition at line 75 of file scbdoc.h.


Function Documentation

void erscribble_doc_add_map_item ( ScbDocPtr  doc,
const ScbTBSItemPtr  ptr 
)

Definition at line 607 of file scbdoc.c.

References _ScbDoc::context, LOGPRINTF, and _ScbDocContext::table.

00608 {
00609     LOGPRINTF("entry");
00610     //ERSCRIBBLE_RET_IF(NULL == doc || NULL == ptr, "Invalid pointer(s)!");
00611     g_array_append_val(doc->context.table,  *ptr);
00612     LOGPRINTF("exit");
00613 }

gboolean erscribble_doc_add_page ( ScbDocPtr  doc,
ScbPagePtr  page 
)

Definition at line 464 of file scbdoc.c.

References erscribble_doc_get_pages(), erscribble_pages_add_page(), and LOGPRINTF.

Referenced by notepad::CNotepadDoc::add_page(), and notepad::CNotepadDoc::on_scribble_end().

00465 {
00466     LOGPRINTF("entry");
00467     ScbPagesPtr pages = erscribble_doc_get_pages(doc);
00468     if (NULL == pages) return FALSE;
00469     LOGPRINTF("exit");
00470     return erscribble_pages_add_page(pages, page);
00471 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean erscribble_doc_delete_page ( ScbDocPtr  doc,
ScbPageIdPtr  pid 
)

Definition at line 596 of file scbdoc.c.

References erscribble_doc_delete_page_impl(), erscribble_doc_get_pages(), and LOGPRINTF.

Referenced by notepad::CNotepadDoc::delete_page().

00597 {
00598     LOGPRINTF("entry");
00599     ScbPagesPtr pages = erscribble_doc_get_pages(doc);
00600     if (NULL == pages) 
00601         return FALSE;
00602     LOGPRINTF("exit");
00603     return erscribble_doc_delete_page_impl(doc, pages, pid);
00604 }

Here is the call graph for this function:

Here is the caller graph for this function:

void erscribble_doc_disable_autodelete ( gboolean  do_disable  ) 

Definition at line 1235 of file scbdoc.c.

References g_enable_autodelete.

Referenced by notepad::CNotepadDoc::CNotepadDoc().

01236 {
01237     g_enable_autodelete = !do_disable ;  // reverse semantics
01238 }

Here is the caller graph for this function:

void erscribble_doc_dump ( ScbDocPtr  ptr  ) 

Definition at line 635 of file scbdoc.c.

References erscribble_pages_dump(), and _ScbDoc::pages.

00636 {
00637     if (ptr)
00638     {
00639         erscribble_pages_dump(&ptr->pages);
00640     }
00641 }

Here is the call graph for this function:

void erscribble_doc_free ( ScbDocPtr  doc  ) 

Definition at line 204 of file scbdoc.c.

References _ScbDocVersion::company, erscribble_doc_free_context(), erscribble_pages_free(), LOGPRINTF, _ScbDoc::pages, _ScbDoc::screen, _ScbScreen::units, and _ScbDoc::version.

Referenced by test::ScribbleMgr::close(), notepad::CNotepadDoc::close(), erscribble_doc_free_without_database(), and erscribble_doc_open_with_database().

00205 {
00206     LOGPRINTF("entry");
00207     if (NULL == ptr)
00208     {
00209         return;
00210     }
00211 
00212     erscribble_doc_free_context(ptr);
00213     erscribble_pages_free(&ptr->pages);
00214 
00215     if (ptr->version.company != NULL)
00216     {
00217         g_string_free(ptr->version.company, TRUE);
00218     }
00219 
00220     if (ptr->screen.units != NULL)
00221     {
00222         g_string_free(ptr->screen.units, TRUE);
00223     }
00224 
00225     g_free(ptr);
00226     LOGPRINTF("exit");
00227 }

Here is the call graph for this function:

Here is the caller graph for this function:

void erscribble_doc_free_without_database ( ScbDocPtr  doc  ) 

Definition at line 230 of file scbdoc.c.

References ermetadb_close(), erscribble_doc_free(), LOGPRINTF, and _ScbDoc::metadata_db.

00231 {
00232     LOGPRINTF("entry");
00233     if (NULL == ptr)
00234     {
00235         return;
00236     }
00237 
00238     // close the database
00239     ermetadb_close(ptr->metadata_db);
00240     ptr->metadata_db = NULL;
00241 
00242     // free the scribbble doc
00243     erscribble_doc_free(ptr);
00244     LOGPRINTF("exit");
00245 }

Here is the call graph for this function:

ScbStrokeAttributesPtr erscribble_doc_get_current_stroke_attributes ( ScbDocPtr  doc  ) 

Definition at line 334 of file scbdoc.c.

References _ScbDoc::context, _ScbDocContext::curStrokeAttr, and LOGPRINTF.

Referenced by notepad::CNotepadDoc::on_scribble_begin().

00335 {
00336     LOGPRINTF("entry");
00337     return &doc->context.curStrokeAttr;
00338 }

Here is the caller graph for this function:

ScbPagePtr erscribble_doc_get_page ( ScbDocPtr  doc,
const ScbPageIdPtr  id 
)

Definition at line 341 of file scbdoc.c.

References ERRORPRINTF, erscribble_doc_get_pages(), erscribble_page_copy_id(), erscribble_page_load(), erscribble_page_new(), erscribble_pages_add_page(), erscribble_pages_get_page(), _ScbPage::id, load_page_data(), LOGPRINTF, _ScbDoc::pages, and update_timestamp().

Referenced by test::ScribbleMgr::clear_page(), notepad::CNotepadDoc::clear_page(), test::ScribbleMgr::draw_scribble_page(), notepad::CNotepadDoc::draw_scribble_page(), test::ScribbleMgr::on_erase_begin(), notepad::CNotepadDoc::on_erase_begin(), test::ScribbleMgr::on_erase_move(), notepad::CNotepadDoc::on_scribble_begin(), and notepad::CNotepadDoc::save_page().

00342 {
00343     LOGPRINTF("entry");
00344     ScbPagesPtr pages = erscribble_doc_get_pages(doc);
00345     if (NULL == pages)
00346     {
00347         ERRORPRINTF("Pages list is not constructed!");
00348         return NULL;
00349     }
00350 
00351     // search the page from cache
00352     ScbPagePtr page = erscribble_pages_get_page(pages, id);
00353 
00354     if (page != NULL)
00355     {
00356         // update the access time of current page
00357         update_timestamp(page);
00358 
00359         // load the BLOB data of current page if it exists
00360         // at this time, the BLOB data of oldest page would be deleted
00361         load_page_data(doc, page);
00362     }
00363     else
00364     {
00365 #ifdef SAVE_TO_FILE
00366         // TEST try to load the page in local file
00367         page = erscribble_page_new();
00368 
00369         ScbStreamPtr stream = doc_load_page_file(id);
00370         if (stream != NULL)
00371         {
00372             erscribble_page_load(page, stream);
00373         }
00374 
00375         erscribble_page_copy_id(&page->id, id);
00376         // add the loaded page into cache
00377         erscribble_pages_add_page(&doc->pages, page);
00378 #else
00379         // if the page is exist, create a new one
00380         page = erscribble_page_new();
00381 
00382         erscribble_page_copy_id(&page->id, id);
00383 
00384         erscribble_pages_add_page(pages, page);
00385 
00386         // update the access time of current page
00387         update_timestamp(page);
00388 #endif
00389     }
00390 
00391     assert(page != NULL);
00392 
00393     LOGPRINTF("exit");
00394     return page;
00395 }

Here is the call graph for this function:

Here is the caller graph for this function:

ScbPagesPtr erscribble_doc_get_pages ( ScbDocPtr  doc  ) 

Definition at line 323 of file scbdoc.c.

References LOGPRINTF, and _ScbDoc::pages.

Referenced by erscribble_doc_add_page(), erscribble_doc_delete_page(), erscribble_doc_get_page(), erscribble_doc_insert_page(), and notepad::CNotepadDoc::get_num_pages().

00324 {
00325     LOGPRINTF("entry");
00326     if (ptr)
00327     {
00328         return &ptr->pages;
00329     }
00330     return NULL;
00331 }

Here is the caller graph for this function:

gboolean erscribble_doc_insert_page ( ScbDocPtr  doc,
ScbPagePtr  page 
)

Definition at line 517 of file scbdoc.c.

References erscribble_doc_get_pages(), erscribble_doc_insert_page_impl(), and LOGPRINTF.

Referenced by notepad::CNotepadDoc::insert_page().

00518 {
00519     LOGPRINTF("entry");
00520     ScbPagesPtr pages = erscribble_doc_get_pages(doc);
00521     if (NULL == pages) 
00522         return FALSE;
00523     LOGPRINTF("exit");
00524     return erscribble_doc_insert_page_impl(doc, pages, page);
00525 }

Here is the call graph for this function:

Here is the caller graph for this function:

ScbDocPtr erscribble_doc_new ( const ScbPathPtr  target_doc_path  ) 

Definition at line 142 of file scbdoc.c.

References ermetadb_close(), ermetadb_local_open(), erscribble_doc_new_with_database(), LOGPRINTF, name, and path.

Referenced by test::ScribbleMgr::open().

00143 {
00144     LOGPRINTF("entry");
00145     g_return_val_if_fail((target_doc_path && target_doc_path->document_path != '\0'), NULL);
00146 
00147     gchar *path = g_path_get_dirname(target_doc_path->document_path);
00148     erMetadb db = ermetadb_local_open(path, TRUE);
00149     g_free(path);
00150     if (db == NULL) return NULL;
00151 
00152     gchar *name = g_path_get_basename(target_doc_path->document_path);
00153     ScbDocPtr doc = erscribble_doc_new_with_database(name, db);
00154     g_free(name);
00155     if (doc == NULL) {
00156         ermetadb_close(db);
00157     }
00158     LOGPRINTF("exit");
00159     return doc;
00160 }

Here is the call graph for this function:

Here is the caller graph for this function:

ScbDocPtr erscribble_doc_new_with_database ( const char *  target_file_name,
erMetadb  metadata_db 
)

Definition at line 163 of file scbdoc.c.

References _ScbDocVersion::company, _ScbScreen::dpi, ERRORPRINTF, ERSCRIBBLE_DEF_SCREEN_DPI, ERSCRIBBLE_DEF_SCREEN_UNITS, erscribble_doc_init_context(), ERSCRIBBLE_LIB_ORG, ERSCRIBBLE_LIB_VERSION_MAJOR, ERSCRIBBLE_LIB_VERSION_MINOR, erscribble_pages_new(), LOGPRINTF, _ScbVersion::major, _ScbDoc::metadata_db, _ScbVersion::minor, _ScbDoc::pages, _ScbDoc::path, _ScbDoc::screen, _ScbScreen::units, _ScbDoc::version, and _ScbDocVersion::version_number.

Referenced by notepad::CNotepadDoc::create(), and erscribble_doc_new().

00164 {
00165 
00166     LOGPRINTF("entry");
00167     g_return_val_if_fail((target_file_name && *target_file_name), NULL);
00168 
00169     ScbDocPtr doc = g_new0(ScbDoc, 1);
00170     if (NULL == doc)
00171     {
00172         ERRORPRINTF("Not enough memory!");
00173         return NULL;
00174     }
00175 
00176     if (!erscribble_pages_new(&doc->pages))
00177     {
00178         g_free(doc);
00179         return NULL;
00180     }
00181 
00182     erscribble_doc_init_context(doc);
00183 
00184     // set version data
00185     doc->version.version_number.major = ERSCRIBBLE_LIB_VERSION_MAJOR;
00186     doc->version.version_number.minor = ERSCRIBBLE_LIB_VERSION_MINOR;
00187     doc->version.company = g_string_new(ERSCRIBBLE_LIB_ORG);
00188 
00189     // set screen data
00190     doc->screen.dpi = ERSCRIBBLE_DEF_SCREEN_DPI;
00191     doc->screen.units = g_string_new(ERSCRIBBLE_DEF_SCREEN_UNITS);
00192 
00193     // use the specified metadata db for the document
00194     doc->metadata_db = metadata_db;
00195 
00196     // set the target document path
00197     strcpy(doc->path.document_path, target_file_name);
00198 
00199     LOGPRINTF("exit");
00200     return doc;
00201 }

Here is the call graph for this function:

Here is the caller graph for this function:

ScbDocPtr erscribble_doc_open ( const ScbPathPtr  target_doc_path  ) 

Definition at line 248 of file scbdoc.c.

References ermetadb_close(), ermetadb_local_open(), erscribble_doc_open_with_database(), LOGPRINTF, name, and path.

Referenced by test::ScribbleMgr::open().

00249 {
00250     LOGPRINTF("entry");
00251     g_return_val_if_fail((target_doc_path && target_doc_path->document_path != '\0'), NULL);
00252 
00253     gchar *path = g_path_get_dirname(target_doc_path->document_path);
00254     erMetadb db = ermetadb_local_open(path, FALSE);
00255     g_free(path);
00256     if (db == NULL) return NULL;
00257     
00258     gchar *name = g_path_get_basename(target_doc_path->document_path);
00259     ScbDocPtr doc = erscribble_doc_open_with_database(name, db);
00260     g_free(name);
00261     if (doc == NULL)
00262     {
00263         ermetadb_close(db);
00264     }
00265     LOGPRINTF("exit");
00266     return doc;
00267 }

Here is the call graph for this function:

Here is the caller graph for this function:

ScbDocPtr erscribble_doc_open_with_database ( const char *  target_file_name,
erMetadb  metadata_db 
)

Definition at line 270 of file scbdoc.c.

References _ScbDoc::context, ERRORPRINTF, erscribble_doc_free(), erscribble_doc_init_context(), erscribble_pages_new(), load_application_data(), load_document_data(), LOGPRINTF, _ScbDoc::metadata_db, _ScbDocContext::need_save_app, _ScbDoc::pages, and _ScbDoc::path.

Referenced by erscribble_doc_open(), and notepad::CNotepadDoc::open().

00271 {
00272     LOGPRINTF("entry");
00273     ScbDocPtr doc = NULL; 
00274     gboolean  ok;
00275 
00276     g_return_val_if_fail((target_file_name && *target_file_name), NULL);
00277 
00278     doc = g_new0(ScbDoc, 1);
00279     if (NULL == doc)
00280     {
00281         ERRORPRINTF("Not enough memory!");
00282         return NULL;
00283     }
00284 
00285     doc->metadata_db = metadata_db;
00286 
00287     // set the target document path
00288     strcpy(doc->path.document_path, target_file_name);
00289 
00290     ok = load_application_data(doc);
00291     if (ok)
00292     {
00293         // the application data has been saved in metadb
00294         // we don't have to save it again
00295         // TODO. if the application data is modified, set the flag to be TRUE
00296         doc->context.need_save_app = FALSE;
00297 
00298         ok = erscribble_pages_new(&doc->pages);
00299     }
00300 
00301     if (ok)
00302     {
00303         // load the document data from data base
00304         ok = (NULL != load_document_data(doc));
00305     }
00306 
00307     if (ok)
00308     {
00309         erscribble_doc_init_context(doc); 
00310     }
00311 
00312     if (!ok)
00313     {
00314         // free the document
00315         erscribble_doc_free(doc);
00316         doc = NULL;
00317     }
00318     LOGPRINTF("exit");
00319     return doc;
00320 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean erscribble_doc_save_page ( ScbDocPtr  doc,
ScbPagePtr  page 
)

Definition at line 398 of file scbdoc.c.

References _ScbDoc::context, erscribble_create_stream(), erscribble_free_stream(), erscribble_page_get_length(), erscribble_page_set_minor_version_number(), erscribble_page_write_stream(), _ScbPageId::id, _ScbPage::id, LOGPRINTF, _ScbVersion::minor, _ScbDocContext::need_save_app, save_application_data(), save_page_data(), _ScbDoc::version, and _ScbDocVersion::version_number.

Referenced by erscribble_doc_delete_page_impl(), erscribble_doc_insert_page_impl(), test::ScribbleMgr::save(), and notepad::CNotepadDoc::save_page().

00399 {
00400     LOGPRINTF("entry");
00401     if (doc->context.need_save_app)
00402     {
00403         gboolean ok = save_application_data(doc);
00404         if (!ok)
00405         {
00406             LOGPRINTF("save_application_data NOK");
00407             return FALSE;
00408         }
00409         doc->context.need_save_app = FALSE;
00410     }
00411 
00412     int page_len = erscribble_page_get_length(page);
00413     LOGPRINTF("page_len %d page %s", page_len, page->id.id);
00414     // need free the stream buffer?
00415     gboolean need_free_stream_buffer = TRUE;
00416 
00417     // create a memory stream for writing, length = page length + 128
00418     ScbStreamPtr stream = erscribble_create_stream(page_len + 128);
00419 
00420     if (NULL == stream)
00421     {
00422         LOGPRINTF("creation of stream failed");
00423         return FALSE;
00424     }
00425 
00426     // set the minor version number of the library
00427     erscribble_page_set_minor_version_number(page, doc->version.version_number.minor);
00428     LOGPRINTF("minor version number %d", doc->version.version_number.minor);
00429     
00430     // write the page data into stream
00431     gboolean ret = erscribble_page_write_stream(page, stream);
00432     if (ret)
00433     {
00434 #ifdef SAVE_TO_FILE
00435         ret = doc_save_page_file(&page->id, stream);
00436 #else
00437         ret = save_page_data(doc, page, stream, &need_free_stream_buffer);
00438 #endif
00439     }
00440 
00441     // Free the stream by the results of saving operation
00442     if (!need_free_stream_buffer)
00443     {
00444         // if the saving operation returns successfully, it means
00445         // that the BLOB has been written into database. The ownership of
00446         // stream's buffer has been transfered to metadata lib.
00447         // Scribble lib MUST NOT free the memory any more.
00448         erscribble_free_stream(stream, FALSE);
00449     }
00450     else
00451     {
00452         // if saving fails, scribble lib considers the ownership has not
00453         // been transfered to metadata lib. So the memory should be released here.
00454         // TODO. HOWEVER, a problem is that the saveing may fail no matter whether
00455         // taking the ownership of BLOB or not. SHOULD BE FIXED.
00456         erscribble_free_stream(stream, TRUE);
00457     }
00458 
00459     LOGPRINTF("exit %d", ret);
00460     return ret;
00461 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean erscribble_state_is_erase ( ScbDocPtr  doc  ) 

Definition at line 629 of file scbdoc.c.

References erscribble_doc_get_current_state(), and ERSCRIBBLE_TBS_ERASE.

00630 {
00631     return ERSCRIBBLE_TBS_ERASE == erscribble_doc_get_current_state(doc);
00632 }

Here is the call graph for this function:

gboolean erscribble_state_is_scribble ( ScbDocPtr  doc  ) 

Definition at line 623 of file scbdoc.c.

References erscribble_doc_get_current_state(), and ERSCRIBBLE_TBS_SCRIBBLE.

00624 {
00625     return ERSCRIBBLE_TBS_SCRIBBLE == erscribble_doc_get_current_state(doc);
00626 }

Here is the call graph for this function:

Generated by  doxygen 1.6.2-20100208