This commit is contained in:
Sang Choe 2019-01-17 15:57:53 -08:00
Родитель 040da47b16
Коммит 16ad433e14
8 изменённых файлов: 72 добавлений и 141 удалений

Просмотреть файл

@ -220,7 +220,7 @@ CameraIotPnpDevice::CameraIotPnpDevice_PropertyCallback(
_In_ PNP_REPORTED_PROPERTY_STATUS pnpReportedStatus,
_In_opt_ void* userContextCallback)
{
TRACELOG("status=%d,context=%s", pnpReportedStatus, (nullptr != userContextCallback ? (const char*)userContextCallback : "nullptr"));
LogInfo("%s:%d pnpstatus=%d,context=0x%p", __FUNCTION__, __LINE__, pnpReportedStatus, userContextCallback);
}
void __cdecl
@ -228,7 +228,7 @@ CameraIotPnpDevice::CameraIotPnpDevice_TelemetryCallback(
_In_ PNP_SEND_TELEMETRY_STATUS pnpTelemetryStatus,
_In_opt_ void* userContextCallback)
{
TRACELOG("status=%d,context=%s", pnpTelemetryStatus, (nullptr != userContextCallback ? (const char*)userContextCallback : "nullptr"));
LogInfo("%s:%d pnpstatus=%d,context=0x%p", __FUNCTION__, __LINE__, pnpTelemetryStatus, userContextCallback);
}
DWORD

Просмотреть файл

