scbpages.c File Reference

#include <string.h>
#include <glib.h>
#include "scblog.h"
#include "scbtype.h"
#include "scbpages.h"
#include "scbpage.h"
Include dependency graph for scbpages.c:

Go to the source code of this file.

Defines

#define _GNU_SOURCE
#define UNUSED(x)   (void)(x)
#define MAX_TIMESTAMP   0x7FFFFFFF
#define CACHE_PAGES_NUMBER   20

Functions

static void _page_release (gpointer data, gpointer userdata)
static void _page_dump (gpointer data, gpointer userdata)
gboolean remove_oldest_page_data (ScbPagesPtr pages)
gboolean erscribble_pages_new (ScbPagesPtr ptr)
void erscribble_pages_free (ScbPagesPtr ptr)
gboolean erscribble_pages_add_page (ScbPagesPtr pages, ScbPagePtr page)
ScbPagePtr erscribble_pages_detach_page (ScbPagesPtr pages, ScbPageIdPtr id)
void erscribble_pages_remove_page (ScbPagesPtr pages, ScbPageIdPtr id)
int erscribble_pages_get_count (ScbPagesPtr pages)
ScbPagePtr erscribble_pages_get_page (ScbPagesPtr pages, ScbPageIdPtr id)
gboolean erscribble_pages_change_page_id (ScbPagesPtr pages, ScbPageIdPtr oldId, ScbPageIdPtr newId)
void erscribble_pages_dump (ScbPagesPtr pages)

Define Documentation

#define _GNU_SOURCE

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

Definition at line 28 of file scbpages.c.

#define CACHE_PAGES_NUMBER   20

Definition at line 59 of file scbpages.c.

Referenced by remove_oldest_page_data().

#define MAX_TIMESTAMP   0x7FFFFFFF

Definition at line 58 of file scbpages.c.

Referenced by remove_oldest_page_data().

#define UNUSED (  )     (void)(x)

Definition at line 46 of file scbpages.c.


Function Documentation

static void _page_dump ( gpointer  data,
gpointer  userdata 
) [static]

Definition at line 291 of file scbpages.c.

References erscribble_page_dump(), and UNUSED.

Referenced by erscribble_pages_dump().

