fixup!cam: use IPCHelper

This commit is contained in:
wwylele 2017-05-25 16:49:09 +03:00
parent 8cd9522526
commit 857510a7c0
2 changed files with 43 additions and 30 deletions

View File

@ -398,6 +398,7 @@ void SetReceiving(Service::Interface* self) {
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.PushCopyHandles(Kernel::g_handle_table.Create(port.completion_event).MoveFrom()); rb.PushCopyHandles(Kernel::g_handle_table.Create(port.completion_event).MoveFrom());
} else { } else {
LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val);
rb.Push(ERROR_INVALID_ENUM_VALUE); rb.Push(ERROR_INVALID_ENUM_VALUE);
rb.PushCopyHandles(0); rb.PushCopyHandles(0);
} }
@ -413,8 +414,9 @@ void IsFinishedReceiving(Service::Interface* self) {
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
if (port_select.IsSingle()) { if (port_select.IsSingle()) {
int port = *port_select.begin(); int port = *port_select.begin();
bool is_busy = ports[port].is_receiving || ports[port].is_pending_receiving;
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.Push(ports[port].is_receiving || ports[port].is_pending_receiving); rb.Push(!is_busy);
} else { } else {
LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val);
rb.Push(ERROR_INVALID_ENUM_VALUE); rb.Push(ERROR_INVALID_ENUM_VALUE);
@ -508,7 +510,7 @@ void GetTransferBytes(Service::Interface* self) {
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
if (port_select.IsSingle()) { if (port_select.IsSingle()) {
int port = *port_select.begin(); int port = *port_select.begin();
rb.Push(RESULT_SUCCESS.raw); rb.Push(RESULT_SUCCESS);
rb.Push(ports[port].transfer_bytes); rb.Push(ports[port].transfer_bytes);
} else { } else {
LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val); LOG_ERROR(Service_CAM, "invalid port_select=%u", port_select.m_val);
@ -930,7 +932,6 @@ void SetPackageParameterWithoutContext(Service::Interface* self) {
PackageParameterWithoutContext package; PackageParameterWithoutContext package;
rp.PopRaw(package); rp.PopRaw(package);
rp.Skip(4, false);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
@ -938,18 +939,11 @@ void SetPackageParameterWithoutContext(Service::Interface* self) {
LOG_WARNING(Service_CAM, "(STUBBED) called"); LOG_WARNING(Service_CAM, "(STUBBED) called");
} }
template <typename PackageParameterType, int command_id, int param_length> template <typename PackageParameterType>
static void SetPackageParameter() { static ResultCode SetPackageParameter(const PackageParameterType& package) {
IPC::RequestParser rp(Kernel::GetCommandBuffer(), command_id, param_length, 0);
PackageParameterType package;
rp.PopRaw(package);
rp.Skip(param_length - (sizeof(PackageParameterType) + 3) / 4, false);
const CameraSet camera_select(package.camera_select); const CameraSet camera_select(package.camera_select);
const ContextSet context_select(package.context_select); const ContextSet context_select(package.context_select);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
if (camera_select.IsValid() && context_select.IsValid()) { if (camera_select.IsValid() && context_select.IsValid()) {
for (int camera_id : camera_select) { for (int camera_id : camera_select) {
CameraConfig& camera = cameras[camera_id]; CameraConfig& camera = cameras[camera_id];
@ -965,31 +959,47 @@ static void SetPackageParameter() {
} }
} }
} }
rb.Push(RESULT_SUCCESS); return RESULT_SUCCESS;
} else { } else {
LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", package.camera_select, LOG_ERROR(Service_CAM, "invalid camera_select=%u, context_select=%u", package.camera_select,
package.context_select); package.context_select);
rb.Push(ERROR_INVALID_ENUM_VALUE); return ERROR_INVALID_ENUM_VALUE;
} }
LOG_DEBUG(Service_CAM, "called");
} }
Resolution PackageParameterWithContext::GetResolution() { Resolution PackageParameterWithContext::GetResolution() const {
return PRESET_RESOLUTION[static_cast<int>(size)]; return PRESET_RESOLUTION[static_cast<int>(size)];
} }
void SetPackageParameterWithContext(Service::Interface* self) { void SetPackageParameterWithContext(Service::Interface* self) {
SetPackageParameter<PackageParameterWithContext, 0x34, 5>(); IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x34, 5, 0);
PackageParameterWithContext package;
rp.PopRaw(package);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
ResultCode result = SetPackageParameter(package);
rb.Push(result);
LOG_DEBUG(Service_CAM, "called");
} }
void SetPackageParameterWithContextDetail(Service::Interface* self) { void SetPackageParameterWithContextDetail(Service::Interface* self) {
SetPackageParameter<PackageParameterWithContextDetail, 0x35, 7>(); IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x35, 7, 0);
PackageParameterWithContextDetail package;
rp.PopRaw(package);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
ResultCode result = SetPackageParameter(package);
rb.Push(result);
LOG_DEBUG(Service_CAM, "called");
} }
void GetSuitableY2rStandardCoefficient(Service::Interface* self) { void GetSuitableY2rStandardCoefficient(Service::Interface* self) {
IPC::RequestBuilder rb = IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x36, 0, 0);
IPC::RequestParser(Kernel::GetCommandBuffer(), 0x36, 0, 0).MakeBuilder(2, 0); IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(RESULT_SUCCESS); rb.Push(RESULT_SUCCESS);
rb.Push<u32>(0); rb.Push<u32>(0);
@ -1007,8 +1017,8 @@ void PlayShutterSound(Service::Interface* self) {
} }
void DriverInitialize(Service::Interface* self) { void DriverInitialize(Service::Interface* self) {
IPC::RequestBuilder rb = IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x39, 0, 0);
IPC::RequestParser(Kernel::GetCommandBuffer(), 0x39, 0, 0).MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
for (int camera_id = 0; camera_id < NumCameras; ++camera_id) { for (int camera_id = 0; camera_id < NumCameras; ++camera_id) {
CameraConfig& camera = cameras[camera_id]; CameraConfig& camera = cameras[camera_id];
@ -1040,8 +1050,8 @@ void DriverInitialize(Service::Interface* self) {
} }
void DriverFinalize(Service::Interface* self) { void DriverFinalize(Service::Interface* self) {
IPC::RequestBuilder rb = IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x3A, 0, 0);
IPC::RequestParser(Kernel::GetCommandBuffer(), 0x3A, 0, 0).MakeBuilder(1, 0); IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
CancelReceiving(0); CancelReceiving(0);
CancelReceiving(1); CancelReceiving(1);

View File

@ -184,9 +184,10 @@ struct PackageParameterWithoutContext {
s16 auto_white_balance_window_y; s16 auto_white_balance_window_y;
s16 auto_white_balance_window_width; s16 auto_white_balance_window_width;
s16 auto_white_balance_window_height; s16 auto_white_balance_window_height;
INSERT_PADDING_WORDS(4);
}; };
static_assert(sizeof(PackageParameterWithoutContext) == 28, static_assert(sizeof(PackageParameterWithoutContext) == 44,
"PackageParameterCameraWithoutContext structure size is wrong"); "PackageParameterCameraWithoutContext structure size is wrong");
struct PackageParameterWithContext { struct PackageParameterWithContext {
@ -196,11 +197,12 @@ struct PackageParameterWithContext {
Effect effect; Effect effect;
Size size; Size size;
INSERT_PADDING_BYTES(3); INSERT_PADDING_BYTES(3);
INSERT_PADDING_WORDS(3);
Resolution GetResolution(); Resolution GetResolution() const;
}; };
static_assert(sizeof(PackageParameterWithContext) == 8, static_assert(sizeof(PackageParameterWithContext) == 20,
"PackageParameterWithContext structure size is wrong"); "PackageParameterWithContext structure size is wrong");
struct PackageParameterWithContextDetail { struct PackageParameterWithContextDetail {
@ -209,13 +211,14 @@ struct PackageParameterWithContextDetail {
Flip flip; Flip flip;
Effect effect; Effect effect;
Resolution resolution; Resolution resolution;
INSERT_PADDING_WORDS(3);
Resolution GetResolution() { Resolution GetResolution() const {
return resolution; return resolution;
} }
}; };
static_assert(sizeof(PackageParameterWithContextDetail) == 16, static_assert(sizeof(PackageParameterWithContextDetail) == 28,
"PackageParameterWithContextDetail structure size is wrong"); "PackageParameterWithContextDetail structure size is wrong");
/** /**