- Remove obsolete structs, rearrange things to group the structs
[wine] / dlls / ole32 / compobj_private.h
1 /*
2  * Copyright 1995 Martin von Loewis
3  * Copyright 1998 Justin Bradford
4  * Copyright 1999 Francis Beaudet
5  * Copyright 1999 Sylvain St-Germain
6  * Copyright 2002 Marcus Meissner
7  * Copyright 2003 Ove Kåven, TransGaming Technologies
8  * Copyright 2004 Mike Hearn, CodeWeavers Inc
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  */
24
25 #ifndef __WINE_OLE_COMPOBJ_H
26 #define __WINE_OLE_COMPOBJ_H
27
28 /* All private prototype functions used by OLE will be added to this header file */
29
30 #include <stdarg.h>
31
32 #include "wine/list.h"
33
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wtypes.h"
37 #include "dcom.h"
38 #include "winreg.h"
39 #include "winternl.h"
40
41 struct apartment;
42 typedef struct apartment APARTMENT;
43
44 /* Thread-safety Annotation Legend:
45  *
46  * RO   - The value is read only. It never changes after creation, so no
47  *        locking is required.
48  * LOCK - The value is written to only using Interlocked* functions.
49  * CS   - The value is read or written to with a critical section held.
50  *        The identifier following "CS" is the specific critical section that
51  *        must be used.
52  */
53
54 /* an interface stub */
55 struct ifstub   
56 {
57     struct list       entry;      /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
58     IRpcStubBuffer   *stubbuffer; /* RO */
59     IID               iid;        /* RO */
60     IPID              ipid;       /* RO */
61     IUnknown         *iface;      /* RO */
62     BOOL              table;      /* CS stub_manager->lock */
63 };
64
65
66 /* stub managers hold refs on the object and each interface stub */
67 struct stub_manager
68 {
69     struct list       entry;      /* entry in apartment stubmgr list (CS apt->cs) */
70     struct list       ifstubs;    /* list of active ifstubs for the object (CS lock) */
71     CRITICAL_SECTION  lock;
72     APARTMENT        *apt;        /* owning apt (RO) */
73
74     ULONG             extrefs;    /* number of 'external' references (LOCK) */
75     ULONG             refs;       /* internal reference count (CS apt->cs) */
76     OID               oid;        /* apartment-scoped unique identifier (RO) */
77     IUnknown         *object;     /* the object we are managing the stub for (RO) */
78     ULONG             next_ipid;  /* currently unused (LOCK) */
79 };
80
81 /* imported interface proxy */
82 struct ifproxy
83 {
84   struct list entry;
85   LPVOID iface;            /* interface pointer (RO) */
86   IID iid;                 /* interface ID (RO) */
87   IPID ipid;               /* imported interface ID (RO) */
88   LPRPCPROXYBUFFER proxy;  /* interface proxy (RO) */
89   DWORD refs;              /* imported (public) references (CS ?) */
90 };
91
92 /* imported object / proxy manager */
93 struct proxy_manager
94 {
95   const IInternalUnknownVtbl *lpVtbl;
96   struct apartment *parent; /* owning apartment (RO) */
97   struct list entry;        /* entry in apartment (CS parent->cs) */
98   LPRPCCHANNELBUFFER chan;  /* channel to object (CS cs) */
99   OXID oxid;                /* object exported ID (RO) */
100   OID oid;                  /* object ID (RO) */
101   struct list interfaces;   /* imported interfaces (CS cs) */
102   DWORD refs;               /* proxy reference count (LOCK) */
103   CRITICAL_SECTION cs;      /* thread safety for this object and children */
104 };
105
106 /* this needs to become a COM object that implements IRemUnknown */
107 struct apartment
108 {
109   struct list entry;       
110
111   DWORD refs;              /* refcount of the apartment (LOCK) */
112   DWORD model;             /* threading model (RO) */
113   DWORD tid;               /* thread id (RO) */
114   HANDLE thread;           /* thread handle (RO) */
115   OXID oxid;               /* object exporter ID (RO) */
116   OID oidc;                /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
117   HWND win;                /* message window (RO) */
118   CRITICAL_SECTION cs;     /* thread safety */
119   LPMESSAGEFILTER filter;  /* message filter (CS cs) */
120   struct list proxies;     /* imported objects (CS cs) */
121   struct list stubmgrs;    /* stub managers for exported objects (CS cs) */
122
123   DWORD listenertid;       /* id of apartment_listener_thread. FIXME: remove me */
124 };
125
126 /* this is what is stored in TEB->ReservedForOle */
127 struct oletls
128 {
129     struct apartment *apt;
130     IErrorInfo       *errorinfo;   /* see errorinfo.c */
131     IUnknown         *state;       /* see CoSetState */
132     DWORD            inits;        /* number of times CoInitializeEx called */
133 };
134
135 extern void* StdGlobalInterfaceTable_Construct(void);
136 extern void  StdGlobalInterfaceTable_Destroy(void* self);
137 extern HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv);
138
139 /* FIXME: these shouldn't be needed, except for 16-bit functions */
140 extern HRESULT WINE_StringFromCLSID(const CLSID *id,LPSTR idstr);
141 HRESULT WINAPI __CLSIDFromStringA(LPCSTR idstr, CLSID *id);
142
143 extern HRESULT create_marshalled_proxy(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
144
145 extern void* StdGlobalInterfaceTableInstance;
146
147 /* Standard Marshalling definitions */
148 typedef struct _wine_marshal_id {
149     OXID    oxid;       /* id of apartment */
150     OID     oid;        /* id of stub manager */
151     IPID    ipid;       /* id of interface pointer */
152 } wine_marshal_id;
153
154 inline static BOOL
155 MARSHAL_Compare_Mids(wine_marshal_id *mid1,wine_marshal_id *mid2) {
156     return
157         (mid1->oxid == mid2->oxid)      &&
158         (mid1->oid == mid2->oid)        &&
159         IsEqualGUID(&(mid1->ipid),&(mid2->ipid))
160     ;
161 }
162
163 HRESULT MARSHAL_Disconnect_Proxies(APARTMENT *apt);
164 HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv);
165
166 ULONG stub_manager_int_addref(struct stub_manager *This);
167 ULONG stub_manager_int_release(struct stub_manager *This);
168 struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object);
169 ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs);
170 ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs);
171 IRpcStubBuffer *stub_manager_ipid_to_stubbuffer(struct stub_manager *m, const IPID *iid);
172 struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid, BOOL tablemarshal);
173 struct stub_manager *get_stub_manager(APARTMENT *apt, OID oid);
174 struct stub_manager *get_stub_manager_from_object(APARTMENT *apt, void *object);
175
176 IRpcStubBuffer *mid_to_stubbuffer(wine_marshal_id *mid);
177
178 void start_apartment_listener_thread(void);
179
180 extern HRESULT PIPE_GetNewPipeBuf(wine_marshal_id *mid, IRpcChannelBuffer **pipebuf);
181 void RPC_StartLocalServer(REFCLSID clsid, IStream *stream);
182
183 /* This function initialize the Running Object Table */
184 HRESULT WINAPI RunningObjectTableImpl_Initialize(void);
185
186 /* This function uninitialize the Running Object Table */
187 HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void);
188
189 /* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */
190 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable);
191
192 /* compobj.c */
193 APARTMENT *COM_CreateApartment(DWORD model);
194 APARTMENT *COM_ApartmentFromOXID(OXID oxid, BOOL ref);
195 DWORD COM_ApartmentAddRef(struct apartment *apt);
196 DWORD COM_ApartmentRelease(struct apartment *apt);
197
198 /*
199  * Per-thread values are stored in the TEB on offset 0xF80,
200  * see http://www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm
201  */
202
203 /* will create if necessary */
204 static inline struct oletls *COM_CurrentInfo(void)
205 {
206     if (!NtCurrentTeb()->ReservedForOle)
207         NtCurrentTeb()->ReservedForOle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct oletls));
208
209     return NtCurrentTeb()->ReservedForOle;
210 }
211
212 static inline APARTMENT* COM_CurrentApt(void)
213 {  
214     return COM_CurrentInfo()->apt;
215 }
216
217 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
218
219 #endif /* __WINE_OLE_COMPOBJ_H */