Skip to content

Commit

Permalink
friend
Browse files Browse the repository at this point in the history
  • Loading branch information
abtink committed Sep 25, 2023
1 parent 69cd776 commit ea1376c
Showing 1 changed file with 90 additions and 11 deletions.
101 changes: 90 additions & 11 deletions src/mdns/dnssd_plat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,46 @@
#include "mdns/mdns.hpp"
#include "ncp/ncp_openthread.hpp"

extern "C" otPlatDnssdState otPlatDnssdGetState(otInstance *aInstance);
extern "C" void otPlatDnssdRegisterService(otInstance *aInstance,
const otPlatDnssdService *aService,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
extern "C" void otPlatDnssdUnregisterService(otInstance *aInstance,
const otPlatDnssdService *aService,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
extern "C" void otPlatDnssdRegisterHost(otInstance *aInstance,
const otPlatDnssdHost *aHost,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
extern "C" void otPlatDnssdUnregisterHost(otInstance *aInstance,
const otPlatDnssdHost *aHost,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
extern "C" void otPlatDnssdRegisterKey(otInstance *aInstance,
const otPlatDnssdKey *aKey,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
extern "C" void otPlatDnssdUnregisterKey(otInstance *aInstance,
const otPlatDnssdKey *aKey,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
extern "C" void otPlatDnssdStartServiceBrowser(otInstance *aInstance, const char *aServiceType, uint32_t aInfraIfIndex);
extern "C" void otPlatDnssdStopServiceBrowser(otInstance *aInstance, const char *aServiceType, uint32_t aInfraIfIndex);
extern "C" void otPlatDnssdStartServiceResolver(otInstance *aInstance,
const otPlatDnssdServiceInstance *aServiceInstance);
extern "C" void otPlatDnssdStopServiceResolver(otInstance *aInstance,
const otPlatDnssdServiceInstance *aServiceInstance);
extern "C" void otPlatDnssdStartIp6AddressResolver(otInstance *aInstance,
const char *aHostName,
uint32_t aInfraIfIndex);
extern "C" void otPlatDnssdStopIp6AddressResolver(otInstance *aInstance, const char *aHostName, uint32_t aInfraIfIndex);
extern "C" void otPlatDnssdStartIp4AddressResolver(otInstance *aInstance,
const char *aHostName,
uint32_t aInfraIfIndex);
extern "C" void otPlatDnssdStopIp4AddressResolver(otInstance *aInstance, const char *aHostName, uint32_t aInfraIfIndex);

namespace otbr {

class BorderAgent;
Expand All @@ -57,36 +97,75 @@ class DnssdPlatform : private NonCopyable
{
friend class BorderAgent;

friend otPlatDnssdState otPlatDnssdGetState(otInstance *aInstance);
friend void otPlatDnssdRegisterService(otInstance *aInstance,
const otPlatDnssdService *aService,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
friend void otPlatDnssdUnregisterService(otInstance *aInstance,
const otPlatDnssdService *aService,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
friend void otPlatDnssdRegisterHost(otInstance *aInstance,
const otPlatDnssdHost *aHost,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
friend void otPlatDnssdUnregisterHost(otInstance *aInstance,
const otPlatDnssdHost *aHost,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
friend void otPlatDnssdRegisterKey(otInstance *aInstance,
const otPlatDnssdKey *aKey,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
friend void otPlatDnssdUnregisterKey(otInstance *aInstance,
const otPlatDnssdKey *aKey,
otPlatDnssdRequestId aRequestId,
otPlatDnssdRegisterCallback aCallback);
friend void otPlatDnssdStartServiceBrowser(otInstance *aInstance, const char *aServiceType, uint32_t aInfraIfIndex);
friend void otPlatDnssdStopServiceBrowser(otInstance *aInstance, const char *aServiceType, uint32_t aInfraIfIndex);
friend void otPlatDnssdStartServiceResolver(otInstance *aInstance,
const otPlatDnssdServiceInstance *aServiceInstance);
friend void otPlatDnssdStopServiceResolver(otInstance *aInstance,
const otPlatDnssdServiceInstance *aServiceInstance);
friend void otPlatDnssdStartIp6AddressResolver(otInstance *aInstance,
const char *aHostName,
uint32_t aInfraIfIndex);
friend void otPlatDnssdStopIp6AddressResolver(otInstance *aInstance, const char *aHostName, uint32_t aInfraIfIndex);
friend void otPlatDnssdStartIp4AddressResolver(otInstance *aInstance,
const char *aHostName,
uint32_t aInfraIfIndex);
friend void otPlatDnssdStopIp4AddressResolver(otInstance *aInstance, const char *aHostName, uint32_t aInfraIfIndex);

public:
DnssdPlatform(Ncp::ControllerOpenThread &aNcp, Mdns::Publisher &aPublisher);

void Start(void);
void Stop(void);

//---------------------------------------
private:
typedef otPlatDnssdState State;
typedef otPlatDnssdService Service;
typedef otPlatDnssdHost Host;
typedef otPlatDnssdKey Key;
typedef otPlatDnssdRequestId RequestId;
typedef otPlatDnssdRegisterCallback RegisterCallback;

// `otPlatDnssd` APIs
State GetState(void) const { return mState; }
void RegisterService(const Service &aService, RequestId aRequestId, RegisterCallback aCallback);
void UnregisterService(const Service &aService, RequestId aRequestId, RegisterCallback aCallback);
void RegisterHost(const Host &aHost, RequestId aRequestId, RegisterCallback aCallback);
void UnregisterHost(const Host &aHost, RequestId aRequestId, RegisterCallback aCallback);
void RegisterKey(const Key &aKey, RequestId aRequestId, RegisterCallback aCallback);
void UnregisterKey(const Key &aKey, RequestId aRequestId, RegisterCallback aCallback);

void RegisterService(const Service &aService, RequestId aRequestId, RegisterCallback aCallback);
void UnregisterService(const Service &aService, RequestId aRequestId, RegisterCallback aCallback);
void RegisterHost(const Host &aHost, RequestId aRequestId, RegisterCallback aCallback);
void UnregisterHost(const Host &aHost, RequestId aRequestId, RegisterCallback aCallback);
void RegisterKey(const Key &aKey, RequestId aRequestId, RegisterCallback aCallback);
void UnregisterKey(const Key &aKey, RequestId aRequestId, RegisterCallback aCallback);
// Callback from BR agent
void HandleMdnsPublisherStateChange(Mdns::Publisher::State aState);

private:
static otError ResultToError(otbrError aOtbrError);
static std::string KeyNameFor(const Key &aKey);

// Callback from BR agent
void HandleMdnsPublisherStateChange(Mdns::Publisher::State aState);

Mdns::Publisher::ResultCallback MakePublisherCallback(RequestId aRequestId, RegisterCallback aCallback);

Ncp::ControllerOpenThread &mNcp;
Expand Down

0 comments on commit ea1376c

Please sign in to comment.