Skip to content

Commit

Permalink
Merge pull request #406 from microsoft/pete-dev
Browse files Browse the repository at this point in the history
Protocol Negotiation callback in the KS MIDI Endpoint manager
  • Loading branch information
Psychlist1972 authored Oct 7, 2024
2 parents abe9449 + 46c49ad commit ee1c058
Show file tree
Hide file tree
Showing 76 changed files with 1,286 additions and 650 deletions.
41 changes: 37 additions & 4 deletions src/api/Abstraction/KSAbstraction/Midi2.KSMidiEndpointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,9 @@ CMidi2KSMidiEndpointManager::OnDeviceAdded(
__uuidof(Midi2KSAbstraction),
newDeviceInterfaceId,
negotiationParams,
nullptr // TODO: Provide callback function to get function blocks
this
));


}

}
else
{
Expand Down Expand Up @@ -818,6 +815,42 @@ CMidi2KSMidiEndpointManager::OnDeviceAdded(
}


_Use_decl_annotations_
HRESULT CMidi2KSMidiEndpointManager::ProtocolNegotiationCompleteCallback(
GUID transportGuid,
LPCWSTR deviceInterfaceId,
PENDPOINTPROTOCOLNEGOTIATIONRESULTS results)
{
// this is not a centralized callback in this case, but is on the transport itself
// so no need to use the parameter here
UNREFERENCED_PARAMETER(transportGuid);

RETURN_HR_IF_NULL(E_INVALIDARG, results);
RETURN_HR_IF_NULL(E_INVALIDARG, deviceInterfaceId);

// iterate through returned function blocks.

if (results->DiscoveredFunctionBlocks != nullptr && results->CountFunctionBlocksReceived > 0)
{
for (uint32_t fbIndex = 0; fbIndex < results->CountFunctionBlocksReceived; fbIndex++)
{
auto pFunctionBlock = results->DiscoveredFunctionBlocks + fbIndex;

// TODO: use this function block information to create the compatible ports
UNREFERENCED_PARAMETER(pFunctionBlock);
}
}
else
{
// TODO: no function blocks. Fall back to group terminal blocks
// when creating MIDI 1.0 ports
}

return S_OK;
}



_Use_decl_annotations_
HRESULT CMidi2KSMidiEndpointManager::OnDeviceRemoved(DeviceWatcher, DeviceInformationUpdate device)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ typedef class _MIDI_PIN_INFO
class CMidi2KSMidiEndpointManager :
public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
IMidiEndpointManager>
IMidiEndpointManager,
IMidiProtocolNegotiationCompleteCallback>
{
public:

STDMETHOD(Initialize(_In_ IUnknown*, _In_ IUnknown*));
STDMETHOD(Cleanup)();

STDMETHOD(ProtocolNegotiationCompleteCallback(
_In_ GUID transportGuid,
_In_ LPCWSTR deviceInterfaceId,
_In_ PENDPOINTPROTOCOLNEGOTIATIONRESULTS results));

private:


Expand Down
32 changes: 16 additions & 16 deletions src/api/Abstraction/UdpNetworkMidi2/Midi2.NetworkMidiBidi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@


#include "pch.h"
#include "midi2.NetworkMidiabstraction.h"
#include "midi2.NetworkMidiTransport.h"

_Use_decl_annotations_
HRESULT
CMidi2NetworkMidiBiDi::Initialize(
LPCWSTR,
PABSTRACTIONCREATIONPARAMS,
DWORD *,
IMidiCallback * Callback,
LONGLONG Context,
IMidiCallback * callback,
LONGLONG context,
GUID /* SessionId */
)
{
TraceLoggingWrite(
MidiNetworkMidiAbstractionTelemetryProvider::Provider(),
MidiNetworkMidiTransportTelemetryProvider::Provider(),
MIDI_TRACE_EVENT_INFO,
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingPointer(this, "this"),
TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD)
);

m_Callback = Callback;
m_Context = Context;
m_callback = callback;
m_context = context;

return S_OK;
}
Expand All @@ -40,47 +40,47 @@ HRESULT
CMidi2NetworkMidiBiDi::Cleanup()
{
TraceLoggingWrite(
MidiNetworkMidiAbstractionTelemetryProvider::Provider(),
MidiNetworkMidiTransportTelemetryProvider::Provider(),
MIDI_TRACE_EVENT_INFO,
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingPointer(this, "this"),
TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD)
);

m_Callback = nullptr;
m_Context = 0;
m_callback = nullptr;
m_context = 0;

return S_OK;
}

