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