MCPcopy Create free account
hub / github.com/averne/Fizeau / command_handler

Method command_handler

sysmodule/src/server.cpp:33–94  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31})
32
33Result Server::command_handler(void *userdata, const IpcServerRequest *r, u8 *out_data, size_t *out_datasize) {
34 auto *self = static_cast<Server *>(userdata);
35
36 switch (r->data.cmdId) {
37 case FizeauCommandId_GetIsActive: {
38 SET_OUTDATA(self->context.is_active);
39 break;
40 }
41 case FizeauCommandId_SetIsActive: {
42 auto prev_active = std::exchange(self->context.is_active, *(bool *)r->data.ptr);
43
44 if (prev_active != self->context.is_active)
45 self->profile.update_active();
46
47 break;
48 }
49 case FizeauCommandId_GetProfile: {
50 auto id = *(FizeauProfileId *)r->data.ptr;
51 if (id < FizeauProfileId_Profile1 || id > FizeauProfileId_Profile4)
52 return FIZEAU_MAKERESULT(INVALID_PROFILEID);
53
54 SET_OUTDATA(self->context.profiles[id]);
55 break;
56 }
57 case FizeauCommandId_SetProfile: {
58 auto id = *(FizeauProfileId *)r->data.ptr;
59 if (id < FizeauProfileId_Profile1 || id > FizeauProfileId_Profile4)
60 return FIZEAU_MAKERESULT(INVALID_PROFILEID);
61
62 self->context.profiles[id] = *(FizeauProfile *)((std::uint8_t *)r->data.ptr + std::max(alignof(FizeauProfileId), alignof(FizeauProfile)));
63
64 if (id == self->context.internal_profile || id == self->context.external_profile) {
65 if (auto rc = self->profile.apply(); R_FAILED(rc))
66 return rc;
67 }
68
69 break;
70 }
71 case FizeauCommandId_GetActiveProfileId: {
72 auto external = *(bool *)r->data.ptr;
73 SET_OUTDATA(!external ? self->context.internal_profile : self->context.external_profile);
74 break;
75 }
76 case FizeauCommandId_SetActiveProfileId: {
77 auto external = *(bool *)r->data.ptr;
78 auto id = *(FizeauProfileId *)((std::uint8_t *)r->data.ptr + std::max(alignof(bool), alignof(FizeauProfileId)));
79 if (id < FizeauProfileId_Profile1 || id > FizeauProfileId_Profile4)
80 return FIZEAU_MAKERESULT(INVALID_PROFILEID);
81
82 (!external ? self->context.internal_profile : self->context.external_profile) = id;
83
84 if (auto rc = self->profile.apply(); R_FAILED(rc))
85 return rc;
86
87 break;
88 }
89 default:
90 return MAKERESULT(10, 221);

Callers

nothing calls this directly

Calls 2

update_activeMethod · 0.80
applyMethod · 0.45

Tested by

no test coverage detected