summaryrefslogtreecommitdiff
path: root/mq_cmd.c
diff options
context:
space:
mode:
authorZoRo <dos21h@gmail.com>2017-01-26 22:23:28 +0000
committerZoRo <dos21h@gmail.com>2017-01-26 22:23:28 +0000
commit67860598185d248756316549a7522968f7294990 (patch)
treeb329576eca4f5dccbfec2bf7a4952abc93b8b9c8 /mq_cmd.c
parenta588aa017512d3cc70dde6627d1218020e755259 (diff)
downloadagni-67860598185d248756316549a7522968f7294990.tar.gz
agni-67860598185d248756316549a7522968f7294990.zip
Made working basic mq IPC communication
Diffstat (limited to 'mq_cmd.c')
-rw-r--r--mq_cmd.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/mq_cmd.c b/mq_cmd.c
index 7f1887a..ce48713 100644
--- a/mq_cmd.c
+++ b/mq_cmd.c
@@ -7,19 +7,29 @@ mq_cmd* mq_cmd_create(int id, char *cmd, size_t cmd_sz, char *param, size_t para
mq_cmd *ret = NULL;
if (cmd == NULL)
+ {
+ PERM();
return NULL;
+ }
if (param == NULL)
+ {
+ PERM();
return NULL;
+ }
ret = malloc(sizeof(mq_cmd));
if (ret == NULL)
+ {
+ ENL();
return NULL;
+ }
ret->id = id;
ret->sz = MQ_CMD_MSG_SIZE;
ret->buf = malloc(ret->sz);
if (!ret->buf)
{
+ ENL();
free(ret);
return NULL;
}
@@ -31,6 +41,25 @@ mq_cmd* mq_cmd_create(int id, char *cmd, size_t cmd_sz, char *param, size_t para
return ret;
}
+mq_cmd* mq_cmd_creates(char *str, size_t sz)
+{
+ mq_cmd *ret = NULL;
+
+ //just naive belive everything is fine in string
+ ret = malloc(sizeof(mq_cmd));
+ ret->buf = malloc(sz);
+ if (ret->buf == NULL)
+ {
+ PERM();
+ return NULL;
+ }
+ ret->sz = sz;
+ memcpy(ret->buf,str,sz);
+ ret->id = -1;
+
+ return ret;
+}
+
int mq_cmd_id(mq_cmd *cmd, int *id)
{
int i,j,strt,sz;
@@ -40,9 +69,15 @@ int mq_cmd_id(mq_cmd *cmd, int *id)
/*:[ID]:*/
if (cmd == NULL)
+ {
+ PERM();
return -1;
+ }
if (id == NULL)
+ {
+ PERM();
return -1;
+ }
i = 0;
while ((cmd->buf[i] != 0) && (i<cmd->sz))
@@ -84,11 +119,20 @@ char* mq_cmd_cmd(mq_cmd *cmd, char **buf, size_t *sz)
char *p;
if (cmd == NULL)
+ {
+ PERM();
return NULL;
+ }
if (buf == NULL)
+ {
+ PERM();
return NULL;
+ }
if (sz == NULL)
+ {
+ PERM();
return NULL;
+ }
p = cmd->buf;
@@ -164,6 +208,7 @@ size_t mq_cmd_size(mq_cmd *cmd)
{
if (cmd == NULL)
{
+ PERM();
return -1;
}
return cmd->sz;
@@ -173,6 +218,7 @@ char *mq_cmd_buf(mq_cmd *cmd)
{
if (cmd == NULL)
{
+ PERM();
return NULL;
}