summaryrefslogtreecommitdiff
path: root/agni.c
diff options
context:
space:
mode:
Diffstat (limited to 'agni.c')
-rw-r--r--agni.c53
1 files changed, 41 insertions, 12 deletions
diff --git a/agni.c b/agni.c
index 79b8441..32b3e12 100644
--- a/agni.c
+++ b/agni.c
@@ -22,6 +22,7 @@
#include "darray.h"
#include "buf.h"
#include "mq_cmd.h"
+#include "tbl_qcmd.h"
/*
no defence programming, no error checking, no argument checking just PoC
@@ -49,6 +50,23 @@ int irc_connect( char *hostname, char *port )
return fd;
}
+/*
+return unique ID, with atomic counter should work in all cases
+*/
+_Atomic int _glbl_id=0;
+int uniq_id()
+{
+ int ret=-1,id;
+
+ //what possible could go wrong?
+ id = atomic_load(&_glbl_id);
+ ret = id;
+ id += 1;
+ atomic_store(&_glbl_id, id);
+ return ret;
+
+}
+
//async io multiplexer
typedef struct mq_ntf_io_mplx
{
@@ -515,7 +533,7 @@ int recv_mq_cmd(mq_ntf_mdt *mq,
recv_sz = err;
//in err should be still the size of recieved buffer
- cmd_recv = mq_cmd_creates(in_buf, recv_sz);
+ cmd_recv = mq_cmd_creates(in_buf, recv_sz, 0);
if (cmd_recv == NULL)
{
printf("Cannot create cmd\n");
@@ -596,12 +614,12 @@ int th_start_client(void *data)
while (run)
{
//printf("Send msg\n");
- err = SEND_CMD_OUT(mq,cmd_id,"INIT","NO");
+ err = SEND_CMD_OUT(mq,cmd_id,"FROM_CLIENT","NO");
printf("err = %d\n",err);
cmd_id += 1;
run += 1;
sleep(1);
- if (run == 10)
+ if (run == 2)
{
break;
}
@@ -641,7 +659,7 @@ int th_event_manager(void *data)
event_handler_cfg *cfg = data;
atomic_fetch_add(&cfg->running,1);
mq_ntf_mdt *mq=NULL;
- char *buf = NULL;
+ char *out_buf = NULL;
int run;
int err;
int mq_event;
@@ -663,14 +681,14 @@ int th_event_manager(void *data)
printf("Cant get attribute\n");
}
- buf = malloc(out_attr.mq_msgsize);
+ out_buf = malloc(out_attr.mq_msgsize);
//maybe its not null
printf("Start event loop\n");
run = 1;
while(run)
{
- //check for messages
+ //check if there is some message and save it to buffer
run += 1;
mq_event = mq_ntf_select(mq);
switch(mq_event)
@@ -680,23 +698,31 @@ int th_event_manager(void *data)
case 1:
break;
case 2:
- if (mq_ntf_read(mq, MQ_OUT, buf, out_attr.mq_msgsize) == -1)
+ if (mq_ntf_read(mq, MQ_OUT, out_buf, out_attr.mq_msgsize) == -1)
{
printf("Cant read message\n");
} else
{
- buf[out_attr.mq_msgsize-1] = 0x0;
- printf("Recieve %s\n", buf);
+ out_buf[out_attr.mq_msgsize-1] = 0x0;
+ printf("Recieve %s\n", out_buf);
}
break;
default:
printf("Unknown event type\n");
}
sleep(1);
- if (run == 10)
- break;
- }
+ //if (run == 10)
+ // break;
+
+ //applay to recieved command executor
+ //if QUIT then quit the thread
+ //other command pass to cmd/execution matching table
+ //pass to exec handler
+ //get response if command is immidieate otherwise wait for response in next execution
+
+ }
+ free(out_buf);
printf("End event thread\n");
atomic_fetch_sub( &cfg->running,1);
@@ -712,6 +738,9 @@ int main(int argc, char **argv)
event_handler_cfg *evhnd_cfg;
mq_ntf_mdt *mq_array;
+ /*set atomic variables to init value*/
+ atomic_store(&_glbl_id, 0);
+
/* Load configuration */
cnt_servers = SIZEOF_SERVER_LIST;
for (i=0;i<SIZEOF_SERVER_LIST;i++)