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
6//
7// File: ShimDataTarget.cpp
8//
9//*****************************************************************************
10#include "stdafx.h"
11#include "safewrap.h"
12
13#include "check.h"
14
15#include <limits.h>
16
17#include "shimpriv.h"
18
19
20// Standard impl of IUnknown::QueryInterface
21HRESULT STDMETHODCALLTYPE ShimDataTarget::QueryInterface(
22 REFIID InterfaceId,
23 PVOID* pInterface
24 )
25{
26 if (InterfaceId == IID_IUnknown)
27 {
28 *pInterface = static_cast<IUnknown *>(static_cast<ICorDebugDataTarget *>(this));
29 }
30 else if (InterfaceId == IID_ICorDebugDataTarget)
31 {
32 *pInterface = static_cast<ICorDebugDataTarget *>(this);
33 }
34 else if (InterfaceId == IID_ICorDebugMutableDataTarget)
35 {
36 *pInterface = static_cast<ICorDebugMutableDataTarget *>(this);
37 }
38 else if (InterfaceId == IID_ICorDebugDataTarget4)
39 {
40 *pInterface = static_cast<ICorDebugDataTarget4 *>(this);
41 }
42 else
43 {
44 *pInterface = NULL;
45 return E_NOINTERFACE;
46 }
47
48 AddRef();
49 return S_OK;
50}
51
52// Standard impl of IUnknown::AddRef
53ULONG STDMETHODCALLTYPE ShimDataTarget::AddRef()
54{
55 LONG ref = InterlockedIncrement(&m_ref);
56 return ref;
57}
58
59// Standard impl of IUnknown::Release
60ULONG STDMETHODCALLTYPE ShimDataTarget::Release()
61{
62 LONG ref = InterlockedDecrement(&m_ref);
63 if (ref == 0)
64 {
65 delete this;
66 }
67 return ref;
68}
69
70//---------------------------------------------------------------------------------------
71//
72// Get the OS Process ID that this DataTarget is for.
73//
74// Return Value:
75// The OS PID of the process this data target is representing.
76DWORD ShimDataTarget::GetPid()
77{
78 return m_processId;
79}
80
81//---------------------------------------------------------------------------------------
82// Hook a custom function to handle ICorDebugMutableDataTarget::ContinueStatusChanged
83//
84// Arguments:
85// fpContinueStatusChanged - callback function to invoke.
86// pUserData - user data to pass to callback
87//
88void ShimDataTarget::HookContinueStatusChanged(FPContinueStatusChanged fpContinueStatusChanged, void * pUserData)
89{
90 m_fpContinueStatusChanged = fpContinueStatusChanged;
91 m_pContinueStatusChangedUserData = pUserData;
92}
93