Reverse the order for deleting the items in resetcontent to correctly
[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, Rob Shearman, 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 typedef enum ifstub_state
55 {
56     STUBSTATE_NORMAL_MARSHALED,
57     STUBSTATE_NORMAL_UNMARSHALED,
58     STUBSTATE_TABLE_WEAK_MARSHALED,
59     STUBSTATE_TABLE_WEAK_UNMARSHALED,
60     STUBSTATE_TABLE_STRONG,
61 } STUB_STATE;
62
63 /* an interface stub */
64 struct ifstub   
65 {
66     struct list       entry;      /* entry in stub_manager->ifstubs list (CS stub_manager->lock) */
67     IRpcStubBuffer   *stubbuffer; /* RO */
68     IID               iid;        /* RO */
69     IPID              ipid;       /* RO */
70     IUnknown         *iface;      /* RO */
71 };
72
73
74 /* stub managers hold refs on the object and each interface stub */
75 struct stub_manager
76 {
77     struct list       entry;      /* entry in apartment stubmgr list (CS apt->cs) */
78     struct list       ifstubs;    /* list of active ifstubs for the object (CS lock) */
79     CRITICAL_SECTION  lock;
80     APARTMENT        *apt;        /* owning apt (RO) */
81
82     ULONG             extrefs;    /* number of 'external' references (CS lock) */
83     ULONG             refs;       /* internal reference count (CS apt->cs) */
84     OID               oid;        /* apartment-scoped unique identifier (RO) */
85     IUnknown         *object;     /* the object we are managing the stub for (RO) */
86     ULONG             next_ipid;  /* currently unused (LOCK) */
87     STUB_STATE        state;      /* state machine (CS lock) */
88 };
89
90 /* imported interface proxy */
91 struct ifproxy
92 {
93   struct list entry;       /* entry in proxy_manager list (CS parent->cs) */
94   struct proxy_manager *parent; /* owning proxy_manager (RO) */
95   LPVOID iface;            /* interface pointer (RO) */
96   IID iid;                 /* interface ID (RO) */
97   IPID ipid;               /* imported interface ID (RO) */
98   LPRPCPROXYBUFFER proxy;  /* interface proxy (RO) */
99   DWORD refs;              /* imported (public) references (CS parent->cs) */
100 };
101
102 /* imported object / proxy manager */
103 struct proxy_manager
104 {
105   const IMultiQIVtbl *lpVtbl;
106   struct apartment *parent; /* owning apartment (RO) */
107   struct list entry;        /* entry in apartment (CS parent->cs) */
108   LPRPCCHANNELBUFFER chan;  /* channel to object (CS cs) */
109   OXID oxid;                /* object exported ID (RO) */
110   OID oid;                  /* object ID (RO) */
111   struct list interfaces;   /* imported interfaces (CS cs) */
112   DWORD refs;               /* proxy reference count (LOCK) */
113   CRITICAL_SECTION cs;      /* thread safety for this object and children */
114   ULONG sorflags;           /* STDOBJREF flags (RO) */
115   IRemUnknown *remunk;      /* proxy to IRemUnknown used for lifecycle management (CS cs) */
116 };
117
118 /* this needs to become a COM object that implements IRemUnknown */
119 struct apartment
120 {
121   struct list entry;       
122
123   DWORD refs;              /* refcount of the apartment (LOCK) */
124   DWORD model;             /* threading model (RO) */
125   DWORD tid;               /* thread id (RO) */
126   HANDLE thread;           /* thread handle (RO) */
127   OXID oxid;               /* object exporter ID (RO) */
128   DWORD ipidc;             /* interface pointer ID counter, starts at 1 (LOCK) */
129   HWND win;                /* message window (RO) */
130   CRITICAL_SECTION cs;     /* thread safety */
131   LPMESSAGEFILTER filter;  /* message filter (CS cs) */
132   struct list proxies;     /* imported objects (CS cs) */
133   struct list stubmgrs;    /* stub managers for exported objects (CS cs) */
134   BOOL remunk_exported;    /* has the IRemUnknown interface for this apartment been created yet? (CS cs) */
135   LONG remoting_started;   /* has the RPC system been started for this apartment? (LOCK) */
136
137   /* FIXME: OID's should be given out by RPCSS */
138   OID oidc;                /* object ID counter, starts at 1, zero is invalid OID (CS cs) */
139 };
140
141 /* this is what is stored in TEB->ReservedForOle */
142 struct oletls
143 {
144     struct apartment *apt;
145     IErrorInfo       *errorinfo;   /* see errorinfo.c */
146     IUnknown         *state;       /* see CoSetState */
147     DWORD            inits;        /* number of times CoInitializeEx called */
148 };
149
150
151 /* Global Interface Table Functions */
152
153 extern void* StdGlobalInterfaceTable_Construct(void);
154 extern void  StdGlobalInterfaceTable_Destroy(void* self);
155 extern HRESULT StdGlobalInterfaceTable_GetFactory(LPVOID *ppv);
156 extern void* StdGlobalInterfaceTableInstance;
157
158 /* FIXME: these shouldn't be needed, except for 16-bit functions */
159 extern HRESULT WINE_StringFromCLSID(const CLSID *id,LPSTR idstr);
160 HRESULT WINAPI __CLSIDFromStringA(LPCSTR idstr, CLSID *id);
161
162 HRESULT MARSHAL_Disconnect_Proxies(APARTMENT *apt);
163 HRESULT MARSHAL_GetStandardMarshalCF(LPVOID *ppv);
164
165 /* Stub Manager */
166
167 ULONG stub_manager_int_addref(struct stub_manager *This);
168 ULONG stub_manager_int_release(struct stub_manager *This);
169 struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object, MSHLFLAGS mshlflags);
170 ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs);
171 ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs);
172 struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid);
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 void apartment_disconnect_object(APARTMENT *apt, void *object);
176 BOOL stub_manager_notify_unmarshal(struct stub_manager *m);
177 BOOL stub_manager_is_table_marshaled(struct stub_manager *m);
178 void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs);
179 HRESULT register_ifstub(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *obj, MSHLFLAGS mshlflags);
180 HRESULT ipid_to_stub_manager(const IPID *ipid, APARTMENT **stub_apt, struct stub_manager **stubmgr_ret);
181 IRpcStubBuffer *ipid_to_apt_and_stubbuffer(const IPID *ipid, APARTMENT **stub_apt);
182 HRESULT start_apartment_remote_unknown(void);
183
184 /* RPC Backend */
185
186 void    RPC_StartRemoting(struct apartment *apt);
187 HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid, IRpcChannelBuffer **pipebuf);
188 HRESULT RPC_ExecuteCall(RPCOLEMESSAGE *msg, IRpcStubBuffer *stub);
189 HRESULT RPC_RegisterInterface(REFIID riid);
190 void    RPC_UnregisterInterface(REFIID riid);
191 void    RPC_StartLocalServer(REFCLSID clsid, IStream *stream);
192 HRESULT RPC_GetLocalClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv);
193
194 /* This function initialize the Running Object Table */
195 HRESULT WINAPI RunningObjectTableImpl_Initialize(void);
196
197 /* This function uninitialize the Running Object Table */
198 HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void);
199
200 /* This function decomposes a String path to a String Table containing all the elements ("\" or "subDirectory" or "Directory" or "FileName") of the path */
201 int WINAPI FileMonikerImpl_DecomposePath(LPCOLESTR str, LPOLESTR** stringTable);
202
203
204 /* Apartment Functions */
205
206 APARTMENT *COM_ApartmentFromOXID(OXID oxid, BOOL ref);
207 APARTMENT *COM_ApartmentFromTID(DWORD tid);
208 DWORD COM_ApartmentAddRef(struct apartment *apt);
209 DWORD COM_ApartmentRelease(struct apartment *apt);
210
211 /* messages used by the apartment window (not compatible with native) */
212 #define DM_EXECUTERPC   (WM_USER + 0) /* WPARAM = (RPCOLEMESSAGE *), LPARAM = (IRpcStubBuffer *) */
213
214 /*
215  * Per-thread values are stored in the TEB on offset 0xF80,
216  * see http://www.microsoft.com/msj/1099/bugslayer/bugslayer1099.htm
217  */
218
219 /* will create if necessary */
220 static inline struct oletls *COM_CurrentInfo(void)
221 {
222     if (!NtCurrentTeb()->ReservedForOle)
223         NtCurrentTeb()->ReservedForOle = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct oletls));
224
225     return NtCurrentTeb()->ReservedForOle;
226 }
227
228 static inline APARTMENT* COM_CurrentApt(void)
229 {  
230     return COM_CurrentInfo()->apt;
231 }
232
233 #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
234
235 #endif /* __WINE_OLE_COMPOBJ_H */