scribble/src/ScribbleSaveThread.c File Reference

#include "ScribbleSaveThread.h"
#include "ScribbleLog.h"
#include "ScribbleUtils.h"

Go to the source code of this file.

Functions

void saveThreadMain (gpointer data)
int initSaveThread (ScribbleUICtx *pScribbleUICtx)
void notifySave (PScribbleUICtx pScribbleUICtx)
void exitSaveThread ()

Variables

GMutex * imgdata_mutex = NULL
GCond * data_cond = NULL
static GThread * s_threadSave = NULL
static gboolean s_bQuit = FALSE
static gboolean s_bNeedSaveResultPage = FALSE
GdkPixbuf * s_pixbuf = NULL


Function Documentation

void exitSaveThread (  ) 

Definition at line 133 of file ScribbleSaveThread.c.

00134 {
00135     SB_TIMEDISPLAY("save-thread ready to exit\n");
00136     g_mutex_lock(imgdata_mutex);
00137     s_bQuit=TRUE;
00138     g_cond_signal(data_cond);
00139     g_mutex_unlock(imgdata_mutex);
00140 
00141     g_thread_join(s_threadSave);
00142     SB_TIMEDISPLAY("save-thread exit\n");
00143     //free resources.
00144     //g_mutex_free(imgdata_mutex);
00145     //g_cond_free(data_cond);
00146 }

int initSaveThread ( ScribbleUICtx pScribbleUICtx  ) 

Definition at line 88 of file ScribbleSaveThread.c.

00089 {
00090     //init the mutex and cond
00091     imgdata_mutex=g_mutex_new();
00092     if(NULL==imgdata_mutex)
00093     {
00094         SB_ERRORPRINTF("imgdata_mutex create error\n");
00095         return -1;
00096     }
00097     data_cond=g_cond_new();
00098     if(NULL==data_cond)
00099     {
00100         SB_ERRORPRINTF("data_cond create error\n");
00101         return -1;
00102     }
00103     //init save thread.
00104     GError *error=NULL;
00105     s_threadSave=g_thread_create((GThreadFunc)saveThreadMain,
00106                                   pScribbleUICtx,TRUE,&error);
00107     if(NULL==s_threadSave)
00108     {
00109         SB_ERRORPRINTF("thread create error\n");
00110         return -1;
00111     }
00112     return 0;
00113 }

Here is the call graph for this function:

void notifySave ( PScribbleUICtx  pScribbleUICtx  ) 

Definition at line 116 of file ScribbleSaveThread.c.

00117 {
00118     SB_TIMEDISPLAY("start\n");
00119     
00120     g_mutex_lock(imgdata_mutex);   
00121     SB_TIMEDISPLAY("fetch pixbuf\n");
00122     s_pixbuf = gdk_pixbuf_get_from_drawable(NULL,
00123                                             (GdkDrawable *)pScribbleUICtx->pixmap,
00124                                             NULL,0,0,0,0,-1,-1);
00125     SB_TIMEDISPLAY("end fetch\n");
00126     s_bNeedSaveResultPage=TRUE;
00127     g_cond_signal(data_cond);
00128     g_mutex_unlock(imgdata_mutex);
00129     SB_TIMEDISPLAY("end\n");
00130 }

void saveThreadMain ( gpointer  data  ) 

Definition at line 57 of file ScribbleSaveThread.c.

00058 {
00059     while( !s_bQuit )
00060     {        
00061         g_mutex_lock(imgdata_mutex);
00062         while(!s_bNeedSaveResultPage && !s_bQuit)
00063             g_cond_wait (data_cond, imgdata_mutex);      
00064         
00065         if(s_bQuit)
00066         {
00067             g_mutex_unlock(imgdata_mutex);
00068             break;
00069         }
00070         SB_TIMEDISPLAY("get save request\n");
00071         char sResultImage[MAX_FILENAME];
00072         PScribbleUICtx pScribbleUICtx=(PScribbleUICtx)data;
00073         PFileManager pFM=&pScribbleUICtx->fileManager;
00074         get_curr_result_filename(sResultImage,MAX_FILENAME,pFM);
00075         
00076         s_bNeedSaveResultPage=FALSE; 
00077         SB_TIMEDISPLAY("start save\n");          
00078         //save the result page
00079         util_savePixbuf(s_pixbuf,sResultImage,TYPE_PNG);
00080         //free memory.
00081         g_object_unref (s_pixbuf);
00082         g_mutex_unlock(imgdata_mutex);
00083         SB_TIMEDISPLAY("end save\n");
00084     }    
00085 }

Here is the call graph for this function:


Variable Documentation

GCond* data_cond = NULL

Definition at line 44 of file ScribbleSaveThread.c.

GMutex* imgdata_mutex = NULL

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

Definition at line 42 of file ScribbleSaveThread.c.

gboolean s_bNeedSaveResultPage = FALSE [static]

Definition at line 50 of file ScribbleSaveThread.c.

gboolean s_bQuit = FALSE [static]

Definition at line 48 of file ScribbleSaveThread.c.

GdkPixbuf* s_pixbuf = NULL

Definition at line 55 of file ScribbleSaveThread.c.

GThread* s_threadSave = NULL [static]

Definition at line 46 of file ScribbleSaveThread.c.


Generated on Sun Dec 14 17:14:39 2008 by  doxygen 1.5.6