atom.h

00001 /*
00002  * Copyright (c) 2005-2012 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: atom.h,v 1.8 2006/01/09 12:38:37 tat Exp $
00009  */
00010 
00011 #ifndef _KLONE_ATOM_H_
00012 #define _KLONE_ATOM_H_
00013 
00014 #include <stdlib.h>
00015 #include <u/libu.h>
00016 
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif 
00020 
00021 /* global server-maintaned atom list */
00022 typedef struct atom_s
00023 {
00024     LIST_ENTRY(atom_s) np;  /* next & prev pointers         */
00025     char *id;               /* atom identifier              */
00026     char *data;             /* atom data block              */
00027     size_t size;            /* atom data block size         */
00028     void *arg;              /* opaque data                  */
00029 } atom_t;
00030 
00031 /* define atom list */
00032 LIST_HEAD(atom_list_s, atom_s);
00033 typedef struct atom_list_s atom_list_t;
00034 
00035 struct atoms_s
00036 {
00037     atom_list_t list;
00038     size_t size, count;
00039 };
00040 
00041 /* create an atom */
00042 int atom_create(const char *id, const char *data, size_t size, void* arg, 
00043     atom_t**pa);
00044 /* free an atom */
00045 int atom_free(atom_t* atom);
00046 
00047 /* atom_t list */
00048 struct atoms_s;
00049 typedef struct atoms_s atoms_t; 
00050 
00051 /* create an atom list */
00052 int atoms_create(atoms_t **);
00053 
00054 /* free an atom list */
00055 int atoms_free(atoms_t *);
00056 
00057 /* sum of atoms size field */
00058 size_t atoms_size(atoms_t *);
00059 
00060 /* # of atoms */
00061 size_t atoms_count(atoms_t *);
00062 
00063 /* return the n-th atom */
00064 int atoms_getn(atoms_t *, size_t n, atom_t**);
00065 
00066 /* return the atom whose ID is id */
00067 int atoms_get(atoms_t *, const char *id, atom_t**);
00068 
00069 /* add an atom to the list */
00070 int atoms_add(atoms_t *, atom_t*);
00071 
00072 /* add an atom to the list */
00073 int atoms_remove(atoms_t *, atom_t*);
00074 
00075 #ifdef __cplusplus
00076 }
00077 #endif 
00078 
00079 #endif

←Products
Copyright © 2005-2012 - KoanLogic S.r.l. - All rights reserved