toolchain: replace ifc interface compiler with xpcg
xpcg is used to generate xpc interfaces
This commit is contained in:
114
toolchain/xpcg/msg.c
Normal file
114
toolchain/xpcg/msg.c
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "msg.h"
|
||||
|
||||
#include <blue/ds/string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct msg_definition *msg_definition_create(const char *name, long long id)
|
||||
{
|
||||
struct msg_definition *out = malloc(sizeof *out);
|
||||
if (!out) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(out, 0x0, sizeof *out);
|
||||
|
||||
out->msg_name = b_strdup(name);
|
||||
out->msg_id = id;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void msg_definition_destroy(struct msg_definition *msg)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_pop_front(&msg->msg_params);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
free(param->p_name);
|
||||
free(param);
|
||||
entry = b_queue_pop_front(&msg->msg_params);
|
||||
}
|
||||
|
||||
entry = b_queue_pop_front(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
free(param->p_name);
|
||||
free(param);
|
||||
entry = b_queue_pop_front(&msg->msg_results);
|
||||
}
|
||||
|
||||
free(msg->msg_name);
|
||||
free(msg);
|
||||
}
|
||||
|
||||
bool msg_definition_has_param(struct msg_definition *msg, const char *name)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_params);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
if (!strcmp(param->p_name, name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool msg_definition_has_result(struct msg_definition *msg, const char *name)
|
||||
{
|
||||
b_queue_entry *entry = b_queue_first(&msg->msg_results);
|
||||
while (entry) {
|
||||
struct msg_parameter *param
|
||||
= b_unbox(struct msg_parameter, entry, p_entry);
|
||||
if (!strcmp(param->p_name, name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
entry = b_queue_next(entry);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int msg_definition_add_param(
|
||||
struct msg_definition *msg,
|
||||
const struct type *type,
|
||||
const char *name)
|
||||
{
|
||||
struct msg_parameter *param = malloc(sizeof *param);
|
||||
if (!param) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(param, 0x0, sizeof *param);
|
||||
|
||||
param->p_type = type;
|
||||
param->p_name = b_strdup(name);
|
||||
|
||||
b_queue_push_back(&msg->msg_params, ¶m->p_entry);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int msg_definition_add_result(
|
||||
struct msg_definition *msg,
|
||||
const struct type *type,
|
||||
const char *name)
|
||||
{
|
||||
struct msg_parameter *param = malloc(sizeof *param);
|
||||
if (!param) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(param, 0x0, sizeof *param);
|
||||
|
||||
param->p_type = type;
|
||||
param->p_name = b_strdup(name);
|
||||
|
||||
b_queue_push_back(&msg->msg_results, ¶m->p_entry);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user