mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-09 13:07:03 +03:00
move to new cspot
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include "MDNSService.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <vector>
|
||||
#include "mdns.h"
|
||||
|
||||
using namespace bell;
|
||||
|
||||
/**
|
||||
* ESP32 implementation of MDNSService
|
||||
* @see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/mdns.html
|
||||
**/
|
||||
void* MDNSService::registerService(
|
||||
const std::string& serviceName,
|
||||
const std::string& serviceType,
|
||||
const std::string& serviceProto,
|
||||
const std::string& serviceHost,
|
||||
int servicePort,
|
||||
const std::map<std::string, std::string> txtData
|
||||
) {
|
||||
std::vector<mdns_txt_item_t> txtItems;
|
||||
txtItems.reserve(txtData.size());
|
||||
for (auto& data : txtData) {
|
||||
mdns_txt_item_t item;
|
||||
item.key = data.first.c_str();
|
||||
item.value = data.second.c_str();
|
||||
txtItems.push_back(item);
|
||||
}
|
||||
|
||||
mdns_service_add(
|
||||
serviceName.c_str(), /* instance_name */
|
||||
serviceType.c_str(), /* service_type */
|
||||
serviceProto.c_str(), /* proto */
|
||||
servicePort, /* port */
|
||||
txtItems.data(), /* txt */
|
||||
txtItems.size() /* num_items */
|
||||
);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "WrappedSemaphore.h"
|
||||
|
||||
/**
|
||||
* Platform semaphopre implementation for the esp-idf.
|
||||
*/
|
||||
|
||||
using namespace bell;
|
||||
|
||||
WrappedSemaphore::WrappedSemaphore(int count)
|
||||
{
|
||||
semaphoreHandle = xSemaphoreCreateCounting(count, 0);
|
||||
}
|
||||
|
||||
WrappedSemaphore::~WrappedSemaphore()
|
||||
{
|
||||
vSemaphoreDelete(semaphoreHandle);
|
||||
}
|
||||
|
||||
int WrappedSemaphore::wait()
|
||||
{
|
||||
if (xSemaphoreTake(semaphoreHandle, portMAX_DELAY) == pdTRUE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WrappedSemaphore::twait(long milliseconds)
|
||||
{
|
||||
if (xSemaphoreTake(semaphoreHandle, milliseconds / portTICK_PERIOD_MS) == pdTRUE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void WrappedSemaphore::give()
|
||||
{
|
||||
|
||||
xSemaphoreGive(semaphoreHandle);
|
||||
}
|
||||
Reference in New Issue
Block a user