@ -31,7 +31,7 @@ CameraPnpDiscovery::~CameraPnpDiscovery(
HRESULT
CameraPnpDiscovery::InitializePnpDiscovery(
_In_ NOTIFY_DEVICE_CHANGE pfnCallback,
_In_ PNPBRIDGE_NOTIFY_DEVICE_CHANGE pfnCallback,
_In_opt_ void* pvContext
)
{
@ -199,9 +199,9 @@ CameraPnpDiscovery::OnWatcherNotification(
_In_ DWORD eventDataSize
)
{
CameraUniqueIdPtrList cameraUniqueIds;
NOTIFY_DEVICE_CHANGE pfn = nullptr;
void* pv = nullptr;
CameraUniqueIdPtrList cameraUniqueIds;
PNPBRIDGE_NOTIFY_DEVICE_CHANGE pfn = nullptr;
void* pv = nullptr;
RETURN_HR_IF_NULL (E_INVALIDARG, eventData);
RETURN_HR_IF (E_INVALIDARG, eventDataSize == 0);
@ -236,8 +236,7 @@ CameraPnpDiscovery::OnWatcherNotification(
// component (i.e., not DA).
if (pfn)
{
DEVICE_CHANGE_PAYLOAD payload = { };
int nResult = 0;
PNPBRIDGE_DEVICE_CHANGE_PAYLOAD payload = { };
payload.Context = this;
payload.Message = nullptr;
@ -245,14 +244,14 @@ CameraPnpDiscovery::OnWatcherNotification(
if (cameraUniqueIds.size() == 0 && m_cameraUniqueIds.size() > 0)
{
// We didn't have a camera, and we just got one (or more).
payload.Type = PNP_INTERFACE_ARRIVAL;
nResult = pfn(&payload);
payload.ChangeType = PNPBRIDGE_INTERFACE_CHANGE_ARRIVAL;
pfn(&payload);
}
else if (cameraUniqueIds.size() > 0 && m_cameraUniqueIds.size() == 0)
{
// We had a camera, and now we don't.
payload.Type = PNP_INTERFACE_REMOVAL;
nResult = pfn(&payload);
payload.ChangeType = PNPBRIDGE_INTERFACE_CHANGE_REMOVAL;
pfn(&payload);
}
else
{
@ -260,11 +259,11 @@ CameraPnpDiscovery::OnWatcherNotification(
{
// We lost our old camera, and got a new one. Remove and
// start over.
payload.Type = PNP_INTERFACE_REMOVAL;
nResult = pfn(&payload);
payload.ChangeType = PNPBRIDGE_INTERFACE_CHANGE_REMOVAL;
pfn(&payload);
payload.Type = PNP_INTERFACE_ARRIVAL;
nResult = pfn(&payload);
payload.ChangeType = PNPBRIDGE_INTERFACE_CHANGE_ARRIVAL;
pfn(&payload);
}
}
}

Просмотреть файл

@ -25,7 +25,7 @@ public:
virtual ~CameraPnpDiscovery();
/// Public methods.
HRESULT InitializePnpDiscovery(_In_ NOTIFY_DEVICE_CHANGE pfnCallback, _In_ void* pvContext);
HRESULT InitializePnpDiscovery(_In_ PNPBRIDGE_NOTIFY_DEVICE_CHANGE pfnCallback, _In_ void* pvContext);
void Shutdown();
HRESULT GetFirstCamera(_Out_ std::wstring& cameraName);
@ -64,7 +64,7 @@ protected:
bool m_fShutdown;
std::vector<HCMNOTIFICATION> m_vecWatcherHandles;
NOTIFY_DEVICE_CHANGE m_pfnCallback;
PNPBRIDGE_NOTIFY_DEVICE_CHANGE m_pfnCallback;
void* m_pvCallbackContext;
};

Просмотреть файл

@ -42,69 +42,26 @@ CameraPnpStopDiscovery(
return 0;
}
int
CameraGetFilterFormatIds(
_Out_ char*** filterFormatIds,
_Out_ int* numberOfFormats
)
{
if (nullptr == filterFormatIds || nullptr == numberOfFormats)
{
return -1;
}
// $$WARNING - We cannot use malloc/new for allocation
// of format IDs. Either we have the numberOfFormats be
// an IN/OUT or we add a new API to get the number of
// format IDs along with their lengths.
*filterFormatIds = (char**) malloc(sizeof(char*) * 1);
(*filterFormatIds)[0] = (char*) "camera-pnp-module";
*numberOfFormats = 1;
return 0;
}
// Interface bind functions.
__inline
PNPBRIDGE_RESULT PnpBridgeFromHresult(
_In_ HRESULT hr
)
{
switch (hr)
{
case S_OK:
return PNPBRIDGE_OK;
case HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER):
case E_OUTOFMEMORY:
return PNPBRIDGE_INSUFFICIENT_MEMORY;
case E_INVALIDARG:
return PNPBRIDGE_INVALID_ARGS;
case HRESULT_FROM_WIN32(ERROR_GEN_FAILURE):
return PNPBRIDGE_CONFIG_READ_FAILED;
default:
return PNPBRIDGE_FAILED;
}
}
PNPBRIDGE_RESULT
int
CameraPnpInterfaceInitialize(
_In_ JSON_Object* adapterArgs
)
{
return PnpBridgeFromHresult(S_OK);
return S_OK;
}
PNPBRIDGE_RESULT
int
CameraPnpInterfaceShutdown(
)
{
return PnpBridgeFromHresult(S_OK);
return S_OK;
}
PNPBRIDGE_RESULT
int
CameraPnpInterfaceBind(
_In_ PNPADAPTER_INTERFACE_HANDLE Interface,
_In_ PNP_DEVICE_CLIENT_HANDLE pnpDeviceClientHandle,
_In_ PNPADAPTER_INTERFACE_HANDLE Interface,
_In_ PNP_DEVICE_CLIENT_HANDLE pnpDeviceClientHandle,
_In_ PPNPBRIDGE_DEVICE_CHANGE_PAYLOAD payload
)
{
@ -135,49 +92,7 @@ CameraPnpInterfaceBind(
RETURN_IF_FAILED (E_UNEXPECTED);
}
return PnpBridgeFromHresult(S_OK);
}
PNPBRIDGE_RESULT
CameraPnpInterfaceRelease(
_In_ PNPADAPTER_INTERFACE_HANDLE Interface
)
{
return PnpBridgeFromHresult(S_OK);
}
int
CameraBindPnpInterface(
_In_ PNPADAPTER_INTERFACE_HANDLE Interface,
_In_ PDEVICE_CHANGE_PAYLOAD payload
)
{
CameraPnpDiscovery* p = nullptr;
std::wstring cameraName;
std::unique_ptr<CameraIotPnpDevice> pIotPnp;
if (nullptr == Interface || nullptr == payload || nullptr == payload->Context)
{
return E_INVALIDARG;
}
p = (CameraPnpDiscovery*)payload->Context;
RETURN_IF_FAILED (p->GetFirstCamera(cameraName));
pIotPnp = std::make_unique<CameraIotPnpDevice>();
RETURN_IF_FAILED (pIotPnp->Initialize(PnpAdapter_GetPnpInterface(Interface), cameraName.c_str()));
RETURN_IF_FAILED (pIotPnp->StartTelemetryWorker());
if (0 == PnpAdapter_SetContext(Interface, (void*)pIotPnp.get()))
{
// Our interface context now owns the object.
pIotPnp.release();
return 0;
}
else
{
RETURN_IF_FAILED (E_UNEXPECTED);
}
return S_OK;
}
int
@ -200,24 +115,6 @@ CameraReleasePnpInterface(
// object around.
(void) PnpAdapter_SetContext(Interface, nullptr);
return 0;
return S_OK;
}
int
CameraGetPnpFilterFormatIds(
_Out_ char*** filterFormatIds,
_Out_ int* numberOfFormats
)
{
return CameraGetFilterFormatIds(filterFormatIds, numberOfFormats);
}
int
CameraPnpInterfaceModuleSupportsInterfaceId(
_In_z_ char* interfaceId,
_Out_ bool* supported
)
{
return 0;
}

Просмотреть файл

@ -7,6 +7,7 @@ extern "C"
#include <DiscoveryAdapterInterface.h>
#include <PnpAdapterInterface.h>
#include <common.h>
#include "pch.h"
@ -22,31 +23,24 @@ int
CameraPnpStopDiscovery(
);
int
CameraGetFilterFormatIds(
_Out_ char*** filterFormatIds,
_Out_ int* numberOfFormats
);
// Interface functions.
PNPBRIDGE_RESULT
int
CameraPnpInterfaceInitialize(
_In_ JSON_Object* adapterArgs
);
PNPBRIDGE_RESULT
int
CameraPnpInterfaceShutdown(
);
PNPBRIDGE_RESULT
int
CameraPnpInterfaceBind(
_In_ PNPADAPTER_INTERFACE_HANDLE Interface,
_In_ PNP_DEVICE_CLIENT_HANDLE pnpDeviceClientHandle,
_In_ PPNPBRIDGE_DEVICE_CHANGE_PAYLOAD payload
);
PNPBRIDGE_RESULT
int
CameraPnpInterfaceRelease(
_In_ PNPADAPTER_INTERFACE_HANDLE Interface
);

Просмотреть файл

@ -3,6 +3,8 @@
#pragma once
#include <common.h>
#ifdef __cplusplus
extern "C"
{

Просмотреть файл

@ -159,6 +159,11 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Adapters\Camera\CameraIotPnpDevice.h" />
<ClInclude Include="Adapters\Camera\CameraPnpDiscovery.h" />
<ClInclude Include="Adapters\Camera\CameraStatConsumer.h" />
<ClInclude Include="Adapters\Camera\iot_pnp_apis.h" />
<ClInclude Include="Adapters\Camera\pch.h" />
<ClInclude Include="Adapters\CoreDeviceHealth\CoreDeviceHealth.h" />
<ClInclude Include="Adapters\CoreDeviceHealth\WindowsPnpDeviceDiscovery.h" />
<ClInclude Include="common.h" />
@ -172,6 +177,10 @@
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Adapters\Camera\CameraIotPnpDevice.cpp" />
<ClCompile Include="Adapters\Camera\CameraPnpDiscovery.cpp" />
<ClCompile Include="Adapters\Camera\CameraStatConsumer.cpp" />
<ClCompile Include="Adapters\Camera\iot_pnp_apis.cpp" />
<ClCompile Include="Adapters\CoreDeviceHealth\CoreDeviceHealth.c" />
<ClCompile Include="Adapters\CoreDeviceHealth\WindowsPnPDeviceDiscovery.c" />
<ClCompile Include="Adapters\Serial\SerialDevice.c" />

Просмотреть файл

@ -25,6 +25,9 @@
<Filter Include="Source Files\inc">
<UniqueIdentifier>{92a538f9-7056-4277-a567-906bc28ce6a8}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Adapters\Camera">
<UniqueIdentifier>{83239274-3c8a-4c29-a27a-4d7aafc2f2e3}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<Text Include="ReadMe.txt" />
@ -63,6 +66,21 @@
<ClInclude Include="Adapters\CoreDeviceHealth\CoreDeviceHealth.h">
<Filter>Source Files\Adapters\CoreDeviceHealth</Filter>
</ClInclude>
<ClInclude Include="Adapters\Camera\CameraIotPnpDevice.h">
<Filter>Source Files\Adapters\Camera</Filter>
</ClInclude>
<ClInclude Include="Adapters\Camera\CameraPnpDiscovery.h">
<Filter>Source Files\Adapters\Camera</Filter>
</ClInclude>
<ClInclude Include="Adapters\Camera\CameraStatConsumer.h">
<Filter>Source Files\Adapters\Camera</Filter>
</ClInclude>
<ClInclude Include="Adapters\Camera\iot_pnp_apis.h">
<Filter>Source Files\Adapters\Camera</Filter>
</ClInclude>
<ClInclude Include="Adapters\Camera\pch.h">
<Filter>Source Files\Adapters\Camera</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="PnpBridge.c">
@ -92,6 +110,18 @@
<ClCompile Include="Adapters\CoreDeviceHealth\CoreDeviceHealth.c">
<Filter>Source Files\Adapters\CoreDeviceHealth</Filter>
</ClCompile>
<ClCompile Include="Adapters\Camera\CameraIotPnpDevice.cpp">
<Filter>Source Files\Adapters\Camera</Filter>
</ClCompile>
<ClCompile Include="Adapters\Camera\CameraPnpDiscovery.cpp">
<Filter>Source Files\Adapters\Camera</Filter>
</ClCompile>
<ClCompile Include="Adapters\Camera\CameraStatConsumer.cpp">
<Filter>Source Files\Adapters\Camera</Filter>
</ClCompile>
<ClCompile Include="Adapters\Camera\iot_pnp_apis.cpp">
<Filter>Source Files\Adapters\Camera</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="config.json" />