mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-14 07:27:03 +03:00
new cspot/bell
This commit is contained in:
@@ -1,16 +1,20 @@
|
||||
#include "MDNSService.h"
|
||||
#include "dns_sd.h"
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <stddef.h> // for NULL
|
||||
#include <utility> // for pair
|
||||
|
||||
#include "dns_sd.h" // for DNSServiceRef, DNSServiceRefDeallocate, DNS...
|
||||
#include "i386/endian.h" // for htons
|
||||
|
||||
using namespace bell;
|
||||
|
||||
class implMDNSService : public MDNSService {
|
||||
private:
|
||||
DNSServiceRef* service;
|
||||
private:
|
||||
DNSServiceRef* service;
|
||||
|
||||
public:
|
||||
implMDNSService(DNSServiceRef* service) : service(service) { }
|
||||
void unregisterService() { DNSServiceRefDeallocate(*service); }
|
||||
public:
|
||||
implMDNSService(DNSServiceRef* service) : service(service) {}
|
||||
void unregisterService() { DNSServiceRefDeallocate(*service); }
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -18,33 +22,30 @@ public:
|
||||
* @see https://developer.apple.com/documentation/dnssd/1804733-dnsserviceregister
|
||||
**/
|
||||
std::unique_ptr<MDNSService> 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
|
||||
) {
|
||||
DNSServiceRef* ref = new DNSServiceRef();
|
||||
TXTRecordRef txtRecord;
|
||||
TXTRecordCreate(&txtRecord, 0, NULL);
|
||||
for (auto& data : txtData) {
|
||||
TXTRecordSetValue(&txtRecord, data.first.c_str(), data.second.size(), data.second.c_str());
|
||||
}
|
||||
DNSServiceRegister(
|
||||
ref, /* sdRef */
|
||||
0, /* flags */
|
||||
0, /* interfaceIndex */
|
||||
serviceName.c_str(), /* name */
|
||||
(serviceType + "." + serviceProto).c_str(), /* regType (_spotify-connect._tcp) */
|
||||
NULL, /* domain */
|
||||
NULL, /* host */
|
||||
htons(servicePort), /* port */
|
||||
TXTRecordGetLength(&txtRecord), /* txtLen */
|
||||
TXTRecordGetBytesPtr(&txtRecord), /* txtRecord */
|
||||
NULL, /* callBack */
|
||||
NULL /* context */
|
||||
);
|
||||
TXTRecordDeallocate(&txtRecord);
|
||||
return std::make_unique<implMDNSService>(ref);
|
||||
}
|
||||
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) {
|
||||
DNSServiceRef* ref = new DNSServiceRef();
|
||||
TXTRecordRef txtRecord;
|
||||
TXTRecordCreate(&txtRecord, 0, NULL);
|
||||
for (auto& data : txtData) {
|
||||
TXTRecordSetValue(&txtRecord, data.first.c_str(), data.second.size(),
|
||||
data.second.c_str());
|
||||
}
|
||||
DNSServiceRegister(ref, /* sdRef */
|
||||
0, /* flags */
|
||||
0, /* interfaceIndex */
|
||||
serviceName.c_str(), /* name */
|
||||
(serviceType + "." + serviceProto)
|
||||
.c_str(), /* regType (_spotify-connect._tcp) */
|
||||
NULL, /* domain */
|
||||
NULL, /* host */
|
||||
htons(servicePort), /* port */
|
||||
TXTRecordGetLength(&txtRecord), /* txtLen */
|
||||
TXTRecordGetBytesPtr(&txtRecord), /* txtRecord */
|
||||
NULL, /* callBack */
|
||||
NULL /* context */
|
||||
);
|
||||
TXTRecordDeallocate(&txtRecord);
|
||||
return std::make_unique<implMDNSService>(ref);
|
||||
}
|
||||
|
||||
@@ -2,30 +2,26 @@
|
||||
|
||||
using namespace bell;
|
||||
|
||||
WrappedSemaphore::WrappedSemaphore(int count)
|
||||
{
|
||||
semaphoreHandle = dispatch_semaphore_create(0);
|
||||
WrappedSemaphore::WrappedSemaphore(int count) {
|
||||
semaphoreHandle = dispatch_semaphore_create(0);
|
||||
}
|
||||
|
||||
WrappedSemaphore::~WrappedSemaphore()
|
||||
{
|
||||
dispatch_release(semaphoreHandle);
|
||||
WrappedSemaphore::~WrappedSemaphore() {
|
||||
dispatch_release(semaphoreHandle);
|
||||
}
|
||||
|
||||
int WrappedSemaphore::wait()
|
||||
{
|
||||
int WrappedSemaphore::wait() {
|
||||
|
||||
return dispatch_semaphore_wait(semaphoreHandle, DISPATCH_TIME_FOREVER);
|
||||
return dispatch_semaphore_wait(semaphoreHandle, DISPATCH_TIME_FOREVER);
|
||||
}
|
||||
|
||||
int WrappedSemaphore::twait(long milliseconds)
|
||||
{
|
||||
dispatch_time_t timeout = dispatch_time(DISPATCH_TIME_NOW, (NSEC_PER_SEC / 1000) * milliseconds);
|
||||
int WrappedSemaphore::twait(long milliseconds) {
|
||||
dispatch_time_t timeout =
|
||||
dispatch_time(DISPATCH_TIME_NOW, (NSEC_PER_SEC / 1000) * milliseconds);
|
||||
|
||||
return dispatch_semaphore_wait(semaphoreHandle, timeout);
|
||||
return dispatch_semaphore_wait(semaphoreHandle, timeout);
|
||||
}
|
||||
|
||||
void WrappedSemaphore::give()
|
||||
{
|
||||
dispatch_semaphore_signal(semaphoreHandle);
|
||||
void WrappedSemaphore::give() {
|
||||
dispatch_semaphore_signal(semaphoreHandle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user