diff --git a/frameworks/native/midi/include/midi_client_private.h b/frameworks/native/midi/include/midi_client_private.h index 6f05c03..af061c0 100644 --- a/frameworks/native/midi/include/midi_client_private.h +++ b/frameworks/native/midi/include/midi_client_private.h @@ -34,9 +34,9 @@ class MidiClientCallback; class MidiInputPort { public: - MidiInputPort(OH_OnMidiReceived callback, void *userData); + MidiInputPort(OH_OnMIDIReceived callback, void *userData); ~MidiInputPort(); - std::shared_ptr &GetRingBuffer(); + std::shared_ptr &GetRingBuffer(); bool StartReceiverThread(); bool StopReceiverThread(); @@ -49,8 +49,8 @@ private: bool ShouldWakeForReadOrExit() const; std::atomic running_ = false; - OH_OnMidiReceived callback_ = nullptr; - std::shared_ptr ringBuffer_ = nullptr; + OH_OnMIDIReceived callback_ = nullptr; + std::shared_ptr ringBuffer_ = nullptr; std::thread receiverThread_; void *userData_ = nullptr; }; @@ -59,9 +59,9 @@ class MidiDevicePrivate : public MidiDevice { public: MidiDevicePrivate(std::shared_ptr midiServiceInterface, int64_t deviceId); virtual ~MidiDevicePrivate(); - OH_MidiStatusCode CloseDevice() override; - OH_MidiStatusCode OpenInputPort(uint32_t portIndex, OH_OnMidiReceived callback, void *userData) override; - OH_MidiStatusCode ClosePort(uint32_t portIndex) override; + OH_MIDIStatusCode CloseDevice() override; + OH_MIDIStatusCode OpenInputPort(uint32_t portIndex, OH_OnMIDIReceived callback, void *userData) override; + OH_MIDIStatusCode ClosePort(uint32_t portIndex) override; private: std::weak_ptr ipc_; @@ -74,16 +74,16 @@ class MidiClientPrivate : public MidiClient { public: MidiClientPrivate(); virtual ~MidiClientPrivate(); - OH_MidiStatusCode Init(OH_MidiCallbacks callbacks, void *userData) override; - OH_MidiStatusCode GetDevices(OH_MidiDeviceInformation *infos, size_t *numDevices) override; - OH_MidiStatusCode OpenDevice(int64_t deviceId, MidiDevice **midiDevice) override; - OH_MidiStatusCode GetDevicePorts(int64_t deviceId, OH_MidiPortInformation *infos, size_t *numPorts) override; - OH_MidiStatusCode DestroyMidiClient() override; - void DeviceChange(OH_MidiDeviceChangeAction change, OH_MidiDeviceInformation info); + OH_MIDIStatusCode Init(OH_MIDICallbacks callbacks, void *userData) override; + OH_MIDIStatusCode GetDevices(OH_MIDIDeviceInformation *infos, size_t *numDevices) override; + OH_MIDIStatusCode OpenDevice(int64_t deviceId, MidiDevice **midiDevice) override; + OH_MIDIStatusCode GetDevicePorts(int64_t deviceId, OH_MIDIPortInformation *infos, size_t *numPorts) override; + OH_MIDIStatusCode DestroyMidiClient() override; + void DeviceChange(OH_MIDIDeviceChangeAction change, OH_MIDIDeviceInformation info); private: std::shared_ptr ipc_; uint32_t clientId_; - std::vector deviceInfos_; + std::vector deviceInfos_; sptr callback_; std::mutex mutex_; }; diff --git a/frameworks/native/midi/include/midi_service_client.h b/frameworks/native/midi/include/midi_service_client.h index 57bb15a..e6f6eab 100644 --- a/frameworks/native/midi/include/midi_service_client.h +++ b/frameworks/native/midi/include/midi_service_client.h @@ -30,15 +30,15 @@ class MidiServiceClient : public MidiServiceInterface { public: MidiServiceClient() = default; virtual ~MidiServiceClient(); - OH_MidiStatusCode Init(sptr callback, uint32_t &clientId) override; - OH_MidiStatusCode GetDevices(std::vector> &deviceInfos) override; - OH_MidiStatusCode OpenDevice(int64_t deviceId) override; - OH_MidiStatusCode CloseDevice(int64_t deviceId) override; - OH_MidiStatusCode GetDevicePorts(int64_t deviceId, std::vector> &portInfos) override; - OH_MidiStatusCode OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, + OH_MIDIStatusCode Init(sptr callback, uint32_t &clientId) override; + OH_MIDIStatusCode GetDevices(std::vector> &deviceInfos) override; + OH_MIDIStatusCode OpenDevice(int64_t deviceId) override; + OH_MIDIStatusCode CloseDevice(int64_t deviceId) override; + OH_MIDIStatusCode GetDevicePorts(int64_t deviceId, std::vector> &portInfos) override; + OH_MIDIStatusCode OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) override; - OH_MidiStatusCode CloseInputPort(int64_t deviceId, uint32_t portIndex) override; - OH_MidiStatusCode DestroyMidiClient() override; + OH_MIDIStatusCode CloseInputPort(int64_t deviceId, uint32_t portIndex) override; + OH_MIDIStatusCode DestroyMidiClient() override; private: sptr ipc_; diff --git a/frameworks/native/midi/include/midi_service_interface.h b/frameworks/native/midi/include/midi_service_interface.h index e06635d..93d2819 100644 --- a/frameworks/native/midi/include/midi_service_interface.h +++ b/frameworks/native/midi/include/midi_service_interface.h @@ -26,16 +26,16 @@ namespace MIDI { class MidiServiceInterface { public: virtual ~MidiServiceInterface() = default; - virtual OH_MidiStatusCode Init(sptr callback, uint32_t &clientId) = 0; - virtual OH_MidiStatusCode GetDevices(std::vector> &deviceInfos) = 0; - virtual OH_MidiStatusCode OpenDevice(int64_t deviceId) = 0; - virtual OH_MidiStatusCode CloseDevice(int64_t deviceId) = 0; - virtual OH_MidiStatusCode GetDevicePorts(int64_t deviceId, + virtual OH_MIDIStatusCode Init(sptr callback, uint32_t &clientId) = 0; + virtual OH_MIDIStatusCode GetDevices(std::vector> &deviceInfos) = 0; + virtual OH_MIDIStatusCode OpenDevice(int64_t deviceId) = 0; + virtual OH_MIDIStatusCode CloseDevice(int64_t deviceId) = 0; + virtual OH_MIDIStatusCode GetDevicePorts(int64_t deviceId, std::vector> &portInfos) = 0; - virtual OH_MidiStatusCode OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, + virtual OH_MIDIStatusCode OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) = 0; - virtual OH_MidiStatusCode CloseInputPort(int64_t deviceId, uint32_t portIndex) = 0; - virtual OH_MidiStatusCode DestroyMidiClient() = 0; + virtual OH_MIDIStatusCode CloseInputPort(int64_t deviceId, uint32_t portIndex) = 0; + virtual OH_MIDIStatusCode DestroyMidiClient() = 0; }; } // namespace MIDI } // namespace OHOS diff --git a/frameworks/native/midi/src/midi_client.cpp b/frameworks/native/midi/src/midi_client.cpp index 1176ac0..9f954db 100644 --- a/frameworks/native/midi/src/midi_client.cpp +++ b/frameworks/native/midi/src/midi_client.cpp @@ -35,18 +35,18 @@ std::mutex clientsMutex; class MidiClientCallback : public MidiCallbackStub { public: - MidiClientCallback(OH_MidiCallbacks callbacks, void *userData, - std::function deviceChange); + MidiClientCallback(OH_MIDICallbacks callbacks, void *userData, + std::function deviceChange); ~MidiClientCallback() = default; int32_t NotifyDeviceChange(int32_t change, const std::map &deviceInfo) override; int32_t NotifyError(int32_t code) override; - OH_MidiCallbacks callbacks_; + OH_MIDICallbacks callbacks_; void *userData_; - std::function deviceChange_; + std::function deviceChange_; }; static bool ConvertToDeviceInformation( - const std::map &deviceInfo, OH_MidiDeviceInformation &outInfo) + const std::map &deviceInfo, OH_MIDIDeviceInformation &outInfo) { // 初始化outInfo memset_s(&outInfo, sizeof(outInfo), 0, sizeof(outInfo)); @@ -57,11 +57,11 @@ static bool ConvertToDeviceInformation( it = deviceInfo.find(DEVICE_TYPE); CHECK_AND_RETURN_RET_LOG(it != deviceInfo.end(), false, "deviceType error"); - outInfo.deviceType = static_cast(std::stoi(it->second)); + outInfo.deviceType = static_cast(std::stoi(it->second)); it = deviceInfo.find(MIDI_PROTOCOL); CHECK_AND_RETURN_RET_LOG(it != deviceInfo.end(), false, "protocol error"); - outInfo.nativeProtocol = static_cast(std::stoi(it->second)); + outInfo.nativeProtocol = static_cast(std::stoi(it->second)); it = deviceInfo.find(PRODUCT_NAME); CHECK_AND_RETURN_RET_LOG(it != deviceInfo.end(), false, "productName error"); @@ -82,7 +82,7 @@ static bool ConvertToDeviceInformation( } static bool ConvertToPortInformation( - const std::map &portInfo, int64_t deviceId, OH_MidiPortInformation &outInfo) + const std::map &portInfo, int64_t deviceId, OH_MIDIPortInformation &outInfo) { memset_s(&outInfo, sizeof(outInfo), 0, sizeof(outInfo)); @@ -94,7 +94,7 @@ static bool ConvertToPortInformation( outInfo.portIndex = static_cast(std::stoll(it->second)); it = portInfo.find(DIRECTION); CHECK_AND_RETURN_RET_LOG(it != portInfo.end(), false, "direction error"); - outInfo.direction = static_cast(std::stoi(it->second)); + outInfo.direction = static_cast(std::stoi(it->second)); it = portInfo.find(PORT_NAME); CHECK_AND_RETURN_RET_LOG(it != portInfo.end() && !it->second.empty(), false, "port name error"); @@ -106,8 +106,8 @@ static bool ConvertToPortInformation( return true; } -MidiClientCallback::MidiClientCallback(OH_MidiCallbacks callbacks, void *userData, - std::function deviceChange) +MidiClientCallback::MidiClientCallback(OH_MIDICallbacks callbacks, void *userData, + std::function deviceChange) : callbacks_(callbacks), userData_(userData), deviceChange_(deviceChange) {} @@ -116,20 +116,20 @@ int32_t MidiClientCallback::NotifyDeviceChange(int32_t change, const std::map(change), info); + deviceChange_(static_cast(change), info); - callbacks_.onDeviceChange(userData_, static_cast(change), info); + callbacks_.onDeviceChange(userData_, static_cast(change), info); return 0; } int32_t MidiClientCallback::NotifyError(int32_t code) { CHECK_AND_RETURN_RET_LOG(callbacks_.onError != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "callbacks_.onError is nullptr"); - callbacks_.onError(userData_, (OH_MidiStatusCode)code); + callbacks_.onError(userData_, (OH_MIDIStatusCode)code); return 0; } @@ -144,14 +144,14 @@ MidiDevicePrivate::~MidiDevicePrivate() MIDI_INFO_LOG("MidiDevicePrivate destroyed"); } -OH_MidiStatusCode MidiDevicePrivate::CloseDevice() +OH_MIDIStatusCode MidiDevicePrivate::CloseDevice() { auto ipc = ipc_.lock(); CHECK_AND_RETURN_RET_LOG(ipc != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "ipc_ is nullptr"); return ipc->CloseDevice(deviceId_); } -OH_MidiStatusCode MidiDevicePrivate::OpenInputPort(uint32_t portIndex, OH_OnMidiReceived callback, void *userData) +OH_MIDIStatusCode MidiDevicePrivate::OpenInputPort(uint32_t portIndex, OH_OnMIDIReceived callback, void *userData) { auto ipc = ipc_.lock(); CHECK_AND_RETURN_RET_LOG(ipc != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "ipc_ is nullptr"); @@ -162,7 +162,7 @@ OH_MidiStatusCode MidiDevicePrivate::OpenInputPort(uint32_t portIndex, OH_OnMidi } auto inputPort = std::make_shared(callback, userData); - std::shared_ptr &buffer = inputPort->GetRingBuffer(); + std::shared_ptr &buffer = inputPort->GetRingBuffer(); auto ret = ipc->OpenInputPort(buffer, deviceId_, portIndex); CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, ret, "open inputport fail"); @@ -177,11 +177,11 @@ OH_MidiStatusCode MidiDevicePrivate::OpenInputPort(uint32_t portIndex, OH_OnMidi return MIDI_STATUS_OK; } -OH_MidiStatusCode MidiDevicePrivate::ClosePort(uint32_t portIndex) +OH_MIDIStatusCode MidiDevicePrivate::ClosePort(uint32_t portIndex) { auto ipc = ipc_.lock(); CHECK_AND_RETURN_RET_LOG(ipc != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "ipc_ is nullptr"); - OH_MidiStatusCode ret = MIDI_STATUS_OK; + OH_MIDIStatusCode ret = MIDI_STATUS_OK; { std::lock_guard lock(inputPortsMutex_); auto it = inputPortsMap_.find(portIndex); @@ -193,7 +193,7 @@ OH_MidiStatusCode MidiDevicePrivate::ClosePort(uint32_t portIndex) return MIDI_STATUS_OK; } -MidiInputPort::MidiInputPort(OH_OnMidiReceived callback, void *userData) : callback_(callback), userData_(userData) +MidiInputPort::MidiInputPort(OH_OnMIDIReceived callback, void *userData) : callback_(callback), userData_(userData) { MIDI_INFO_LOG("InputPort created"); } @@ -260,7 +260,7 @@ bool MidiInputPort::ShouldWakeForReadOrExit() const return true; } - SharedMidiRing::PeekedEvent peekedEvent{}; + MidiSharedRing::PeekedEvent peekedEvent{}; MidiStatusCode status = ringBuffer_->PeekNext(peekedEvent); return (status == MidiStatusCode::OK); } @@ -280,11 +280,11 @@ void MidiInputPort::DrainRingAndDispatch() return; } - std::vector callbackEvents; + std::vector callbackEvents; callbackEvents.reserve(midiEvents.size()); for (const auto &event : midiEvents) { - OH_MidiEvent callbackEvent{}; + OH_MIDIEvent callbackEvent{}; callbackEvent.timestamp = event.timestamp; callbackEvent.length = event.length; callbackEvent.data = event.data; @@ -299,7 +299,7 @@ MidiInputPort::~MidiInputPort() (void)StopReceiverThread(); } -std::shared_ptr &MidiInputPort::GetRingBuffer() +std::shared_ptr &MidiInputPort::GetRingBuffer() { return ringBuffer_; } @@ -314,12 +314,12 @@ MidiClientPrivate::~MidiClientPrivate() MIDI_INFO_LOG("MidiClientPrivate destroyed"); } -OH_MidiStatusCode MidiClientPrivate::Init(OH_MidiCallbacks callbacks, void *userData) +OH_MIDIStatusCode MidiClientPrivate::Init(OH_MIDICallbacks callbacks, void *userData) { CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "ipc_ is nullptr"); callback_ = sptr::MakeSptr(callbacks, userData, - [this](OH_MidiDeviceChangeAction change, OH_MidiDeviceInformation info) { this->DeviceChange(change, info); }); + [this](OH_MIDIDeviceChangeAction change, OH_MIDIDeviceInformation info) { this->DeviceChange(change, info); }); auto ret = ipc_->Init(callback_, clientId_); CHECK_AND_RETURN_RET(ret == MIDI_STATUS_OK, ret); std::lock_guard lock(mutex_); @@ -327,7 +327,7 @@ OH_MidiStatusCode MidiClientPrivate::Init(OH_MidiCallbacks callbacks, void *user ret = ipc_->GetDevices(deviceInfos); CHECK_AND_RETURN_RET(ret == MIDI_STATUS_OK, ret); for (auto deviceInfo : deviceInfos) { - OH_MidiDeviceInformation info; + OH_MIDIDeviceInformation info; bool ret = ConvertToDeviceInformation(deviceInfo, info); CHECK_AND_CONTINUE_LOG(ret, "ConvertToDeviceInformation failed"); deviceInfos_.push_back(info); @@ -335,7 +335,7 @@ OH_MidiStatusCode MidiClientPrivate::Init(OH_MidiCallbacks callbacks, void *user return MIDI_STATUS_OK; } -void MidiClientPrivate::DeviceChange(OH_MidiDeviceChangeAction change, OH_MidiDeviceInformation info) +void MidiClientPrivate::DeviceChange(OH_MIDIDeviceChangeAction change, OH_MIDIDeviceInformation info) { std::lock_guard lock(mutex_); MIDI_INFO_LOG("DeviceChange: %{public}d", change); @@ -353,7 +353,7 @@ void MidiClientPrivate::DeviceChange(OH_MidiDeviceChangeAction change, OH_MidiDe } } -OH_MidiStatusCode MidiClientPrivate::GetDevices(OH_MidiDeviceInformation *infos, size_t *numDevices) +OH_MIDIStatusCode MidiClientPrivate::GetDevices(OH_MIDIDeviceInformation *infos, size_t *numDevices) { std::lock_guard lock(mutex_); if (*numDevices < deviceInfos_.size()) { @@ -370,7 +370,7 @@ OH_MidiStatusCode MidiClientPrivate::GetDevices(OH_MidiDeviceInformation *infos, return MIDI_STATUS_OK; } -OH_MidiStatusCode MidiClientPrivate::OpenDevice(int64_t deviceId, MidiDevice **midiDevice) +OH_MIDIStatusCode MidiClientPrivate::OpenDevice(int64_t deviceId, MidiDevice **midiDevice) { CHECK_AND_RETURN_RET_LOG(midiDevice != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "midiDevice is nullptr"); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "ipc_ is nullptr"); @@ -382,7 +382,7 @@ OH_MidiStatusCode MidiClientPrivate::OpenDevice(int64_t deviceId, MidiDevice **m return MIDI_STATUS_OK; } -OH_MidiStatusCode MidiClientPrivate::GetDevicePorts(int64_t deviceId, OH_MidiPortInformation *infos, size_t *numPorts) +OH_MIDIStatusCode MidiClientPrivate::GetDevicePorts(int64_t deviceId, OH_MIDIPortInformation *infos, size_t *numPorts) { std::lock_guard lock(mutex_); std::vector> portInfos; @@ -398,7 +398,7 @@ OH_MidiStatusCode MidiClientPrivate::GetDevicePorts(int64_t deviceId, OH_MidiPor CHECK_AND_RETURN_RET(infos != nullptr, MIDI_STATUS_GENERIC_INVALID_ARGUMENT); for (size_t i = 0; i < portInfos.size(); i++) { - OH_MidiPortInformation info; + OH_MIDIPortInformation info; bool ret = ConvertToPortInformation(portInfos[i], deviceId, info); CHECK_AND_CONTINUE_LOG(ret, "ConvertToPortInformation failed"); infos[i] = info; @@ -407,17 +407,17 @@ OH_MidiStatusCode MidiClientPrivate::GetDevicePorts(int64_t deviceId, OH_MidiPor return MIDI_STATUS_OK; } -OH_MidiStatusCode MidiClientPrivate::DestroyMidiClient() +OH_MIDIStatusCode MidiClientPrivate::DestroyMidiClient() { CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "ipc_ is nullptr"); return ipc_->DestroyMidiClient(); } -OH_MidiStatusCode MidiClient::CreateMidiClient(MidiClient **client, OH_MidiCallbacks callbacks, void *userData) +OH_MIDIStatusCode MidiClient::CreateMidiClient(MidiClient **client, OH_MIDICallbacks callbacks, void *userData) { CHECK_AND_RETURN_RET_LOG(client != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "client is nullptr"); *client = new MidiClientPrivate(); - OH_MidiStatusCode ret = (*client)->Init(callbacks, userData); + OH_MIDIStatusCode ret = (*client)->Init(callbacks, userData); CHECK_AND_RETURN_RET(ret != MIDI_STATUS_OK, ret); delete *client; return ret; diff --git a/frameworks/native/midi/src/midi_service_client.cpp b/frameworks/native/midi/src/midi_service_client.cpp index 693a3a5..3da6a72 100644 --- a/frameworks/native/midi/src/midi_service_client.cpp +++ b/frameworks/native/midi/src/midi_service_client.cpp @@ -32,7 +32,7 @@ MidiServiceClient::~MidiServiceClient() MIDI_INFO_LOG("~MidiServiceClient"); } -OH_MidiStatusCode MidiServiceClient::Init(sptr callback, uint32_t &clientId) +OH_MIDIStatusCode MidiServiceClient::Init(sptr callback, uint32_t &clientId) { auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); CHECK_AND_RETURN_RET_LOG(samgr != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "Get samgr failed."); @@ -45,7 +45,7 @@ OH_MidiStatusCode MidiServiceClient::Init(sptr callback, uint3 sptr ipcProxy = nullptr; auto ret = gsp->CreateClientInServer(callback, ipcProxy, clientId); - CHECK_AND_RETURN_RET(ret == MIDI_STATUS_OK, (OH_MidiStatusCode)ret); + CHECK_AND_RETURN_RET(ret == MIDI_STATUS_OK, (OH_MIDIStatusCode)ret); ipc_ = iface_cast(ipcProxy); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "ipc_ is NULL."); callback_ = callback; @@ -60,51 +60,51 @@ OH_MidiStatusCode MidiServiceClient::Init(sptr callback, uint3 return MIDI_STATUS_OK; } -OH_MidiStatusCode MidiServiceClient::GetDevices(std::vector> &deviceInfos) +OH_MIDIStatusCode MidiServiceClient::GetDevices(std::vector> &deviceInfos) { std::lock_guard lock(lock_); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "ipc_ is NULL."); - return (OH_MidiStatusCode)ipc_->GetDevices(deviceInfos); + return (OH_MIDIStatusCode)ipc_->GetDevices(deviceInfos); } -OH_MidiStatusCode MidiServiceClient::OpenDevice(int64_t deviceId) +OH_MIDIStatusCode MidiServiceClient::OpenDevice(int64_t deviceId) { std::lock_guard lock(lock_); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "ipc_ is NULL."); - return (OH_MidiStatusCode)ipc_->OpenDevice(deviceId); + return (OH_MIDIStatusCode)ipc_->OpenDevice(deviceId); } -OH_MidiStatusCode MidiServiceClient::CloseDevice(int64_t deviceId) +OH_MIDIStatusCode MidiServiceClient::CloseDevice(int64_t deviceId) { std::lock_guard lock(lock_); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "ipc_ is NULL."); - return (OH_MidiStatusCode)ipc_->CloseDevice(deviceId); + return (OH_MIDIStatusCode)ipc_->CloseDevice(deviceId); } -OH_MidiStatusCode MidiServiceClient::GetDevicePorts(int64_t deviceId, +OH_MIDIStatusCode MidiServiceClient::GetDevicePorts(int64_t deviceId, std::vector> &portInfos) { std::lock_guard lock(lock_); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "ipc_ is NULL."); - return (OH_MidiStatusCode)ipc_->GetDevicePorts(deviceId, portInfos); + return (OH_MIDIStatusCode)ipc_->GetDevicePorts(deviceId, portInfos); } -OH_MidiStatusCode MidiServiceClient::OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, +OH_MIDIStatusCode MidiServiceClient::OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) { std::lock_guard lock(lock_); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "ipc_ is NULL."); - return (OH_MidiStatusCode)ipc_->OpenInputPort(buffer, deviceId, portIndex); + return (OH_MIDIStatusCode)ipc_->OpenInputPort(buffer, deviceId, portIndex); } -OH_MidiStatusCode MidiServiceClient::CloseInputPort(int64_t deviceId, uint32_t portIndex) +OH_MIDIStatusCode MidiServiceClient::CloseInputPort(int64_t deviceId, uint32_t portIndex) { std::lock_guard lock(lock_); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "ipc_ is NULL."); - return (OH_MidiStatusCode)ipc_->CloseInputPort(deviceId, portIndex); + return (OH_MIDIStatusCode)ipc_->CloseInputPort(deviceId, portIndex); } -OH_MidiStatusCode MidiServiceClient::DestroyMidiClient() +OH_MIDIStatusCode MidiServiceClient::DestroyMidiClient() { std::lock_guard lock(lock_); CHECK_AND_RETURN_RET_LOG(ipc_ != nullptr, MIDI_STATUS_GENERIC_IPC_FAILURE, "ipc_ is NULL."); @@ -119,7 +119,7 @@ OH_MidiStatusCode MidiServiceClient::DestroyMidiClient() auto ret = ipc_->DestroyMidiClient(); ipc_ = nullptr; callback_ = nullptr; - CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, (OH_MidiStatusCode)ret, "DestroyMidiClient failed"); + CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, (OH_MIDIStatusCode)ret, "DestroyMidiClient failed"); return MIDI_STATUS_OK; } } // namespace MIDI diff --git a/frameworks/native/ohmidi/OHMidi.cpp b/frameworks/native/ohmidi/OHMidi.cpp index 5f0aadc..3f85675 100644 --- a/frameworks/native/ohmidi/OHMidi.cpp +++ b/frameworks/native/ohmidi/OHMidi.cpp @@ -21,27 +21,27 @@ #include "midi_client.h" #include "midi_log.h" -OH_MidiStatusCode OH_MidiClientCreate(OH_MidiClient **client, OH_MidiCallbacks callbacks, void *userData) +OH_MIDIStatusCode OH_MIDIClientCreate(OH_MIDIClient **client, OH_MIDICallbacks callbacks, void *userData) { CHECK_AND_RETURN_RET_LOG(client != nullptr, MIDI_STATUS_GENERIC_INVALID_ARGUMENT, "client is nullptr"); OHOS::MIDI::MidiClient *midiclient = nullptr; - OH_MidiStatusCode ret = OHOS::MIDI::MidiClient::CreateMidiClient(&midiclient, callbacks, userData); + OH_MIDIStatusCode ret = OHOS::MIDI::MidiClient::CreateMidiClient(&midiclient, callbacks, userData); CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, ret, "CreateMidiClient falid"); - *client = (OH_MidiClient *)midiclient; + *client = (OH_MIDIClient *)midiclient; return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiClientDestroy(OH_MidiClient *client) +OH_MIDIStatusCode OH_MIDIClientDestroy(OH_MIDIClient *client) { OHOS::MIDI::MidiClient *midiclient = (OHOS::MIDI::MidiClient *)client; CHECK_AND_RETURN_RET_LOG(midiclient != nullptr, MIDI_STATUS_INVALID_CLIENT, "convert builder failed"); - OH_MidiStatusCode ret = midiclient->DestroyMidiClient(); + OH_MIDIStatusCode ret = midiclient->DestroyMidiClient(); delete midiclient; CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, ret, "DestroyMidiClient falid"); return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiGetDevices(OH_MidiClient *client, OH_MidiDeviceInformation *infos, size_t *numDevices) +OH_MIDIStatusCode OH_MIDIGetDevices(OH_MIDIClient *client, OH_MIDIDeviceInformation *infos, size_t *numDevices) { OHOS::MIDI::MidiClient *midiclient = (OHOS::MIDI::MidiClient *)client; CHECK_AND_RETURN_RET_LOG(midiclient != nullptr, MIDI_STATUS_INVALID_CLIENT, "Invalid client"); @@ -50,7 +50,7 @@ OH_MidiStatusCode OH_MidiGetDevices(OH_MidiClient *client, OH_MidiDeviceInformat return midiclient->GetDevices(infos, numDevices); } -OH_MidiStatusCode OH_MidiOpenDevice(OH_MidiClient *client, int64_t deviceId, OH_MidiDevice **device) +OH_MIDIStatusCode OH_MIDIOpenDevice(OH_MIDIClient *client, int64_t deviceId, OH_MIDIDevice **device) { OHOS::MIDI::MidiClient *midiclient = (OHOS::MIDI::MidiClient *)client; CHECK_AND_RETURN_RET_LOG(midiclient != nullptr, MIDI_STATUS_INVALID_CLIENT, "Invalid client"); @@ -58,32 +58,32 @@ OH_MidiStatusCode OH_MidiOpenDevice(OH_MidiClient *client, int64_t deviceId, OH_ CHECK_AND_RETURN_RET_LOG(device != nullptr, MIDI_STATUS_GENERIC_INVALID_ARGUMENT, "Invalid parameter"); OHOS::MIDI::MidiDevice *midiDevice = nullptr; - OH_MidiStatusCode ret = midiclient->OpenDevice(deviceId, &midiDevice); + OH_MIDIStatusCode ret = midiclient->OpenDevice(deviceId, &midiDevice); CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, ret, "OpenDevice falid"); - *device = (OH_MidiDevice *)midiDevice; + *device = (OH_MIDIDevice *)midiDevice; return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiOpenBleDevice( - OH_MidiClient *client, const char *deviceAddr, OH_MidiDevice **device, int64_t *deviceId) +OH_MIDIStatusCode OH_MIDIOpenBleDevice( + OH_MIDIClient *client, const char *deviceAddr, OH_MIDIDevice **device, int64_t *deviceId) { (void)deviceAddr; return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiCloseDevice(OH_MidiDevice *device) +OH_MIDIStatusCode OH_MIDICloseDevice(OH_MIDIDevice *device) { OHOS::MIDI::MidiDevice *midiDevice = (OHOS::MIDI::MidiDevice *)device; CHECK_AND_RETURN_RET_LOG(midiDevice != nullptr, MIDI_STATUS_INVALID_DEVICE_HANDLE, "Invalid parameter"); - OH_MidiStatusCode ret = midiDevice->CloseDevice(); + OH_MIDIStatusCode ret = midiDevice->CloseDevice(); delete midiDevice; CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, ret, "CloseDevice falid"); return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiGetDevicePorts( - OH_MidiClient *client, int64_t deviceId, OH_MidiPortInformation *infos, size_t *numPorts) +OH_MIDIStatusCode OH_MIDIGetDevicePorts( + OH_MIDIClient *client, int64_t deviceId, OH_MIDIPortInformation *infos, size_t *numPorts) { OHOS::MIDI::MidiClient *midiclient = (OHOS::MIDI::MidiClient *)client; CHECK_AND_RETURN_RET_LOG(midiclient != nullptr, MIDI_STATUS_INVALID_CLIENT, "Invalid client"); @@ -91,35 +91,35 @@ OH_MidiStatusCode OH_MidiGetDevicePorts( return midiclient->GetDevicePorts(deviceId, infos, numPorts); } -OH_MidiStatusCode OH_MidiOpenInputPort( - OH_MidiDevice *device, OH_MidiPortDescriptor descriptor, OH_OnMidiReceived callback, void *userData) +OH_MIDIStatusCode OH_MIDIOpenInputPort( + OH_MIDIDevice *device, OH_MIDIPortDescriptor descriptor, OH_OnMIDIReceived callback, void *userData) { OHOS::MIDI::MidiDevice *midiDevice = (OHOS::MIDI::MidiDevice *)device; CHECK_AND_RETURN_RET_LOG(midiDevice != nullptr, MIDI_STATUS_INVALID_DEVICE_HANDLE, "Invalid parameter"); - OH_MidiStatusCode ret = midiDevice->OpenInputPort(descriptor.portIndex, callback, userData); + OH_MIDIStatusCode ret = midiDevice->OpenInputPort(descriptor.portIndex, callback, userData); CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, ret, "OpenInputPort falid"); return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiOpenOutputPort(OH_MidiDevice *device, OH_MidiPortDescriptor descriptor) +OH_MIDIStatusCode OH_MIDIOpenOutputPort(OH_MIDIDevice *device, OH_MIDIPortDescriptor descriptor) { (void)descriptor; return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiClosePort(OH_MidiDevice *device, uint32_t portIndex) +OH_MIDIStatusCode OH_MIDIClosePort(OH_MIDIDevice *device, uint32_t portIndex) { OHOS::MIDI::MidiDevice *midiDevice = (OHOS::MIDI::MidiDevice *)device; CHECK_AND_RETURN_RET_LOG(midiDevice != nullptr, MIDI_STATUS_GENERIC_INVALID_ARGUMENT, "Invalid parameter"); - OH_MidiStatusCode ret = midiDevice->ClosePort(portIndex); + OH_MIDIStatusCode ret = midiDevice->ClosePort(portIndex); CHECK_AND_RETURN_RET_LOG(ret == MIDI_STATUS_OK, ret, "OpenInputPort falid"); return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiSend( - OH_MidiDevice *device, uint32_t portIndex, OH_MidiEvent *events, uint32_t eventCount, uint32_t *eventsWritten) +OH_MIDIStatusCode OH_MIDISend( + OH_MIDIDevice *device, uint32_t portIndex, OH_MIDIEvent *events, uint32_t eventCount, uint32_t *eventsWritten) { (void)portIndex; (void)events; @@ -127,7 +127,7 @@ OH_MidiStatusCode OH_MidiSend( return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiSendSysEx(OH_MidiDevice *device, uint32_t portIndex, uint8_t *data, uint32_t byteSize) +OH_MIDIStatusCode OH_MIDISendSysEx(OH_MIDIDevice *device, uint32_t portIndex, uint8_t *data, uint32_t byteSize) { (void)portIndex; (void)data; @@ -135,7 +135,7 @@ OH_MidiStatusCode OH_MidiSendSysEx(OH_MidiDevice *device, uint32_t portIndex, ui return MIDI_STATUS_OK; } -OH_MidiStatusCode OH_MidiFlushOutputPort(OH_MidiDevice *device, uint32_t portIndex) +OH_MIDIStatusCode OH_MIDIFlushOutputPort(OH_MIDIDevice *device, uint32_t portIndex) { (void)portIndex; return MIDI_STATUS_OK; diff --git a/interfaces/inner_api/native/midi_client.h b/interfaces/inner_api/native/midi_client.h index ddea538..aeea2ab 100644 --- a/interfaces/inner_api/native/midi_client.h +++ b/interfaces/inner_api/native/midi_client.h @@ -22,20 +22,20 @@ namespace MIDI { class MidiDevice { public: virtual ~MidiDevice() = default; - virtual OH_MidiStatusCode CloseDevice(); - virtual OH_MidiStatusCode OpenInputPort(uint32_t portIndex, OH_OnMidiReceived callback, void *userData); - virtual OH_MidiStatusCode ClosePort(uint32_t portIndex); + virtual OH_MIDIStatusCode CloseDevice(); + virtual OH_MIDIStatusCode OpenInputPort(uint32_t portIndex, OH_OnMIDIReceived callback, void *userData); + virtual OH_MIDIStatusCode ClosePort(uint32_t portIndex); }; class MidiClient { public: virtual ~MidiClient() = default; - static OH_MidiStatusCode CreateMidiClient(MidiClient **client, OH_MidiCallbacks callbacks, void *userData); - virtual OH_MidiStatusCode Init(OH_MidiCallbacks callbacks, void *userData); - virtual OH_MidiStatusCode GetDevices(OH_MidiDeviceInformation *infos, size_t *numDevices); - virtual OH_MidiStatusCode OpenDevice(int64_t deviceId, MidiDevice **midiDevice); - virtual OH_MidiStatusCode GetDevicePorts(int64_t deviceId, OH_MidiPortInformation *infos, size_t *numPorts); - virtual OH_MidiStatusCode DestroyMidiClient(); + static OH_MIDIStatusCode CreateMidiClient(MidiClient **client, OH_MIDICallbacks callbacks, void *userData); + virtual OH_MIDIStatusCode Init(OH_MIDICallbacks callbacks, void *userData); + virtual OH_MIDIStatusCode GetDevices(OH_MIDIDeviceInformation *infos, size_t *numDevices); + virtual OH_MIDIStatusCode OpenDevice(int64_t deviceId, MidiDevice **midiDevice); + virtual OH_MIDIStatusCode GetDevicePorts(int64_t deviceId, OH_MIDIPortInformation *infos, size_t *numPorts); + virtual OH_MIDIStatusCode DestroyMidiClient(); }; } // namespace MIDI } // namespace OHOS diff --git a/interfaces/kits/c/midi/native_midi.h b/interfaces/kits/c/midi/native_midi.h index 1ab1b34..0ae2161 100644 --- a/interfaces/kits/c/midi/native_midi.h +++ b/interfaces/kits/c/midi/native_midi.h @@ -16,7 +16,7 @@ * @addtogroup OHMIDI * @{ * - * @brief Provide the definition of the C interface for the Midi module. + * @brief Provide the definition of the C interface for the MIDI module. * * @since 24 * @version 1.0 @@ -24,10 +24,10 @@ /** * @file native_midi.h * - * @brief Declare Midi related interfaces. + * @brief Declare MIDI related interfaces. * - * This file interfaces are used for Midi device management, - * Midi message sending and receiving, and device status monitoring. + * This file interfaces are used for MIDI device management, + * MIDI message sending and receiving, and device status monitoring. * * @library libohmidi.so * @syscap SystemCapability.Multimedia.Audio.MIDI @@ -45,7 +45,7 @@ extern "C" { #endif /** - * @brief Create Midi client instance + * @brief Create MIDI client instance * * @param client Pointer to receive the new client handle. * @param callbacks Callback structure for system events. @@ -55,10 +55,10 @@ extern "C" { * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiClientCreate(OH_MidiClient **client, OH_MidiCallbacks callbacks, void *userData); +OH_MIDIStatusCode OH_MIDIClientCreate(OH_MIDIClient **client, OH_MIDICallbacks callbacks, void *userData); /** - * @brief Destroy Midi client and release resources + * @brief Destroy MIDI client and release resources * * @param client Target client handle. * @return {@link #MIDI_STATUS_OK} if execution succeeds. @@ -66,10 +66,10 @@ OH_MidiStatusCode OH_MidiClientCreate(OH_MidiClient **client, OH_MidiCallbacks c * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiClientDestroy(OH_MidiClient *client); +OH_MIDIStatusCode OH_MIDIClientDestroy(OH_MIDIClient *client); /** - * @brief Enumerate all Midi devices (Double Call Pattern) + * @brief Enumerate all MIDI devices (Double Call Pattern) * * Pattern: * 1. Call with informations=nullptr to get the count in numDevices. @@ -86,10 +86,10 @@ OH_MidiStatusCode OH_MidiClientDestroy(OH_MidiClient *client); * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiGetDevices(OH_MidiClient *client, OH_MidiDeviceInformation *infos, size_t *numDevices); +OH_MIDIStatusCode OH_MIDIGetDevices(OH_MIDIClient *client, OH_MIDIDeviceInformation *infos, size_t *numDevices); /** - * @brief Open Midi device + * @brief Open MIDI device * * @param client Target client handle. * @param deviceId Device ID. @@ -101,10 +101,10 @@ OH_MidiStatusCode OH_MidiGetDevices(OH_MidiClient *client, OH_MidiDeviceInformat * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiOpenDevice(OH_MidiClient *client, int64_t deviceId, OH_MidiDevice **device); +OH_MIDIStatusCode OH_MIDIOpenDevice(OH_MIDIClient *client, int64_t deviceId, OH_MIDIDevice **device); /** - * @brief Open Midi BLE device + * @brief Open MIDI BLE device * * @permission ohos.permission.ACCESS_BLUETOOTH * @param client Target client handle. @@ -118,18 +118,18 @@ OH_MidiStatusCode OH_MidiOpenDevice(OH_MidiClient *client, int64_t deviceId, OH_ * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiOpenBleDevice(OH_MidiClient *client, const char *deviceAddr, OH_MidiDevice **device, - int64_t *deviceId); +OH_MIDIStatusCode OH_MIDIOpenBleDevice( + OH_MIDIClient *client, const char *deviceAddr, OH_MIDIDevice **device, int64_t *deviceId); /** - * @brief Close Midi device + * @brief Close MIDI device * * @param device Target device handle. * @return {@link #MIDI_STATUS_OK} if execution succeeds. * or {@link #MIDI_STATUS_INVALID_DEVICE_HANDLE} if device is invalid. * @since 24 */ -OH_MidiStatusCode OH_MidiCloseDevice(OH_MidiDevice *device); +OH_MIDIStatusCode OH_MIDICloseDevice(OH_MIDIDevice *device); /** * @brief Get port information (Double Call Pattern) @@ -145,13 +145,13 @@ OH_MidiStatusCode OH_MidiCloseDevice(OH_MidiDevice *device); * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiGetDevicePorts(OH_MidiClient *client, int64_t deviceId, OH_MidiPortInformation *infos, - size_t *numPorts); +OH_MIDIStatusCode OH_MIDIGetDevicePorts( + OH_MIDIClient *client, int64_t deviceId, OH_MIDIPortInformation *infos, size_t *numPorts); /** - * @brief Open Midi input port (Receive Data) + * @brief Open MIDI input port (Receive Data) * - * Registers a callback to receive Midi data in batches. + * Registers a callback to receive MIDI data in batches. * * @param device Target device handle. * @param descriptor Port index and protocol configuration. @@ -166,11 +166,11 @@ OH_MidiStatusCode OH_MidiGetDevicePorts(OH_MidiClient *client, int64_t deviceId, * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiOpenInputPort(OH_MidiDevice *device, OH_MidiPortDescriptor portIndex, - OH_OnMidiReceived callback, void *userData); +OH_MIDIStatusCode OH_MIDIOpenInputPort( + OH_MIDIDevice *device, OH_MIDIPortDescriptor portIndex, OH_OnMIDIReceived callback, void *userData); /** - * @brief Open Midi output port (Send Data) + * @brief Open MIDI output port (Send Data) * * @param device Target device handle. * @param descriptor Port index and protocol configuration. @@ -182,10 +182,10 @@ OH_MidiStatusCode OH_MidiOpenInputPort(OH_MidiDevice *device, OH_MidiPortDescrip * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiOpenOutputPort(OH_MidiDevice *device, OH_MidiPortDescriptor descriptor); +OH_MIDIStatusCode OH_MIDIOpenOutputPort(OH_MIDIDevice *device, OH_MIDIPortDescriptor descriptor); /** - * @brief Close Midi input port + * @brief Close MIDI input port * * @param device Target device handle. * @param portIndex Port index. @@ -195,10 +195,10 @@ OH_MidiStatusCode OH_MidiOpenOutputPort(OH_MidiDevice *device, OH_MidiPortDescri * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiClosePort(OH_MidiDevice *device, uint32_t portIndex); +OH_MIDIStatusCode OH_MIDIClosePort(OH_MIDIDevice *device, uint32_t portIndex); /** - * @brief Send Midi messages (Batch, Non-blocking & Atomic) + * @brief Send MIDI messages (Batch, Non-blocking & Atomic) * * Attempts to write an array of events to the shared memory buffer. * @@ -221,19 +221,19 @@ OH_MidiStatusCode OH_MidiClosePort(OH_MidiDevice *device, uint32_t portIndex); * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiSend(OH_MidiDevice *device, uint32_t portIndex, OH_MidiEvent *events, uint32_t eventCount, - uint32_t *eventsWritten); +OH_MIDIStatusCode OH_MIDISend( + OH_MIDIDevice *device, uint32_t portIndex, OH_MIDIEvent *events, uint32_t eventCount, uint32_t *eventsWritten); /** * @brief Send a large SysEx message (Byte-Stream to UMP Helper) * - * This is a UTILITY function for applications that handle SysEx as raw byte streams(Midi 1.0 style, F0...F7). + * This is a UTILITY function for applications that handle SysEx as raw byte streams(MIDI 1.0 style, F0...F7). * This works for BOTH MIDI_PROTOCOL_1_0 and MIDI_PROTOCOL_2_0 sessions. * The underlying service handles the final conversion based on the device's actual capabilities. * * How it works: * 1. It automatically fragments the raw bytes into a sequence of UMP Type 3(64-bit Data Message) packets. - * 2. It sends these packets sequentially using OH_MidiSend. + * 2. It sends these packets sequentially using OH_MIDISend. * * @warning **BLOCKING CALL**: This function executes a loop and may block if the buffer fills up. * @@ -249,7 +249,7 @@ OH_MidiStatusCode OH_MidiSend(OH_MidiDevice *device, uint32_t portIndex, OH_Midi * or {@link #MIDI_STATUS_GENERIC_INVALID_ARGUMENT} if arguments are invalid. * @since 24 */ -OH_MidiStatusCode OH_MidiSendSysEx(OH_MidiDevice *device, uint32_t portIndex, uint8_t *data, uint32_t byteSize); +OH_MIDIStatusCode OH_MIDISendSysEx(OH_MIDIDevice *device, uint32_t portIndex, uint8_t *data, uint32_t byteSize); /** * @brief Flush pending messages in output buffer @@ -268,7 +268,7 @@ OH_MidiStatusCode OH_MidiSendSysEx(OH_MidiDevice *device, uint32_t portIndex, ui * or {@link #MIDI_STATUS_GENERIC_IPC_FAILURE} if connection to system service fails. * @since 24 */ -OH_MidiStatusCode OH_MidiFlushOutputPort(OH_MidiDevice *device, uint32_t portIndex); +OH_MIDIStatusCode OH_MIDIFlushOutputPort(OH_MIDIDevice *device, uint32_t portIndex); #ifdef __cplusplus } diff --git a/interfaces/kits/c/midi/native_midi_base.h b/interfaces/kits/c/midi/native_midi_base.h index c91039d..e575bb3 100644 --- a/interfaces/kits/c/midi/native_midi_base.h +++ b/interfaces/kits/c/midi/native_midi_base.h @@ -16,7 +16,7 @@ * @addtogroup OHMIDI * @{ * - * @brief Provide the definition of the C interface for the Midi module. + * @brief Provide the definition of the C interface for the MIDI module. * * @since 24 * @version 1.0 @@ -24,7 +24,7 @@ /** * @file native_midi_base.h * - * @brief Declare underlying data structure for Midi module. + * @brief Declare underlying data structure for MIDI module. * * @library libohmidi.so * @syscap SystemCapability.Multimedia.Audio.MIDI @@ -45,7 +45,7 @@ extern "C" { #endif /** - * @brief Midi status code enumeration + * @brief MIDI status code enumeration * @since 24 */ typedef enum { @@ -121,7 +121,7 @@ typedef enum { MIDI_STATUS_PORT_ALREADY_OPEN, /** - * @error The Midi system service has died or disconnected. + * @error The MIDI system service has died or disconnected. * The client must be destroyed and recreated. */ MIDI_STATUS_SERVICE_DIED, @@ -130,7 +130,7 @@ typedef enum { * @error Unknown system error. */ MIDI_STATUS_UNKNOWN_ERROR = -1 -} OH_MidiStatusCode; +} OH_MIDIStatusCode; /** * @brief Port direction enumeration @@ -146,12 +146,12 @@ typedef enum { * @brief Output port (Host -> Device). */ MIDI_PORT_DIRECTION_OUTPUT = 1 -} OH_MidiPortDirection; +} OH_MIDIPortDirection; /** - * @brief Midi transport protocol semantics. + * @brief MIDI transport protocol semantics. * - * @note **CRITICAL**: The SDK ALWAYS uses UMP (Universal Midi Packet) format for data transfer, + * @note **CRITICAL**: The SDK ALWAYS uses UMP (Universal MIDI Packet) format for data transfer, * regardless of the selected protocol. This enum defines the "Behavior" and "Semantics" * of the connection, not the data structure. * @@ -159,44 +159,44 @@ typedef enum { */ typedef enum { /** - * @brief Legacy Midi 1.0 Semantics. + * @brief Legacy MIDI 1.0 Semantics. * * Behavior: - * - The service expects UMP packets strictly compatible with Midi 1.0. + * - The service expects UMP packets strictly compatible with MIDI 1.0. * - **MT 0x0**: Utility Messages (e.g., JR Timestamps). * - **MT 0x1**: System Real Time and System Common Messages. * - **MT 0x2**: MIDI 1.0 Channel Voice Messages (32-bit). * - **MT 0x3**: Data Messages (64-bit) used for SysEx (7-bit payload). * - * - If the target hardware is Midi 1.0: The service converts UMP back to Byte Stream (F0...F7). - * - If the target hardware is Midi 2.0: The service sends these packets as-is (encapsulated Midi 1.0). + * - If the target hardware is MIDI 1.0: The service converts UMP back to Byte Stream (F0...F7). + * - If the target hardware is MIDI 2.0: The service sends these packets as-is (encapsulated MIDI 1.0). */ MIDI_PROTOCOL_1_0 = 1, /** - * @brief Midi 2.0 Semantics. + * @brief MIDI 2.0 Semantics. * * Behavior: - * - The service expects UMP packets leveraging Midi 2.0 features. + * - The service expects UMP packets leveraging MIDI 2.0 features. * - **MT 0x4**: MIDI 2.0 Channel Voice Messages (64-bit, high resolution). * - **MT 0x0**: Utility Messages (JR Timestamps). * - **MT 0xD**: Flex Data Messages (128-bit, e.g., Text, Lyrics). * - **MT 0xF**: UMP Stream Messages (128-bit, Endpoint Discovery, Function Blocks). * - **MT 0x3 / MT 0x5**: Data Messages (64-bit or 128-bit). * - * @note Fallback Policy: If this protocol is requested but the hardware only supports Midi 1.0, + * @note Fallback Policy: If this protocol is requested but the hardware only supports MIDI 1.0, * the service will perform "Best-Effort" translation (e.g., downscaling 32-bit velocity * to 7-bit, converting Type 4 back to Type 2). Some data precision or message types (like Flex Data) * may be lost or ignored. */ MIDI_PROTOCOL_2_0 = 2 -} OH_MidiProtocol; +} OH_MIDIProtocol; /** - * @brief Midi Device Type + * @brief MIDI Device Type * @since 24 */ -typedef enum { MIDI_DEVICE_TYPE_USB = 0, MIDI_DEVICE_TYPE_BLE = 1 } OH_MidiDeviceType; +typedef enum { MIDI_DEVICE_TYPE_USB = 0, MIDI_DEVICE_TYPE_BLE = 1 } OH_MIDIDeviceType; /** * @brief Device connection state change action @@ -205,11 +205,11 @@ typedef enum { MIDI_DEVICE_TYPE_USB = 0, MIDI_DEVICE_TYPE_BLE = 1 } OH_MidiDevic typedef enum { MIDI_DEVICE_CHANGE_ACTION_CONNECTED = 0, MIDI_DEVICE_CHANGE_ACTION_DISCONNECTED = 1 -} OH_MidiDeviceChangeAction; +} OH_MIDIDeviceChangeAction; /** - * @brief Midi Event Structure (Universal) - * Designed to handle both raw Byte Stream (Midi 1.0) and UMP. + * @brief MIDI Event Structure (Universal) + * Designed to handle both raw Byte Stream (MIDI 1.0) and UMP. * @since 24 */ typedef struct { @@ -231,7 +231,7 @@ typedef struct { * This contains the raw UMP words (uint32_t). */ uint32_t *data; -} OH_MidiEvent; +} OH_MIDIEvent; /** * @brief Device Information @@ -240,14 +240,14 @@ typedef struct { */ typedef struct { /** - * @brief Unique identifier for the Midi device. + * @brief Unique identifier for the MIDI device. */ int64_t midiDeviceId; /** * @brief Type of the device (USB, BLE, etc.). */ - OH_MidiDeviceType deviceType; + OH_MIDIDeviceType deviceType; /** * @brief The native protocol supported by the hardware. @@ -255,7 +255,7 @@ typedef struct { * - If MIDI_PROTOCOL_2_0: The device supports MIDI 2.0 features. * * @note Applications can use this to decide whether to enable high-resolution UI controls. */ - OH_MidiProtocol nativeProtocol; + OH_MIDIProtocol nativeProtocol; /** * @brief Product name of the device. @@ -271,7 +271,7 @@ typedef struct { * @brief Physical address or unique identifier. */ char deviceAddress[64]; -} OH_MidiDeviceInformation; +} OH_MIDIDeviceInformation; /** * @brief Port Descriptor @@ -292,18 +292,18 @@ typedef struct { * * 1. **Request MIDI_PROTOCOL_1_0 on a 2.0 Device**: (Safe) * - The service creates a virtual 1.0 view. - * - App sends UMP Type 2 (Midi 1.0 Channel Voice). + * - App sends UMP Type 2 (MIDI 1.0 Channel Voice). * - Device receives UMP Type 2. * - Fully compatible. * * 2. **Request MIDI_PROTOCOL_2_0 on a 1.0 Device**: (Lossy) * - The service creates a virtual 2.0 view. - * - App sends UMP Type 4 (Midi 2.0 Voice). + * - App sends UMP Type 4 (MIDI 2.0 Voice). * - Service **Down-converts** Type 4 to Type 2 (e.g., clipping Velocity, dropping Per-Note data). * - **Warning**: Data precision will be lost. Advanced messages may be dropped. */ - OH_MidiProtocol protocol; -} OH_MidiPortDescriptor; + OH_MIDIProtocol protocol; +} OH_MIDIPortDescriptor; /** * @brief Port Information (Detailed) @@ -324,23 +324,23 @@ typedef struct { /** * @brief Direction of the port (Input/Output). */ - OH_MidiPortDirection direction; + OH_MIDIPortDirection direction; /** * @brief Name of the port. */ char name[64]; -} OH_MidiPortInformation; +} OH_MIDIPortInformation; /** * @brief Declare the midi client */ -typedef struct OH_MidiClientStruct OH_MidiClient; +typedef struct OH_MIDIClientStruct OH_MIDIClient; /** * @brief Declare the midi device */ -typedef struct OH_MidiDeviceStruct OH_MidiDevice; +typedef struct OH_MIDIDeviceStruct OH_MIDIDevice; /** * @brief Callback for monitoring device connection/disconnection @@ -350,33 +350,33 @@ typedef struct OH_MidiDeviceStruct OH_MidiDevice; * @param deviceInfo Information of the changed device. * @since 24 */ -typedef void (*OH_OnMidiDeviceChange)(void *userData, OH_MidiDeviceChangeAction action, - OH_MidiDeviceInformation deviceInfo); +typedef void (*OH_OnMIDIDeviceChange)( + void *userData, OH_MIDIDeviceChangeAction action, OH_MIDIDeviceInformation deviceInfo); /** - * @brief Callback for receiving Midi data (Batch Processing) + * @brief Callback for receiving MIDI data (Batch Processing) * * @note The callback is invoked on a high-priority thread. * @note The 'events' array and its data pointers are transient and valid ONLY * for the duration of this callback. If you need to keep the data, copy it. * * @param userData User context provided during port opening. - * @param events Pointer to the array of Midi events received. + * @param events Pointer to the array of MIDI events received. * @param eventCount The number of events in the array. * @since 24 */ -typedef void (*OH_OnMidiReceived)(void *userData, const OH_MidiEvent *events, size_t eventCount); +typedef void (*OH_OnMIDIReceived)(void *userData, const OH_MIDIEvent *events, size_t eventCount); /** * @brief Callback for handling client-level errors - * * Invoked when a critical error occurs in the Midi service (e.g., service crash). + * * Invoked when a critical error occurs in the MIDI service (e.g., service crash). * Applications may need to recreate the client when this occurs. * * @param userData User context provided during client creation. * @param code The error code indicating the cause. * @since 24 */ -typedef void (*OH_OnMidiError)(void *userData, OH_MidiStatusCode code); +typedef void (*OH_OnMIDIError)(void *userData, OH_MIDIStatusCode code); /** * @brief Client callbacks structure @@ -386,13 +386,13 @@ typedef struct { /** * @brief Handler for device hotplug events. */ - OH_OnMidiDeviceChange onDeviceChange; + OH_OnMIDIDeviceChange onDeviceChange; /** * @brief Handler for critical service errors. */ - OH_OnMidiError onError; -} OH_MidiCallbacks; + OH_OnMIDIError onError; +} OH_MIDICallbacks; #ifdef __cplusplus } diff --git a/services/common/include/midi_shared_ring.h b/services/common/include/midi_shared_ring.h index 30ffd4c..b342ff0 100644 --- a/services/common/include/midi_shared_ring.h +++ b/services/common/include/midi_shared_ring.h @@ -50,23 +50,23 @@ struct ShmMidiEventHeader { uint32_t flags; }; -class SharedMidiRing : public Parcelable { +class MidiSharedRing : public Parcelable { public: - explicit SharedMidiRing(uint32_t ringCapacityBytes); + explicit MidiSharedRing(uint32_t ringCapacityBytes); - // creat SharedMidiRing locally or remotely - static std::shared_ptr CreateFromLocal( - size_t ringCapacityBytes); // todo 客户端持有,mididevice持有 - static std::shared_ptr CreateFromRemote(size_t ringCapacityBytes, int dataFd); + // creat MidiSharedRing locally or remotely + static std::shared_ptr CreateFromLocal( + size_t ringCapacityBytes); + static std::shared_ptr CreateFromRemote(size_t ringCapacityBytes, int dataFd); // idl bool Marshalling(Parcel &parcel) const override; - static SharedMidiRing *Unmarshalling(Parcel &parcel); + static MidiSharedRing *Unmarshalling(Parcel &parcel); int32_t Init(int dataFd); - SharedMidiRing(const SharedMidiRing &) = delete; - SharedMidiRing &operator=(const SharedMidiRing &) = delete; - ~SharedMidiRing() = default; + MidiSharedRing(const MidiSharedRing &) = delete; + MidiSharedRing &operator=(const MidiSharedRing &) = delete; + ~MidiSharedRing() = default; uint32_t GetCapacity() const; uint32_t GetReadPosition() const; diff --git a/services/common/src/midi_shared_ring.cpp b/services/common/src/midi_shared_ring.cpp index de5d243..62f5ca3 100644 --- a/services/common/src/midi_shared_ring.cpp +++ b/services/common/src/midi_shared_ring.cpp @@ -14,7 +14,7 @@ */ #ifndef LOG_TAG -#define LOG_TAG "SharedMidiRing" +#define LOG_TAG "MidiSharedRing" #endif #include @@ -258,14 +258,14 @@ inline bool IsValidOffset(uint32_t off, uint32_t cap) return off < cap; } -//==================== SharedMidiRing Public ====================// +//==================== MidiSharedRing Public ====================// -SharedMidiRing::SharedMidiRing(uint32_t ringCapacityBytes) : capacity_(ringCapacityBytes) +MidiSharedRing::MidiSharedRing(uint32_t ringCapacityBytes) : capacity_(ringCapacityBytes) { totalMemorySize_ = sizeof(ControlHeader) + ringCapacityBytes; } -int32_t SharedMidiRing::Init(int dataFd) +int32_t MidiSharedRing::Init(int dataFd) { CHECK_AND_RETURN_RET_LOG(totalMemorySize_ <= MAX_MMAP_BUFFER_SIZE, MIDI_STATUS_GENERIC_INVALID_ARGUMENT, @@ -287,23 +287,23 @@ int32_t SharedMidiRing::Init(int dataFd) return MIDI_STATUS_OK; } -std::shared_ptr SharedMidiRing::CreateFromLocal(size_t ringCapacityBytes) +std::shared_ptr MidiSharedRing::CreateFromLocal(size_t ringCapacityBytes) { MIDI_DEBUG_LOG("ringCapacityBytes %{public}zu", ringCapacityBytes); - std::shared_ptr buffer = std::make_shared(ringCapacityBytes); + std::shared_ptr buffer = std::make_shared(ringCapacityBytes); CHECK_AND_RETURN_RET_LOG(buffer->Init(INVALID_FD) == MIDI_STATUS_OK, nullptr, "failed to init."); return buffer; } -std::shared_ptr SharedMidiRing::CreateFromRemote(size_t ringCapacityBytes, int dataFd) +std::shared_ptr MidiSharedRing::CreateFromRemote(size_t ringCapacityBytes, int dataFd) { MIDI_DEBUG_LOG("dataFd %{public}d", dataFd); int minfd = 2; // ignore stdout, stdin and stderr. CHECK_AND_RETURN_RET_LOG(dataFd > minfd, nullptr, "invalid dataFd: %{public}d", dataFd); - std::shared_ptr buffer = std::make_shared(ringCapacityBytes); + std::shared_ptr buffer = std::make_shared(ringCapacityBytes); if (buffer->Init(dataFd) != MIDI_STATUS_OK) { MIDI_ERR_LOG("failed to init."); return nullptr; @@ -311,14 +311,14 @@ std::shared_ptr SharedMidiRing::CreateFromRemote(size_t ringCapa return buffer; } -bool SharedMidiRing::Marshalling(Parcel &parcel) const +bool MidiSharedRing::Marshalling(Parcel &parcel) const { MessageParcel &messageParcel = static_cast(parcel); CHECK_AND_RETURN_RET_LOG(dataMem_ != nullptr, false, "dataMem_ is nullptr."); return messageParcel.WriteUint32(capacity_) && messageParcel.WriteFileDescriptor(dataMem_->GetFd()); } -SharedMidiRing *SharedMidiRing::Unmarshalling(Parcel &parcel) +MidiSharedRing *MidiSharedRing::Unmarshalling(Parcel &parcel) { MIDI_DEBUG_LOG("ReadFromParcel start."); MessageParcel &messageParcel = static_cast(parcel); @@ -328,7 +328,7 @@ SharedMidiRing *SharedMidiRing::Unmarshalling(Parcel &parcel) int minfd = 2; // ignore stdout, stdin and stderr. CHECK_AND_RETURN_RET_LOG(dataFd > minfd, nullptr, "invalid dataFd: %{public}d", dataFd); - auto buffer = new (std::nothrow) SharedMidiRing(ringSize); + auto buffer = new (std::nothrow) MidiSharedRing(ringSize); if (buffer == nullptr || buffer->Init(dataFd) != MIDI_STATUS_OK) { MIDI_ERR_LOG("failed to init."); if (buffer != nullptr) @@ -345,32 +345,32 @@ SharedMidiRing *SharedMidiRing::Unmarshalling(Parcel &parcel) return buffer; } -uint32_t SharedMidiRing::GetCapacity() const +uint32_t MidiSharedRing::GetCapacity() const { return capacity_; } -uint32_t SharedMidiRing::GetReadPosition() const +uint32_t MidiSharedRing::GetReadPosition() const { return controler_->readPosition.load(); } -uint32_t SharedMidiRing::GetWritePosition() const +uint32_t MidiSharedRing::GetWritePosition() const { return controler_->writePosition.load(); } -uint8_t *SharedMidiRing::GetDataBase() +uint8_t *MidiSharedRing::GetDataBase() { return ringBase_; } -bool SharedMidiRing::IsEmpty() const +bool MidiSharedRing::IsEmpty() const { return GetReadPosition() == GetWritePosition(); } -std::atomic *SharedMidiRing::GetFutex() +std::atomic *MidiSharedRing::GetFutex() { if (!controler_) { return nullptr; @@ -378,37 +378,37 @@ std::atomic *SharedMidiRing::GetFutex() return &controler_->futexObj; } -ControlHeader *SharedMidiRing::GetControlHeader() +ControlHeader *MidiSharedRing::GetControlHeader() { return controler_; } -FutexCode SharedMidiRing::WaitFor(int64_t timeoutInNs, const std::function &pred) +FutexCode MidiSharedRing::WaitFor(int64_t timeoutInNs, const std::function &pred) { return FutexTool::FutexWait(GetFutex(), timeoutInNs, [&pred]() { return pred(); }); } -void SharedMidiRing::WakeFutex(uint32_t wakeVal) +void MidiSharedRing::WakeFutex(uint32_t wakeVal) { if (controler_) { FutexTool::FutexWake(GetFutex(), wakeVal); } } -void SharedMidiRing::NotifyConsumer(uint32_t wakeVal) +void MidiSharedRing::NotifyConsumer(uint32_t wakeVal) { WakeFutex(wakeVal); } //==================== Write Side ====================// -MidiStatusCode SharedMidiRing::TryWriteEvent(const MidiEventInner &event, bool notify) +MidiStatusCode MidiSharedRing::TryWriteEvent(const MidiEventInner &event, bool notify) { uint32_t written = 0; return TryWriteEvents(&event, 1, &written, notify); } -MidiStatusCode SharedMidiRing::TryWriteEvents( +MidiStatusCode MidiSharedRing::TryWriteEvents( const MidiEventInner *events, uint32_t eventCount, uint32_t *eventsWritten, bool notify) { if (eventsWritten) { @@ -454,7 +454,7 @@ MidiStatusCode SharedMidiRing::TryWriteEvents( //==================== Read Side (Peek + Commit) ====================// -MidiStatusCode SharedMidiRing::PeekNext(PeekedEvent &outEvent) +MidiStatusCode MidiSharedRing::PeekNext(PeekedEvent &outEvent) { outEvent = PeekedEvent{}; @@ -482,7 +482,7 @@ MidiStatusCode SharedMidiRing::PeekNext(PeekedEvent &outEvent) } } -void SharedMidiRing::CommitRead(const PeekedEvent &ev) +void MidiSharedRing::CommitRead(const PeekedEvent &ev) { uint32_t end = ev.endOffset; if (end >= capacity_) { @@ -491,7 +491,7 @@ void SharedMidiRing::CommitRead(const PeekedEvent &ev) controler_->readPosition.store(end); } -void SharedMidiRing::DrainToBatch( +void MidiSharedRing::DrainToBatch( std::vector &outEvents, std::vector> &outPayloadBuffers, uint32_t maxEvents) { uint32_t count = 0; @@ -518,7 +518,7 @@ void SharedMidiRing::DrainToBatch( //==================== Private Helpers (All <= 50 lines) ====================// -MidiStatusCode SharedMidiRing::ValidateWriteArgs(const MidiEventInner *events, uint32_t eventCount) const +MidiStatusCode MidiSharedRing::ValidateWriteArgs(const MidiEventInner *events, uint32_t eventCount) const { if (eventCount == 0) { return MidiStatusCode::OK; @@ -532,7 +532,7 @@ MidiStatusCode SharedMidiRing::ValidateWriteArgs(const MidiEventInner *events, u return MidiStatusCode::OK; } -bool SharedMidiRing::ValidateOneEvent(const MidiEventInner &event) const +bool MidiSharedRing::ValidateOneEvent(const MidiEventInner &event) const { CHECK_AND_RETURN_RET_LOG(event.data != nullptr, false, "invalid event!"); @@ -545,7 +545,7 @@ bool SharedMidiRing::ValidateOneEvent(const MidiEventInner &event) const return true; } -MidiStatusCode SharedMidiRing::TryWriteOneEvent( +MidiStatusCode MidiSharedRing::TryWriteOneEvent( const MidiEventInner &event, uint32_t totalBytes, uint32_t readIndex, uint32_t &writeIndex) { const uint32_t freeSize = RingFree(readIndex, writeIndex, capacity_); @@ -563,7 +563,7 @@ MidiStatusCode SharedMidiRing::TryWriteOneEvent( return MidiStatusCode::OK; } -bool SharedMidiRing::UpdateWriteIndexIfNeed(uint32_t &writeIndex, uint32_t totalBytes) +bool MidiSharedRing::UpdateWriteIndexIfNeed(uint32_t &writeIndex, uint32_t totalBytes) { const uint32_t tail = capacity_ - writeIndex; if (tail >= totalBytes) { @@ -582,7 +582,7 @@ bool SharedMidiRing::UpdateWriteIndexIfNeed(uint32_t &writeIndex, uint32_t total return true; } -void SharedMidiRing::WriteEvent(uint32_t writeIndex, const MidiEventInner &event) +void MidiSharedRing::WriteEvent(uint32_t writeIndex, const MidiEventInner &event) { uint8_t *dst = ringBase_ + writeIndex; auto *header = reinterpret_cast(dst); @@ -596,7 +596,7 @@ void SharedMidiRing::WriteEvent(uint32_t writeIndex, const MidiEventInner &event memcpy_s(payload, payloadBytes, reinterpret_cast(event.data), payloadBytes); } -MidiStatusCode SharedMidiRing::UpdateReadIndexIfNeed(uint32_t &readIndex, uint32_t writeIndex) +MidiStatusCode MidiSharedRing::UpdateReadIndexIfNeed(uint32_t &readIndex, uint32_t writeIndex) { if (!IsValidOffset(readIndex, capacity_) || !IsValidOffset(writeIndex, capacity_)) { return MidiStatusCode::SHM_BROKEN; @@ -614,7 +614,7 @@ MidiStatusCode SharedMidiRing::UpdateReadIndexIfNeed(uint32_t &readIndex, uint32 return MidiStatusCode::OK; } -MidiStatusCode SharedMidiRing::HandleWrapIfNeeded(const ShmMidiEventHeader &header, uint32_t &readIndex) +MidiStatusCode MidiSharedRing::HandleWrapIfNeeded(const ShmMidiEventHeader &header, uint32_t &readIndex) { if ((header.flags & SHM_EVENT_FLAG_WRAP) == 0) { return MidiStatusCode::WOULD_BLOCK; // no wrap @@ -627,7 +627,7 @@ MidiStatusCode SharedMidiRing::HandleWrapIfNeeded(const ShmMidiEventHeader &head return MidiStatusCode::OK; // wrap, continue } -MidiStatusCode SharedMidiRing::BuildPeekedEvent( +MidiStatusCode MidiSharedRing::BuildPeekedEvent( const ShmMidiEventHeader &header, uint32_t readIndex, PeekedEvent &outEvent) { const uint32_t needed = static_cast(sizeof(ShmMidiEventHeader) + header.length * sizeof(uint32_t)); @@ -652,7 +652,7 @@ MidiStatusCode SharedMidiRing::BuildPeekedEvent( return MidiStatusCode::OK; } -MidiEvent SharedMidiRing::CopyOut(const PeekedEvent &peekedEvent, std::vector &outPayloadBuffer) const +MidiEvent MidiSharedRing::CopyOut(const PeekedEvent &peekedEvent, std::vector &outPayloadBuffer) const { MidiEvent event{}; event.timestamp = peekedEvent.timestamp; diff --git a/services/idl/IIpcMidiClientInServer.idl b/services/idl/IIpcMidiClientInServer.idl index 4ab892a..865690f 100644 --- a/services/idl/IIpcMidiClientInServer.idl +++ b/services/idl/IIpcMidiClientInServer.idl @@ -14,13 +14,13 @@ */ package OHOS.MIDI; sequenceable OHOS.IRemoteObject; -sequenceable midi_shared_ring..OHOS.MIDI.SharedMidiRing; +sequenceable midi_shared_ring..OHOS.MIDI.MidiSharedRing; interface IIpcMidiClientInServer{ [ipccode 0] void GetDevices([out] List> devices); void GetDevicePorts([in] long deviceId, [out] List> ports); void OpenDevice([in] long deviceId); - void OpenInputPort([out] sharedptr buffer, [in] long deviceId, [in] unsigned int portIndex); + void OpenInputPort([out] sharedptr buffer, [in] long deviceId, [in] unsigned int portIndex); void CloseInputPort([in] long deviceId, [in] unsigned int portIndex); void CloseDevice([in] long deviceId); void DestroyMidiClient(); diff --git a/services/server/include/midi_client_connection.h b/services/server/include/midi_client_connection.h index 78c81bc..c9165a2 100644 --- a/services/server/include/midi_client_connection.h +++ b/services/server/include/midi_client_connection.h @@ -54,7 +54,7 @@ public: uint32_t GetClientId() const { return clientId_; } int64_t GetPortIndex() const { return portIndex_; } - std::shared_ptr GetRingBuffer(); + std::shared_ptr GetRingBuffer(); int32_t TrySendToClient(const MidiEventInner& event); @@ -72,7 +72,7 @@ private: int64_t deviceHandle_ = -1; uint32_t portIndex_ = -1; - std::shared_ptr sharedRingBuffer_ = nullptr; + std::shared_ptr sharedRingBuffer_ = nullptr; size_t maxPending_ = 1024; std::priority_queue, PendingGreater> pending_; diff --git a/services/server/include/midi_client_in_server.h b/services/server/include/midi_client_in_server.h index 6aab199..451d79c 100644 --- a/services/server/include/midi_client_in_server.h +++ b/services/server/include/midi_client_in_server.h @@ -28,7 +28,7 @@ public: int32_t GetDevicePorts(int64_t deviceId, std::vector> &ports) override; int32_t OpenDevice(int64_t deviceId) override; int32_t CloseDevice(int64_t deviceId) override; - int32_t OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) override; + int32_t OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) override; int32_t CloseInputPort(int64_t deviceId, uint32_t portIndex) override; int32_t DestroyMidiClient() override; void NotifyDeviceChange(DeviceChangeType change, std::map deviceInfo); diff --git a/services/server/include/midi_device_connection.h b/services/server/include/midi_device_connection.h index c9d3828..f05b030 100644 --- a/services/server/include/midi_device_connection.h +++ b/services/server/include/midi_device_connection.h @@ -69,7 +69,7 @@ public: const DeviceConnectionInfo &GetInfo() const { return info_; } virtual int32_t AddClientConnection(uint32_t clientId, int64_t deviceHandle, - std::shared_ptr &buffer); + std::shared_ptr &buffer); virtual void RemoveClientConnection(uint32_t clientId); @@ -117,9 +117,9 @@ private: void DrainAllClientsRings(); void DrainSingleClientRing(ClientConnectionInServer &clientConnection); - bool ConsumeRealtimeEvent(SharedMidiRing &clientRing, const SharedMidiRing::PeekedEvent &ringEvent); - bool ConsumeNonRealtimeEvent(ClientConnectionInServer &clientConnection, SharedMidiRing &clientRing, - const SharedMidiRing::PeekedEvent &ringEvent); + bool ConsumeRealtimeEvent(MidiSharedRing &clientRing, const MidiSharedRing::PeekedEvent &ringEvent); + bool ConsumeNonRealtimeEvent(ClientConnectionInServer &clientConnection, MidiSharedRing &clientRing, + const MidiSharedRing::PeekedEvent &ringEvent); // todo: due + (1 or 2)ms <= now void CollectDueEventsFromClientHeaps(); diff --git a/services/server/include/midi_service_controller.h b/services/server/include/midi_service_controller.h index 01c578a..4114b86 100644 --- a/services/server/include/midi_service_controller.h +++ b/services/server/include/midi_service_controller.h @@ -54,7 +54,7 @@ public: int32_t OpenDevice(uint32_t clientId, int64_t deviceId); int32_t CloseDevice(uint32_t clientId, int64_t deviceId); int32_t OpenInputPort( - uint32_t clientId, std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex); + uint32_t clientId, std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex); int32_t CloseInputPort(uint32_t clientId, int64_t deviceId, uint32_t portIndex); int32_t DestroyMidiClient(uint32_t clientId); void NotifyDeviceChange(DeviceChangeType change, DeviceInformation devices); diff --git a/services/server/src/midi_client_connection.cpp b/services/server/src/midi_client_connection.cpp index 72d2d67..4b1d766 100644 --- a/services/server/src/midi_client_connection.cpp +++ b/services/server/src/midi_client_connection.cpp @@ -26,14 +26,14 @@ namespace OHOS { namespace MIDI { -std::shared_ptr ClientConnectionInServer::GetRingBuffer() +std::shared_ptr ClientConnectionInServer::GetRingBuffer() { return sharedRingBuffer_; } int32_t ClientConnectionInServer::CreateRingBuffer() { - sharedRingBuffer_ = SharedMidiRing::CreateFromLocal(DEFAULT_RING_BUFFER_SIZE); + sharedRingBuffer_ = MidiSharedRing::CreateFromLocal(DEFAULT_RING_BUFFER_SIZE); CHECK_AND_RETURN_RET_LOG(sharedRingBuffer_ != nullptr, MIDI_STATUS_UNKNOWN_ERROR, "create fail"); memset_s(sharedRingBuffer_->GetDataBase(), sharedRingBuffer_->GetCapacity(), 0, diff --git a/services/server/src/midi_client_in_server.cpp b/services/server/src/midi_client_in_server.cpp index 354dc3f..075b974 100644 --- a/services/server/src/midi_client_in_server.cpp +++ b/services/server/src/midi_client_in_server.cpp @@ -51,7 +51,7 @@ int32_t MidiClientInServer::OpenDevice(int64_t deviceId) return MidiServiceController::GetInstance()->OpenDevice(clientId_, deviceId); } -int32_t MidiClientInServer::OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) +int32_t MidiClientInServer::OpenInputPort(std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) { MIDI_INFO_LOG("deviceId[%{public}" PRId64 "]---->portIndex[%{public}u]", deviceId, portIndex); return MidiServiceController::GetInstance()->OpenInputPort(clientId_, buffer, deviceId, portIndex); diff --git a/services/server/src/midi_device_connection.cpp b/services/server/src/midi_device_connection.cpp index aaed989..86d58c0 100644 --- a/services/server/src/midi_device_connection.cpp +++ b/services/server/src/midi_device_connection.cpp @@ -95,7 +95,7 @@ DeviceConnectionBase::DeviceConnectionBase(DeviceConnectionInfo info) : info_(in {} int32_t DeviceConnectionBase::AddClientConnection( - uint32_t clientId, int64_t deviceHandle, std::shared_ptr &buffer) + uint32_t clientId, int64_t deviceHandle, std::shared_ptr &buffer) { std::lock_guard lock(clientsMutex_); auto clientConnection = std::make_shared(clientId, deviceHandle, GetInfo().portIndex); @@ -308,12 +308,12 @@ void DeviceConnectionForOutput::DrainAllClientsRings() void DeviceConnectionForOutput::DrainSingleClientRing(ClientConnectionInServer &clientConnection) { - std::shared_ptr ringShared = clientConnection.GetRingBuffer(); + std::shared_ptr ringShared = clientConnection.GetRingBuffer(); if (!ringShared) { return; } - SharedMidiRing &clientRing = *ringShared; - SharedMidiRing::PeekedEvent ringEvent{}; + MidiSharedRing &clientRing = *ringShared; + MidiSharedRing::PeekedEvent ringEvent{}; MidiStatusCode status = MidiStatusCode::OK; while ((status = clientRing.PeekNext(ringEvent)) == MidiStatusCode::OK) { if (status == MidiStatusCode::WOULD_BLOCK) { // todo: no need @@ -336,7 +336,7 @@ void DeviceConnectionForOutput::DrainSingleClientRing(ClientConnectionInServer & } bool DeviceConnectionForOutput::ConsumeRealtimeEvent( - SharedMidiRing &clientRing, const SharedMidiRing::PeekedEvent &ringEvent) + MidiSharedRing &clientRing, const MidiSharedRing::PeekedEvent &ringEvent) { std::vector payload; // todo: do not create vector here @@ -354,7 +354,7 @@ bool DeviceConnectionForOutput::ConsumeRealtimeEvent( } bool DeviceConnectionForOutput::ConsumeNonRealtimeEvent(ClientConnectionInServer &clientConnection, - SharedMidiRing &clientRing, const SharedMidiRing::PeekedEvent &ringEvent) + MidiSharedRing &clientRing, const MidiSharedRing::PeekedEvent &ringEvent) { if (clientConnection.IsPendingFull()) { return false; diff --git a/services/server/src/midi_service_controller.cpp b/services/server/src/midi_service_controller.cpp index c0b0fac..f429392 100644 --- a/services/server/src/midi_service_controller.cpp +++ b/services/server/src/midi_service_controller.cpp @@ -137,7 +137,7 @@ int32_t MidiServiceController::OpenDevice(uint32_t clientId, int64_t deviceId) } int32_t MidiServiceController::OpenInputPort( - uint32_t clientId, std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) + uint32_t clientId, std::shared_ptr &buffer, int64_t deviceId, uint32_t portIndex) { MIDI_INFO_LOG( "clientId: %{public}u, deviceId: %{public}" PRId64 " portIndex: %{public}u", clientId, deviceId, portIndex); diff --git a/test/demo/midi_demo.cpp b/test/demo/midi_demo.cpp index 1b9c9fd..abfe9f0 100644 --- a/test/demo/midi_demo.cpp +++ b/test/demo/midi_demo.cpp @@ -25,7 +25,7 @@ using namespace std; namespace { constexpr int32_t HEX_WIDTH = 8; -constexpr OH_MidiProtocol MIDI_PROTOCOL_VERSION = MIDI_PROTOCOL_1_0; +constexpr OH_MIDIProtocol MIDI_PROTOCOL_VERSION = MIDI_PROTOCOL_1_0; constexpr int32_t NOTE_ON_DELAY_MS = 500; // MIDI 1.0 Note On (Ch0, Note 60, Vel 100) constexpr uint32_t NOTE_ON_MSG = 0x20903C64; @@ -46,7 +46,7 @@ void PrintUmpData(const uint32_t *data, size_t length) } // namespace // 1. 设备热插拔回调 -static void OnDeviceChange(void *userData, OH_MidiDeviceChangeAction action, OH_MidiDeviceInformation info) +static void OnDeviceChange(void *userData, OH_MIDIDeviceChangeAction action, OH_MIDIDeviceInformation info) { if (action == MIDI_DEVICE_CHANGE_ACTION_CONNECTED) { cout << "[Hotplug] Device Connected: ID=" << info.midiDeviceId << ", Name=" << info.productName << endl; @@ -56,13 +56,13 @@ static void OnDeviceChange(void *userData, OH_MidiDeviceChangeAction action, OH_ } // 2. 服务错误回调 -static void OnError(void *userData, OH_MidiStatusCode code) +static void OnError(void *userData, OH_MIDIStatusCode code) { cout << "[Error] Critical Service Error! Code=" << code << endl; } // 3. 数据接收回调 -static void OnMidiReceived(void *userData, const OH_MidiEvent *events, size_t eventCount) +static void OnMidiReceived(void *userData, const OH_MIDIEvent *events, size_t eventCount) { for (size_t i = 0; i < eventCount; ++i) { cout << "[Rx] Timestamp=" << events[i].timestamp << " "; @@ -71,16 +71,16 @@ static void OnMidiReceived(void *userData, const OH_MidiEvent *events, size_t ev } // 发送 MIDI 数据的 Demo 逻辑 -static void SendMidiNote(OH_MidiDevice *device, int8_t portIndex) +static void SendMidiNote(OH_MIDIDevice *device, int8_t portIndex) { uint32_t noteOnMsg[1] = {NOTE_ON_MSG}; - OH_MidiEvent event; + OH_MIDIEvent event; event.timestamp = 0; event.length = 1; event.data = noteOnMsg; uint32_t written = 0; - int ret = OH_MidiSend(device, portIndex, &event, 1, &written); + int ret = OH_MIDISend(device, portIndex, &event, 1, &written); if (ret == MIDI_STATUS_OK) { cout << "[Tx] Note On sent to port " << static_cast(portIndex) << endl; } else { @@ -91,32 +91,32 @@ static void SendMidiNote(OH_MidiDevice *device, int8_t portIndex) uint32_t noteOffMsg[1] = {NOTE_OFF_MSG}; event.data = noteOffMsg; - OH_MidiSend(device, portIndex, &event, 1, &written); + OH_MIDISend(device, portIndex, &event, 1, &written); cout << "[Tx] Note Off sent to port " << static_cast(portIndex) << endl; } // 辅助函数:初始化并打开端口 -static void SetupPorts(OH_MidiClient *client, OH_MidiDevice *device, int64_t deviceId, vector &outOpenedPorts) +static void SetupPorts(OH_MIDIClient *client, OH_MIDIDevice *device, int64_t deviceId, vector &outOpenedPorts) { size_t portCount = 0; - OH_MidiGetDevicePorts(client, deviceId, nullptr, &portCount); + OH_MIDIGetDevicePorts(client, deviceId, nullptr, &portCount); if (portCount == 0) { return; } - vector ports(portCount); - OH_MidiGetDevicePorts(client, deviceId, ports.data(), &portCount); + vector ports(portCount); + OH_MIDIGetDevicePorts(client, deviceId, ports.data(), &portCount); for (const auto &port : ports) { - OH_MidiPortDescriptor desc = {port.portIndex, MIDI_PROTOCOL_VERSION}; + OH_MIDIPortDescriptor desc = {port.portIndex, MIDI_PROTOCOL_VERSION}; if (port.direction == MIDI_PORT_DIRECTION_INPUT) { - if (OH_MidiOpenInputPort(device, desc, OnMidiReceived, nullptr) == MIDI_STATUS_OK) { + if (OH_MIDIOpenInputPort(device, desc, OnMidiReceived, nullptr) == MIDI_STATUS_OK) { cout << "Input Port " << port.portIndex << " opened (Listening...)" << endl; outOpenedPorts.push_back(port.portIndex); } } else if (port.direction == MIDI_PORT_DIRECTION_OUTPUT) { - if (OH_MidiOpenOutputPort(device, desc) == MIDI_STATUS_OK) { + if (OH_MIDIOpenOutputPort(device, desc) == MIDI_STATUS_OK) { cout << "Output Port " << port.portIndex << " opened." << endl; outOpenedPorts.push_back(port.portIndex); SendMidiNote(device, port.portIndex); @@ -130,33 +130,33 @@ static int RunMidiDemo() { cout << "Starting MIDI Demo..." << endl; - OH_MidiClient *client = nullptr; - OH_MidiCallbacks callbacks = {OnDeviceChange, OnError}; + OH_MIDIClient *client = nullptr; + OH_MIDICallbacks callbacks = {OnDeviceChange, OnError}; - if (OH_MidiClientCreate(&client, callbacks, nullptr) != MIDI_STATUS_OK) { + if (OH_MIDIClientCreate(&client, callbacks, nullptr) != MIDI_STATUS_OK) { cout << "Failed to create MIDI client." << endl; return -1; } size_t devCount = 0; - OH_MidiGetDevices(client, nullptr, &devCount); + OH_MIDIGetDevices(client, nullptr, &devCount); if (devCount == 0) { cout << "No MIDI devices found." << endl; - OH_MidiClientDestroy(client); + OH_MIDIClientDestroy(client); return 0; } - vector devices(devCount); - OH_MidiGetDevices(client, devices.data(), &devCount); + vector devices(devCount); + OH_MIDIGetDevices(client, devices.data(), &devCount); // 默认操作第一个设备 int64_t targetDeviceId = devices[0].midiDeviceId; cout << "Opening Device: " << devices[0].productName << " (ID: " << targetDeviceId << ")" << endl; - OH_MidiDevice *device = nullptr; - if (OH_MidiOpenDevice(client, targetDeviceId, &device) != MIDI_STATUS_OK || !device) { + OH_MIDIDevice *device = nullptr; + if (OH_MIDIOpenDevice(client, targetDeviceId, &device) != MIDI_STATUS_OK || !device) { cout << "Failed to open device." << endl; - OH_MidiClientDestroy(client); + OH_MIDIClientDestroy(client); return -1; } @@ -169,10 +169,10 @@ static int RunMidiDemo() cout << "Cleaning up..." << endl; for (int portIndex : openedPorts) { - OH_MidiClosePort(device, portIndex); + OH_MIDIClosePort(device, portIndex); } - OH_MidiCloseDevice(device); - OH_MidiClientDestroy(client); + OH_MIDICloseDevice(device); + OH_MIDIClientDestroy(client); cout << "MIDI Demo End." << endl; return 0; diff --git a/test/fuzzer/midi_service_controller_fuzzer.cpp b/test/fuzzer/midi_service_controller_fuzzer.cpp index b046eec..0b687f0 100644 --- a/test/fuzzer/midi_service_controller_fuzzer.cpp +++ b/test/fuzzer/midi_service_controller_fuzzer.cpp @@ -82,7 +82,7 @@ void OpenInputPort(FuzzedDataProvider &fdp) uint32_t portIndex = fdp.ConsumeIntegral(); // Create a dummy buffer pointer (or nullptr to test robustness) - std::shared_ptr buffer = std::make_shared(RING_BUFFER_DEFAULT_SIZE); + std::shared_ptr buffer = std::make_shared(RING_BUFFER_DEFAULT_SIZE); midiServiceController_->OpenInputPort(clientId, buffer, deviceId, portIndex); } diff --git a/test/unittest/common/src/midi_shared_ring_unit_test.cpp b/test/unittest/common/src/midi_shared_ring_unit_test.cpp index 0ef5f56..752460e 100644 --- a/test/unittest/common/src/midi_shared_ring_unit_test.cpp +++ b/test/unittest/common/src/midi_shared_ring_unit_test.cpp @@ -55,14 +55,14 @@ static void FillU32(std::vector &buf, uint32_t base) } /** - * @tc.name : Test SharedMidiRing Init API - * @tc.number : SharedMidiRingInit_001 + * @tc.name : Test MidiSharedRing Init API + * @tc.number : MidiSharedRingInit_001 * @tc.desc : Init with local shared memory (dataFd = -1). */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_001, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingInit_001, TestSize.Level0) { constexpr uint32_t RING_CAPACITY_BYTES = 256; - SharedMidiRing ring(RING_CAPACITY_BYTES); + MidiSharedRing ring(RING_CAPACITY_BYTES); int32_t ret = ring.Init(INVALID_FD); EXPECT_EQ(MIDI_STATUS_OK, ret); @@ -80,11 +80,11 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_001, TestSize.Level0) } /** - * @tc.name : Test SharedMidiRing Init API - * @tc.number : SharedMidiRingInit_002 + * @tc.name : Test MidiSharedRing Init API + * @tc.number : MidiSharedRingInit_002 * @tc.desc : Init with remote fd created by ashmem. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_002, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingInit_002, TestSize.Level0) { constexpr uint32_t RING_CAPACITY_BYTES = 512; const size_t totalSize = sizeof(ControlHeader) + static_cast(RING_CAPACITY_BYTES); @@ -92,7 +92,7 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_002, TestSize.Level0) int fd = AshmemCreate("midi_shared_buffer_ut", totalSize); ASSERT_GT(fd, 2); - SharedMidiRing ring(RING_CAPACITY_BYTES); + MidiSharedRing ring(RING_CAPACITY_BYTES); int32_t ret = ring.Init(fd); EXPECT_EQ(MIDI_STATUS_OK, ret); @@ -111,14 +111,14 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_002, TestSize.Level0) } /** - * @tc.name : Test SharedMidiRing Init API - * @tc.number : SharedMidiRingInit_003 + * @tc.name : Test MidiSharedRing Init API + * @tc.number : MidiSharedRingInit_003 * @tc.desc : Init with zero ring capacity (edge case). */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_003, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingInit_003, TestSize.Level0) { constexpr uint32_t RING_CAPACITY_BYTES = 0; - SharedMidiRing ring(RING_CAPACITY_BYTES); + MidiSharedRing ring(RING_CAPACITY_BYTES); int32_t ret = ring.Init(INVALID_FD); EXPECT_EQ(MIDI_STATUS_OK, ret); @@ -136,17 +136,17 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_003, TestSize.Level0) } /** - * @tc.name : Test SharedMidiRing Init API - * @tc.number : SharedMidiRingInit_004 + * @tc.name : Test MidiSharedRing Init API + * @tc.number : MidiSharedRingInit_004 * @tc.desc : Init failed when totalMemorySize_ exceeds MAX_MMAP_BUFFER_SIZE. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_004, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingInit_004, TestSize.Level0) { // totalMemorySize_ = sizeof(ControlHeader) + ringCapacityBytes // 这里 ringCapacityBytes >= MAX_MMAP_BUFFER_SIZE,必然超过上限 constexpr uint32_t TOO_LARGE_RING_CAPACITY = MAX_MMAP_BUFFER_SIZE; - SharedMidiRing ring(TOO_LARGE_RING_CAPACITY); + MidiSharedRing ring(TOO_LARGE_RING_CAPACITY); int32_t ret = ring.Init(INVALID_FD); EXPECT_NE(MIDI_STATUS_OK, ret); @@ -156,14 +156,14 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_004, TestSize.Level0) } /** - * @tc.name : Test SharedMidiRing Init API - * @tc.number : SharedMidiRingInit_005 + * @tc.name : Test MidiSharedRing Init API + * @tc.number : MidiSharedRingInit_005 * @tc.desc : Init called twice should reset read/write positions. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_005, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingInit_005, TestSize.Level0) { constexpr uint32_t RING_CAPACITY_BYTES = 256; - SharedMidiRing ring(RING_CAPACITY_BYTES); + MidiSharedRing ring(RING_CAPACITY_BYTES); EXPECT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); auto *ctrl = ring.GetControlHeader(); @@ -182,31 +182,31 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingInit_005, TestSize.Level0) } /** - * @tc.name : Test SharedMidiRing CreateFromRemote API - * @tc.number : SharedMidiRingCreateFromRemote_001 + * @tc.name : Test MidiSharedRing CreateFromRemote API + * @tc.number : MidiSharedRingCreateFromRemote_001 * @tc.desc : CreateFromRemote should return nullptr when fd is invalid (<=2). */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingCreateFromRemote_001, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingCreateFromRemote_001, TestSize.Level0) { constexpr uint32_t RING_CAPACITY_BYTES = 128; - auto ring = SharedMidiRing::CreateFromRemote(RING_CAPACITY_BYTES, 2); // STDERR_FILENO + auto ring = MidiSharedRing::CreateFromRemote(RING_CAPACITY_BYTES, 2); // STDERR_FILENO EXPECT_EQ(nullptr, ring); } /** - * @tc.name : Test SharedMidiRing Marshalling & Unmarshalling - * @tc.number : SharedMidiRingMarshalling_001 + * @tc.name : Test MidiSharedRing Marshalling & Unmarshalling + * @tc.number : MidiSharedRingMarshalling_001 * @tc.desc : Marshalling then Unmarshalling should succeed and produce a usable ring. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingMarshalling_001, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingMarshalling_001, TestSize.Level0) { constexpr uint32_t RING_CAPACITY_BYTES = 256; - auto ring = SharedMidiRing::CreateFromLocal(RING_CAPACITY_BYTES); + auto ring = MidiSharedRing::CreateFromLocal(RING_CAPACITY_BYTES); ASSERT_NE(nullptr, ring); MessageParcel parcel; ASSERT_TRUE(ring->Marshalling(parcel)); - auto *out = SharedMidiRing::Unmarshalling(parcel); + auto *out = MidiSharedRing::Unmarshalling(parcel); ASSERT_NE(nullptr, out); EXPECT_EQ(RING_CAPACITY_BYTES, out->GetCapacity()); @@ -227,13 +227,13 @@ static MidiEventInner MakeEvent(uint64_t ts, const std::vector &payloa } /** - * @tc.name : Test SharedMidiRing TryWriteEvents API - * @tc.number : SharedMidiRingTryWriteEvents_001 + * @tc.name : Test MidiSharedRing TryWriteEvents API + * @tc.number : MidiSharedRingTryWriteEvents_001 * @tc.desc : eventCount == 0 should return INVALID_ARGUMENT and write 0 events. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_001, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvents_001, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); uint32_t written = 123; @@ -244,13 +244,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_001, TestSize.Leve } /** - * @tc.name : Test SharedMidiRing TryWriteEvents API - * @tc.number : SharedMidiRingTryWriteEvents_002 + * @tc.name : Test MidiSharedRing TryWriteEvents API + * @tc.number : MidiSharedRingTryWriteEvents_002 * @tc.desc : events == nullptr and eventCount > 0 should return INVALID_ARGUMENT. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_002, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvents_002, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); uint32_t written = 0; @@ -261,13 +261,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_002, TestSize.Leve } /** - * @tc.name : Test SharedMidiRing TryWriteEvents API - * @tc.number : SharedMidiRingTryWriteEvents_003 + * @tc.name : Test MidiSharedRing TryWriteEvents API + * @tc.number : MidiSharedRingTryWriteEvents_003 * @tc.desc : capacity too small should return SHM_BROKEN. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_003, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvents_003, TestSize.Level0) { - SharedMidiRing ring(0); + MidiSharedRing ring(0); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); std::vector payload{0x11223344}; @@ -280,13 +280,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_003, TestSize.Leve } /** - * @tc.name : Test SharedMidiRing TryWriteEvents API - * @tc.number : SharedMidiRingTryWriteEvents_004 + * @tc.name : Test MidiSharedRing TryWriteEvents API + * @tc.number : MidiSharedRingTryWriteEvents_004 * @tc.desc : invalid event (data == nullptr) should not write anything and return WOULD_BLOCK. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_004, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvents_004, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); MidiEventInner ev{}; @@ -302,13 +302,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_004, TestSize.Leve } /** - * @tc.name : Test SharedMidiRing TryWriteEvents API - * @tc.number : SharedMidiRingTryWriteEvents_005 + * @tc.name : Test MidiSharedRing TryWriteEvents API + * @tc.number : MidiSharedRingTryWriteEvents_005 * @tc.desc : write single event successfully. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_005, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvents_005, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); std::vector payload{0x11111111, 0x22222222}; @@ -322,13 +322,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_005, TestSize.Leve } /** - * @tc.name : Test SharedMidiRing TryWriteEvents API - * @tc.number : SharedMidiRingTryWriteEvents_006 + * @tc.name : Test MidiSharedRing TryWriteEvents API + * @tc.number : MidiSharedRingTryWriteEvents_006 * @tc.desc : partial write when ring free space not enough for all events. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_006, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvents_006, TestSize.Level0) { - SharedMidiRing ring(64); + MidiSharedRing ring(64); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); std::vector payload1(8, 0x11111111); @@ -343,13 +343,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_006, TestSize.Leve } /** - * @tc.name : Test SharedMidiRing TryWriteEvents API - * @tc.number : SharedMidiRingTryWriteEvents_007 + * @tc.name : Test MidiSharedRing TryWriteEvents API + * @tc.number : MidiSharedRingTryWriteEvents_007 * @tc.desc : cover wrap marker branch in UpdateWriteIndexIfNeed. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_007, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvents_007, TestSize.Level0) { - SharedMidiRing ring(128); + MidiSharedRing ring(128); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); // payload1: 21 words => 84 bytes payload, totalBytes = 16 + 84 = 100 @@ -381,13 +381,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_007, TestSize.Leve } /** - * @tc.name : Test SharedMidiRing TryWriteEvents API - * @tc.number : SharedMidiRingTryWriteEvents_008 + * @tc.name : Test MidiSharedRing TryWriteEvents API + * @tc.number : MidiSharedRingTryWriteEvents_008 * @tc.desc : length == 0 should be accepted, payload copy skipped (WriteEvent early return). */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_008, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvents_008, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); uint32_t dummyWord = 0x12345678; @@ -401,20 +401,20 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvents_008, TestSize.Leve EXPECT_EQ(MidiStatusCode::OK, ret); EXPECT_EQ(1u, written); - SharedMidiRing::PeekedEvent peek; + MidiSharedRing::PeekedEvent peek; EXPECT_EQ(MidiStatusCode::OK, ring.PeekNext(peek)); EXPECT_EQ(77u, peek.timestamp); EXPECT_EQ(0u, peek.length); } /** - * @tc.name : Test SharedMidiRing TryWriteEvent API - * @tc.number : SharedMidiRingTryWriteEvent1_001 + * @tc.name : Test MidiSharedRing TryWriteEvent API + * @tc.number : MidiSharedRingTryWriteEvent1_001 * @tc.desc : write single event successfully. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvent_001, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingTryWriteEvent_001, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); std::vector payload{0x11111111, 0x22222222}; @@ -427,41 +427,41 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingTryWriteEvent_001, TestSize.Level //==================== PeekNext / CommitRead / DrainToBatch ====================// /** - * @tc.name : Test SharedMidiRing PeekNext API - * @tc.number : SharedMidiRingPeekNext_001 + * @tc.name : Test MidiSharedRing PeekNext API + * @tc.number : MidiSharedRingPeekNext_001 * @tc.desc : empty ring -> WOULD_BLOCK. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_001, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingPeekNext_001, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); - SharedMidiRing::PeekedEvent peek; + MidiSharedRing::PeekedEvent peek; EXPECT_EQ(MidiStatusCode::WOULD_BLOCK, ring.PeekNext(peek)); } /** - * @tc.name : Test SharedMidiRing PeekNext API - * @tc.number : SharedMidiRingPeekNext_002 + * @tc.name : Test MidiSharedRing PeekNext API + * @tc.number : MidiSharedRingPeekNext_002 * @tc.desc : capacity too small -> SHM_BROKEN. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_002, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingPeekNext_002, TestSize.Level0) { - SharedMidiRing ring(0); + MidiSharedRing ring(0); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); - SharedMidiRing::PeekedEvent peek; + MidiSharedRing::PeekedEvent peek; EXPECT_EQ(MidiStatusCode::SHM_BROKEN, ring.PeekNext(peek)); } /** - * @tc.name : Test SharedMidiRing PeekNext API - * @tc.number : SharedMidiRingPeekNext_003 + * @tc.name : Test MidiSharedRing PeekNext API + * @tc.number : MidiSharedRingPeekNext_003 * @tc.desc : invalid offsets -> SHM_BROKEN. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_003, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingPeekNext_003, TestSize.Level0) { - SharedMidiRing ring(128); + MidiSharedRing ring(128); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); auto *ctrl = ring.GetControlHeader(); @@ -469,18 +469,18 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_003, TestSize.Level0) ctrl->readPosition.store(128); // invalid offset (==cap) ctrl->writePosition.store(0); - SharedMidiRing::PeekedEvent peek; + MidiSharedRing::PeekedEvent peek; EXPECT_EQ(MidiStatusCode::SHM_BROKEN, ring.PeekNext(peek)); } /** - * @tc.name : Test SharedMidiRing PeekNext/CommitRead API - * @tc.number : SharedMidiRingPeekNext_004 + * @tc.name : Test MidiSharedRing PeekNext/CommitRead API + * @tc.number : MidiSharedRingPeekNext_004 * @tc.desc : wrap marker should be consumed and continue to next event. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_004, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingPeekNext_004, TestSize.Level0) { - SharedMidiRing ring(128); + MidiSharedRing ring(128); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); // event1 totalBytes = 16 + 21*4 = 100, so writePosition becomes 100. @@ -495,7 +495,7 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_004, TestSize.Level0) ASSERT_EQ(100u, writeAfterEv1); // Read event1 first. - SharedMidiRing::PeekedEvent p1{}; + MidiSharedRing::PeekedEvent p1{}; ASSERT_EQ(MidiStatusCode::OK, ring.PeekNext(p1)); EXPECT_EQ(10u, p1.timestamp); EXPECT_EQ(21u, p1.length); @@ -509,7 +509,7 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_004, TestSize.Level0) ASSERT_EQ(1u, written); // Now readIndex points to WRAP header; PeekNext should consume it and return event2 at offset 0. - SharedMidiRing::PeekedEvent p2{}; + MidiSharedRing::PeekedEvent p2{}; ASSERT_EQ(MidiStatusCode::OK, ring.PeekNext(p2)); EXPECT_EQ(20u, p2.timestamp); EXPECT_EQ(4u, p2.length); @@ -517,13 +517,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_004, TestSize.Level0) } /** - * @tc.name : Test SharedMidiRing PeekNext API - * @tc.number : SharedMidiRingPeekNext_005 + * @tc.name : Test MidiSharedRing PeekNext API + * @tc.number : MidiSharedRingPeekNext_005 * @tc.desc : corrupted header (needed > cap-1) -> SHM_BROKEN. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_005, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingPeekNext_005, TestSize.Level0) { - SharedMidiRing ring(128); + MidiSharedRing ring(128); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); auto *ctrl = ring.GetControlHeader(); @@ -539,25 +539,25 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingPeekNext_005, TestSize.Level0) hdr->flags = SHM_EVENT_FLAG_NONE; hdr->length = 1000; // needed way larger than cap-1 => SHM_BROKEN - SharedMidiRing::PeekedEvent peek; + MidiSharedRing::PeekedEvent peek; EXPECT_EQ(MidiStatusCode::SHM_BROKEN, ring.PeekNext(peek)); } /** - * @tc.name : Test SharedMidiRing CommitRead API - * @tc.number : SharedMidiRingCommitRead_001 + * @tc.name : Test MidiSharedRing CommitRead API + * @tc.number : MidiSharedRingCommitRead_001 * @tc.desc : endOffset >= capacity should wrap to 0. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingCommitRead_001, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingCommitRead_001, TestSize.Level0) { - SharedMidiRing ring(128); + MidiSharedRing ring(128); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); auto *ctrl = ring.GetControlHeader(); ASSERT_NE(nullptr, ctrl); ctrl->readPosition.store(10); - SharedMidiRing::PeekedEvent ev{}; + MidiSharedRing::PeekedEvent ev{}; ev.endOffset = 128; // == capacity ring.CommitRead(ev); EXPECT_EQ(0u, ring.GetReadPosition()); @@ -569,13 +569,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingCommitRead_001, TestSize.Level0) } /** - * @tc.name : Test SharedMidiRing DrainToBatch API - * @tc.number : SharedMidiRingDrainToBatch_001 + * @tc.name : Test MidiSharedRing DrainToBatch API + * @tc.number : MidiSharedRingDrainToBatch_001 * @tc.desc : drain all events when maxEvents==0. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingDrainToBatch_001, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingDrainToBatch_001, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); std::vector p1(3, 0); @@ -607,13 +607,13 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingDrainToBatch_001, TestSize.Level0 } /** - * @tc.name : Test SharedMidiRing DrainToBatch API - * @tc.number : SharedMidiRingDrainToBatch_002 + * @tc.name : Test MidiSharedRing DrainToBatch API + * @tc.number : MidiSharedRingDrainToBatch_002 * @tc.desc : respect maxEvents limit. */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingDrainToBatch_002, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingDrainToBatch_002, TestSize.Level0) { - SharedMidiRing ring(256); + MidiSharedRing ring(256); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); std::vector p1(1, 0x111); @@ -633,19 +633,19 @@ HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingDrainToBatch_002, TestSize.Level0 EXPECT_EQ(1u, out[0].timestamp); // still has one event - SharedMidiRing::PeekedEvent peek; + MidiSharedRing::PeekedEvent peek; EXPECT_EQ(MidiStatusCode::OK, ring.PeekNext(peek)); EXPECT_EQ(2u, peek.timestamp); } /** - * @tc.name : Test SharedMidiRing DrainToBatch API - * @tc.number : SharedMidiRingDrainToBatch_003 + * @tc.name : Test MidiSharedRing DrainToBatch API + * @tc.number : MidiSharedRingDrainToBatch_003 * @tc.desc : stop draining when PeekNext returns SHM_BROKEN (corrupted header). */ -HWTEST_F(MidiSharedRingUnitTest, SharedMidiRingDrainToBatch_003, TestSize.Level0) +HWTEST_F(MidiSharedRingUnitTest, MidiSharedRingDrainToBatch_003, TestSize.Level0) { - SharedMidiRing ring(128); + MidiSharedRing ring(128); ASSERT_EQ(MIDI_STATUS_OK, ring.Init(INVALID_FD)); std::vector p1(1, 0xabc); diff --git a/test/unittest/midi_client_connection/src/midi_client_connection_unit_test.cpp b/test/unittest/midi_client_connection/src/midi_client_connection_unit_test.cpp index a407345..096930e 100644 --- a/test/unittest/midi_client_connection/src/midi_client_connection_unit_test.cpp +++ b/test/unittest/midi_client_connection/src/midi_client_connection_unit_test.cpp @@ -76,7 +76,7 @@ HWTEST_F(MidiClientConnectionUnitTest, ClientConnectionInServerCreateRingBuffer_ EXPECT_EQ(MIDI_STATUS_OK, clientConnection.CreateRingBuffer()); - std::shared_ptr sharedRing = clientConnection.GetRingBuffer(); + std::shared_ptr sharedRing = clientConnection.GetRingBuffer(); ASSERT_NE(nullptr, sharedRing); // Sanity: ring should be initialized and empty. @@ -109,10 +109,10 @@ HWTEST_F(MidiClientConnectionUnitTest, ClientConnectionInServerTrySendToClient_0 EXPECT_EQ(MIDI_STATUS_OK, clientConnection.TrySendToClient(midiEventInner)); // Verify data is really in ring (PeekNext should succeed). - std::shared_ptr sharedRing = clientConnection.GetRingBuffer(); + std::shared_ptr sharedRing = clientConnection.GetRingBuffer(); ASSERT_NE(nullptr, sharedRing); - SharedMidiRing::PeekedEvent peekedEvent{}; + MidiSharedRing::PeekedEvent peekedEvent{}; EXPECT_EQ(MidiStatusCode::OK, sharedRing->PeekNext(peekedEvent)); EXPECT_EQ(12345u, peekedEvent.timestamp); EXPECT_EQ(payloadWords.size(), peekedEvent.length); diff --git a/test/unittest/midi_client_unit_test/midi_client_unit_test.cpp b/test/unittest/midi_client_unit_test/midi_client_unit_test.cpp index a59a491..15a0ac2 100644 --- a/test/unittest/midi_client_unit_test/midi_client_unit_test.cpp +++ b/test/unittest/midi_client_unit_test/midi_client_unit_test.cpp @@ -40,7 +40,7 @@ static MidiEventInner MakeMidiEventInner(uint64_t timestamp, const std::vector lock(mutex_); receivedCount_ += eventCount; @@ -71,7 +71,7 @@ public: return lastEventCount_; } - std::vector GetLastEvents() const + std::vector GetLastEvents() const { std::lock_guard lock(mutex_); return lastEvents_; @@ -82,10 +82,10 @@ private: std::condition_variable condition_; uint32_t receivedCount_ = 0; uint32_t lastEventCount_ = 0; - std::vector lastEvents_; + std::vector lastEvents_; }; -static void MidiReceivedTrampoline(void *userData, const OH_MidiEvent *events, size_t eventCount) +static void MidiReceivedTrampoline(void *userData, const OH_MIDIEvent *events, size_t eventCount) { auto *capture = reinterpret_cast(userData); if (capture != nullptr) { @@ -97,16 +97,16 @@ static void MidiReceivedTrampoline(void *userData, const OH_MidiEvent *events, s class MidiServiceMock : public MidiServiceInterface { public: - MOCK_METHOD(OH_MidiStatusCode, Init, (sptr callback, uint32_t &clientId), (override)); - MOCK_METHOD(OH_MidiStatusCode, GetDevices, ((std::vector>)&deviceInfos), (override)); - MOCK_METHOD(OH_MidiStatusCode, OpenDevice, (int64_t deviceId), (override)); - MOCK_METHOD(OH_MidiStatusCode, CloseDevice, (int64_t deviceId), (override)); - MOCK_METHOD(OH_MidiStatusCode, GetDevicePorts, + MOCK_METHOD(OH_MIDIStatusCode, Init, (sptr callback, uint32_t &clientId), (override)); + MOCK_METHOD(OH_MIDIStatusCode, GetDevices, ((std::vector>)&deviceInfos), (override)); + MOCK_METHOD(OH_MIDIStatusCode, OpenDevice, (int64_t deviceId), (override)); + MOCK_METHOD(OH_MIDIStatusCode, CloseDevice, (int64_t deviceId), (override)); + MOCK_METHOD(OH_MIDIStatusCode, GetDevicePorts, (int64_t deviceId, (std::vector>)&portInfos), (override)); - MOCK_METHOD(OH_MidiStatusCode, OpenInputPort, - ((std::shared_ptr)&buffer, int64_t deviceId, uint32_t portIndex), (override)); - MOCK_METHOD(OH_MidiStatusCode, CloseInputPort, (int64_t deviceId, uint32_t portIndex), (override)); - MOCK_METHOD(OH_MidiStatusCode, DestroyMidiClient, (), (override)); + MOCK_METHOD(OH_MIDIStatusCode, OpenInputPort, + ((std::shared_ptr)&buffer, int64_t deviceId, uint32_t portIndex), (override)); + MOCK_METHOD(OH_MIDIStatusCode, CloseInputPort, (int64_t deviceId, uint32_t portIndex), (override)); + MOCK_METHOD(OH_MIDIStatusCode, DestroyMidiClient, (), (override)); }; class MidiClientUnitTest : public testing::Test { @@ -165,17 +165,17 @@ HWTEST_F(MidiClientUnitTest, GetDevices_001, TestSize.Level0) {VENDOR_NAME, "MockVendor_2"}}); return MIDI_STATUS_OK; })); - OH_MidiCallbacks callbacks; + OH_MIDICallbacks callbacks; callbacks.onDeviceChange = - [](void *userData, OH_MidiDeviceChangeAction action, OH_MidiDeviceInformation deviceInfo) {}; - callbacks.onError = [](void *userData, OH_MidiStatusCode code) { + [](void *userData, OH_MIDIDeviceChangeAction action, OH_MIDIDeviceInformation deviceInfo) {}; + callbacks.onError = [](void *userData, OH_MIDIStatusCode code) { }; void *userData = nullptr; client->Init(callbacks, userData); - OH_MidiDeviceInformation infoArray[2]; + OH_MIDIDeviceInformation infoArray[2]; size_t numDevices = 2; - OH_MidiStatusCode status = client->GetDevices(infoArray, &numDevices); + OH_MIDIStatusCode status = client->GetDevices(infoArray, &numDevices); // 3. Verify EXPECT_EQ(status, MIDI_STATUS_OK); @@ -212,23 +212,23 @@ HWTEST_F(MidiClientUnitTest, GetDevices_002, TestSize.Level0) {VENDOR_NAME, "MockVendor_2"}}); return MIDI_STATUS_OK; })); - OH_MidiCallbacks callbacks; + OH_MIDICallbacks callbacks; callbacks.onDeviceChange = - [](void *userData, OH_MidiDeviceChangeAction action, OH_MidiDeviceInformation deviceInfo) {}; - callbacks.onError = [](void *userData, OH_MidiStatusCode code) { + [](void *userData, OH_MIDIDeviceChangeAction action, OH_MIDIDeviceInformation deviceInfo) {}; + callbacks.onError = [](void *userData, OH_MIDIStatusCode code) { }; void *userData = nullptr; client->Init(callbacks, userData); - OH_MidiDeviceInformation infoArrayTest[1]; // Only 1 slot + OH_MIDIDeviceInformation infoArrayTest[1]; // Only 1 slot size_t numDevices = 1; - OH_MidiStatusCode status = client->GetDevices(infoArrayTest, &numDevices); + OH_MIDIStatusCode status = client->GetDevices(infoArrayTest, &numDevices); // Should return insufficient space and update numDevices to required size EXPECT_EQ(status, MIDI_STATUS_INSUFFICIENT_RESULT_SPACE); EXPECT_EQ(numDevices, 2); - OH_MidiDeviceInformation infoArray[2]; + OH_MIDIDeviceInformation infoArray[2]; status = client->GetDevices(infoArray, &numDevices); // 3. Verify @@ -265,9 +265,9 @@ HWTEST_F(MidiClientUnitTest, GetDevicePorts_001, TestSize.Level0) {PORT_NAME, "Midi_Out_Port"}}); return MIDI_STATUS_OK; })); - OH_MidiPortInformation portArray[2]; + OH_MIDIPortInformation portArray[2]; size_t numPorts = 2; - OH_MidiStatusCode status = client->GetDevicePorts(deviceId, portArray, &numPorts); + OH_MIDIStatusCode status = client->GetDevicePorts(deviceId, portArray, &numPorts); EXPECT_EQ(status, MIDI_STATUS_OK); EXPECT_EQ(numPorts, 2); @@ -293,9 +293,9 @@ HWTEST_F(MidiClientUnitTest, GetDevicePorts_002, TestSize.Level0) // Simulate IPC returning error for invalid device EXPECT_CALL(*mockService, GetDevicePorts(invalidId, _)).WillOnce(Return(MIDI_STATUS_GENERIC_INVALID_ARGUMENT)); - OH_MidiPortInformation portArray[1]; + OH_MIDIPortInformation portArray[1]; size_t numPorts = 1; - OH_MidiStatusCode status = client->GetDevicePorts(invalidId, portArray, &numPorts); + OH_MIDIStatusCode status = client->GetDevicePorts(invalidId, portArray, &numPorts); EXPECT_EQ(status, MIDI_STATUS_GENERIC_INVALID_ARGUMENT); } @@ -344,19 +344,19 @@ HWTEST_F(MidiClientUnitTest, MidiDevicePrivate_OpenInputPort_001, TestSize.Level EXPECT_CALL(*mockService, OpenInputPort(_, deviceId, portIndex)) .Times(1) - .WillOnce(Invoke([](std::shared_ptr &buffer, int64_t, uint32_t) { - buffer = SharedMidiRing::CreateFromLocal(256); + .WillOnce(Invoke([](std::shared_ptr &buffer, int64_t, uint32_t) { + buffer = MidiSharedRing::CreateFromLocal(256); return (buffer != nullptr) ? MIDI_STATUS_OK : MIDI_STATUS_UNKNOWN_ERROR; })); EXPECT_CALL(*mockService, CloseInputPort(deviceId, portIndex)).Times(1).WillOnce(Return(MIDI_STATUS_OK)); // Open input port -> should start receiver thread internally - OH_MidiStatusCode openStatus = device->OpenInputPort(portIndex, MidiReceivedTrampoline, &callbackCapture); + OH_MIDIStatusCode openStatus = device->OpenInputPort(portIndex, MidiReceivedTrampoline, &callbackCapture); EXPECT_EQ(openStatus, MIDI_STATUS_OK); // Close port -> should stop thread (via MidiInputPort destructor) and call IPC CloseInputPort - OH_MidiStatusCode closeStatus = device->ClosePort(portIndex); + OH_MIDIStatusCode closeStatus = device->ClosePort(portIndex); EXPECT_EQ(closeStatus, MIDI_STATUS_OK); EXPECT_EQ(device->ClosePort(portIndex), MIDI_STATUS_GENERIC_INVALID_ARGUMENT); @@ -377,8 +377,8 @@ HWTEST_F(MidiClientUnitTest, MidiDevicePrivate_OpenInputPort_002, TestSize.Level EXPECT_CALL(*mockService, OpenInputPort(_, deviceId, portIndex)) .Times(1) - .WillOnce(Invoke([](std::shared_ptr &buffer, int64_t, uint32_t) { - buffer = SharedMidiRing::CreateFromLocal(256); + .WillOnce(Invoke([](std::shared_ptr &buffer, int64_t, uint32_t) { + buffer = MidiSharedRing::CreateFromLocal(256); return MIDI_STATUS_OK; })); @@ -408,7 +408,7 @@ HWTEST_F(MidiClientUnitTest, MidiDevicePrivate_OpenInputPort_003, TestSize.Level .Times(1) .WillOnce(Return(MIDI_STATUS_GENERIC_INVALID_ARGUMENT)); - OH_MidiStatusCode status = device->OpenInputPort(portIndex, MidiReceivedTrampoline, &callbackCapture); + OH_MIDIStatusCode status = device->OpenInputPort(portIndex, MidiReceivedTrampoline, &callbackCapture); EXPECT_EQ(status, MIDI_STATUS_GENERIC_INVALID_ARGUMENT); EXPECT_EQ(device->ClosePort(portIndex), MIDI_STATUS_GENERIC_INVALID_ARGUMENT); @@ -450,7 +450,7 @@ HWTEST_F(MidiClientUnitTest, MidiInputPort_ReceiverDispatch_001, TestSize.Level0 CallbackCapture callbackCapture; MidiInputPort inputPort(MidiReceivedTrampoline, &callbackCapture); - std::shared_ptr localRing = SharedMidiRing::CreateFromLocal(512); + std::shared_ptr localRing = MidiSharedRing::CreateFromLocal(512); ASSERT_NE(localRing, nullptr); // Assign ring buffer (public ref getter) @@ -489,7 +489,7 @@ HWTEST_F(MidiClientUnitTest, MidiInputPort_StartReceiverThread_002, TestSize.Lev CallbackCapture callbackCapture; MidiInputPort inputPort(MidiReceivedTrampoline, &callbackCapture); - std::shared_ptr localRing = SharedMidiRing::CreateFromLocal(256); + std::shared_ptr localRing = MidiSharedRing::CreateFromLocal(256); ASSERT_NE(localRing, nullptr); inputPort.GetRingBuffer() = localRing; diff --git a/test/unittest/midi_device_connection/midi_device_connection_unit_test.cpp b/test/unittest/midi_device_connection/midi_device_connection_unit_test.cpp index 88be7db..6520f35 100644 --- a/test/unittest/midi_device_connection/midi_device_connection_unit_test.cpp +++ b/test/unittest/midi_device_connection/midi_device_connection_unit_test.cpp @@ -135,13 +135,13 @@ HWTEST_F(MidiDeviceConnectionUnitTest, DeviceConnectionBaseClients_001, TestSize EXPECT_TRUE(deviceConnectionBase.IsEmptyClientConections()); - std::shared_ptr clientRingBuffer; + std::shared_ptr clientRingBuffer; EXPECT_EQ(MIDI_STATUS_OK, deviceConnectionBase.AddClientConnection(100, 999, clientRingBuffer)); ASSERT_NE(nullptr, clientRingBuffer); EXPECT_FALSE(deviceConnectionBase.IsEmptyClientConections()); // Add another client - std::shared_ptr anotherClientRingBuffer; + std::shared_ptr anotherClientRingBuffer; EXPECT_EQ(MIDI_STATUS_OK, deviceConnectionBase.AddClientConnection(200, 888, anotherClientRingBuffer)); ASSERT_NE(nullptr, anotherClientRingBuffer); EXPECT_FALSE(deviceConnectionBase.IsEmptyClientConections()); @@ -181,8 +181,8 @@ HWTEST_F(MidiDeviceConnectionUnitTest, DeviceConnectionForInput_001, TestSize.Le DeviceConnectionForInput inputConnection(deviceConnectionInfo); - std::shared_ptr clientRingBuffer1; - std::shared_ptr clientRingBuffer2; + std::shared_ptr clientRingBuffer1; + std::shared_ptr clientRingBuffer2; ASSERT_EQ(MIDI_STATUS_OK, inputConnection.AddClientConnection(1, 1000, clientRingBuffer1)); ASSERT_EQ(MIDI_STATUS_OK, inputConnection.AddClientConnection(2, 1001, clientRingBuffer2)); ASSERT_NE(nullptr, clientRingBuffer1); @@ -199,20 +199,20 @@ HWTEST_F(MidiDeviceConnectionUnitTest, DeviceConnectionForInput_001, TestSize.Le // Verify both client rings received 2 events in order. for (auto *ringPointer : {clientRingBuffer1.get(), clientRingBuffer2.get()}) { - SharedMidiRing::PeekedEvent peekedEvent1{}; + MidiSharedRing::PeekedEvent peekedEvent1{}; ASSERT_EQ(MidiStatusCode::OK, ringPointer->PeekNext(peekedEvent1)); EXPECT_EQ(10u, peekedEvent1.timestamp); - // SharedMidiRing stores payload length in bytes + // MidiSharedRing stores payload length in bytes EXPECT_EQ(payloadWords1.size(), static_cast(peekedEvent1.length)); ringPointer->CommitRead(peekedEvent1); - SharedMidiRing::PeekedEvent peekedEvent2{}; + MidiSharedRing::PeekedEvent peekedEvent2{}; ASSERT_EQ(MidiStatusCode::OK, ringPointer->PeekNext(peekedEvent2)); EXPECT_EQ(20u, peekedEvent2.timestamp); EXPECT_EQ(payloadWords2.size(), static_cast(peekedEvent2.length)); ringPointer->CommitRead(peekedEvent2); - SharedMidiRing::PeekedEvent peekedEvent3{}; + MidiSharedRing::PeekedEvent peekedEvent3{}; EXPECT_EQ(MidiStatusCode::WOULD_BLOCK, ringPointer->PeekNext(peekedEvent3)); } @@ -225,7 +225,7 @@ HWTEST_F(MidiDeviceConnectionUnitTest, DeviceConnectionForInput_001, TestSize.Le inputConnection.HandleDeviceUmpInput(deviceEvents2); // client 1 ring should have no new data - SharedMidiRing::PeekedEvent peekedEventAfterRemove{}; + MidiSharedRing::PeekedEvent peekedEventAfterRemove{}; EXPECT_EQ(MidiStatusCode::WOULD_BLOCK, clientRingBuffer1->PeekNext(peekedEventAfterRemove)); // client 2 ring should have the new event @@ -288,7 +288,7 @@ HWTEST_F(MidiDeviceConnectionUnitTest, DeviceConnectionForOutput_002, TestSize.L ASSERT_EQ(MIDI_STATUS_OK, outputConnection.Start()); - std::shared_ptr clientRingBuffer; + std::shared_ptr clientRingBuffer; ASSERT_EQ(MIDI_STATUS_OK, outputConnection.AddClientConnection(10, 1234, clientRingBuffer)); ASSERT_NE(nullptr, clientRingBuffer); @@ -330,7 +330,7 @@ HWTEST_F(MidiDeviceConnectionUnitTest, DeviceConnectionForOutput_002, TestSize.L // Ring should have been drained (best-effort check; if pending was full it might stop early, // but in current implementation pending limit is not wired, so it should drain). - SharedMidiRing::PeekedEvent peekedEvent{}; + MidiSharedRing::PeekedEvent peekedEvent{}; EXPECT_TRUE(clientRingBuffer->PeekNext(peekedEvent) == MidiStatusCode::WOULD_BLOCK || clientRingBuffer->PeekNext(peekedEvent) == MidiStatusCode::OK); } diff --git a/test/unittest/midi_server_unit_test/midi_server_unit_test.cpp b/test/unittest/midi_server_unit_test/midi_server_unit_test.cpp index d640ff6..41183b7 100644 --- a/test/unittest/midi_server_unit_test/midi_server_unit_test.cpp +++ b/test/unittest/midi_server_unit_test/midi_server_unit_test.cpp @@ -125,7 +125,7 @@ HWTEST_F(MidiServerUnitTest, MidiClientInServer_OpenInputPort001, TestSize.Level { auto mockCallback = std::make_shared(); uint32_t id = 123; - std::shared_ptr buffer; + std::shared_ptr buffer; int64_t deviceId = 12345; uint32_t portIndex = 1; diff --git a/test/unittest/midi_service_client_unit_test/midi_service_client_unit_test.cpp b/test/unittest/midi_service_client_unit_test/midi_service_client_unit_test.cpp index c30dadf..ffa17bb 100644 --- a/test/unittest/midi_service_client_unit_test/midi_service_client_unit_test.cpp +++ b/test/unittest/midi_service_client_unit_test/midi_service_client_unit_test.cpp @@ -38,7 +38,7 @@ public: MOCK_METHOD(int32_t, OpenDevice, (int64_t), (override)); MOCK_METHOD(int32_t, CloseDevice, (int64_t), (override)); MOCK_METHOD(int32_t, GetDevicePorts, (int64_t, (std::vector> &)), (override)); - MOCK_METHOD(int32_t, OpenInputPort, (std::shared_ptr &, int64_t, uint32_t), (override)); + MOCK_METHOD(int32_t, OpenInputPort, (std::shared_ptr &, int64_t, uint32_t), (override)); MOCK_METHOD(int32_t, CloseInputPort, (int64_t, uint32_t), (override)); MOCK_METHOD(int32_t, DestroyMidiClient, (), (override)); MOCK_METHOD(sptr, AsObject, (), (override)); @@ -228,7 +228,7 @@ HWTEST_F(MidiServiceClientUnitTest, GetDevicePorts_002, TestSize.Level0) HWTEST_F(MidiServiceClientUnitTest, OpenInputPort_001, TestSize.Level0) { MidiServiceClient client; - std::shared_ptr buffer; + std::shared_ptr buffer; EXPECT_EQ(client.OpenInputPort(buffer, 1, 0), MIDI_STATUS_GENERIC_IPC_FAILURE); } @@ -244,14 +244,14 @@ HWTEST_F(MidiServiceClientUnitTest, OpenInputPort_002, TestSize.Level0) ASSERT_NE(mockIpc, nullptr); InjectIpcForTest(client, mockIpc); - std::shared_ptr buffer; + std::shared_ptr buffer; int64_t deviceId = 1003; uint32_t portIndex = 3; EXPECT_CALL(*mockIpc, OpenInputPort(_, deviceId, portIndex)) .Times(1) - .WillOnce(Invoke([](std::shared_ptr &outBuffer, int64_t, uint32_t) { - outBuffer = SharedMidiRing::CreateFromLocal(256); + .WillOnce(Invoke([](std::shared_ptr &outBuffer, int64_t, uint32_t) { + outBuffer = MidiSharedRing::CreateFromLocal(256); return (outBuffer != nullptr) ? MIDI_STATUS_OK : MIDI_STATUS_UNKNOWN_ERROR; })); diff --git a/test/unittest/midi_service_controller_unit_test/midi_service_controller_unit_test.cpp b/test/unittest/midi_service_controller_unit_test/midi_service_controller_unit_test.cpp index 9530fb0..1be9a35 100644 --- a/test/unittest/midi_service_controller_unit_test/midi_service_controller_unit_test.cpp +++ b/test/unittest/midi_service_controller_unit_test/midi_service_controller_unit_test.cpp @@ -356,7 +356,7 @@ HWTEST_F(MidiServiceControllerUnitTest, OpenInputPort001, TestSize.Level0) EXPECT_CALL(*rawMockDriver_, OpenInputPort(driverId, portIndex, _)).WillOnce(Return(MIDI_STATUS_OK)); - std::shared_ptr buffer; + std::shared_ptr buffer; int32_t ret = controller_->OpenInputPort(clientId_, buffer, deviceId, portIndex); EXPECT_EQ(ret, MIDI_STATUS_OK); auto it = controller_->deviceClientContexts_.find(deviceId); @@ -377,7 +377,7 @@ HWTEST_F(MidiServiceControllerUnitTest, OpenInputPort002, TestSize.Level0) uint32_t portIndex = 0; // Device not opened via OpenDevice - std::shared_ptr buffer; + std::shared_ptr buffer; int32_t ret = controller_->OpenInputPort(clientId_, buffer, deviceId, portIndex); EXPECT_NE(ret, MIDI_STATUS_OK); } @@ -403,10 +403,10 @@ HWTEST_F(MidiServiceControllerUnitTest, OpenInputPort003, TestSize.Level0) EXPECT_CALL(*rawMockDriver_, OpenInputPort(driverId, portIndex, _)).WillOnce(Return(MIDI_STATUS_OK)); - std::shared_ptr buffer; + std::shared_ptr buffer; int32_t ret = controller_->OpenInputPort(clientId_, buffer, deviceId, portIndex); EXPECT_EQ(ret, MIDI_STATUS_OK); - std::shared_ptr buffer2; + std::shared_ptr buffer2; ret = controller_->OpenInputPort(clientId2, buffer2, deviceId, portIndex); EXPECT_EQ(ret, MIDI_STATUS_UNKNOWN_ERROR); } @@ -433,10 +433,10 @@ HWTEST_F(MidiServiceControllerUnitTest, OpenInputPort004, TestSize.Level0) EXPECT_CALL(*rawMockDriver_, OpenInputPort(driverId, portIndex, _)).WillOnce(Return(MIDI_STATUS_OK)); - std::shared_ptr buffer; + std::shared_ptr buffer; int32_t ret = controller_->OpenInputPort(clientId_, buffer, deviceId, portIndex); EXPECT_EQ(ret, MIDI_STATUS_OK); - std::shared_ptr buffer2; + std::shared_ptr buffer2; ret = controller_->OpenInputPort(clientId2, buffer2, deviceId, portIndex); EXPECT_EQ(ret, MIDI_STATUS_OK); auto it = controller_->deviceClientContexts_.find(deviceId); @@ -462,7 +462,7 @@ HWTEST_F(MidiServiceControllerUnitTest, CloseInputPort001, TestSize.Level0) controller_->OpenDevice(clientId_, deviceId); EXPECT_CALL(*rawMockDriver_, OpenInputPort(driverId, portIndex, _)).WillOnce(Return(MIDI_STATUS_OK)); - std::shared_ptr buffer; + std::shared_ptr buffer; controller_->OpenInputPort(clientId_, buffer, deviceId, portIndex); EXPECT_CALL(*rawMockDriver_, CloseInputPort(driverId, portIndex)).WillOnce(Return(MIDI_STATUS_OK)); @@ -495,9 +495,9 @@ HWTEST_F(MidiServiceControllerUnitTest, CloseInputPort002, TestSize.Level0) controller_->OpenDevice(clientId2, deviceId); EXPECT_CALL(*rawMockDriver_, OpenInputPort(driverId, portIndex, _)).WillOnce(Return(MIDI_STATUS_OK)); - std::shared_ptr buffer; + std::shared_ptr buffer; controller_->OpenInputPort(clientId_, buffer, deviceId, portIndex); - std::shared_ptr buffer2; + std::shared_ptr buffer2; int32_t ret = controller_->OpenInputPort(clientId2, buffer2, deviceId, portIndex); ret = controller_->CloseInputPort(clientId_, deviceId, portIndex); EXPECT_EQ(ret, MIDI_STATUS_OK); @@ -532,7 +532,7 @@ HWTEST_F(MidiServiceControllerUnitTest, DestroyClient001, TestSize.Level0) EXPECT_CALL(*rawMockDriver_, OpenInputPort(driverId, portIndex, _)).WillOnce(Return(MIDI_STATUS_OK)); controller_->OpenDevice(clientId_, deviceId); - std::shared_ptr buffer = std::make_shared(2048); + std::shared_ptr buffer = std::make_shared(2048); controller_->OpenInputPort(clientId_, buffer, deviceId, portIndex); EXPECT_CALL(*rawMockDriver_, CloseInputPort(driverId, portIndex)).WillOnce(Return(MIDI_STATUS_OK)); diff --git a/xts/midi/midisdk/src/midi_sdk_test.cpp b/xts/midi/midisdk/src/midi_sdk_test.cpp index 7f08a7b..55ed288 100644 --- a/xts/midi/midisdk/src/midi_sdk_test.cpp +++ b/xts/midi/midisdk/src/midi_sdk_test.cpp @@ -27,12 +27,12 @@ using namespace testing::ext; class MidiSdkTest : public testing::Test { protected: - OH_MidiClient *client = nullptr; + OH_MIDIClient *client = nullptr; virtual void SetUp() { - OH_MidiCallbacks callbacks = {nullptr, nullptr}; - OH_MidiStatusCode ret = OH_MidiClientCreate(&client, callbacks, nullptr); + OH_MIDICallbacks callbacks = {nullptr, nullptr}; + OH_MIDIStatusCode ret = OH_MIDIClientCreate(&client, callbacks, nullptr); ASSERT_EQ(ret, MIDI_STATUS_OK); ASSERT_NE(client, nullptr); } @@ -40,21 +40,21 @@ protected: virtual void TearDown() { if (client) { - OH_MidiClientDestroy(client); + OH_MIDIClientDestroy(client); client = nullptr; } } int64_t GetFirstDeviceId() { size_t count = 0; - if (OH_MidiGetDevices(client, nullptr, &count) != MIDI_STATUS_OK) { + if (OH_MIDIGetDevices(client, nullptr, &count) != MIDI_STATUS_OK) { return -1; } if (count == 0) { return -1; } - std::vector infos(count); - if (OH_MidiGetDevices(client, infos.data(), &count) != MIDI_STATUS_OK) { + std::vector infos(count); + if (OH_MIDIGetDevices(client, infos.data(), &count) != MIDI_STATUS_OK) { return -1; } return infos[0].midiDeviceId; @@ -63,7 +63,7 @@ protected: /** * @tc.number : SUB_MULTIMEDIA_MIDI_CLIENT_0100 - * @tc.name : Test OH_MidiClientCreate with valid parameters + * @tc.name : Test OH_MIDIClientCreate with valid parameters * @tc.desc : Verify that a client can be created successfully. */ HWTEST_F(MidiSdkTest, MidiClient_Create_001, Function | MediumTest | Level1) { @@ -72,28 +72,28 @@ HWTEST_F(MidiSdkTest, MidiClient_Create_001, Function | MediumTest | Level1) { /** * @tc.number : SUB_MULTIMEDIA_MIDI_CLIENT_0200 - * @tc.name : Test OH_MidiClientCreate with nullptr + * @tc.name : Test OH_MIDIClientCreate with nullptr * @tc.desc : Verify error handling when client pointer is null. */ HWTEST_F(MidiSdkTest, MidiClient_Create_002, Function | MediumTest | Level1) { - OH_MidiCallbacks callbacks = {nullptr, nullptr}; - OH_MidiStatusCode ret = OH_MidiClientCreate(nullptr, callbacks, nullptr); + OH_MIDICallbacks callbacks = {nullptr, nullptr}; + OH_MIDIStatusCode ret = OH_MIDIClientCreate(nullptr, callbacks, nullptr); EXPECT_EQ(ret, MIDI_STATUS_GENERIC_INVALID_ARGUMENT); } /** * @tc.number : SUB_MULTIMEDIA_MIDI_DISCOVERY_0100 - * @tc.name : Test OH_MidiGetDevices double call pattern + * @tc.name : Test OH_MIDIGetDevices double call pattern * @tc.desc : Verify device enumeration logic. */ HWTEST_F(MidiSdkTest, MidiGetDevices_001, Function | MediumTest | Level1) { size_t count = 0; - OH_MidiStatusCode ret = OH_MidiGetDevices(client, nullptr, &count); + OH_MIDIStatusCode ret = OH_MIDIGetDevices(client, nullptr, &count); EXPECT_EQ(ret, MIDI_STATUS_OK); if (count > 0) { - std::vector infos(count); - ret = OH_MidiGetDevices(client, infos.data(), &count); + std::vector infos(count); + ret = OH_MIDIGetDevices(client, infos.data(), &count); EXPECT_EQ(ret, MIDI_STATUS_OK); EXPECT_NE(infos[0].midiDeviceId, 0); } else { @@ -113,19 +113,19 @@ HWTEST_F(MidiSdkTest, MidiOpenDevice_001, Function | MediumTest | Level1) { return; } - OH_MidiDevice *device = nullptr; + OH_MIDIDevice *device = nullptr; // 1. Open - OH_MidiStatusCode ret = OH_MidiOpenDevice(client, devId, &device); + OH_MIDIStatusCode ret = OH_MIDIOpenDevice(client, devId, &device); EXPECT_EQ(ret, MIDI_STATUS_OK); EXPECT_NE(device, nullptr); // 2. Duplicate Open (Should fail) - OH_MidiDevice *device2 = nullptr; - ret = OH_MidiOpenDevice(client, devId, &device2); + OH_MIDIDevice *device2 = nullptr; + ret = OH_MIDIOpenDevice(client, devId, &device2); EXPECT_EQ(ret, MIDI_STATUS_DEVICE_ALREADY_OPEN); // 3. Close - ret = OH_MidiCloseDevice(device); + ret = OH_MIDICloseDevice(device); EXPECT_EQ(ret, MIDI_STATUS_OK); } @@ -135,9 +135,9 @@ HWTEST_F(MidiSdkTest, MidiOpenDevice_001, Function | MediumTest | Level1) { * @tc.desc : Verify error handling for non-existent device ID. */ HWTEST_F(MidiSdkTest, MidiOpenDevice_002, Function | MediumTest | Level1) { - OH_MidiDevice *device = nullptr; + OH_MIDIDevice *device = nullptr; int64_t invalidId = 999999; - OH_MidiStatusCode ret = OH_MidiOpenDevice(client, invalidId, &device); + OH_MIDIStatusCode ret = OH_MIDIOpenDevice(client, invalidId, &device); EXPECT_NE(ret, MIDI_STATUS_OK); } @@ -153,17 +153,17 @@ HWTEST_F(MidiSdkTest, MidiOpenOutputPort_001, Function | MediumTest | Level1) { return; } - OH_MidiDevice *device = nullptr; - OH_MidiOpenDevice(client, devId, &device); + OH_MIDIDevice *device = nullptr; + OH_MIDIOpenDevice(client, devId, &device); ASSERT_NE(device, nullptr); // 1. Get Ports size_t portCount = 0; - OH_MidiGetDevicePorts(device, nullptr, &portCount); + OH_MIDIGetDevicePorts(device, nullptr, &portCount); if (portCount > 0) { - std::vector ports(portCount); - OH_MidiGetDevicePorts(device, ports.data(), &portCount); + std::vector ports(portCount); + OH_MIDIGetDevicePorts(device, ports.data(), &portCount); // 2. Find an Output Port int targetPortIndex = -1; @@ -176,27 +176,27 @@ HWTEST_F(MidiSdkTest, MidiOpenOutputPort_001, Function | MediumTest | Level1) { if (targetPortIndex >= 0) { // 3. Open Output Port - OH_MidiPortDescriptor desc; + OH_MIDIPortDescriptor desc; desc.portIndex = targetPortIndex; desc.protocol = MIDI_PROTOCOL_1_0; // Default test - OH_MidiStatusCode ret = OH_MidiOpenOutputPort(device, desc); + OH_MIDIStatusCode ret = OH_MIDIOpenOutputPort(device, desc); EXPECT_EQ(ret, MIDI_STATUS_OK); // 4. Close Port - ret = OH_MidiClosePort(device, targetPortIndex); + ret = OH_MIDIClosePort(device, targetPortIndex); EXPECT_EQ(ret, MIDI_STATUS_OK); } else { printf("[MidiSdkTest] Skip: No OUTPUT port found on device.\n"); } } - OH_MidiCloseDevice(device); + OH_MIDICloseDevice(device); } /** * @tc.number : SUB_MULTIMEDIA_MIDI_IO_0100 - * @tc.name : Test OH_MidiSend (Smoke Test) + * @tc.name : Test OH_MIDISend (Smoke Test) * @tc.desc : Verify Send does not crash and returns OK. */ HWTEST_F(MidiSdkTest, MidiSend_001, Function | MediumTest | Level1) { @@ -206,61 +206,61 @@ HWTEST_F(MidiSdkTest, MidiSend_001, Function | MediumTest | Level1) { return; } - OH_MidiDevice *device = nullptr; - OH_MidiOpenDevice(client, devId, &device); + OH_MIDIDevice *device = nullptr; + OH_MIDIOpenDevice(client, devId, &device); - OH_MidiPortDescriptor desc = {0, MIDI_PROTOCOL_1_0}; - OH_MidiStatusCode ret = OH_MidiOpenOutputPort(device, desc); + OH_MIDIPortDescriptor desc = {0, MIDI_PROTOCOL_1_0}; + OH_MIDIStatusCode ret = OH_MIDIOpenOutputPort(device, desc); if (ret == MIDI_STATUS_OK) { // Type=2, Group=0, Status=0x90, Note=60, Vel=100 uint32_t umpData = 0x20903C64; - OH_MidiEvent event; + OH_MIDIEvent event; event.timestamp = 0; // Immediate event.length = 1; // 1 word event.data = &umpData; uint32_t written = 0; - ret = OH_MidiSend(device, desc, &event, 1, &written); + ret = OH_MIDISend(device, desc, &event, 1, &written); EXPECT_EQ(ret, MIDI_STATUS_OK); EXPECT_EQ(written, 1); - OH_MidiClosePort(device, 0); + OH_MIDIClosePort(device, 0); } - OH_MidiCloseDevice(device); + OH_MIDICloseDevice(device); } /** * @tc.number : SUB_MULTIMEDIA_MIDI_BLE_0100 - * @tc.name : Test OH_MidiOpenBleDevice with invalid arguments + * @tc.name : Test OH_MIDIOpenBleDevice with invalid arguments * @tc.desc : Verify error handling for BLE connection parameters. */ HWTEST_F(MidiSdkTest, MidiOpenBleDevice_Negative_001, Function | MediumTest | Level2) { - OH_MidiDevice *device = nullptr; + OH_MIDIDevice *device = nullptr; const char *validMac = "AA:BB:CC:DD:EE:FF"; // Case 1: Null Client - OH_MidiStatusCode ret = OH_MidiOpenBleDevice(nullptr, validMac, &device); + OH_MIDIStatusCode ret = OH_MIDIOpenBleDevice(nullptr, validMac, &device); EXPECT_EQ(ret, MIDI_STATUS_INVALID_CLIENT); // Case 2: Null Address - ret = OH_MidiOpenBleDevice(client, nullptr, &device); + ret = OH_MIDIOpenBleDevice(client, nullptr, &device); EXPECT_EQ(ret, MIDI_STATUS_GENERIC_INVALID_ARGUMENT); // Case 3: Empty Address - ret = OH_MidiOpenBleDevice(client, "", &device); + ret = OH_MIDIOpenBleDevice(client, "", &device); EXPECT_NE(ret, MIDI_STATUS_OK); // Should fail immediately } -void TestOnMidiReceived(void *userData, const OH_MidiEvent *events, size_t eventCount) { +void TestOnMidiReceived(void *userData, const OH_MIDIEvent *events, size_t eventCount) { // No-op } /** * @tc.number : SUB_MULTIMEDIA_MIDI_INPUT_0100 - * @tc.name : Test OH_MidiOpenInputPort parameter validation + * @tc.name : Test OH_MIDIOpenInputPort parameter validation * @tc.desc : Verify callback registration and direction checks. */ HWTEST_F(MidiSdkTest, MidiOpenInputPort_Validation_001, Function | MediumTest | Level1) { @@ -269,44 +269,44 @@ HWTEST_F(MidiSdkTest, MidiOpenInputPort_Validation_001, Function | MediumTest | return; // Skip } - OH_MidiDevice *device = nullptr; - OH_MidiOpenDevice(client, devId, &device); + OH_MIDIDevice *device = nullptr; + OH_MIDIOpenDevice(client, devId, &device); ASSERT_NE(device, nullptr); size_t portCount = 0; - OH_MidiGetDevicePorts(device, nullptr, &portCount); + OH_MIDIGetDevicePorts(device, nullptr, &portCount); if (portCount == 0) { - OH_MidiCloseDevice(device); + OH_MIDICloseDevice(device); return; } - std::vector ports(portCount); - OH_MidiGetDevicePorts(device, ports.data(), &portCount); + std::vector ports(portCount); + OH_MIDIGetDevicePorts(device, ports.data(), &portCount); for (const auto& port : ports) { - OH_MidiPortDescriptor desc = {port.portIndex, MIDI_PROTOCOL_1_0}; + OH_MIDIPortDescriptor desc = {port.portIndex, MIDI_PROTOCOL_1_0}; if (port.direction == MIDI_PORT_DIRECTION_INPUT) { // Case A: Valid Input Open - OH_MidiStatusCode ret = OH_MidiOpenInputPort(device, desc, TestOnMidiReceived, nullptr); + OH_MIDIStatusCode ret = OH_MIDIOpenInputPort(device, desc, TestOnMidiReceived, nullptr); EXPECT_EQ(ret, MIDI_STATUS_OK); - OH_MidiClosePort(device, port.portIndex); + OH_MIDIClosePort(device, port.portIndex); // Case B: Null Callback (Negative) - ret = OH_MidiOpenInputPort(device, desc, nullptr, nullptr); + ret = OH_MIDIOpenInputPort(device, desc, nullptr, nullptr); EXPECT_EQ(ret, MIDI_STATUS_GENERIC_INVALID_ARGUMENT); } else { // Case C: Open Output as Input (Negative) - OH_MidiStatusCode ret = OH_MidiOpenInputPort(device, desc, TestOnMidiReceived, nullptr); + OH_MIDIStatusCode ret = OH_MIDIOpenInputPort(device, desc, TestOnMidiReceived, nullptr); EXPECT_EQ(ret, MIDI_STATUS_INVALID_PORT); } } - OH_MidiCloseDevice(device); + OH_MIDICloseDevice(device); } /** * @tc.number : SUB_MULTIMEDIA_MIDI_SYSEX_0100 - * @tc.name : Test OH_MidiSendSysEx helper function + * @tc.name : Test OH_MIDISendSysEx helper function * @tc.desc : Verify the byte-stream to UMP helper logic. */ HWTEST_F(MidiSdkTest, MidiSendSysEx_001, Function | MediumTest | Level1) { @@ -315,13 +315,13 @@ HWTEST_F(MidiSdkTest, MidiSendSysEx_001, Function | MediumTest | Level1) { return; } - OH_MidiDevice *device = nullptr; - OH_MidiOpenDevice(client, devId, &device); + OH_MIDIDevice *device = nullptr; + OH_MIDIOpenDevice(client, devId, &device); size_t portCount = 0; - OH_MidiGetDevicePorts(device, nullptr, &portCount); - std::vector ports(portCount); - OH_MidiGetDevicePorts(device, ports.data(), &portCount); + OH_MIDIGetDevicePorts(device, nullptr, &portCount); + std::vector ports(portCount); + OH_MIDIGetDevicePorts(device, ports.data(), &portCount); int outPortIndex = -1; for (auto &p : ports) { @@ -332,30 +332,30 @@ HWTEST_F(MidiSdkTest, MidiSendSysEx_001, Function | MediumTest | Level1) { } if (outPortIndex >= 0) { - OH_MidiPortDescriptor desc = {(uint32_t)outPortIndex, MIDI_PROTOCOL_1_0}; - OH_MidiOpenOutputPort(device, desc); + OH_MIDIPortDescriptor desc = {(uint32_t)outPortIndex, MIDI_PROTOCOL_1_0}; + OH_MIDIOpenOutputPort(device, desc); // Case 1: Valid SysEx (Identity Request: F0 7E 7F 06 01 F7) uint8_t sysExMsg[] = {0xF0, 0x7E, 0x7F, 0x06, 0x01, 0xF7}; - OH_MidiStatusCode ret = OH_MidiSendSysEx(device, outPortIndex, sysExMsg, sizeof(sysExMsg)); + OH_MIDIStatusCode ret = OH_MIDISendSysEx(device, outPortIndex, sysExMsg, sizeof(sysExMsg)); EXPECT_EQ(ret, MIDI_STATUS_OK); // Case 2: Null Data (Negative) - ret = OH_MidiSendSysEx(device, outPortIndex, nullptr, 5); + ret = OH_MIDISendSysEx(device, outPortIndex, nullptr, 5); EXPECT_EQ(ret, MIDI_STATUS_GENERIC_INVALID_ARGUMENT); // Case 3: Zero Size (Negative) - ret = OH_MidiSendSysEx(device, outPortIndex, sysExMsg, 0); + ret = OH_MIDISendSysEx(device, outPortIndex, sysExMsg, 0); EXPECT_NE(ret, MIDI_STATUS_OK); // Should fail - OH_MidiClosePort(device, outPortIndex); + OH_MIDIClosePort(device, outPortIndex); } - OH_MidiCloseDevice(device); + OH_MIDICloseDevice(device); } /** * @tc.number : SUB_MULTIMEDIA_MIDI_FLUSH_0100 - * @tc.name : Test OH_MidiFlushOutputPort + * @tc.name : Test OH_MIDIFlushOutputPort * @tc.desc : Verify flush operation on output ports. */ HWTEST_F(MidiSdkTest, MidiFlush_001, Function | MediumTest | Level1) { @@ -364,39 +364,39 @@ HWTEST_F(MidiSdkTest, MidiFlush_001, Function | MediumTest | Level1) { return; } - OH_MidiDevice *device = nullptr; - OH_MidiOpenDevice(client, devId, &device); + OH_MIDIDevice *device = nullptr; + OH_MIDIOpenDevice(client, devId, &device); size_t count = 0; - OH_MidiGetDevicePorts(device, nullptr, &count); + OH_MIDIGetDevicePorts(device, nullptr, &count); if (count > 0) { - OH_MidiPortDescriptor desc = {0, MIDI_PROTOCOL_1_0}; // 尝试 index 0 - if (OH_MidiOpenOutputPort(device, desc) == MIDI_STATUS_OK) { + OH_MIDIPortDescriptor desc = {0, MIDI_PROTOCOL_1_0}; // 尝试 index 0 + if (OH_MIDIOpenOutputPort(device, desc) == MIDI_STATUS_OK) { // Case 1: Valid Flush - OH_MidiStatusCode ret = OH_MidiFlushOutputPort(device, 0); + OH_MIDIStatusCode ret = OH_MIDIFlushOutputPort(device, 0); EXPECT_EQ(ret, MIDI_STATUS_OK); - OH_MidiClosePort(device, 0); + OH_MIDIClosePort(device, 0); } // Case 2: Flush Closed Port (Negative) - OH_MidiStatusCode ret = OH_MidiFlushOutputPort(device, 0); + OH_MIDIStatusCode ret = OH_MIDIFlushOutputPort(device, 0); EXPECT_NE(ret, MIDI_STATUS_GENERIC_IPC_FAILURE); } - OH_MidiCloseDevice(device); + OH_MIDICloseDevice(device); } /** * @tc.number : SUB_MULTIMEDIA_MIDI_DESTROY_0100 - * @tc.name : Test OH_MidiClientDestroy robustness + * @tc.name : Test OH_MIDIClientDestroy robustness * @tc.desc : Verify destroying null or invalid clients. */ HWTEST_F(MidiSdkTest, MidiClient_Destroy_Negative_001, Function | MediumTest | Level1) { // Case 1: Destroy Nullptr - OH_MidiStatusCode ret = OH_MidiClientDestroy(nullptr); + OH_MIDIStatusCode ret = OH_MIDIClientDestroy(nullptr); EXPECT_EQ(ret, MIDI_STATUS_INVALID_CLIENT); // Case 2: Double Destroy is NOT safe to test directly if it crashes, @@ -404,7 +404,7 @@ HWTEST_F(MidiSdkTest, MidiClient_Destroy_Negative_001, Function | MediumTest | L // In SetUp/TearDown pattern, client is destroyed at TearDown. // Here we manually destroy it to test success. if (client) { - ret = OH_MidiClientDestroy(client); + ret = OH_MIDIClientDestroy(client); EXPECT_EQ(ret, MIDI_STATUS_OK); client = nullptr; // Prevent TearDown from double-freeing }