summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/glue/notif.h
blob: ef2522fdfb5d18ae6de247336886bbf977fae970 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <array>
#include <vector>

#include "common/uuid.h"
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h"

namespace Core {
class System;
}

namespace Service::Glue {

// This is nn::notification::AlarmSettingId
using AlarmSettingId = u16;
static_assert(sizeof(AlarmSettingId) == 0x2, "AlarmSettingId is an invalid size");

using ApplicationParameter = std::array<u8, 0x400>;
static_assert(sizeof(ApplicationParameter) == 0x400, "ApplicationParameter is an invalid size");

struct DailyAlarmSetting {
    s8 hour;
    s8 minute;
};
static_assert(sizeof(DailyAlarmSetting) == 0x2, "DailyAlarmSetting is an invalid size");

struct WeeklyScheduleAlarmSetting {
    INSERT_PADDING_BYTES_NOINIT(0xA);
    std::array<DailyAlarmSetting, 0x7> day_of_week;
};
static_assert(sizeof(WeeklyScheduleAlarmSetting) == 0x18,
              "WeeklyScheduleAlarmSetting is an invalid size");

// This is nn::notification::AlarmSetting
struct AlarmSetting {
    AlarmSettingId alarm_setting_id;
    u8 kind;
    u8 muted;
    INSERT_PADDING_BYTES_NOINIT(0x4);
    Common::UUID account_id;
    u64 application_id;
    INSERT_PADDING_BYTES_NOINIT(0x8);
    WeeklyScheduleAlarmSetting schedule;
};
static_assert(sizeof(AlarmSetting) == 0x40, "AlarmSetting is an invalid size");

enum class NotificationChannel : u8 {
    Unknown0 = 0,
};

struct NotificationPresentationSetting {
    INSERT_PADDING_BYTES_NOINIT(0x10);
};
static_assert(sizeof(NotificationPresentationSetting) == 0x10,
              "NotificationPresentationSetting is an invalid size");

class NotificationServiceImpl {
public:
    Result RegisterAlarmSetting(AlarmSettingId* out_alarm_setting_id,
                                const AlarmSetting& alarm_setting,
                                std::span<const u8> application_parameter);
    Result UpdateAlarmSetting(const AlarmSetting& alarm_setting,
                              std::span<const u8> application_parameter);
    Result ListAlarmSettings(s32* out_count, std::span<AlarmSetting> out_alarms);
    Result LoadApplicationParameter(u32* out_size, std::span<u8> out_application_parameter,
                                    AlarmSettingId alarm_setting_id);
    Result DeleteAlarmSetting(AlarmSettingId alarm_setting_id);
    Result Initialize(u64 aruid);

private:
    std::vector<AlarmSetting>::iterator GetAlarmFromId(AlarmSettingId alarm_setting_id);
    std::vector<AlarmSetting> alarms{};
    AlarmSettingId last_alarm_setting_id{};
};

class INotificationServicesForApplication final
    : public ServiceFramework<INotificationServicesForApplication> {
public:
    explicit INotificationServicesForApplication(Core::System& system_);
    ~INotificationServicesForApplication() override;

private:
    Result RegisterAlarmSetting(Out<AlarmSettingId> out_alarm_setting_id,
                                InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
                                InBuffer<BufferAttr_HipcMapAlias> application_parameter);
    Result UpdateAlarmSetting(InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
                              InBuffer<BufferAttr_HipcMapAlias> application_parameter);
    Result ListAlarmSettings(Out<s32> out_count,
                             OutArray<AlarmSetting, BufferAttr_HipcMapAlias> out_alarms);
    Result LoadApplicationParameter(Out<u32> out_size,
                                    OutBuffer<BufferAttr_HipcMapAlias> out_application_parameter,
                                    AlarmSettingId alarm_setting_id);
    Result DeleteAlarmSetting(AlarmSettingId alarm_setting_id);
    Result Initialize(ClientAppletResourceUserId aruid);

    NotificationServiceImpl impl;
};

class INotificationSystemEventAccessor;

class INotificationServices final : public ServiceFramework<INotificationServices> {
public:
    explicit INotificationServices(Core::System& system_);
    ~INotificationServices() override;

private:
    Result RegisterAlarmSetting(Out<AlarmSettingId> out_alarm_setting_id,
                                InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
                                InBuffer<BufferAttr_HipcMapAlias> application_parameter);
    Result UpdateAlarmSetting(InLargeData<AlarmSetting, BufferAttr_HipcMapAlias> alarm_setting,
                              InBuffer<BufferAttr_HipcMapAlias> application_parameter);
    Result ListAlarmSettings(Out<s32> out_count,
                             OutArray<AlarmSetting, BufferAttr_HipcMapAlias> out_alarms);
    Result LoadApplicationParameter(Out<u32> out_size,
                                    OutBuffer<BufferAttr_HipcMapAlias> out_application_parameter,
                                    AlarmSettingId alarm_setting_id);
    Result DeleteAlarmSetting(AlarmSettingId alarm_setting_id);
    Result Initialize(ClientAppletResourceUserId aruid);
    Result OpenNotificationSystemEventAccessor(Out<SharedPointer<INotificationSystemEventAccessor>>
                                                   out_notification_system_event_accessor);
    Result GetNotificationPresentationSetting(
        Out<NotificationPresentationSetting> out_notification_presentation_setting,
        NotificationChannel notification_channel);

    NotificationServiceImpl impl;
};
} // namespace Service::Glue