tesses.broadcast/libbroadcast/include/tessesbroadcast.h

47 lines
1.2 KiB
C
Raw Permalink Normal View History

2024-03-26 19:34:54 +00:00
#pragma once
#include <stdbool.h>
#include <stdint.h>
#include <errno.h>
#if defined(GEKKO) && !defined(USE_WIISOCKET)
#include <network.h>
#define net_recvfrom recvfrom
#define net_sendto sendto
#define net_bind bind
#define net_close close
#define net_setsockopt setsockopt
#define net_socket socket
#else
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#define BROADCAST_DEFAULT_PORT 6942
typedef struct {
char* name;
char* url;
struct sockaddr addr;
socklen_t addrlen;
void* user;
} broadcast_device_t;
typedef struct {
bool toSend;
struct sockaddr addr;
socklen_t addrlen;
char* serviceName;
char* serviceUrl;
char* deviceName;
} broadcast_server_ctx_t;
typedef bool (*broadcast_sleep_t)(void* user,int times);
typedef void (*broadcast_client_device_t)(broadcast_device_t* dev);
typedef void (*broadcast_server_cb_t)(broadcast_server_ctx_t* ctx);
char* broadcast_fromconst(const char* text);
void broadcast_client(const char* serviceName,uint16_t port,void* user,broadcast_sleep_t sleepcb,broadcast_client_device_t deviceCb);
void broadcast_server(broadcast_server_cb_t cb,uint16_t port);