pdmqry: Updated for new-ipc and updated for using AccountUid. Renamed pdmqryGetUserPlayedApplications to pdmqryQueryRecentlyPlayedApplication. Renamed pdmqryGetUserAccountEvent to pdmqryGetRecentlyPlayedApplicationUpdateEvent. Minor param name adjustment.

This commit is contained in:
yellows8 2019-10-10 21:06:14 -04:00
parent 39288a832e
commit 1b610070f5
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
2 changed files with 84 additions and 343 deletions

View File

@ -6,7 +6,8 @@
*/ */
#pragma once #pragma once
#include "../types.h" #include "../types.h"
#include "../services/sm.h" #include "../sf/service.h"
#include "../services/acc.h"
#include "../kernel/event.h" #include "../kernel/event.h"
/// PlayEventType /// PlayEventType
@ -132,7 +133,7 @@ typedef struct {
/// AccountEvent /// AccountEvent
typedef struct { typedef struct {
union { u128 userID; } PACKED; ///< userID. AccountUid userID; ///< \ref AccountUid
u32 entryindex; ///< Entry index. u32 entryindex; ///< Entry index.
u8 pad[4]; ///< Padding. u8 pad[4]; ///< Padding.
u64 timestampUser; ///< See PdmPlayEvent::timestampUser. u64 timestampUser; ///< See PdmPlayEvent::timestampUser.
@ -182,10 +183,10 @@ Result pdmqryQueryPlayStatisticsByApplicationId(u64 titleID, PdmPlayStatistics *
/** /**
* @brief Gets \ref PdmPlayStatistics for the specified titleID and account userID. * @brief Gets \ref PdmPlayStatistics for the specified titleID and account userID.
* @param[in] titleID Application titleID. * @param[in] titleID Application titleID.
* @param[in] userID Account userID. * @param[in] userID \ref AccountUid
* @param[out] stats \ref PdmPlayStatistics * @param[out] stats \ref PdmPlayStatistics
*/ */
Result pdmqryQueryPlayStatisticsByApplicationIdAndUserAccountId(u64 titleID, u128 userID, PdmPlayStatistics *stats); Result pdmqryQueryPlayStatisticsByApplicationIdAndUserAccountId(u64 titleID, AccountUid *userID, PdmPlayStatistics *stats);
/** /**
* @brief Gets \ref PdmLastPlayTime for the specified titles. * @brief Gets \ref PdmLastPlayTime for the specified titles.
@ -226,39 +227,39 @@ Result pdmqryQueryAccountEvent(u32 entryindex, PdmAccountEvent *events, s32 coun
* @brief Gets a list of \ref PdmAccountPlayEvent. * @brief Gets a list of \ref PdmAccountPlayEvent.
* @note Only available with [4.0.0+]. * @note Only available with [4.0.0+].
* @param[in] entryindex Start entry index. * @param[in] entryindex Start entry index.
* @param[in] userID Account userID. * @param[in] userID \ref AccountUid
* @param[out] events Output \ref PdmAccountPlayEvent array. * @param[out] events Output \ref PdmAccountPlayEvent array.
* @param[in] count Max entries in the output array. * @param[in] count Max entries in the output array.
* @param[out] total_out Total output entries. * @param[out] total_out Total output entries.
*/ */
Result pdmqryQueryAccountPlayEvent(u32 entryindex, u128 userID, PdmAccountPlayEvent *events, s32 count, s32 *total_out); Result pdmqryQueryAccountPlayEvent(u32 entryindex, AccountUid *userID, PdmAccountPlayEvent *events, s32 count, s32 *total_out);
/** /**
* @brief Gets range fields which can then be used with \ref pdmqryQueryAccountPlayEvent. * @brief Gets range fields which can then be used with \ref pdmqryQueryAccountPlayEvent.
* @param[in] userID Account userID. * @param[in] userID \ref AccountUid
* @param[out] total_entries Total entries. * @param[out] total_entries Total entries.
* @param[out] start_entryindex Start entry index. * @param[out] start_entryindex Start entry index.
* @param[out] end_entryindex End entry index. * @param[out] end_entryindex End entry index.
*/ */
Result pdmqryGetAvailableAccountPlayEventRange(u128 userID, u32 *total_entries, u32 *start_entryindex, u32 *end_entryindex); Result pdmqryGetAvailableAccountPlayEventRange(AccountUid *userID, u32 *total_entries, u32 *start_entryindex, u32 *end_entryindex);
/** /**
* @brief Gets a list of titles played by the specified user. * @brief Gets a list of titles played by the specified user.
* @note Only available with [6.0.0+]. * @note Only available with [6.0.0+].
* @param[in] userID Account userID. * @param[in] userID \ref AccountUid
* @param[out] titleIDs Output titleID array. * @param[out] titleIDs Output titleID array.
* @param[in] count Max entries in the output array. * @param[in] count Max entries in the output array.
* @param[out] total_out Total output entries. * @param[out] total_out Total output entries.
*/ */
Result pdmqryGetUserPlayedApplications(u128 userID, u64 *titleIDs, size_t count, u32 *total_out); Result pdmqryQueryRecentlyPlayedApplication(AccountUid *userID, u64 *titleIDs, size_t count, u32 *total_out);
/** /**
* @brief Gets an Event which is signaled when logging a new \ref PdmPlayEvent which would be available via \ref pdmqryQueryAccountEvent, where PdmPlayEvent::eventData::account::type is 0. * @brief Gets an Event which is signaled when logging a new \ref PdmPlayEvent which would be available via \ref pdmqryQueryAccountEvent, where PdmPlayEvent::eventData::account::type is 0.
* @note Only available with [6.0.0+]. * @note Only available with [6.0.0+].
* @note The Event must be closed by the user once finished with it. * @note The Event must be closed by the user once finished with it.
* @param[out] event_out Output Event with autoclear=false. * @param[out] out_event Output Event with autoclear=false.
*/ */
Result pdmqryGetUserAccountEvent(Event* event_out); Result pdmqryGetRecentlyPlayedApplicationUpdateEvent(Event* out_event);
/** /**
* @brief Helper function which converts a Play timestamp from the Pdm*Event structs to POSIX. * @brief Helper function which converts a Play timestamp from the Pdm*Event structs to POSIX.

View File

@ -1,193 +1,75 @@
#define NX_SERVICE_ASSUME_NON_DOMAIN
#include "service_guard.h"
#include <string.h> #include <string.h>
#include "types.h"
#include "result.h"
#include "arm/atomics.h"
#include "kernel/ipc.h"
#include "kernel/event.h" #include "kernel/event.h"
#include "services/sm.h"
#include "services/pdm.h" #include "services/pdm.h"
#include "services/acc.h"
#include "runtime/hosversion.h" #include "runtime/hosversion.h"
static Service g_pdmqrySrv; static Service g_pdmqrySrv;
static u64 g_pdmqryRefCnt;
Result pdmqryInitialize(void) { NX_GENERATE_SERVICE_GUARD(pdmqry);
atomicIncrement64(&g_pdmqryRefCnt);
if (serviceIsActive(&g_pdmqrySrv)) Result _pdmqryInitialize(void) {
return 0; return smGetService(&g_pdmqrySrv, "pdm:qry");
Result rc = smGetService(&g_pdmqrySrv, "pdm:qry");
if (R_FAILED(rc)) pdmqryExit();
return rc;
} }
void pdmqryExit(void) { void _pdmqryCleanup(void) {
if (atomicDecrement64(&g_pdmqryRefCnt) == 0) serviceClose(&g_pdmqrySrv);
serviceClose(&g_pdmqrySrv);
} }
Service* pdmqryGetServiceSession(void) { Service* pdmqryGetServiceSession(void) {
return &g_pdmqrySrv; return &g_pdmqrySrv;
} }
static Result _pdmqryQueryEvent(u64 cmd_id, u32 entryindex, void* events, size_t entrysize, s32 count, s32 *total_out) { static Result _pdmCmdGetEvent(Service* srv, Event* out_event, bool autoclear, u32 cmd_id) {
IpcCommand c; Handle event = INVALID_HANDLE;
ipcInitialize(&c); Result rc = serviceDispatch(srv, cmd_id,
.out_handle_attrs = { SfOutHandleAttr_HipcCopy },
.out_handles = &event,
);
ipcAddRecvBuffer(&c, events, count*entrysize, BufferType_Normal); if (R_SUCCEEDED(rc))
eventLoadRemote(out_event, event, autoclear);
struct {
u64 magic;
u64 cmd_id;
u32 entryindex;
} *raw;
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = cmd_id;
raw->entryindex = entryindex;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
s32 total_out;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && total_out) *total_out = resp->total_out;
}
return rc; return rc;
} }
static Result _pdmqryQueryEvent(u32 cmd_id, u32 entryindex, void* events, size_t entrysize, s32 count, s32 *total_out) {
return serviceDispatchInOut(&g_pdmqrySrv, cmd_id, entryindex, *total_out,
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
.buffers = { { events, count*entrysize } },
);
}
Result pdmqryQueryApplicationEvent(u32 entryindex, PdmApplicationEvent *events, s32 count, s32 *total_out) { Result pdmqryQueryApplicationEvent(u32 entryindex, PdmApplicationEvent *events, s32 count, s32 *total_out) {
return _pdmqryQueryEvent(0, entryindex, events, sizeof(PdmApplicationEvent), count, total_out); return _pdmqryQueryEvent(0, entryindex, events, sizeof(PdmApplicationEvent), count, total_out);
} }
Result pdmqryQueryPlayStatisticsByApplicationId(u64 titleID, PdmPlayStatistics *stats) { Result pdmqryQueryPlayStatisticsByApplicationId(u64 titleID, PdmPlayStatistics *stats) {
IpcCommand c; return serviceDispatchInOut(&g_pdmqrySrv, 4, titleID, *stats);
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
u64 titleID;
} *raw;
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 4;
raw->titleID = titleID;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
PdmPlayStatistics stats;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && stats) memcpy(stats, &resp->stats, sizeof(resp->stats));
}
return rc;
} }
Result pdmqryQueryPlayStatisticsByApplicationIdAndUserAccountId(u64 titleID, u128 userID, PdmPlayStatistics *stats) { Result pdmqryQueryPlayStatisticsByApplicationIdAndUserAccountId(u64 titleID, AccountUid *userID, PdmPlayStatistics *stats) {
IpcCommand c; const struct {
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
u64 titleID; u64 titleID;
union { u128 userID; } PACKED; AccountUid userID;
} *raw; } in = { titleID, *userID };
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw)); return serviceDispatchInOut(&g_pdmqrySrv, 5, in, *stats);
raw->magic = SFCI_MAGIC;
raw->cmd_id = 5;
raw->titleID = titleID;
raw->userID = userID;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
PdmPlayStatistics stats;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && stats) memcpy(stats, &resp->stats, sizeof(resp->stats));
}
return rc;
} }
Result pdmqryQueryLastPlayTime(PdmLastPlayTime *playtimes, const u64 *titleIDs, s32 count, s32 *total_out) { Result pdmqryQueryLastPlayTime(PdmLastPlayTime *playtimes, const u64 *titleIDs, s32 count, s32 *total_out) {
IpcCommand c; return serviceDispatchOut(&g_pdmqrySrv, 7, *total_out,
ipcInitialize(&c); .buffer_attrs = {
SfBufferAttr_HipcMapAlias | SfBufferAttr_Out,
ipcAddSendBuffer(&c, titleIDs, count*sizeof(u64), BufferType_Normal); SfBufferAttr_HipcMapAlias | SfBufferAttr_In,
ipcAddRecvBuffer(&c, playtimes, count*sizeof(PdmLastPlayTime), BufferType_Normal); },
.buffers = {
struct { { playtimes, count*sizeof(PdmLastPlayTime) },
u64 magic; { titleIDs, count*sizeof(u64) },
u64 cmd_id; },
} *raw; );
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 7;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
s32 total_out;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && total_out) *total_out = resp->total_out;
}
return rc;
} }
Result pdmqryQueryPlayEvent(u32 entryindex, PdmPlayEvent *events, s32 count, s32 *total_out) { Result pdmqryQueryPlayEvent(u32 entryindex, PdmPlayEvent *events, s32 count, s32 *total_out) {
@ -195,41 +77,18 @@ Result pdmqryQueryPlayEvent(u32 entryindex, PdmPlayEvent *events, s32 count, s32
} }
Result pdmqryGetAvailablePlayEventRange(u32 *total_entries, u32 *start_entryindex, u32 *end_entryindex) { Result pdmqryGetAvailablePlayEventRange(u32 *total_entries, u32 *start_entryindex, u32 *end_entryindex) {
IpcCommand c;
ipcInitialize(&c);
struct { struct {
u64 magic; u32 total_entries;
u64 cmd_id; u32 start_entryindex;
} *raw; u32 end_entryindex;
} out;
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 9;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
Result rc = serviceDispatchOut(&g_pdmqrySrv, 9, out);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; if (total_entries) *total_entries = out.total_entries;
struct { if (start_entryindex) *start_entryindex = out.start_entryindex;
u64 magic; if (end_entryindex) *end_entryindex = out.end_entryindex;
u64 result;
u32 total_entries;
u32 start_entryindex;
u32 end_entryindex;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && total_entries) *total_entries = resp->total_entries;
if (R_SUCCEEDED(rc) && start_entryindex) *start_entryindex = resp->start_entryindex;
if (R_SUCCEEDED(rc) && end_entryindex) *end_entryindex = resp->end_entryindex;
} }
return rc; return rc;
} }
@ -237,173 +96,54 @@ Result pdmqryQueryAccountEvent(u32 entryindex, PdmAccountEvent *events, s32 coun
return _pdmqryQueryEvent(10, entryindex, events, sizeof(PdmAccountEvent), count, total_out); return _pdmqryQueryEvent(10, entryindex, events, sizeof(PdmAccountEvent), count, total_out);
} }
Result pdmqryQueryAccountPlayEvent(u32 entryindex, u128 userID, PdmAccountPlayEvent *events, s32 count, s32 *total_out) { Result pdmqryQueryAccountPlayEvent(u32 entryindex, AccountUid *userID, PdmAccountPlayEvent *events, s32 count, s32 *total_out) {
IpcCommand c;
ipcInitialize(&c);
if (hosversionBefore(4,0,0)) if (hosversionBefore(4,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
ipcAddRecvBuffer(&c, events, count*sizeof(PdmAccountPlayEvent), BufferType_Normal); const struct {
struct {
u64 magic;
u64 cmd_id;
u32 entryindex; u32 entryindex;
u32 pad; AccountUid userID;
union { u128 userID; } PACKED; } in = { entryindex, *userID };
} *raw;
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw)); return serviceDispatchInOut(&g_pdmqrySrv, 11, in, *total_out,
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
raw->magic = SFCI_MAGIC; .buffers = { { events, count*sizeof(PdmAccountPlayEvent) } },
raw->cmd_id = 11; );
raw->entryindex = entryindex;
raw->userID = userID;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
s32 total_out;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && total_out) *total_out = resp->total_out;
}
return rc;
} }
Result pdmqryGetAvailableAccountPlayEventRange(u128 userID, u32 *total_entries, u32 *start_entryindex, u32 *end_entryindex) { Result pdmqryGetAvailableAccountPlayEventRange(AccountUid *userID, u32 *total_entries, u32 *start_entryindex, u32 *end_entryindex) {
IpcCommand c;
ipcInitialize(&c);
if (hosversionBefore(4,0,0)) if (hosversionBefore(4,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
struct { struct {
u64 magic; u32 total_entries;
u64 cmd_id; u32 start_entryindex;
u128 userID; u32 end_entryindex;
} *raw; } out;
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 12;
raw->userID = userID;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
Result rc = serviceDispatchInOut(&g_pdmqrySrv, 12, *userID, out);
if (R_SUCCEEDED(rc)) { if (R_SUCCEEDED(rc)) {
IpcParsedCommand r; if (total_entries) *total_entries = out.total_entries;
struct { if (start_entryindex) *start_entryindex = out.start_entryindex;
u64 magic; if (end_entryindex) *end_entryindex = out.end_entryindex;
u64 result;
u32 total_entries;
u32 start_entryindex;
u32 end_entryindex;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && total_entries) *total_entries = resp->total_entries;
if (R_SUCCEEDED(rc) && start_entryindex) *start_entryindex = resp->start_entryindex;
if (R_SUCCEEDED(rc) && end_entryindex) *end_entryindex = resp->end_entryindex;
} }
return rc; return rc;
} }
Result pdmqryGetUserPlayedApplications(u128 userID, u64 *titleIDs, size_t count, u32 *total_out) { Result pdmqryQueryRecentlyPlayedApplication(AccountUid *userID, u64 *titleIDs, size_t count, u32 *total_out) {
IpcCommand c;
ipcInitialize(&c);
if (hosversionBefore(6,0,0)) if (hosversionBefore(6,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
ipcAddRecvBuffer(&c, titleIDs, count*sizeof(u64), BufferType_Normal); return serviceDispatchInOut(&g_pdmqrySrv, 14, *userID, *total_out,
.buffer_attrs = { SfBufferAttr_HipcMapAlias | SfBufferAttr_Out },
struct { .buffers = { { titleIDs, count*sizeof(u64) } },
u64 magic; );
u64 cmd_id;
u128 userID;
} *raw;
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 14;
raw->userID = userID;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
u32 total_out;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && total_out) *total_out = resp->total_out;
}
return rc;
} }
Result pdmqryGetUserAccountEvent(Event* event_out) { Result pdmqryGetRecentlyPlayedApplicationUpdateEvent(Event* out_event) {
IpcCommand c;
ipcInitialize(&c);
if (hosversionBefore(6,0,0)) if (hosversionBefore(6,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
struct { return _pdmCmdGetEvent(&g_pdmqrySrv, out_event, false, 15);
u64 magic;
u64 cmd_id;
} *raw;
raw = serviceIpcPrepareHeader(&g_pdmqrySrv, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 15;
Result rc = serviceIpcDispatch(&g_pdmqrySrv);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
} *resp;
serviceIpcParse(&g_pdmqrySrv, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc)) {
eventLoadRemote(event_out, r.Handles[0], false);
}
}
return rc;
} }