gs_proxy.cpp
2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "gs_id.h"
#include "gs_base.h"
// We only gen proxy when GS_USE_PROXY is enabled
#ifdef GS_USE_PROXY
struct GS_IBaseProxy;
struct GS_IBaseVT
{
int (CALLCC *addRef)(GS_IBaseProxy* self);
int (CALLCC *release)(GS_IBaseProxy* self);
int (CALLCC *queryInterface)(GS_IBaseProxy* self, int iid, GS_IBase** pptr);
};
struct GS_IBaseProxyBase
{
static void* operator new (unsigned int size, void *buf)
{
return buf;
}
void* operator new (unsigned int size)
{
gs_assert(0);
return NULL;
}
void operator delete (void* ptr)
{
gs_free_proxy(ptr);
}
};
struct GS_IBaseProxy : public GS_IBaseProxyBase
{
const GS_IBaseVT* vt;
GS_IBase* obj;
int refCount;
GS_IBaseProxy(GS_IBase* ptr);
};
int CALLCC GS_IBaseProxy_addRef(GS_IBaseProxy* self)
{
self->refCount++;
return self->obj->addRef();
}
int CALLCC GS_IBaseProxy_release(GS_IBaseProxy* self)
{
GS_IBase* obj= self->obj;
self->refCount--;
obj->addRef();
obj->release();
if (self->refCount == 0)
{
GS_DEL(self);
}
int r = obj->release();
return r;
}
int CALLCC GS_IBaseProxy_queryInterface(GS_IBaseProxy* self, int iid, GS_IBase** pptr)
{
return self->obj->queryInterface(iid, pptr);
}
const GS_IBaseVT g_GS_IBaseVT = {
&GS_IBaseProxy_addRef,
&GS_IBaseProxy_release,
&GS_IBaseProxy_queryInterface
};
GS_IBaseProxy::GS_IBaseProxy(GS_IBase* ptr)
{
vt = &g_GS_IBaseVT;
obj = ptr;
refCount = 1;
}
GS_IBase* GS_IBaseProxy_bind(GS_IBase* ptr)
{
GS_IBaseProxy* p = NULL;
GS_NEW_EX(p, GS_IBaseProxy, (ptr));
return (GS_IBase*)p;
}
#define GS_GEN_INTERFACE
#include "gs_all_interface_def.h"
#undef GS_GEN_INTERFACE
#define GS_GEN_PROXY_HEADER
#include "gs_all_interface_def.h"
#undef GS_GEN_PROXY_HEADER
#define GS_GEN_PROXY_IMPL
#include "gs_all_interface_def.h"
#undef GS_GEN_PROXY_IMPL
#define GS_GEN_PROXY_VT
#include "gs_all_interface_def.h"
#undef GS_GEN_PROXY_VT
#endif // GS_USE_PROXY