scbstream.c File Reference

#include <memory.h>
#include "scbstream.h"
#include "scblog.h"
Include dependency graph for scbstream.c:

Go to the source code of this file.

Defines

#define _GNU_SOURCE

Functions

ScbStreamPtr erscribble_create_stream (const int size)
void erscribble_free_stream (ScbStreamPtr stream, gboolean is_free_buffer)
gboolean erscribble_read_stream (ScbStreamPtr stream, void *data, const int length)
gboolean erscribble_write_stream (ScbStreamPtr stream, const void *data, const int length)
void erscribble_reset_offset (ScbStreamPtr stream)

Define Documentation

#define _GNU_SOURCE

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

Definition at line 28 of file scbstream.c.


Function Documentation

ScbStreamPtr erscribble_create_stream ( const int  size  ) 

Definition at line 68 of file scbstream.c.

References ERRORPRINTF.

Referenced by erscribble_doc_save_page(), and load_page_data().

00069 {
00070     ScbStreamPtr ptr = g_new0(ScbStream, 1);
00071 
00072     if (ptr == NULL)
00073     {
00074         ERRORPRINTF("Could not allocate memory stream!");
00075         return NULL;
00076     }
00077 
00078     ptr->buffer = g_malloc0(size);
00079     if (ptr->buffer == NULL)
00080     {
00081         ERRORPRINTF("Could not allocate memory stream!");
00082         g_free(ptr);
00083         return NULL;
00084     }
00085     ptr->size = size;
00086 
00087     return ptr;
00088 }

Here is the caller graph for this function:

void erscribble_free_stream ( ScbStreamPtr  stream,
gboolean  is_free_buffer 
)

Definition at line 91 of file scbstream.c.

Referenced by erscribble_doc_save_page(), and load_page_data().

00092 {
00093     if (stream)
00094     {
00095         // release the memory
00096         if (stream->buffer && is_free_buffer)
00097         {
00098             g_free(stream->buffer);
00099             stream->buffer = NULL;
00100         }
00101 
00102         g_free(stream);
00103     }
00104 }

Here is the caller graph for this function:

gboolean erscribble_read_stream ( ScbStreamPtr  stream,
void *  data,
const int  length 
)

Definition at line 107 of file scbstream.c.

Referenced by erscribble_page_load(), erscribble_point_load(), and erscribble_stroke_load().

00108 {
00109     if (stream->offset + length > stream->size)
00110     {
00111         return FALSE;
00112     }
00113 
00114     unsigned char * src = (unsigned char*)stream->buffer + stream->offset;
00115 
00116     memcpy(data, src, length);
00117 
00118     stream->offset += length;
00119 
00120     return TRUE;
00121 }

Here is the caller graph for this function:

void erscribble_reset_offset ( ScbStreamPtr  stream  ) 

Definition at line 158 of file scbstream.c.

Referenced by load_page_data().

00159 {
00160     stream->offset = 0;
00161 }

Here is the caller graph for this function:

gboolean erscribble_write_stream ( ScbStreamPtr  stream,
const void *  data,
const int  length 
)

Definition at line 124 of file scbstream.c.

Referenced by erscribble_page_write_stream(), erscribble_stroke_write_stream(), and load_page_data().

00125 {
00126     if (stream->offset + length > stream->size)
00127     {
00128         // reallocate memory
00129         void * new_mem = g_malloc0(stream->size + length);
00130 
00131         if (new_mem == NULL)
00132         {
00133             return FALSE;
00134         }
00135 
00136         // copy the content from previous buffer to new buffer
00137         memcpy(new_mem, stream->buffer, stream->offset);
00138 
00139         // free the previous buffer
00140         g_free(stream->buffer);
00141 
00142         stream->buffer = new_mem;
00143 
00144         stream->size += length;
00145     }
00146 
00147     unsigned char * dst = (unsigned char *)stream->buffer + stream->offset;
00148 
00149     // copy the memory to the buffer
00150     memcpy(dst, data, length);
00151 
00152     stream->offset += length;
00153     
00154     return TRUE;
00155 }

Here is the caller graph for this function:

Generated by  doxygen 1.6.2-20100208