]> Chaos Git - corbenik/ctrulib.git/commitdiff
Add news:u commands.
authorSteven Smith <Steveice10@gmail.com>
Tue, 14 Apr 2015 16:45:51 +0000 (09:45 -0700)
committerSteven Smith <Steveice10@gmail.com>
Tue, 14 Apr 2015 19:37:20 +0000 (12:37 -0700)
libctru/include/3ds.h
libctru/include/3ds/services/news.h [new file with mode: 0644]
libctru/source/services/news.c [new file with mode: 0644]

index 1d8f6faebb77f999c2f392ec646c2a6f367e8b95..91ef308c50d576708442dd195e0bc8f876600a05 100644 (file)
@@ -34,6 +34,7 @@ extern "C" {
 #include <3ds/services/soc.h>
 #include <3ds/services/mic.h>
 #include <3ds/services/mvd.h>
+#include <3ds/services/news.h>
 #include <3ds/services/qtm.h>
 #include <3ds/services/hb.h>
 
diff --git a/libctru/include/3ds/services/news.h b/libctru/include/3ds/services/news.h
new file mode 100644 (file)
index 0000000..bf1c825
--- /dev/null
@@ -0,0 +1,22 @@
+#pragma once
+
+/*
+       Requires access to "news:u" service.
+*/
+
+
+Result newsInit();
+Result newsExit();
+
+/* NEWSU_AddNotification()
+About: Adds a notification to the home menu Notifications applet.
+
+  title        UTF-16 title of the notification.
+  titleLength  Number of characters in the title, not including the null-terminator.
+  title        UTF-16 message of the notification, or NULL for no message.
+  titleLength  Number of characters in the message, not including the null-terminator.
+  image        Data of the image to show in the notification, or NULL for no image.
+  imageSize    Size of the image data in bytes.
+  jpeg         Whether the image is a JPEG or not.
+*/
+Result NEWSU_AddNotification(const u16* title, u32 titleLength, const u16* message, u32 messageLength, const void* imageData, u32 imageSize, bool jpeg);
diff --git a/libctru/source/services/news.c b/libctru/source/services/news.c
new file mode 100644 (file)
index 0000000..51a8cea
--- /dev/null
@@ -0,0 +1,59 @@
+#include <string.h>
+#include <3ds/types.h>
+#include <3ds/os.h>
+#include <3ds/svc.h>
+#include <3ds/srv.h>
+#include <3ds/services/news.h>
+
+typedef struct {
+       bool dataSet;
+       bool unread;
+       bool enableJPEG;
+       u8 unkFlag1;
+       u8 unkFlag2;
+       u64 processID;
+       u8 unkData[24];
+       u64 time;
+       u16 title[32];
+} NotificationHeader;
+
+static Handle newsHandle = 0;
+
+Result newsInit() {
+       return srvGetServiceHandle(&newsHandle, "news:u");
+}
+
+Result newsExit() {
+       return svcCloseHandle(newsHandle);
+}
+
+Result NEWSU_AddNotification(const u16* title, u32 titleLength, const u16* message, u32 messageLength, const void* imageData, u32 imageSize, bool jpeg)
+{
+       NotificationHeader header = { 0 };
+       header.dataSet = true;
+       header.unread = true;
+       header.enableJPEG = jpeg;
+       header.processID = 0; // Filled automatically from FS:GetProgramLaunchInfo
+       header.time = osGetTime();
+       memcpy(header.title, title, (titleLength < 32 ? titleLength + 1 : 32) * sizeof(u16));
+
+       Result ret = 0;
+       u32 *cmdbuf = getThreadCommandBuffer();
+
+       cmdbuf[0] = 0x000100C8;
+       cmdbuf[1] = sizeof(NotificationHeader);
+       cmdbuf[2] = (messageLength + 1) * sizeof(u16);
+       cmdbuf[3] = imageSize;
+       cmdbuf[4] = 0x20;
+       cmdbuf[5] = 0; // Process ID, Filled automatically by the ARM11 kernel.
+       cmdbuf[6] = (sizeof(NotificationHeader) << 4) | 10;
+       cmdbuf[7] = (u32) &header;
+       cmdbuf[8] = (((messageLength + 1) * sizeof(u16)) << 4) | 10;
+       cmdbuf[9] = (u32) message;
+       cmdbuf[10] = (imageSize << 4) | 10;
+       cmdbuf[11] = (u32) imageData;
+
+       if((ret = svcSendSyncRequest(newsHandle))!=0) return ret;
+
+       return (Result)cmdbuf[1];
+}