source: trunk/src/ole32/moniker.cpp@ 1036

Last change on this file since 1036 was 872, checked in by davidr, 26 years ago

Added CVS ID lines to all source files

File size: 15.0 KB
Line 
1/* $Id: moniker.cpp,v 1.3 1999-09-08 11:29:27 davidr 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 return S_OK;
282}
283
284// ----------------------------------------------------------------------
285// RunningObjectTableImpl_Revoke
286// ----------------------------------------------------------------------
287HRESULT WIN32API RunningObjectTableImpl_Revoke
288 (IRunningObjectTable * iface,
289 DWORD dwRegister) /* Value identifying registration to be revoked*/
290{
291
292 ICOM_THIS(RunningObjectTableImpl, iface);
293
294 dprintf(("OLE32: RunningObjectTableImpl_Revoke(%p, %ld)", This, dwRegister));
295
296 DWORD index, j;
297
298 /* verify if the object to be revoked was registred befor or not */
299 if (GetObjectIndex(This, dwRegister, NULL, &index) == S_FALSE)
300 return E_INVALIDARG;
301
302 /* release the object if it was registred with a strong registrantion option */
303 if ((This->runObjTab[index].regTypeObj & ROTFLAGS_REGISTRATIONKEEPSALIVE) != 0)
304 IUnknown_Release(This->runObjTab[index].pObj);
305
306 IMoniker_Release(This->runObjTab[index].pmkObj);
307
308 /* remove the object from the table */
309 for(j = index; j < This->runObjTabLastIndx - 1; j++)
310 This->runObjTab[j]= This->runObjTab[j + 1];
311
312 This->runObjTabLastIndx--;
313
314 return S_OK;
315}
316
317// ----------------------------------------------------------------------
318// RunningObjectTableImpl_IsRunning
319// ----------------------------------------------------------------------
320HRESULT WIN32API RunningObjectTableImpl_IsRunning
321 (IRunningObjectTable * iface,
322 IMoniker * pmkObjectName) /* Pointer to the moniker of the object whose status is desired */
323{
324 ICOM_THIS(RunningObjectTableImpl, iface);
325
326 dprintf(("OLE32: RunningObjectTableImpl_IsRunning(%p, %p)", This, pmkObjectName));
327
328 return GetObjectIndex(This, -1, pmkObjectName, NULL);
329}
330
331// ----------------------------------------------------------------------
332// RunningObjectTableImpl_GetObject
333// ----------------------------------------------------------------------
334HRESULT WIN32API RunningObjectTableImpl_GetObject
335 (IRunningObjectTable * iface,
336 IMoniker * pmkObjectName, /* Pointer to the moniker on the object */
337 IUnknown **ppunkObject) /* Address of output variable that receives the IUnknown interface pointer */
338{
339 ICOM_THIS(RunningObjectTableImpl, iface);
340
341 dprintf(("OLE32: RunningObjectTableImpl_GetObject(%p, %p, %p)", This, pmkObjectName, ppunkObject));
342
343 DWORD index;
344
345 if (ppunkObject == NULL)
346 return E_POINTER;
347
348 *ppunkObject = 0;
349
350 /* verify if the object was registred befor or not */
351 if (GetObjectIndex(This, -1, pmkObjectName, &index) == S_FALSE)
352 return MK_E_UNAVAILABLE;
353
354 /* add a reference to the object then set output object argument */
355 IUnknown_AddRef(This->runObjTab[index].pObj);
356 *ppunkObject = This->runObjTab[index].pObj;
357
358 return S_OK;
359}
360
361// ----------------------------------------------------------------------
362// RunningObjectTableImpl_NoteChangeTime
363// ----------------------------------------------------------------------
364HRESULT WIN32API RunningObjectTableImpl_NoteChangeTime
365 (IRunningObjectTable * iface,
366 DWORD dwRegister, /* Value identifying registration being updated */
367 FILETIME * pfiletime) /* Pointer to structure containing object's last change time */
368{
369 ICOM_THIS(RunningObjectTableImpl, iface);
370
371 dprintf(( "OLE32: RunningObjectTableImpl_NoteChangeTime(%p, %ld, %p)", This, dwRegister, pfiletime));
372
373 DWORD index=-1;
374
375 /* verify if the object to be changed was registred befor or not */
376 if (GetObjectIndex(This, dwRegister, NULL, &index) == S_FALSE)
377 return E_INVALIDARG;
378
379 /* set the new value of the last time change */
380 This->runObjTab[index].lastModifObj = (* pfiletime);
381
382 return S_OK;
383}
384
385// ----------------------------------------------------------------------
386// RunningObjectTableImpl_GetTimeOfLastChange
387// ----------------------------------------------------------------------
388HRESULT WIN32API RunningObjectTableImpl_GetTimeOfLastChange
389 (IRunningObjectTable * iface,
390 IMoniker * pmkObjectName, /* Pointer to moniker on the object whose status is desired */
391 FILETIME * pfiletime) /* Pointer to structure that receives object's last change time */
392{
393 ICOM_THIS(RunningObjectTableImpl, iface);
394
395 dprintf(( "OLE32: RunningObjectTableImpl_GetTimeOfLastChange(%p, %p, %p)", This, pmkObjectName, pfiletime));
396
397 DWORD index = -1;
398
399 if (pmkObjectName == NULL || pfiletime == NULL)
400 return E_INVALIDARG;
401
402 /* verify if the object was registred befor or not */
403 if (GetObjectIndex(This, -1, pmkObjectName, &index) == S_FALSE)
404 return MK_E_UNAVAILABLE;;
405
406 (* pfiletime)= This->runObjTab[index].lastModifObj;
407
408 return S_OK;
409}
410
411// ----------------------------------------------------------------------
412// RunningObjectTableImpl_EnumRunning
413// ----------------------------------------------------------------------
414HRESULT WIN32API RunningObjectTableImpl_EnumRunning
415 (IRunningObjectTable * iface,
416 IEnumMoniker **ppenumMoniker) /* Address of output variable that receives the IEnumMoniker interface pointer */
417{
418 dprintf(( "OLE32: RunningObjectTableImpl_EnumRunning - stub"));
419 return E_NOTIMPL;
420}
421
422// ======================================================================
423// API Methods
424// ======================================================================
425
426// ----------------------------------------------------------------------
427// GetRunningObjectTable
428// ----------------------------------------------------------------------
429HRESULT WIN32API GetRunningObjectTable(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
430{
431 IID riid = IID_IRunningObjectTable;
432 HRESULT hr;
433
434 dprintf(("OLE32: GetRunningObjectTable"));
435
436 if (reserved != 0)
437 return E_UNEXPECTED;
438
439 if (runningObjectTableInstance == NULL)
440 return CO_E_NOTINITIALIZED;
441
442 hr = RunningObjectTableImpl_QueryInterface(
443 (IRunningObjectTable*)runningObjectTableInstance, &riid, (void**)pprot);
444
445 return hr;
446}
447
Note: See TracBrowser for help on using the repository browser.