169 lines
7.6 KiB
C
169 lines
7.6 KiB
C
/* meow_ipc.h — MeowOS IPC 协议定义(FRAMEWORK_DESIGN §1 / MEOWOS_API.md §1)。
|
||
*
|
||
* 客户端(meow_ipc 测试钩子)与守护进程(meow_launcherd)共用一份,杜绝两端漂移。
|
||
* 传输:AF_UNIX SOCK_STREAM,路径默认 /usr/data/meow_ipc.sock(可被 --ipc-sock /
|
||
* MEOW_IPC_SOCK 覆盖,供 qemu sim)。
|
||
* 帧格式:定长头(16B) + 变长负载,**全部小端 LE**(mipsel 原生)。
|
||
*
|
||
* struct ipc_hdr { LE 字节序
|
||
* uint32_t magic; = 0x4D4F5701 == 'MEOW'|1
|
||
* uint16_t version; = 1
|
||
* uint16_t type; = msg_type
|
||
* uint32_t req_id; = 请求id,响应回显
|
||
* uint32_t len; = payload 字节数
|
||
* };
|
||
*
|
||
* 本阶段(D · M0+M1)通讯子集:MSG_HELLO/ACK/ERR + MSG_ACT_DECLARE/QUERY/RESULT。
|
||
*/
|
||
#ifndef MEOW_IPC_H
|
||
#define MEOW_IPC_H
|
||
|
||
#include <stdint.h>
|
||
#include <stddef.h>
|
||
|
||
#define MEOW_IPC_MAGIC 0x4D4F5701u
|
||
#define MEOW_IPC_VERSION 1u
|
||
#define MEOW_IPC_PATH "/usr/data/meow_ipc.sock"
|
||
#define MEOW_IPC_SOCK_LEN 108 /* sockaddr_un.sun_path */
|
||
#define MEOW_IPC_MAX 4096u /* 单帧负载上限 */
|
||
#define MEOW_IPC_HDR_LEN 16u
|
||
|
||
/* 列表编码上限(count 个 NUL 字符串时,distinct 工作缓冲上限) */
|
||
#define MEOW_IPC_CARGO 1024u /* 守护进程入队拷贝上限(可小于 MEOW_IPC_MAX) */
|
||
|
||
/* ---- 消息类型(FRAMEWORK_DESIGN §1 表)---- */
|
||
enum {
|
||
MSG_NONE = 0x0000,
|
||
MSG_HELLO = 0x0001, /* ↑ 声明 app_id/版本/能力 */
|
||
MSG_ACK = 0x0002, /* ↓ 握手/应答 */
|
||
MSG_ERR = 0x0003, /* ↓ 错误码 */
|
||
MSG_REGISTER = 0x0010, /* ↑ 注册后台服务(保持连接) */
|
||
MSG_SERVICE_OK = 0x0011, /* ↓ 服务登记成功 */
|
||
MSG_SERVICE_STOP = 0x0012, /* ↑ 请求停止服务 */
|
||
MSG_NOTIFY = 0x0020, /* ↑ 推送/更新通知 */
|
||
MSG_NOTIFY_ACK = 0x0021, /* ↓ 落库结果 */
|
||
MSG_NOTIFY_DISMISS = 0x0022, /* ↑ 撤下通知 */
|
||
MSG_NOTIFY_LIST = 0x0023, /* ↓ 下发通知清单(重同步) */
|
||
MSG_NOTIFY_PROGRESS = 0x0024,/* ↑ 实时更新通知进度(仅改内存活跃槽,不落盘) */
|
||
MSG_ACT_DECLARE = 0x0030, /* ↑ (重)声明路由表 */
|
||
MSG_ACT_QUERY = 0x0031, /* ↑ 解析 activity 链路 */
|
||
MSG_ACT_RESULT = 0x0032, /* ↓ 返回链路 */
|
||
MSG_ACT_FOCUS = 0x0033, /* ↑ 上报当前顶层 activity(keep_awake 判定,M2.17) */
|
||
MSG_ACT_BACK = 0x0034, /* ↑ 上报回到根/无 activity(清 keep_awake,M2.17) */
|
||
MSG_NAV = 0x0040, /* ↑ 上报导航/请求退出 */
|
||
MSG_SHOW_ACTIVITY= 0x0041, /* ↓ 令前端应用显示某屏 */
|
||
MSG_SYS = 0x00F0 /* ↓ 系统事件(守护关闭/服务死亡/播放器状态) */
|
||
};
|
||
|
||
/* ---- 返回码(MEOWOS_API.md §1,与 HTTP 层一致)---- */
|
||
enum {
|
||
MEOW_OK = 0,
|
||
MEOW_ERR_INVAL = -1,
|
||
MEOW_ERR_NOENT = -2,
|
||
MEOW_ERR_EXISTS = -3,
|
||
MEOW_ERR_PERM = -4,
|
||
MEOW_ERR_IO = -5,
|
||
MEOW_ERR_NOMEM = -6,
|
||
MEOW_ERR_NOTINIT = -7,
|
||
MEOW_ERR_BUSY = -8,
|
||
MEOW_ERR_TIMEOUT = -9,
|
||
MEOW_ERR_NODEV = -10,
|
||
MEOW_ERR_INTERNAL = -255
|
||
};
|
||
|
||
/* ---- HELLO flags(附录 A 声明式权限)---- */
|
||
#define MF_BACKGROUND 0x00000001u /* 可后台常驻 */
|
||
#define MF_PLAYBACK 0x00000002u /* 后台音频/播放 */
|
||
|
||
/* ---- 标识/长度 ---- */
|
||
#define MEOW_APP_ID_MAX 32
|
||
#define MEOW_ACT_MAX 64
|
||
#define MEOW_CHAIN_MAX 160
|
||
|
||
/* ---- 负载结构(全部 LE;mipsel 原生对齐,字段 4 字节对齐)---- */
|
||
|
||
/* MSG_HELLO ↑:应用声明 */
|
||
typedef struct m_hello {
|
||
char app_id[MEOW_APP_ID_MAX];
|
||
uint32_t version;
|
||
uint32_t flags;
|
||
uint32_t caps; /* 预留能力位 */
|
||
} m_hello_t; /* 44 B */
|
||
|
||
/* MSG_ACK ↓:握手/应答 */
|
||
typedef struct m_ack {
|
||
uint32_t code; /* 0=MEOW_OK */
|
||
uint32_t status; /* 附加(如已注册 app 数) */
|
||
} m_ack_t; /* 8 B */
|
||
|
||
/* MSG_ERR ↓:错误码 + 短消息 */
|
||
typedef struct m_err {
|
||
uint32_t code;
|
||
uint16_t msg_len;
|
||
char msg[64];
|
||
} m_err_t;
|
||
|
||
/* MSG_ACT_QUERY ↑:解析某 app 的 activity 链路 */
|
||
typedef struct m_act_query {
|
||
char app_id[MEOW_APP_ID_MAX];
|
||
char activity[MEOW_ACT_MAX];
|
||
} m_act_query_t; /* 96 B */
|
||
|
||
/* MSG_ACT_FOCUS ↑:上报当前顶层 activity(keep_awake 判定,M2.17) */
|
||
typedef struct m_act_focus {
|
||
char app_id[MEOW_APP_ID_MAX];
|
||
char activity[MEOW_ACT_MAX];
|
||
} m_act_focus_t; /* 96 B */
|
||
|
||
/* MSG_ACT_RESULT ↓:返回链路(root..target),depth=链路逻辑深度 */
|
||
typedef struct m_act_result {
|
||
uint32_t depth;
|
||
uint32_t code; /* MEOW_OK / MEOW_ERR_NOENT(act 未注册) */
|
||
uint16_t chain_len; /* chain 有效字节 */
|
||
uint16_t pad;
|
||
char chain[MEOW_CHAIN_MAX];
|
||
} m_act_result_t; /* 172 B */
|
||
|
||
/* MSG_ACT_DECLARE ↑:运行时声明路由表。app_id + count 个 NUL 结尾字符串,
|
||
* 每串形如 "<route_id>=<chain>"(如 "nowplaying=home;search;nowplaying")。
|
||
* 守护进程并集覆盖静态 app.json 路由。 */
|
||
typedef struct m_act_declare {
|
||
char app_id[MEOW_APP_ID_MAX];
|
||
uint16_t count;
|
||
uint16_t pad;
|
||
char entries[MEOW_IPC_CARGO - MEOW_APP_ID_MAX - 4];
|
||
} m_act_declare_t;
|
||
|
||
/* MSG_NOTIFY ↑:推送/更新通知(freedesktop 对齐 + MeowOS 扩展;定长 LE)。
|
||
* - summary/body/app_icon/expire_timeout 直通 freedesktop 字段;app_icon 即 SDK `icon`
|
||
* (icon name 或 path;映射为空串时 launcher 用该 app 默认图标回退);
|
||
* - target_activity/progress 为 MeowOS 专有(存储层映射为 hints 的
|
||
* meow.target_activity / meow.progress);
|
||
* - urgency 为 MeowOS 扩展(0-3,缺省 NORMAL;旧调用置 0=旧 pad 位);
|
||
* - actions[]/hints{} v1 走定长空串(M2b D-Bus 桥再填);media/ongoing 标记。
|
||
* 宿主:NOTIFICATION_SYSTEM.md §2/§4 + FRAMEWORK_DESIGN §4/附C。 */
|
||
typedef struct m_notify {
|
||
char app_id[MEOW_APP_ID_MAX]; /* 来源应用;系统事件="system" */
|
||
char category[24]; /* 通知类型(媒体通知="media") */
|
||
char summary[64];
|
||
char body[96];
|
||
char app_icon[48]; /* SDK icon;空=launcher 按 app_id 回退 app 图标 */
|
||
char target_activity[MEOW_ACT_MAX]; /* MeowOS:点击跳转目标 activity */
|
||
uint32_t replaces_id; /* 0=新建;>0=替换已存在通知 */
|
||
uint32_t expire_timeout; /* ms;0xFFFFFFFF=ONGOING 常驻 */
|
||
int32_t progress; /* MeowOS:0-100;<0=无 */
|
||
uint8_t media; /* 1=媒体通知 */
|
||
uint8_t ongoing; /* 1=常驻通知 */
|
||
uint8_t urgency; /* 0-3(低/普通/高/紧急);越界由 SDK 钳位缺省 NORMAL;旧调用置 0=旧 pad 位 → LOW/静默 */
|
||
uint8_t pad;
|
||
} m_notify_t; /* 定长 LE;尾部 4 字节(media/ongoing/urgency/pad)与旧版 pad 等宽 */
|
||
|
||
/* MSG_NOTIFY_PROGRESS ↑:实时更新一条已存在通知的进度(仅改 launcher 内存活跃槽,
|
||
* 不落盘——TF 快照只在创建/结束(100% 或 dismiss)写)。 */
|
||
typedef struct m_notify_progress {
|
||
uint32_t nid; /* launcher 分配的通知 id(MSG_NOTIFY_ACK.status) */
|
||
int32_t progress; /* 0-100;<0=清除进度条 */
|
||
} m_notify_progress_t; /* 8 B */
|
||
|
||
#endif /* MEOW_IPC_H */
|