_Use_decl_annotations_
HRESULT
CMidi2NetworkMidiBiDi::SendMidiMessage(
PVOID Message,
UINT Size,
LONGLONG Position
PVOID message,
UINT size,
LONGLONG position
)
{
if (m_Callback == nullptr)
if (m_callback == nullptr)
{
// TODO log that callback is null
return E_FAIL;
}

if (Message == nullptr)
if (message == nullptr)
{
// TODO log that message was null
return E_FAIL;
}

if (Size < sizeof(uint32_t))
if (size < sizeof(uint32_t))
{
// TODO log that data was smaller than minimum UMP size
return E_FAIL;
}

m_Callback->Callback(Message, Size, Position, m_Context);
m_callback->Callback(message, size, position, m_context);

return S_OK;

Expand Down
4 changes: 2 additions & 2 deletions src/api/Abstraction/UdpNetworkMidi2/Midi2.NetworkMidiBidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class CMidi2NetworkMidiBiDi :
STDMETHOD(Cleanup)();

private:
IMidiCallback* m_Callback;
LONGLONG m_Context;
IMidiCallback* m_callback;
LONGLONG m_context;
};


Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ using namespace winrt::Windows::Networking;
_Use_decl_annotations_
HRESULT
CMidi2NetworkMidiConfigurationManager::Initialize(
GUID AbstractionId,
IUnknown* MidiDeviceManager,
IUnknown* MidiServiceConfigurationManagerInterface
GUID transportId,
IUnknown* midiDeviceManager,
IUnknown* midiServiceConfigurationManagerInterface
)
{
UNREFERENCED_PARAMETER(MidiServiceConfigurationManagerInterface);
UNREFERENCED_PARAMETER(midiServiceConfigurationManagerInterface);


TraceLoggingWrite(
MidiNetworkMidiAbstractionTelemetryProvider::Provider(),
MidiNetworkMidiTransportTelemetryProvider::Provider(),
MIDI_TRACE_EVENT_INFO,
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingPointer(this, "this"),
TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD)
);

RETURN_HR_IF_NULL(E_INVALIDARG, MidiDeviceManager);
RETURN_IF_FAILED(MidiDeviceManager->QueryInterface(__uuidof(IMidiDeviceManagerInterface), (void**)&m_MidiDeviceManager));
RETURN_HR_IF_NULL(E_INVALIDARG, midiDeviceManager);
RETURN_IF_FAILED(midiDeviceManager->QueryInterface(__uuidof(IMidiDeviceManagerInterface), (void**)&m_midiDeviceManager));

m_abstractionId = AbstractionId;
m_transportId = transportId;

