Data Object

A data object is an abstraction for objects that can provide data. More...

Typedefs

typedef struct data_object data_object_t
 Opaque type for data object ADT.
typedef int( data_object_file_close_func )(int fd)
 A function used to close the file owned by a file data_object_t.
typedef void( data_object_memory_free_func )(void *)
 A function used to free the data owned by a memory data_object_t.

Enumerations

enum  data_object_flags { DATA_OBJECT_READ = 1, DATA_OBJECT_WRITE = 2, DATA_OBJECT_RW = 3 }
 

Flags for the usage of data returned by data_object_get_data().

More...

Functions

int data_object_get_data (data_object_t *obj, void **buf, off_t offset, off_t *length, data_object_flags flags)
 Gets a pointer to data from the data object.
int data_object_free (data_object_t *obj)
 Frees the data object and its resources.
int data_object_update_usage (void *obj, int change)
 Updates the usage count of this data object.
int data_object_get_size (data_object_t *obj, off_t *size)
 Gets the size of the data object.
int data_object_compare (int *result, data_object_t *obj1, data_object_t *obj2)
 Compares the data held by two data objects.

Constructors



int data_object_file_new (data_object_t **obj, int fd)
 Creates a new file data object.
int data_object_tempfile_new (data_object_t **obj, int fd, char *path)
 Creates a new temporary file data object.
int data_object_file_set_close_func (data_object_t *obj, data_object_file_close_func *file_close)
 Sets the function used to close the file associated with the data object.

Constructors



int data_object_memory_new (data_object_t **obj, void *data, size_t size)
 Creates a new memory data object initialized with data.
int data_object_memory_set_free_func (data_object_t *obj, data_object_memory_free_func *mem_free)
 Sets the function used to free the data held by the data object.

Detailed Description

A data object is an abstraction for objects that can provide data.

It provides a common API to transparently get the data regardless of the particular source they come from.

The two main data object types are the memory data object and the file data object. To create a data object one must use the provided constructor for the particular type.


Enumeration Type Documentation

Flags for the usage of data returned by data_object_get_data().

Enumerator:
DATA_OBJECT_READ 

Data will be used just for reading.

DATA_OBJECT_WRITE 

Data will be used just for writing.

DATA_OBJECT_RW 

Data will be used for both reading and writing.

Definition at line 58 of file data_object.h.


Function Documentation

int data_object_compare ( int *  result,
data_object_t obj1,
data_object_t obj2 
)

Compares the data held by two data objects.

Note that the compare is based on reference equality (eg for memory data objects if their data is located at the same memory area, for file objects if they are associated with the same file) not byte by byte comparison.

Parameters:
[out] result 0 if they are equal, 1 otherwise
obj1 one of the data objects to compare
obj2 the other data object to compare
Returns:
the operation error code

Definition at line 194 of file data_object.c.

Referenced by create_overlap_graph(), and write_segcol_rest().

Here is the caller graph for this function:

int data_object_file_new ( data_object_t **  obj,
int  fd 
)

Creates a new file data object.

The data object by default doesn't own the file passed to it. That means that when the data object is freed the file will not be closed. To change data ownership by the data_object_t use data_object_set_data_ownership().

Parameters:
[out] obj the created data object
fd the file descriptor of the file to use
Returns:
the operation error code

Definition at line 90 of file data_object_file.c.

References data_object_create_impl().

Referenced by bless_buffer_save(), bless_buffer_source_file(), and data_object_tempfile_new().

Here is the call graph for this function:

Here is the caller graph for this function:

int data_object_file_set_close_func ( data_object_t obj,
data_object_file_close_func file_close 
)

Sets the function used to close the file associated with the data object.

If the function is NULL, the file wont be closed when the data object is freed.

Parameters:
obj the data object
file_close the function used to close the file associated with the data object
Returns:
the operation error code

Definition at line 204 of file data_object_file.c.

References data_object_get_impl().

Referenced by bless_buffer_source_file(), and segcol_store_in_file().

Here is the call graph for this function:

Here is the caller graph for this function:

