1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4//
5// File: COMDependentHandle.cpp
6//
7
8//
9// FCall's for the DependentHandle class
10//
11// Handle functions require cooperative mode, making these fcalls poor candidates for QCall conversion.
12//
13
14
15#include "common.h"
16#include "comdependenthandle.h"
17
18
19
20FCIMPL2(OBJECTHANDLE, DependentHandle::nInitialize, Object *_primary, Object *_secondary)
21{
22 FCALL_CONTRACT;
23
24 OBJECTREF primary(_primary);
25 OBJECTREF secondary(_secondary);
26 OBJECTHANDLE result = NULL;
27
28 HELPER_METHOD_FRAME_BEGIN_RET_NOPOLL();
29
30 // Create the handle.
31 result = GetAppDomain()->CreateDependentHandle(primary, secondary);
32
33 HELPER_METHOD_FRAME_END_POLL();
34
35 return result;
36}
37FCIMPLEND
38
39
40
41FCIMPL1(VOID, DependentHandle::nFree, OBJECTHANDLE handle)
42{
43 FCALL_CONTRACT;
44
45 _ASSERTE(handle != NULL);
46
47 HELPER_METHOD_FRAME_BEGIN_0();
48
49 DestroyDependentHandle(handle);
50
51 HELPER_METHOD_FRAME_END();
52
53}
54FCIMPLEND
55
56
57
58FCIMPL1(Object*, DependentHandle::nGetPrimary, OBJECTHANDLE handle)
59{
60 FCALL_CONTRACT;
61 FCUnique(0x54);
62 _ASSERTE(handle != NULL);
63 return OBJECTREFToObject(ObjectFromHandle(handle));
64}
65FCIMPLEND
66
67
68
69FCIMPL2(Object*, DependentHandle::nGetPrimaryAndSecondary, OBJECTHANDLE handle, Object **outSecondary)
70{
71 FCALL_CONTRACT;
72 _ASSERTE(handle != NULL && outSecondary != NULL);
73
74 OBJECTREF primary = ObjectFromHandle(handle);
75
76 IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
77 // Secondary is tracked only if primary is non-null
78 *outSecondary = (primary != NULL) ? mgr->GetDependentHandleSecondary(handle) : NULL;
79
80 return OBJECTREFToObject(primary);
81}
82FCIMPLEND
83
84FCIMPL2(VOID, DependentHandle::nSetPrimary, OBJECTHANDLE handle, Object *_primary)
85{
86 FCALL_CONTRACT;
87
88 _ASSERTE(handle != NULL);
89
90 IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
91 mgr->StoreObjectInHandle(handle, _primary);
92}
93FCIMPLEND
94
95FCIMPL2(VOID, DependentHandle::nSetSecondary, OBJECTHANDLE handle, Object *_secondary)
96{
97 FCALL_CONTRACT;
98
99 _ASSERTE(handle != NULL);
100
101 IGCHandleManager *mgr = GCHandleUtilities::GetGCHandleManager();
102 mgr->SetDependentHandleSecondary(handle, _secondary);
103}
104FCIMPLEND
105