__object.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * 文件名: __object.h
  3. * 目标: 定义aft对象的结构体
  4. */
  5. #ifndef AFUN_OBJECT_H_
  6. #define AFUN_OBJECT_H_
  7. #include "tool.h"
  8. #include "obj_api.h" // 该文件不包含在object.h中, object.h并不依赖该文件
  9. // 这些typedef可能会被下面include的文件使用
  10. typedef struct af_ObjectData af_ObjectData;
  11. typedef struct af_ObjectAPINode af_ObjectAPINode;
  12. #include "object.h"
  13. #include "__gc.h"
  14. #include "pthread.h"
  15. #define API_HASHTABLE_SIZE (8)
  16. typedef void objectAPIFunc();
  17. NEW_DLC_SYMBOL(objectAPIFunc, objectAPIFunc);
  18. struct af_ObjectAPINode {
  19. char *name; // api名字
  20. DLC_SYMBOL(objectAPIFunc) api; // api函数
  21. struct af_ObjectAPINode *next;
  22. };
  23. struct af_ObjectAPI {
  24. ObjAPIUint count; // api个数记录
  25. struct af_ObjectAPINode *(node[API_HASHTABLE_SIZE]);
  26. };
  27. struct af_ObjectData {
  28. char *id; // 对象类型标识符(一个字符串)
  29. void *data;
  30. size_t size; // 标记data的大小
  31. struct af_ObjectAPI *api; // 继承的api必须位于Inherit链中
  32. bool allow_inherit; // 是否允许被继承
  33. bool free_api; // 是否释放api
  34. struct af_VarSpace *var_space;
  35. struct af_Inherit *inherit; // 只有顶级继承对象的inherit属性可为NULL
  36. struct af_Object *base; // 在gc机制中, 当对想要被释放前, 调用析构函数是对象以该base的身份出现
  37. pthread_rwlock_t lock;
  38. GC_ObjectData gc;
  39. };
  40. struct af_Object {
  41. struct af_Object *belong; // 只有顶级属对象的belong属性可为NULL
  42. struct af_ObjectData *data;
  43. pthread_rwlock_t lock; // 保护上面两个字段
  44. GC_Object gc;
  45. };
  46. struct af_Inherit {
  47. struct af_Object *obj;
  48. struct af_VarSpace *vs; // 共享变量空间
  49. struct af_Inherit *next;
  50. };
  51. /* 对象 创建与释放 */
  52. AFUN_CORE_NO_EXPORT void freeObject(af_Object *obj, af_Environment *env);
  53. /* ObjectData 属性访问 */
  54. AFUN_CORE_NO_EXPORT af_Object *findObjectAttributesByObjectData(char *name, af_Object *visitor, af_ObjectData *od);
  55. /* ObjectData 释放函数 */
  56. AFUN_CORE_NO_EXPORT void freeObjectDataData(af_ObjectData *od, af_Environment *env);
  57. AFUN_CORE_NO_EXPORT void freeObjectData(af_ObjectData *od, af_Environment *env);
  58. #endif //AFUN_OBJECT_H_