int data_object_free ( data_object_t obj  ) 

Frees the data object and its resources.

Parameters:
obj the data object to free
Returns:
the operation error code

Definition at line 121 of file data_object.c.

Referenced by bless_buffer_save(), bless_buffer_source_file(), bless_buffer_source_memory(), data_object_tempfile_new(), data_object_update_usage(), segcol_store_in_file(), and segcol_store_in_memory().

Here is the caller graph for this function:

int data_object_get_data ( data_object_t obj,
void **  buf,
off_t  offset,
off_t *  length,
data_object_flags  flags 
)

Gets a pointer to data from the data object.

This function provides a pointer that points to a location that contains the data range requested. It is possible that a call to this function retrieves only some of the requested data. Subsequent calls may be needed to complete the whole operation.

Furthermore, the pointer returned is valid only as long as no other access is made to the data object (watch out for concurrency issues!).

Parameters:
obj the obj to get the data from
[out] buf the location that will contain the data
offset the offset in the data object to get data from
[in,out] length the length of the data to get, on return will contain the length of the data that was actually retrieved. The returned length always fits in an ssize_t variable.
flags whether the data will be read or written to (or both)
Returns:
the operation error code

Definition at line 108 of file data_object.c.

Referenced by read_data_object(), and write_data_object().

Here is the caller graph for this function:

int data_object_get_size ( data_object_t obj,
off_t *  size 
)

Gets the size of the data object.

Parameters:
obj the data object to get the size of
[out] size the size of the data object
Returns:
the operation error code

Definition at line 175 of file data_object.c.

int data_object_memory_new ( data_object_t **  obj,
void *  data,
size_t  size 
)

Creates a new memory data object initialized with data.

The data object by default doesn't own the data passed to it. That means that when the data object is freed the data will not be freed. To change data ownership by the data_object_t use data_object_set_data_ownership().

Parameters:
[out] obj the created data object
data the data that this data object will contain
size the size of the data (and the data object)
Returns:
the operation error code

Definition at line 76 of file data_object_memory.c.

References data_object_create_impl().

Referenced by bless_buffer_source_memory(), and segcol_store_in_memory().

Here is the call graph for this function:

Here is the caller graph for this function:

int data_object_memory_set_free_func ( data_object_t obj,
data_object_memory_free_func mem_free 
)

Sets the function used to free the data held by the data object.

If the function is NULL, the data won't be freed when the data object is freed.

Parameters:
obj the data object
mem_free the function used to free the data held by the data object
Returns:
the operation error code

Definition at line 122 of file data_object_memory.c.

References data_object_get_impl().

Referenced by bless_buffer_source_memory(), and segcol_store_in_memory().

Here is the call graph for this function:

Here is the caller graph for this function:

int data_object_tempfile_new ( data_object_t **  obj,
int  fd,
char *  path 
)

Creates a new temporary file data object.

When the data object is freed the temporary file will be deleted from the file system.

The data object by default doesn't own the file passed to it. That means that when the data object is freed the file will not be closed. To change data ownership by the data_object_t use data_object_set_data_ownership().

Parameters:
[out] obj the created data object
fd the file descriptor of the file to use
path the path of the file the file descriptor points to
Returns:
the operation error code

Definition at line 170 of file data_object_file.c.

References data_object_file_new(), data_object_free(), and data_object_get_impl().

Referenced by segcol_store_in_file().

Here is the call graph for this function:

Here is the caller graph for this function:

int data_object_update_usage ( void *  obj,
int  change 
)

Updates the usage count of this data object.

If the usage count falls to zero (or below) the data object is freed. This function is to be called by the memory management system of segment_t.

Parameters:
obj the data object
change the change in the usage count or 0 to reset the count
Returns:
the operation error code

Definition at line 145 of file data_object.c.

References data_object_free().

Referenced by bless_buffer_save(), bless_buffer_source_file(), bless_buffer_source_memory(), bless_buffer_source_unref(), segcol_store_in_file(), and segcol_store_in_memory().

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Sun Nov 15 15:27:56 2009 for libbls by  doxygen 1.6.1