00292 {
00293     UNUSED(userdata);
00294     if (data)
00295     {
00296         erscribble_page_dump((ScbPagePtr)data);
00297     }
00298 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void _page_release ( gpointer  data,
gpointer  userdata 
) [static]

Definition at line 282 of file scbpages.c.

References erscribble_page_free(), and UNUSED.

Referenced by erscribble_pages_free().

00283 {
00284     UNUSED(userdata);
00285     if (data)
00286     {
00287         erscribble_page_free((ScbPagePtr)data);
00288     }
00289 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean erscribble_pages_add_page ( ScbPagesPtr  pages,
ScbPagePtr  page 
)

Definition at line 152 of file scbpages.c.

References ERSCRIBBLE_RET_FALSE_IF, _ScbPage::id, and _ScbPageId::position.

Referenced by erscribble_doc_add_page(), erscribble_doc_get_page(), and load_pages_basic_data().

00153 {
00154     ERSCRIBBLE_RET_FALSE_IF(NULL == pages || NULL == page, "Invalid pages or page pointer!");
00155     
00156     ScbPagePtr cur_page  = NULL;
00157     GList* ptr = g_list_first(pages->pages);
00158     while(ptr)
00159     {
00160         cur_page = (ScbPagePtr)ptr->data;
00161         // if (cur_page && 0 == strncmp(cur_page->id.id, page->id.id, ERSCRIBBLE_MAX_PAGEID_LEN))
00162         if (cur_page && (cur_page->id.position == page->id.position))
00163         {
00164             // The querying page already exist, quit, it's ok,
00165             // The new page should be removed.
00166             // WARNPRINTF("Duplicated page id %s!", page->id.id);
00167             return FALSE;
00168         }
00169         ptr = g_list_next(ptr);
00170     }
00171 
00172     pages->pages = g_list_append(pages->pages, page);
00173     return TRUE;
00174 }

Here is the caller graph for this function:

gboolean erscribble_pages_change_page_id ( ScbPagesPtr  pages,
ScbPageIdPtr  oldId,
ScbPageIdPtr  newId 
)

Definition at line 245 of file scbpages.c.

References _ScbPageId::annotation_id, ERSCRIBBLE_MAX_PAGEID_LEN, _ScbPageId::id, _ScbPage::id, and _ScbPageId::position.

00247 {
00248     // change page id, make sure the id does not conflict. we do not check here
00249     
00250     ScbPagePtr cur_page  = NULL;
00251     GList* ptr = g_list_first(pages->pages);
00252     while(ptr)
00253     {
00254         cur_page = (ScbPagePtr)ptr->data;
00255         // if (cur_page && 0 == strncmp(cur_page->id.id, oldId->id, ERSCRIBBLE_MAX_PAGEID_LEN))
00256         if (cur_page && (cur_page->id.position == oldId->position))
00257         {
00258             strncpy(cur_page->id.id, newId->id, ERSCRIBBLE_MAX_PAGEID_LEN);
00259             cur_page->id.position = newId->position;
00260             cur_page->id.annotation_id = newId->annotation_id;
00261 
00262             return TRUE;
00263         }
00264         ptr = g_list_next(ptr);
00265     }
00266     return FALSE;
00267 }

ScbPagePtr erscribble_pages_detach_page ( ScbPagesPtr  pages,
ScbPageIdPtr  id 
)

Definition at line 177 of file scbpages.c.

References _ScbPage::id, and _ScbPageId::position.

00178 {
00179     ScbPagePtr cur_page  = NULL;
00180     GList* ptr = g_list_first(pages->pages);
00181     while(ptr)
00182     {
00183         cur_page = (ScbPagePtr)ptr->data;
00184         // if (cur_page && 0 == strncmp(cur_page->id.id, id->id, ERSCRIBBLE_MAX_PAGEID_LEN))
00185         if (cur_page && (cur_page->id.position == id->position))
00186         {
00187             // ok, hit. notice.......
00188             pages->pages = g_list_remove(pages->pages, cur_page);
00189             return cur_page;
00190         }
00191         ptr = g_list_next(ptr);
00192     }
00193     return NULL;
00194 }

void erscribble_pages_dump ( ScbPagesPtr  pages  ) 

Definition at line 270 of file scbpages.c.

References _page_dump(), and ERSCRIBBLE_RET_IF.

Referenced by erscribble_doc_dump().

00272 {
00273     ERSCRIBBLE_RET_IF(NULL == pages, "NULL pointer!");
00274     g_list_foreach(pages->pages, _page_dump, 0);
00275 }

Here is the call graph for this function:

Here is the caller graph for this function:

void erscribble_pages_free ( ScbPagesPtr  ptr  ) 

Definition at line 136 of file scbpages.c.

References _page_release().

Referenced by erscribble_doc_delete_page_impl(), and erscribble_doc_free().

00137 {
00138     if (ptr)
00139     {
00140         // release all stroke
00141         g_list_foreach(ptr->pages, _page_release, NULL);
00142 
00143         // now the pointers are wild pointers
00144         g_list_free(ptr->pages);
00145         ptr->pages = NULL;
00146     }
00147 }

Here is the call graph for this function:

Here is the caller graph for this function:

int erscribble_pages_get_count ( ScbPagesPtr  pages  ) 

Definition at line 219 of file scbpages.c.

References ERSCRIBBLE_INVALID_COUNT, and ERSCRIBBLE_RET_INT_IF.

00220 {
00221     ERSCRIBBLE_RET_INT_IF(NULL == pages, ERSCRIBBLE_INVALID_COUNT, "Invalid pages pointer!");
00222     return g_list_length(pages->pages);
00223 }

ScbPagePtr erscribble_pages_get_page ( ScbPagesPtr  pages,
ScbPageIdPtr  id 
)

Definition at line 226 of file scbpages.c.

References _ScbPage::id, and _ScbPageId::position.

Referenced by erscribble_doc_delete_page_impl(), and erscribble_doc_get_page().

00227 {
00228     ScbPagePtr cur_page  = NULL;
00229     GList* ptr = g_list_first(pages->pages);
00230     while(ptr)
00231     {
00232         cur_page = (ScbPagePtr)ptr->data;
00233         // if (cur_page && 0 == strncmp(cur_page->id.id, id->id, ERSCRIBBLE_MAX_PAGEID_LEN))
00234         if (cur_page && (cur_page->id.position == id->position))
00235         {
00236             // ok, hit. notice.......
00237            return cur_page;
00238         }
00239         ptr = g_list_next(ptr);
00240     }
00241     return NULL;
00242 }

Here is the caller graph for this function:

gboolean erscribble_pages_new ( ScbPagesPtr  ptr  ) 

Definition at line 127 of file scbpages.c.

References ERSCRIBBLE_RET_FALSE_IF.

Referenced by erscribble_doc_delete_page_impl(), erscribble_doc_new_with_database(), and erscribble_doc_open_with_database().

00128 {
00129     ERSCRIBBLE_RET_FALSE_IF(NULL == ptr, "Invalid pointer!");
00130 
00131     ptr->pages = NULL;
00132     return TRUE;
00133 }

Here is the caller graph for this function:

void erscribble_pages_remove_page ( ScbPagesPtr  pages,
ScbPageIdPtr  id 
)

Definition at line 197 of file scbpages.c.

References erscribble_page_free(), ERSCRIBBLE_RET_IF, _ScbPage::id, and _ScbPageId::position.

00198 {
00199     ERSCRIBBLE_RET_IF(NULL == pages || NULL == id, "Invalid pointer!");
00200     
00201     ScbPagePtr cur_page  = NULL;
00202     GList* ptr = g_list_first(pages->pages);
00203     while(ptr)
00204     {
00205         cur_page = (ScbPagePtr)ptr->data;
00206         // if (cur_page && 0 == strncmp(cur_page->id.id, id->id, ERSCRIBBLE_MAX_PAGEID_LEN))
00207         if (cur_page && (cur_page->id.position == id->position))
00208         {
00209             // ok, hit. notice.......
00210             erscribble_page_free(cur_page);
00211             pages->pages = g_list_remove(pages->pages, ptr->data);
00212             return;
00213         }
00214         ptr = g_list_next(ptr);
00215     }
00216 }

Here is the call graph for this function:

gboolean remove_oldest_page_data ( ScbPagesPtr  pages  ) 

Definition at line 82 of file scbpages.c.

References CACHE_PAGES_NUMBER, erscribble_page_clear_strokes(), erscribble_strokes_get_count(), _ScbPage::is_blob_loaded, MAX_TIMESTAMP, _ScbPage::strokes, and _ScbPage::timestamp.

Referenced by remove_oldest_page_scribbles().

00083 {
00084     // Get the page with oldest timestamp, and calculate the sum
00085     ScbPagePtr oldest_page = NULL;
00086     int oldest_timestamp = MAX_TIMESTAMP;
00087     int loaded_pages_number = 0;
00088     GList* ptr = g_list_first(pages->pages);
00089 
00090     while(ptr)
00091     {
00092         ScbPagePtr cur_page = (ScbPagePtr)ptr->data;
00093         if (cur_page != NULL && (erscribble_strokes_get_count(&cur_page->strokes) > 0))
00094         {
00095             loaded_pages_number++;
00096             if (cur_page->timestamp < oldest_timestamp)
00097             {
00098                 oldest_timestamp = cur_page->timestamp;
00099                 oldest_page = cur_page;
00100             }
00101         }
00102         ptr = g_list_next(ptr);
00103     }
00104 
00105     if (loaded_pages_number <= CACHE_PAGES_NUMBER)
00106     {
00107         return TRUE;
00108     }
00109 
00110     // clear strokes of the oldest page
00111     
00112     // TODO. Handle the situation that the number of loaded pages
00113     // are much more than the cached pages number
00114     erscribble_page_clear_strokes(oldest_page);
00115     oldest_page->is_blob_loaded = FALSE;
00116     loaded_pages_number--;
00117 
00118     if (loaded_pages_number > CACHE_PAGES_NUMBER)
00119     {
00120         return FALSE;
00121     }
00122 
00123     return TRUE;
00124 }

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208