Browse Source
moved the class and memory management into a separate project libtrbase / prefix all of the public interface of libtrbase with TR_
next
moved the class and memory management into a separate project libtrbase / prefix all of the public interface of libtrbase with TR_
next
182 changed files with 637 additions and 2647 deletions
-
6configure.ac
-
4include/application/adapter/http.h
-
4include/application/application.h
-
5include/asset.h
-
4include/auth/auth.h
-
4include/auth/credential.h
-
10include/auth/interface/auth.h
-
4include/auth/ldap.h
-
4include/auth/storage.h
-
7include/cbuf.h
-
10include/class.h
-
143include/class/class.h
-
59include/class/interface.h
-
64include/class/interface/class.h
-
48include/commons.h
-
4include/config/config.h
-
4include/config/value.h
-
4include/hash/hash.h
-
8include/hash/interface/hashable.h
-
4include/hash/value.h
-
4include/http/cookie.h
-
4include/http/header.h
-
8include/http/interface/http_intro.h
-
4include/http/message.h
-
5include/http/parser.h
-
6include/http/request.h
-
6include/http/response.h
-
5include/http/worker.h
-
6include/http/writer.h
-
49include/interface/indexable.h
-
40include/interface/observer.h
-
42include/interface/serializable.h
-
46include/interface/subject.h
-
8include/logger/interface/logger.h
-
12include/logger/logger.h
-
4include/permission.h
-
5include/queue.h
-
4include/rbac/object.h
-
4include/rbac/operation.h
-
4include/rbac/user.h
-
4include/role.h
-
4include/router.h
-
4include/server.h
-
4include/session.h
-
4include/socket.h
-
4include/storage/storage.h
-
7include/stream/interface/reader.h
-
7include/stream/interface/writer.h
-
4include/stream/stream.h
-
4include/tree.h
-
5include/user.h
-
40include/utils/memory.h
-
5include/uuid.h
-
21src/Makefile.am
-
16src/application/adapter/http/http.c
-
3src/application/adapter/http/update.c
-
19src/application/application.c
-
5src/application/controller/_get_credential_from_args.c
-
6src/application/controller/_get_user_from_args.c
-
7src/application/controller/_process_user_create_args.c
-
8src/application/controller/_update_user_from_args.c
-
4src/application/controller/_validate_email.c
-
3src/application/controller/_validate_password.c
-
4src/application/controller/_validate_password_repeat.c
-
7src/application/controller/authenticate/create.c
-
2src/application/controller/authenticate/delete.c
-
6src/application/controller/currentuser/read.c
-
5src/application/controller/loc/read.c
-
6src/application/controller/randval/read.c
-
5src/application/controller/sessinfo/read.c
-
8src/application/controller/signup/create.c
-
8src/application/controller/user/create.c
-
6src/application/controller/user/read.c
-
5src/application/controller/user/update.c
-
5src/application/controller/version/read.c
-
14src/application/create_user.c
-
12src/application/get_user.c
-
27src/application/login.c
-
5src/application/logout.c
-
7src/application/session_cleanup.c
-
3src/application/session_get.c
-
5src/application/session_start.c
-
3src/application/session_stop.c
-
12src/application/update_password.c
-
13src/application/update_user.c
-
8src/asset/asset.c
-
16src/asset/pool.c
-
12src/auth/auth.c
-
9src/auth/create.c
-
16src/auth/credential.c
-
7src/auth/interface/auth.c
-
18src/auth/ldap.c
-
10src/auth/storage/hash_pw.c
-
16src/auth/storage/storage.c
-
12src/cbuf/cbuf.c
-
2src/cbuf/is_locked.c
-
9src/class/Makefile.am
-
64src/class/interface.c
-
99src/class/interface/i_class.c
-
22src/config/config.c
@ -1,10 +0,0 @@ |
|||
#ifndef __CLASS_H__ |
|||
#define __CLASS_H__ |
|||
|
|||
#include "class/class.h" |
|||
#include "class/interface.h" |
|||
#include "class/interface/class.h" |
|||
|
|||
#endif // __CLASS_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,143 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* My own class implementation for C. It combines a data structure |
|||
* with a set of dynamically linked methods defined by an interface. A |
|||
* dynamically linked method will be called via a selector method which in |
|||
* turn gets the implementation stored in the class. |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __CLASS_CLASS_H__ |
|||
#define __CLASS_CLASS_H__ |
|||
|
|||
#include <stdarg.h> |
|||
#include <sys/types.h> |
|||
#include <string.h> |
|||
#include <assert.h> |
|||
|
|||
#include "class/interface.h" |
|||
|
|||
#ifndef _ISOC99_SOURCE |
|||
#define _ISOC99_SOURCE |
|||
#endif |
|||
|
|||
#define CLASS_MAGIC 0xFEFE |
|||
|
|||
#define CLASS(name) \ |
|||
struct c_##name; \ |
|||
typedef struct c_##name * name; \ |
|||
extern struct class * const _##name; \ |
|||
struct c_##name |
|||
|
|||
#define EXTENDS(parent) \ |
|||
const char _[sizeof(struct c_##parent)] |
|||
|
|||
#define _NULL NULL |
|||
#define CREATE_CLASS(name,_parent,...) \ |
|||
static struct class c_##name; \ |
|||
static class_ptr _classInit##name##_(void) { \ |
|||
c_##name.parent = _##_parent; \ |
|||
c_##name.init = NULL; \ |
|||
return &c_##name; \ |
|||
} \ |
|||
static struct class c_##name = { \ |
|||
CLASS_MAGIC, \ |
|||
NULL, \ |
|||
sizeof(struct c_##name), \ |
|||
_classInit##name##_, \ |
|||
INIT_IFACE_IMPL(__VA_ARGS__) \ |
|||
}; struct class * const _##name = &c_##name; \ |
|||
struct c_##name##_object { void * class; struct c_##name data; } |
|||
|
|||
|
|||
/** |
|||
* create a static instance of a class. |
|||
* \todo |
|||
* this macro requires to close the initializer |
|||
* with an extra curly brancket. This is not nice...find a |
|||
* way to prevent this. |
|||
*/ |
|||
#define INSTANCE(class, name) \ |
|||
struct c_##class##_object _##name; \ |
|||
class name = &(_##name.data); \ |
|||
struct c_##class##_object _##name = { \ |
|||
&c_##class, |
|||
|
|||
#define INIT_CLASS(class) ((class)->init? (class)->init() : (class)) |
|||
#define GET_CLASS(object) (INIT_CLASS(*(class_ptr *)((void*)(object) - sizeof(void*)))) |
|||
#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface))) |
|||
#define HAS_PARENT(class) (NULL != ((class)->parent) && INIT_CLASS((class)->parent)) |
|||
|
|||
#define IS_OBJECT(obj) ((GET_CLASS((obj)))->magic == CLASS_MAGIC) |
|||
#define INSTANCE_OF(class,obj) ((GET_CLASS((obj))) == _##class) |
|||
|
|||
/** |
|||
* \todo actually i use gcc feature ## for variadoc... think about |
|||
* a way to make this standard. |
|||
*/ |
|||
#define _CALL(_class,_iface,method,...) \ |
|||
do { \ |
|||
class_ptr class = _class; \ |
|||
iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ |
|||
while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \ |
|||
class = class->parent; \ |
|||
iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \ |
|||
} \ |
|||
assert(NULL != iface->method); \ |
|||
} while(0) |
|||
|
|||
#define CALL(object,_iface,method,...) \ |
|||
do { \ |
|||
struct i_##_iface * iface; \ |
|||
_CALL(GET_CLASS(object), _iface, method, ##__VA_ARGS__); \ |
|||
iface->method(object, ##__VA_ARGS__); \ |
|||
} while(0) |
|||
|
|||
#define RETCALL(object,_iface,method,ret,...) \ |
|||
do { \ |
|||
struct i_##_iface * iface; \ |
|||
_CALL(GET_CLASS(object), _iface, method, ##__VA_ARGS__); \ |
|||
ret = iface->method(object, ##__VA_ARGS__); \ |
|||
} while(0) |
|||
|
|||
#define PARENTCALL(object,_iface,method,...) \ |
|||
do { \ |
|||
struct i_##_iface * iface; \ |
|||
class_ptr pc_class = GET_CLASS((object)); \ |
|||
assert(HAS_PARENT(pc_class)); \ |
|||
_CALL(pc_class->parent, _iface, method, ##__VA_ARGS__); \ |
|||
iface->method(object, ##__VA_ARGS__); \ |
|||
} while(0) |
|||
|
|||
|
|||
struct class; |
|||
typedef struct class * class_ptr; |
|||
typedef class_ptr (* fptr_classInit)(void); |
|||
struct class { |
|||
const int magic; |
|||
class_ptr parent; |
|||
size_t object_size; |
|||
fptr_classInit init; |
|||
struct iface_impl impl; |
|||
}; |
|||
|
|||
#endif // __CLASS_CLASS_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,59 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* Interface definition code. Each interface is a set of selector functions |
|||
* as well as a data structure where the concrete implementation will be stored. |
|||
* This structure is the intergrated in the class that implements the |
|||
* interface. |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __CLASS_INTERFACE_H__ |
|||
#define __CLASS_INTERFACE_H__ |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
#define MAX_IFACE 32 // ATTENTION: every iface_impl will use MAX_IFACE * sizeof(void*) |
|||
|
|||
#define IFACE(name) ((const struct i_##name const*)&i_##name##_impl) |
|||
#define INIT_IFACE(name,...) \ |
|||
static const struct i_##name i_##name##_impl = {&i_##name,__VA_ARGS__} |
|||
|
|||
#define NUMARGS(...) (sizeof((const void*[]){__VA_ARGS__})/sizeof(void*)) |
|||
#define INIT_IFACE_IMPL(...) {NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}} |
|||
|
|||
|
|||
struct interface { |
|||
const char * name; |
|||
const size_t nmethods; |
|||
}; |
|||
typedef const struct interface * iface_ptr; |
|||
|
|||
struct iface_impl { |
|||
const size_t nimpl; // number of interface implementations |
|||
char simpl; // implementations sorted?? |
|||
const void * impl[MAX_IFACE]; // implementations |
|||
}; |
|||
typedef struct iface_impl * iface_impl_ptr; |
|||
|
|||
extern iface_ptr interfaceGet(iface_impl_ptr, const iface_ptr); |
|||
|
|||
#endif // __CLASS_INTERFACE_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,64 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* Interface for class handling. Defines new, delete and clone selectors |
|||
* which in turn use the ctor, dtor and clone implementation from the |
|||
* class implementation. |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __CLASS_INTERFACE_CLASS_H__ |
|||
#define __CLASS_INTERFACE_CLASS_H__ |
|||
|
|||
#include <stdarg.h> |
|||
|
|||
#include "class/class.h" |
|||
#include "class/interface.h" |
|||
|
|||
typedef int (* fptr_ctor)(void *, va_list *); |
|||
typedef void (* fptr_dtor)(void *); |
|||
typedef void (* fptr_clone)(void *, void * const); |
|||
|
|||
extern const struct interface i_Class; |
|||
|
|||
struct i_Class { |
|||
const struct interface * const _; |
|||
fptr_ctor ctor; |
|||
fptr_dtor dtor; |
|||
fptr_clone clone; |
|||
}; |
|||
|
|||
extern void * classNew(class_ptr, ...); |
|||
extern void classDelete(void **); |
|||
extern void * classClone(void *); |
|||
|
|||
#define new(class,...) classNew(_##class, ##__VA_ARGS__) |
|||
#define delete(object) classDelete((void **)&(object)) |
|||
#define clone(object) classClone((void *)(object)) |
|||
|
|||
/** |
|||
* With this one we can create a new instance via a |
|||
* intermidiary that gets the arguments. |
|||
*/ |
|||
extern void * classNewParams(class_ptr, va_list *); |
|||
#define newParams(class,args) classNewParams(_##class, args) |
|||
|
|||
#endif // __CLASS_INTERFACE_CLASS_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,48 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __COMMONS_H__ |
|||
#define __COMMONS_H__ |
|||
|
|||
#define Bool char |
|||
#define TRUE 1 |
|||
#define FALSE 0 |
|||
|
|||
#ifndef MAX |
|||
# define MAX(a,b) ((a)>(b)? (a) : (b)) |
|||
#endif |
|||
|
|||
#ifndef MIN |
|||
# define MIN(a,b) ((a)<(b)? (a) : (b)) |
|||
#endif |
|||
|
|||
#define SWAP_FUN(a, b) ((a)^=(b),(b)^=(a),(a)^=(b)) |
|||
|
|||
#define SWAP(type, a, b) do { \ |
|||
type tmp = (a); \ |
|||
(a) = (b); \ |
|||
(b) = tmp; \ |
|||
} while(0); |
|||
|
|||
#endif // __COMMONS_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,49 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* This interface provides only one function at all. |
|||
* indexUuid will generate a uuid to the current object. |
|||
* |
|||
* \todo |
|||
* Maybe merge hashable and indexable. Thus we might get an |
|||
* easy way to exchange the hashing mechanism used for my |
|||
* associative arrays. |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __INDEXABLE_H__ |
|||
#define __INDEXABLE_H__ |
|||
|
|||
#include "uuid.h" |
|||
|
|||
|
|||
typedef Uuid (* fptr_indexUuid)(void *, Uuid); |
|||
|
|||
extern const struct interface i_Indexable; |
|||
|
|||
struct i_Indexable { |
|||
const struct interface * const _; |
|||
fptr_indexUuid uuid; |
|||
}; |
|||
|
|||
extern Uuid indexUuid(void *, Uuid); |
|||
|
|||
#endif // __INDEXABLE_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,40 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* Definition of the observer pattern implementation. |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __OBSERVER_H__ |
|||
#define __OBSERVER_H__ |
|||
|
|||
typedef void (* fptr_observerUpdate)(void *, void*); |
|||
|
|||
extern const struct interface i_Observer; |
|||
|
|||
struct i_Observer { |
|||
const struct interface * const _; |
|||
fptr_observerUpdate update; |
|||
}; |
|||
|
|||
extern void observerUpdate(void *, void *); |
|||
|
|||
#endif // __OBSERVER_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,42 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __SERIALIZABLE_H__ |
|||
#define __SERIALIZABLE_H__ |
|||
|
|||
typedef void (* fptr_serialize)(void *, unsigned char **, size_t *); |
|||
typedef void (* fptr_unserialize)(void *, const unsigned char *, size_t); |
|||
|
|||
extern const struct interface i_Serializable; |
|||
|
|||
struct i_Serializable { |
|||
const struct interface * const _; |
|||
fptr_serialize serialize; |
|||
fptr_unserialize unserialize; |
|||
}; |
|||
|
|||
extern void serialize(void *, unsigned char **, size_t *); |
|||
extern void unserialize(void *, const unsigned char *, size_t); |
|||
|
|||
#endif // __SERIALIZABLE_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,46 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* Definition of the subject pattern implementation. |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __SUBJECT_H__ |
|||
#define __SUBJECT_H__ |
|||
|
|||
typedef void (* fptr_subjectAttach)(void *, void *); |
|||
typedef void (* fptr_subjectDetach)(void *, void *); |
|||
typedef void (* fptr_subjectNotify)(void *); |
|||
|
|||
extern const struct interface i_Subject; |
|||
|
|||
struct i_Subject { |
|||
const struct interface * const _; |
|||
fptr_subjectAttach attach; |
|||
fptr_subjectDetach detach; |
|||
fptr_subjectNotify notify; |
|||
}; |
|||
|
|||
extern void subjectAttach(void *, void *); |
|||
extern void subjectDetach(void *, void *); |
|||
extern void subjectNotify(void *); |
|||
|
|||
#endif // __SUBJECT_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,40 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#ifndef __UTILS_MEMORY_H__ |
|||
#define __UTILS_MEMORY_H__ |
|||
|
|||
#define CSTRA(val) val, sizeof(val)-1 //!< Const STRing Argument |
|||
|
|||
#define MEM_FREE(seg) (memFree((void **)&(seg))) |
|||
|
|||
#include <sys/types.h> |
|||
|
|||
void * memMalloc(size_t); |
|||
void * memCalloc(size_t, size_t); |
|||
void memFree(void **); |
|||
size_t memGetSize(void *); |
|||
void memCleanup(); |
|||
|
|||
#endif // __UTILS_MEMORY_H__ |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,9 +0,0 @@ |
|||
ACLOCAL_AMFLAGS = -I m4 |
|||
AUTOMAKE_OPTIONS = subdir-objects |
|||
|
|||
AM_CFLAGS += -I../../include/ |
|||
|
|||
noinst_LTLIBRARIES = libclass.la |
|||
|
|||
libclass_la_SOURCES = interface.c interface/i_class.c |
|||
libclass_la_CFLAGS = $(AM_CFLAGS) |
|||
@ -1,64 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <sys/types.h> |
|||
#include <stdlib.h> |
|||
|
|||
#include "class/interface.h" |
|||
#include "commons.h" |
|||
|
|||
static |
|||
inline |
|||
int |
|||
comp(const void * _a, const void * _b) |
|||
{ |
|||
const struct interface * a = **(const struct interface ***)_a; |
|||
const struct interface * b = **(const struct interface ***)_b; |
|||
return ((a)<(b))? -1 : ((a)>(b))? 1 : 0; |
|||
} |
|||
|
|||
/** |
|||
* this one is important in selector functions to get the correct interface |
|||
* implementation of a class. |
|||
*/ |
|||
iface_ptr |
|||
interfaceGet(iface_impl_ptr iface_impl, const iface_ptr _iface) |
|||
{ |
|||
const iface_ptr * iface = &_iface; |
|||
iface_ptr * found; |
|||
|
|||
if (! iface_impl->simpl) { |
|||
qsort((void**)(iface_impl->impl), iface_impl->nimpl, sizeof(iface_ptr), comp); |
|||
iface_impl->simpl=TRUE; |
|||
} |
|||
|
|||
found = bsearch( |
|||
&iface, |
|||
iface_impl->impl, |
|||
iface_impl->nimpl, |
|||
sizeof(iface_ptr), |
|||
comp); |
|||
|
|||
return found? *found : (iface_ptr)NULL; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
@ -1,99 +0,0 @@ |
|||
/** |
|||
* \file |
|||
* |
|||
* \author Georg Hopp |
|||
* |
|||
* \copyright |
|||
* Copyright © 2012 Georg Hopp |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation, either version 3 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
#include <stdarg.h> |
|||
#include <stdlib.h> |
|||
#include <assert.h> |
|||
|
|||
#include "class/class.h" |
|||
#include "class/interface/class.h" |
|||
|
|||
#include "utils/memory.h" |
|||
|
|||
|
|||
const |
|||
struct interface i_Class = { |
|||
"class", |
|||
3 |
|||
}; |
|||
|
|||
void * |
|||
classNewParams(class_ptr class, va_list * params) |
|||
{ |
|||
void * object = memCalloc(1, class->object_size + sizeof(void*)); |
|||
int ret; |
|||
|
|||
* (class_ptr *)object = class; |
|||
object += sizeof(void*); |
|||
|
|||
RETCALL(object, Class, ctor, ret, params); |
|||
|
|||
if (-1 == ret) { |
|||
classDelete(&object); |
|||
} |
|||
|
|||
return object; |
|||
} |
|||
|
|||
void * |
|||
classNew(class_ptr class, ...) |
|||
{ |
|||
va_list params; |
|||
void * object; |
|||
|
|||
va_start(params, class); |
|||
object = classNewParams(class, ¶ms); |
|||
va_end(params); |
|||
|
|||
return object; |
|||
} |
|||
|
|||
void |
|||
classDelete(void ** object) |
|||
{ |
|||
if (NULL != *object) { |
|||
void * mem; |
|||
|
|||
CALL(*object, Class, dtor); |
|||
|
|||
mem = *object - sizeof(void*); |
|||
MEM_FREE(mem); |
|||
*object = NULL; |
|||
} |
|||
} |
|||
|
|||
void * |
|||
classClone(void * _object) |
|||
{ |
|||
class_ptr class = GET_CLASS(_object); |
|||
void * object = memCalloc(1, class->object_size + sizeof(void*)); |
|||
|
|||
* (class_ptr *)object = class; |
|||
object += sizeof(void*); |
|||
|
|||
#undef clone |
|||
CALL(object, Class, clone, _object); |
|||
|
|||
return object; |
|||
} |
|||
|
|||
// vim: set ts=4 sw=4: |
|||
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue