source: trunk/src/ole32/old/moniker.cpp@ 5601

Last change on this file since 5601 was 5601, checked in by sandervl, 24 years ago

created

File size: 15.0 KB
Line 
1/* $Id: moniker.cpp,v 1.1 2001-04-26 19:26:11 sandervl Exp $ */
2/*
3 *
4 * Project Odin Software License can be found in LICENSE.TXT
5 *
6 */
7/*
8 * COM Monikers.
9 *
10 * 1/7/99
11 *
12 * Copyright 1999 David J. Raison
13 *
14 * Some portions from Wine Implementation
15 * Copyright 1998 Marcus Meissner
16 * Copyright 1999 Noomen Hamza
17 */
18
19#include "ole32.h"
20
21#include "moniker.h"
22
23// ======================================================================
24// DATA
25// ======================================================================
26
27// Singleton instance of ROT
28RunningObjectTableImpl * runningObjectTableInstance = 0;
29
30// VTABLE instance
31static ICOM_VTABLE(IRunningObjectTable) VT_RunningObjectTableImpl =
32{
33 RunningObjectTableImpl_QueryInterface,
34 RunningObjectTableImpl_AddRef,
35 RunningObjectTableImpl_Release,
36 RunningObjectTableImpl_Register,
37 RunningObjectTableImpl_Revoke,
38 RunningObjectTableImpl_IsRunning,
39 RunningObjectTableImpl_GetObject,
40 RunningObjectTableImpl_NoteChangeTime,
41 RunningObjectTableImpl_GetTimeOfLastChange,
42 RunningObjectTableImpl_EnumRunning
43};
44
45// ======================================================================
46// Local Methods
47// ======================================================================
48
49// ----------------------------------------------------------------------
50// Initialize
51// ----------------------------------------------------------------------
52HRESULT RunningObjectTableImpl_Initialize()
53{
54 // create singleton ROT
55 runningObjectTableInstance = (RunningObjectTableImpl *)
56 HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl));
57
58 if (runningObjectTableInstance == 0)
59 return E_OUTOFMEMORY;
60
61 /* initialize the virtual table function */
62 runningObjectTableInstance->lpvtbl = &VT_RunningObjectTableImpl;
63 runningObjectTableInstance->ref = 1;
64 runningObjectTableInstance->runObjTabSize = ROT_BLOCK_SIZE;
65 runningObjectTableInstance->runObjTabRegister = 0;
66 runningObjectTableInstance->runObjTabLastIndx = 0;
67 runningObjectTableInstance->runObjTab = (RunObject *)
68 HeapAlloc(GetProcessHeap(), 0, sizeof(RunObject[ROT_BLOCK_SIZE]));
69
70 if (runningObjectTableInstance->runObjTab == NULL)
71 return E_OUTOFMEMORY;
72
73 return S_OK;
74}
75
76// ----------------------------------------------------------------------
77// UnInitialize
78// ----------------------------------------------------------------------
79HRESULT RunningObjectTableImpl_UnInitialize()
80{
81 RunningObjectTableImpl_Release((IRunningObjectTable * )runningObjectTableInstance);
82 Destroy();
83
84 return S_OK;
85}
86
87// ----------------------------------------------------------------------
88// Destroy
89// ----------------------------------------------------------------------
90static HRESULT Destroy()
91{
92 HeapFree(GetProcessHeap(), 0, runningObjectTableInstance->runObjTab);
93 HeapFree(GetProcessHeap(), 0, runningObjectTableInstance);
94
95 return S_OK;
96}
97
98// ----------------------------------------------------------------------
99// GetObjectIndex
100// ----------------------------------------------------------------------
101static HRESULT GetObjectIndex(RunningObjectTableImpl * This, DWORD identReg,
102 IMoniker * pmk, DWORD * indx)
103{
104 DWORD i;
105
106 if (pmk != NULL)
107 /* search object identified by a moniker*/
108 for(i = 0; (i < This->runObjTabLastIndx) && (!IMoniker_IsEqual(This->runObjTab[i].pmkObj, pmk) == S_OK); i++)
109 ;
110 else
111 /* search object identified by a register identifier*/
112 for(i = 0; ((i<This->runObjTabLastIndx) && (This->runObjTab[i].identRegObj != identReg)); i++)
113 ;
114
115 if (i == This->runObjTabLastIndx)
116 return S_FALSE;
117
118 if (indx != NULL)
119 *indx = i;
120
121 return S_OK;
122}
123
124// ======================================================================
125// COM INTERFACE FUNCTIONS
126// ======================================================================
127
128// ----------------------------------------------------------------------
129// RunningObjectTableImpl_QueryInterface
130// ----------------------------------------------------------------------
131HRESULT WIN32API RunningObjectTableImpl_QueryInterface
132 (IRunningObjectTable * iface,
133 REFIID riid,
134 void**ppvObject)
135{
136 ICOM_THIS(RunningObjectTableImpl, iface);
137
138 dprintf(("OLE32: RunningObjectTableImpl_QueryInterface(%p, %p, %p)", This, riid, ppvObject));
139
140 /* validate arguments*/
141 if (This == 0)
142 return CO_E_NOTINITIALIZED;
143
144 if (ppvObject == 0)
145 return E_INVALIDARG;
146
147 * ppvObject = 0;
148
149 if (IsEqualIID(&IID_IUnknown, riid))
150 * ppvObject = (IRunningObjectTable * )This;
151 else
152 if (IsEqualIID(&IID_IRunningObjectTable, riid))
153 * ppvObject = (IRunningObjectTable * )This;
154
155 if ((* ppvObject) == 0)
156 return E_NOINTERFACE;
157
158 RunningObjectTableImpl_AddRef(iface);
159
160 return S_OK;
161}
162
163// ----------------------------------------------------------------------
164// RunningObjectTableImpl_AddRef
165// ----------------------------------------------------------------------
166ULONG WIN32API RunningObjectTableImpl_AddRef
167 (IRunningObjectTable * iface)
168{
169 ICOM_THIS(RunningObjectTableImpl, iface);
170
171 dprintf(("OLE32: RunningObjectTableImpl_AddRef(%p)", This));
172
173 return ++(This->ref);
174}
175
176// ----------------------------------------------------------------------
177// RunningObjectTableImpl_Release
178// ----------------------------------------------------------------------
179ULONG WIN32API RunningObjectTableImpl_Release
180 (IRunningObjectTable * iface)
181{
182 ICOM_THIS(RunningObjectTableImpl, iface);
183
184 DWORD i;
185
186 dprintf(("OLE32: RunningObjectTableImpl_Release(%p)", This));
187
188 This->ref--;
189
190 /* unitialize ROT structure if there's no more reference to it*/
191 if (This->ref == 0){
192
193 /* release all registred objects */
194 for( i = 0; i < This->runObjTabLastIndx; i++)
195 {
196 if (( This->runObjTab[i].regTypeObj & ROTFLAGS_REGISTRATIONKEEPSALIVE) != 0)
197 IUnknown_Release(This->runObjTab[i].pObj);
198
199 IMoniker_Release(This->runObjTab[i].pmkObj);
200 }
201
202 /*
203 * RunningObjectTable data structure will be not destroyed here !
204 * The destruction will be done only
205 * when RunningObjectTableImpl_UnInitialize function is called
206 */
207
208 /* there's no more elements in the table */
209 This->runObjTabRegister = 0;
210 This->runObjTabLastIndx = 0;
211
212 return 0;
213 }
214
215 return This->ref;
216}
217
218// ----------------------------------------------------------------------
219// RunningObjectTableImpl_Register
220// ----------------------------------------------------------------------
221HRESULT WIN32API RunningObjectTableImpl_Register
222 (IRunningObjectTable * iface,
223 DWORD grfFlags, /* Registration options */
224 IUnknown * punkObject, /* Pointer to the object being registered */
225 IMoniker * pmkObjectName, /* Pointer to the moniker of the object being registered */
226 DWORD * pdwRegister) /* Pointer to the value identifying the registration */
227{
228 ICOM_THIS(RunningObjectTableImpl, iface);
229
230 dprintf(("OLE32: RunningObjectTableImpl_Register(%p, %ld, %p, %p, %p)", This, grfFlags, punkObject, pmkObjectName, pdwRegister));
231
232 HRESULT res = S_OK;
233
234 /* there's only two types of register : strong and or weak registration (only one must be passed on parameter) */
235 if ( ( (grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) || !(grfFlags & ROTFLAGS_ALLOWANYCLIENT)) &&
236 (!(grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) || (grfFlags & ROTFLAGS_ALLOWANYCLIENT)) &&
237 (grfFlags) )
238 return E_INVALIDARG;
239
240 if ((punkObject == NULL) || (pmkObjectName == NULL) || (pdwRegister == NULL))
241 return E_INVALIDARG;
242
243 /* verify if the object to be registred was registred befor */
244 if (GetObjectIndex(This, -1, pmkObjectName, NULL) == S_OK)
245 res = MK_S_MONIKERALREADYREGISTERED;
246
247 /* put the new registred object in the first free element in the table */
248 This->runObjTab[This->runObjTabLastIndx].pObj = punkObject;
249 This->runObjTab[This->runObjTabLastIndx].pmkObj = pmkObjectName;
250 This->runObjTab[This->runObjTabLastIndx].regTypeObj = grfFlags;
251 This->runObjTab[This->runObjTabLastIndx].identRegObj = This->runObjTabRegister;
252 CoFileTimeNow(&(This->runObjTab[This->runObjTabLastIndx].lastModifObj));
253
254 /* gives a registration identifier to the registred object*/
255 (* pdwRegister)= This->runObjTabRegister;
256
257 if (This->runObjTabRegister == 0xFFFFFFFF)
258 {
259 WriteLog("OLE32: Rot_Impl_Register() - runObjTabRegister: %ld overflow! ", This->runObjTabRegister);
260 return E_FAIL;
261 }
262 This->runObjTabRegister++;
263 This->runObjTabLastIndx++;
264
265 if (This->runObjTabLastIndx == This->runObjTabSize)
266 { /* table is full ! so it must be resized */
267
268 This->runObjTabSize += ROT_BLOCK_SIZE; /* newsize table */
269 This->runObjTab = (RunObject *)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->runObjTab,
270 This->runObjTabSize * sizeof(RunObject));
271 if (!This->runObjTab)
272 return E_OUTOFMEMORY;
273 }
274 /* add a reference to the object in the strong registration case */
275 if ((grfFlags & ROTFLAGS_REGISTRATIONKEEPSALIVE) != 0 )
276 IUnknown_AddRef(punkObject);
277
278 IMoniker_AddRef(pmkObjectName);
279
280 return res;
281}
282
283// ----------------------------------------------------------------------
284// RunningObjectTableImpl_Revoke
285// ----------------------------------------------------------------------
286HRESULT WIN32API RunningObjectTableImpl_Revoke
287 (IRunningObjectTable * iface,
288 DWORD dwRegister) /* Value identifying registration to be revoked*/
289{
290
291 ICOM_THIS(RunningObjectTableImpl, iface);
292
293 dprintf(("OLE32: RunningObjectTableImpl_Revoke(%p, %ld)", This, dwRegister));
294
295 DWORD index, j;
296
297 /* verify if the object to be revoked was registred befor or not */
298 if (GetObjectIndex(This, dwRegister, NULL, &index) == S_FALSE)
299 return E_INVALIDARG;
300
301 /* release the object if it was registred with a strong registrantion option */
302 if ((This->runObjTab[index].regTypeObj & ROTFLAGS_REGISTRATIONKEEPSALIVE) != 0)
303 IUnknown_Release(This->runObjTab[index].pObj);
304
305 IMoniker_Release(This->runObjTab[index].pmkObj);
306
307 /* remove the object from the table */
308 for(j = index; j < This->runObjTabLastIndx - 1; j++)
309 This->runObjTab[j]= This->runObjTab[j + 1];
310
311 This->runObjTabLastIndx--;
312
313 return S_OK;
314}
315
316// ----------------------------------------------------------------------
317// RunningObjectTableImpl_IsRunning
318// ----------------------------------------------------------------------
319HRESULT WIN32API RunningObjectTableImpl_IsRunning
320 (IRunningObjectTable * iface,
321 IMoniker * pmkObjectName) /* Pointer to the moniker of the object whose status is desired */
322{
323 ICOM_THIS(RunningObjectTableImpl, iface);
324
325 dprintf(("OLE32: RunningObjectTableImpl_IsRunning(%p, %p)", This, pmkObjectName));
326
327 return GetObjectIndex(This, -1, pmkObjectName, NULL);
328}
329
330// ----------------------------------------------------------------------
331// RunningObjectTableImpl_GetObject
332// ----------------------------------------------------------------------
333HRESULT WIN32API RunningObjectTableImpl_GetObject
334 (IRunningObjectTable * iface,
335 IMoniker * pmkObjectName, /* Pointer to the moniker on the object */
336 IUnknown **ppunkObject) /* Address of output variable that receives the IUnknown interface pointer */
337{
338 ICOM_THIS(RunningObjectTableImpl, iface);
339
340 dprintf(("OLE32: RunningObjectTableImpl_GetObject(%p, %p, %p)", This, pmkObjectName, ppunkObject));
341
342 DWORD index;
343
344 if (ppunkObject == NULL)
345 return E_POINTER;
346
347 *ppunkObject = 0;
348
349 /* verify if the object was registred befor or not */
350 if (GetObjectIndex(This, -1, pmkObjectName, &index) == S_FALSE)
351 return MK_E_UNAVAILABLE;
352
353 /* add a reference to the object then set output object argument */
354 IUnknown_AddRef(This->runObjTab[index].pObj);
355 *ppunkObject = This->runObjTab[index].pObj;
356
357 return S_OK;
358}
359
360// ----------------------------------------------------------------------
361// RunningObjectTableImpl_NoteChangeTime
362// ----------------------------------------------------------------------
363HRESULT WIN32API RunningObjectTableImpl_NoteChangeTime
364 (IRunningObjectTable * iface,
365 DWORD dwRegister, /* Value identifying registration being updated */
366 FILETIME * pfiletime) /* Pointer to structure containing object's last change time */
367{
368 ICOM_THIS(RunningObjectTableImpl, iface);
369
370 dprintf(( "OLE32: RunningObjectTableImpl_NoteChangeTime(%p, %ld, %p)", This, dwRegister, pfiletime));
371
372 DWORD index=-1;
373
374 /* verify if the object to be changed was registred befor or not */
375 if (GetObjectIndex(This, dwRegister, NULL, &index) == S_FALSE)
376 return E_INVALIDARG;
377
378 /* set the new value of the last time change */
379 This->runObjTab[index].lastModifObj = (* pfiletime);
380
381 return S_OK;
382}
383
384// ----------------------------------------------------------------------
385// RunningObjectTableImpl_GetTimeOfLastChange
386// ----------------------------------------------------------------------
387HRESULT WIN32API RunningObjectTableImpl_GetTimeOfLastChange
388 (IRunningObjectTable * iface,
389 IMoniker * pmkObjectName, /* Pointer to moniker on the object whose status is desired */
390 FILETIME * pfiletime) /* Pointer to structure that receives object's last change time */
391{
392 ICOM_THIS(RunningObjectTableImpl, iface);
393
394 dprintf(( "OLE32: RunningObjectTableImpl_GetTimeOfLastChange(%p, %p, %p)", This, pmkObjectName, pfiletime));
395
396 DWORD index = -1;
397
398 if (pmkObjectName == NULL || pfiletime == NULL)
399 return E_INVALIDARG;
400
401 /* verify if the object was registred befor or not */
402 if (GetObjectIndex(This, -1, pmkObjectName, &index) == S_FALSE)
403 return MK_E_UNAVAILABLE;;
404
405 (* pfiletime)= This->runObjTab[index].lastModifObj;
406
407 return S_OK;
408}
409
410// ----------------------------------------------------------------------
411// RunningObjectTableImpl_EnumRunning
412// ----------------------------------------------------------------------
413HRESULT WIN32API RunningObjectTableImpl_EnumRunning
414 (IRunningObjectTable * iface,
415 IEnumMoniker **ppenumMoniker) /* Address of output variable that receives the IEnumMoniker interface pointer */
416{
417 dprintf(( "OLE32: RunningObjectTableImpl_EnumRunning - stub"));
418 return E_NOTIMPL;
419}
420
421// ======================================================================
422// API Methods
423// ======================================================================
424
425// ----------------------------------------------------------------------
426// GetRunningObjectTable
427// ----------------------------------------------------------------------
428HRESULT WIN32API GetRunningObjectTable(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
429{
430 IID riid = IID_IRunningObjectTable;
431 HRESULT hr;
432
433 dprintf(("OLE32: GetRunningObjectTable"));
434
435 if (reserved != 0)
436 return E_UNEXPECTED;
437
438 if (runningObjectTableInstance == NULL)
439 return CO_E_NOTINITIALIZED;
440
441 hr = RunningObjectTableImpl_QueryInterface(
442 (IRunningObjectTable*)runningObjectTableInstance, &riid, (void**)pprot);
443
444 return hr;
445}
446
Note: See TracBrowser for help on using the repository browser.