return S_OK;
}
Expand Down Expand Up @@ -153,24 +153,24 @@ CMidi2NetworkMidiConfigurationManager::ValidateHostDefinition(
_Use_decl_annotations_
HRESULT
CMidi2NetworkMidiConfigurationManager::UpdateConfiguration(
LPCWSTR ConfigurationJsonSection,
BOOL IsFromConfigurationFile,
BSTR* Response
LPCWSTR configurationJsonSection,
BOOL isFromConfigurationFile,
BSTR* response
)
{
TraceLoggingWrite(
MidiNetworkMidiAbstractionTelemetryProvider::Provider(),
MidiNetworkMidiTransportTelemetryProvider::Provider(),
MIDI_TRACE_EVENT_INFO,
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingPointer(this, "this"),
TraceLoggingWideString(L"Enter", MIDI_TRACE_EVENT_MESSAGE_FIELD)
);

UNREFERENCED_PARAMETER(IsFromConfigurationFile);
UNREFERENCED_PARAMETER(isFromConfigurationFile);

// if we're passed a null or empty json, we just quietly exit
if (ConfigurationJsonSection == nullptr) return S_OK;
if (configurationJsonSection == nullptr) return S_OK;

// default to failure

Expand Down Expand Up @@ -236,19 +236,19 @@ CMidi2NetworkMidiConfigurationManager::UpdateConfiguration(
jsonFalse);


if (!json::JsonObject::TryParse(winrt::to_hstring(ConfigurationJsonSection), jsonObject))
if (!json::JsonObject::TryParse(winrt::to_hstring(configurationJsonSection), jsonObject))
{
TraceLoggingWrite(
MidiNetworkMidiAbstractionTelemetryProvider::Provider(),
MidiNetworkMidiTransportTelemetryProvider::Provider(),
MIDI_TRACE_EVENT_ERROR,
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_ERROR),
TraceLoggingPointer(this, "this"),
TraceLoggingWideString(L"Failed to parse Configuration JSON", MIDI_TRACE_EVENT_MESSAGE_FIELD),
TraceLoggingWideString(ConfigurationJsonSection, "json")
TraceLoggingWideString(configurationJsonSection, "json")
);

internal::JsonStringifyObjectToOutParam(responseObject, &Response);
internal::JsonStringifyObjectToOutParam(responseObject, &response);

RETURN_IF_FAILED(E_INVALIDARG);
}
Expand All @@ -261,7 +261,7 @@ CMidi2NetworkMidiConfigurationManager::UpdateConfiguration(

// TODO: Set the response to something meaningful here

internal::JsonStringifyObjectToOutParam(responseObject, &Response);
internal::JsonStringifyObjectToOutParam(responseObject, &response);

// once we enable update/delete we need to move this
return S_OK;
Expand Down Expand Up @@ -414,7 +414,7 @@ CMidi2NetworkMidiConfigurationManager::UpdateConfiguration(


TraceLoggingWrite(
MidiNetworkMidiAbstractionTelemetryProvider::Provider(),
MidiNetworkMidiTransportTelemetryProvider::Provider(),
MIDI_TRACE_EVENT_INFO,
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
Expand All @@ -423,7 +423,7 @@ CMidi2NetworkMidiConfigurationManager::UpdateConfiguration(
);

// return the json with the information the client will need
internal::JsonStringifyObjectToOutParam(responseObject, &Response);
internal::JsonStringifyObjectToOutParam(responseObject, &response);

return S_OK;
}
Expand All @@ -433,7 +433,7 @@ HRESULT
CMidi2NetworkMidiConfigurationManager::Cleanup()
{
TraceLoggingWrite(
MidiNetworkMidiAbstractionTelemetryProvider::Provider(),
MidiNetworkMidiTransportTelemetryProvider::Provider(),
MIDI_TRACE_EVENT_INFO,
TraceLoggingString(__FUNCTION__, MIDI_TRACE_EVENT_LOCATION_FIELD),
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class CMidi2NetworkMidiConfigurationManager :

{
public:
STDMETHOD(Initialize(_In_ GUID AbstractionId, _In_ IUnknown* MidiDeviceManager, _In_ IUnknown* MidiServiceConfigurationManagerInterface));
STDMETHOD(UpdateConfiguration(_In_ LPCWSTR ConfigurationJsonSection, _In_ BOOL IsFromConfigurationFile, _Out_ BSTR* Response));
STDMETHOD(Initialize(_In_ GUID transportId, _In_ IUnknown* midiDeviceManager, _In_ IUnknown* midiServiceConfigurationManagerInterface));
STDMETHOD(UpdateConfiguration(_In_ LPCWSTR configurationJsonSection, _In_ BOOL isFromConfigurationFile, _Out_ BSTR* Response));
STDMETHOD(Cleanup)();

STDMETHOD(ValidateHostDefinition(_In_ MidiNetworkUdpHostDefinition& definition, _Out_ winrt::hstring& errorMessage));
// STDMETHOD(ValidateClientDefinition(_In_ MidiNetworkUdpClientDefinition& definition));

private:
wil::com_ptr_nothrow<IMidiDeviceManagerInterface> m_MidiDeviceManager;
wil::com_ptr_nothrow<IMidiDeviceManagerInterface> m_midiDeviceManager;

GUID m_abstractionId; // kept for convenience
GUID m_transportId; // kept for convenience
};
Loading

0 comments on commit ee1c058

Please sign in to comment.