-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
511 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
target_sources(moonlight-lib PRIVATE discovery_callback.c) | ||
|
||
add_subdirectory(discovery) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,2 @@ | ||
include(CheckSymbolExists) | ||
|
||
check_symbol_exists(DNSServiceCreateConnection "dns_sd.h" HAVE_DNSSD) | ||
|
||
if (HAVE_DNSSD) | ||
target_sources(moonlight-lib PRIVATE discovery_dnssd.c) | ||
elseif (OS_WINDOWS) | ||
pkg_check_modules(MICRODNS REQUIRED microdns) | ||
target_link_libraries(moonlight-lib PUBLIC ${MICRODNS_LIBRARIES}) | ||
target_sources(moonlight-lib PRIVATE discovery_libmicrodns.c) | ||
else () | ||
set(BUILD_SHARED_LIBS ON) | ||
include(BuildMicrodns) | ||
target_link_libraries(moonlight-lib PUBLIC microdns) | ||
unset(BUILD_SHARED_LIBS) | ||
target_sources(moonlight-lib PRIVATE discovery_libmicrodns.c) | ||
endif () | ||
target_sources(moonlight-lib PRIVATE discovery.c throttle.c) | ||
add_subdirectory(impl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "discovery.h" | ||
#include "throttle.h" | ||
|
||
#include "impl/impl.h" | ||
|
||
#include "util/bus.h" | ||
#include "logging.h" | ||
|
||
static int discovery_worker_wrapper(void *arg); | ||
|
||
void discovery_init(discovery_t *discovery, discovery_callback callback, void *user_data) { | ||
discovery->lock = SDL_CreateMutex(); | ||
discovery->task = NULL; | ||
discovery_throttle_init(&discovery->throttle, callback, user_data); | ||
} | ||
|
||
void discovery_deinit(discovery_t *discovery) { | ||
discovery_throttle_deinit(&discovery->throttle); | ||
discovery_stop(discovery); | ||
SDL_DestroyMutex(discovery->lock); | ||
} | ||
|
||
void discovery_start(discovery_t *discovery) { | ||
SDL_LockMutex(discovery->lock); | ||
if (discovery->task != NULL) { | ||
SDL_UnlockMutex(discovery->lock); | ||
return; | ||
} | ||
discovery_task_t *task = SDL_calloc(1, sizeof(discovery_task_t)); | ||
commons_log_info("Discovery", "Start task %p", task); | ||
task->discovery = discovery; | ||
task->lock = SDL_CreateMutex(); | ||
task->stop = false; | ||
SDL_Thread *thread = SDL_CreateThread(discovery_worker_wrapper, "discovery", task); | ||
SDL_DetachThread(thread); | ||
discovery->task = task; | ||
SDL_UnlockMutex(discovery->lock); | ||
} | ||
|
||
void discovery_stop(discovery_t *discovery) { | ||
SDL_LockMutex(discovery->lock); | ||
discovery_task_t *task = discovery->task; | ||
if (task == NULL) { | ||
SDL_UnlockMutex(discovery->lock); | ||
return; | ||
} | ||
discovery->task = NULL; | ||
discovery_worker_stop(task); | ||
SDL_UnlockMutex(discovery->lock); | ||
} | ||
|
||
void discovery_discovered(struct discovery_t *discovery, const sockaddr_t *addr) { | ||
discovery_throttle_on_discovered(&discovery->throttle, addr, 10000); | ||
} | ||
|
||
int discovery_worker_wrapper(void *arg) { | ||
discovery_task_t *task = (discovery_task_t *) arg; | ||
int result = discovery_worker(task); | ||
SDL_DestroyMutex(task->lock); | ||
free(arg); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2024 Mariotaku <https://github.com/mariotaku>. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include <SDL2/SDL.h> | ||
#include "sockaddr.h" | ||
|
||
typedef void (*discovery_callback)(const sockaddr_t *addr, void *user_data); | ||
|
||
typedef struct discovery_throttle_host_t discovery_throttle_host_t; | ||
|
||
typedef struct discovery_throttle_t { | ||
discovery_callback callback; | ||
void *user_data; | ||
discovery_throttle_host_t *hosts; | ||
SDL_mutex *lock; | ||
} discovery_throttle_t; | ||
|
||
typedef struct discovery_t { | ||
SDL_mutex *lock; | ||
struct discovery_task_t *task; | ||
discovery_throttle_t throttle; | ||
} discovery_t; | ||
|
||
void discovery_init(discovery_t *discovery, discovery_callback callback, void *user_data); | ||
|
||
void discovery_start(discovery_t *discovery); | ||
|
||
void discovery_stop(discovery_t *discovery); | ||
|
||
void discovery_deinit(discovery_t *discovery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
include(CheckSymbolExists) | ||
|
||
check_symbol_exists(DNSServiceCreateConnection "dns_sd.h" HAVE_DNSSD) | ||
|
||
if (HAVE_DNSSD) | ||
target_sources(moonlight-lib PRIVATE dnssd.c) | ||
else () | ||
target_sources(moonlight-lib PRIVATE microdns.c) | ||
if (OS_WINDOWS) | ||
pkg_check_modules(MICRODNS REQUIRED microdns) | ||
target_link_libraries(moonlight-lib PUBLIC ${MICRODNS_LIBRARIES}) | ||
endif () | ||
set(BUILD_SHARED_LIBS ON) | ||
include(BuildMicrodns) | ||
target_link_libraries(moonlight-lib PUBLIC microdns) | ||
unset(BUILD_SHARED_LIBS) | ||
endif () |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2024 Mariotaku <https://github.com/mariotaku>. | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <stdbool.h> | ||
#include <SDL2/SDL.h> | ||
|
||
#include "sockaddr.h" | ||
|
||
typedef struct discovery_task_t { | ||
struct discovery_t *discovery; | ||
SDL_mutex *lock; | ||
bool stop; | ||
} discovery_task_t; | ||
|
||
int discovery_worker(discovery_task_t *task); | ||
|
||
void discovery_worker_stop(discovery_task_t *task); | ||
|
||
void discovery_discovered(struct discovery_t *discovery, const sockaddr_t *addr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.