Initialize controller in two steps
There is a dependency cycle in the initialization order: - keyboard depends on controller - controller depends on acksync - acksync depends on keyboard initialization To break this cycle, bind the async instance to the controller in a second step.
This commit is contained in:
parent
676c1a3319
commit
267eb2c0df
@ -7,8 +7,7 @@
|
|||||||
#define SC_CONTROL_MSG_QUEUE_MAX 64
|
#define SC_CONTROL_MSG_QUEUE_MAX 64
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
sc_controller_init(struct sc_controller *controller, sc_socket control_socket) {
|
||||||
struct sc_acksync *acksync) {
|
|
||||||
sc_vecdeque_init(&controller->queue);
|
sc_vecdeque_init(&controller->queue);
|
||||||
|
|
||||||
bool ok = sc_vecdeque_reserve(&controller->queue, SC_CONTROL_MSG_QUEUE_MAX);
|
bool ok = sc_vecdeque_reserve(&controller->queue, SC_CONTROL_MSG_QUEUE_MAX);
|
||||||
@ -16,7 +15,7 @@ sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = sc_receiver_init(&controller->receiver, control_socket, acksync);
|
ok = sc_receiver_init(&controller->receiver, control_socket);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
sc_vecdeque_destroy(&controller->queue);
|
sc_vecdeque_destroy(&controller->queue);
|
||||||
return false;
|
return false;
|
||||||
@ -43,6 +42,12 @@ sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sc_controller_set_acksync(struct sc_controller *controller,
|
||||||
|
struct sc_acksync *acksync) {
|
||||||
|
controller->receiver.acksync = acksync;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_controller_destroy(struct sc_controller *controller) {
|
sc_controller_destroy(struct sc_controller *controller) {
|
||||||
sc_cond_destroy(&controller->msg_cond);
|
sc_cond_destroy(&controller->msg_cond);
|
||||||
|
@ -25,8 +25,11 @@ struct sc_controller {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_controller_init(struct sc_controller *controller, sc_socket control_socket,
|
sc_controller_init(struct sc_controller *controller, sc_socket control_socket);
|
||||||
struct sc_acksync *acksync);
|
|
||||||
|
void
|
||||||
|
sc_controller_set_acksync(struct sc_controller *controller,
|
||||||
|
struct sc_acksync *acksync);
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_controller_destroy(struct sc_controller *controller);
|
sc_controller_destroy(struct sc_controller *controller);
|
||||||
|
@ -8,15 +8,14 @@
|
|||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket,
|
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket) {
|
||||||
struct sc_acksync *acksync) {
|
|
||||||
bool ok = sc_mutex_init(&receiver->mutex);
|
bool ok = sc_mutex_init(&receiver->mutex);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
receiver->control_socket = control_socket;
|
receiver->control_socket = control_socket;
|
||||||
receiver->acksync = acksync;
|
receiver->acksync = NULL;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,7 @@ struct sc_receiver {
|
|||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket,
|
sc_receiver_init(struct sc_receiver *receiver, sc_socket control_socket);
|
||||||
struct sc_acksync *acksync);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sc_receiver_destroy(struct sc_receiver *receiver);
|
sc_receiver_destroy(struct sc_receiver *receiver);
|
||||||
|
@ -663,12 +663,13 @@ aoa_hid_end:
|
|||||||
mp = &s->mouse_sdk.mouse_processor;
|
mp = &s->mouse_sdk.mouse_processor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sc_controller_init(&s->controller, s->server.control_socket,
|
if (!sc_controller_init(&s->controller, s->server.control_socket)) {
|
||||||
acksync)) {
|
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
controller_initialized = true;
|
controller_initialized = true;
|
||||||
|
|
||||||
|
sc_controller_set_acksync(&s->controller, acksync);
|
||||||
|
|
||||||
if (!sc_controller_start(&s->controller)) {
|
if (!sc_controller_start(&s->controller)) {
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user