aboutsummaryrefslogtreecommitdiffstats
path: root/tbl_qcmd.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-03-04 01:38:56 +0000
committerFreeArtMan <dos21h@gmail.com>2017-03-04 01:38:56 +0000
commit65e7a20b5d440b0c224a665fccdb5c9d475fa509 (patch)
tree421fd088737379b671b55eaf8c4c0022c6eee949 /tbl_qcmd.c
parent6e883c423473bb7a7cc72432d0afe55a34bdfa49 (diff)
downloadagni-65e7a20b5d440b0c224a665fccdb5c9d475fa509.tar.gz
agni-65e7a20b5d440b0c224a665fccdb5c9d475fa509.zip
execution table improvments
Diffstat (limited to 'tbl_qcmd.c')
-rw-r--r--tbl_qcmd.c96
1 files changed, 74 insertions, 22 deletions
diff --git a/tbl_qcmd.c b/tbl_qcmd.c
index 261259d..7045af9 100644
--- a/tbl_qcmd.c
+++ b/tbl_qcmd.c
@@ -13,15 +13,16 @@ tbl_exec *tbl_exec_list_c(int size)
MVAR_ALLOC_STRC(ret,tbl_exec,{
return NULL;});
+ ret->id = uniq_id();
ret->size = 0;
ret->max_size = size;
- MVAR_ALLOC_ARR(reg_cmd,tble_exec*,size,{
+ MVAR_ALLOC_ARR(cmd,tble_exec*,size,{
free(ret);
return NULL;
})
- ret->reg_cmd = reg_cmd;
+ ret->cmd = cmd;
return ret;
}
@@ -34,7 +35,7 @@ int tbl_exec_add(tbl_exec *tbl, tble_exec *cmd)
return -1;
}
- tbl->reg_cmd[tbl->size] = cmd;
+ tbl->cmd[tbl->size] = cmd;
if (tbl->size+1<tbl->max_size)
{
tbl->size += 1;
@@ -51,24 +52,34 @@ int tbl_exec_in_s(tbl_exec *tbl, char *cmd)
return -1;
}
-tble_exec *tbl_exec_search_cmd(tbl_exec *tbl, char *cmd)
+tble_exec *tbl_exec_search_cmd(tbl_exec *tbl, tble_qcmd *cmd)
{
tble_exec *ret = NULL;
- tble_exec *cur_cmd = NULL;
+ tble_exec *cur_exec = NULL;
int i;
if ((tbl == NULL)||(cmd == NULL))
{
+ PERM();
+ return NULL;
+ }
+
+ if (tbl->id != cmd->tid)
+ {
+ PERM();
return NULL;
}
for (i=0;i<tbl->max_size;i++)
{
- cur_cmd = tbl->reg_cmd[i];
- if ((strncmp(cur_cmd->cmd,cmd,strlen(cmd)) == 0) &&
- (strlen(cmd) == strlen(cur_cmd->cmd)))
+ cur_exec = tbl->cmd[i];
+ //command match
+ if ((strncmp(cur_exec->cmd, cmd->cmd, strlen(cmd->cmd)) == 0) &&
+ (strlen(cur_exec->cmd) == strlen(cmd->cmd)))
+ // command id and exec id match
+ if (cur_exec->id == cmd->tidx)
{
- ret = cur_cmd;
+ ret = cur_exec;
break;
}
}
@@ -121,7 +132,7 @@ int tbl_exec_print_tbl(tbl_exec *tbl, int flags)
for (i=0; i<tbl->size; i++)
{
- el = tbl->reg_cmd[i];
+ el = tbl->cmd[i];
if (el != NULL)
{
printf(">%02d< ",i);
@@ -144,6 +155,7 @@ tbl_qcmd* tbl_qcmd_c(int size)
MVAR_ALLOC_STRC(ret,tbl_qcmd,{
return NULL;});
+ ret->id = uniq_id();
ret->size = 0;
ret->max_size = size;
@@ -158,21 +170,43 @@ tbl_qcmd* tbl_qcmd_c(int size)
return ret;
}
-int tbl_qcmd_set_exec(tble_qcmd *qcmd, tble_exec *exec)
+
+int tbl_qcmd_exec(tbl_qcmd *tcmd, tbl_exec *texec)
{
- int ret = -1;
+ int ret=-1;
+ int i,j;
- if ((qcmd == NULL) || (exec == NULL))
+ if (tcmd == NULL)
+ {
+ PERM();
return -1;
+ }
- //set executed command
- qcmd->cmd = alloc_new_str(exec->cmd);
- qcmd->state = QCMD_PREPARE;
- qcmd->idx_exec = exec->id;
+ if (texec == NULL)
+ {
+ PERM();
+ return -1;
+ }
- ret = 0;
+ //EFFICIENT CODE MATE
+ //search for commands that are in NONE state
+ for (i=0; i<tcmd->size; i++)
+ {
+ tble_qcmd *tc = tcmd->cmd[i];
+ if (tc->state == QCMD_INIT)
+ for (j=0;j<texec->size;j++)
+ {
+ tble_exec *e = texec->cmd[j];
+ if (strncmp(e->cmd, tc->cmd, strlen(e->cmd)) == 0)
+ {
+ tc->tid = texec->id; //save table id
+ tc->tidx = e->id; //set executor id
+ tc->state = QCMD_READY; //change state, that we ready to be executed
+ }
+ }
+ }
- return ret;
+ return 0;
}
@@ -181,6 +215,9 @@ int tbl_qcmd_add(tbl_qcmd *tbl, tble_qcmd *cmd)
if (tbl == NULL || cmd == NULL)
return -1;
cmd->id = uniq_id();
+ //all command that are just added will be in zero state
+ //should match to some executot then can change state
+ cmd->state = QCMD_INIT;
tbl->cmd[tbl->size] = cmd;
if (tbl->size+1<tbl->max_size)
{
@@ -277,6 +314,17 @@ int tbl_qcmd_resp(tbl_qcmd *tbl, tble_cmd_resp *resp)
tble_cmd_param* tbl_cmd_param(tble_qcmd *cmd)
{
+ if (cmd == NULL)
+ {
+ return NULL;
+ }
+
+ if (cmd->state != QCMD_READY)
+ {
+ PERM();
+ return NULL;
+ }
+
MVAR_ALLOC_STRC(ret,tble_cmd_param,{
PERM();
@@ -361,7 +409,7 @@ int tbl_cmd_resp_print(tble_cmd_resp *resp)
printf("QID:[%d] ", resp->qid);
printf("TYPE:[%d] ", resp->type);
printf("RET_CODE:[%d] ", resp->ret_code);
- printf("RESP:[%d] ", resp->resp);
+ printf("RESP:[%s] ", resp->resp);
printf("\n");
return 0;
@@ -410,9 +458,13 @@ int tbl_qcmd_print_cmd(tble_qcmd *tbl, int flags)
{
printf("IN_Q:[%d] ", tbl->in_q);
}
- if (flags&TBL_PF_QCMD_IDX_EXEC)
+ if (flags&TBL_PF_QCMD_TID)
+ {
+ printf("TID:[%d] ", tbl->tid);
+ }
+ if (flags&TBL_PF_QCMD_TIDX)
{
- printf("IDX_EXEC:[%d] ", tbl->idx_exec);
+ printf("TIDX:[%d] ", tbl->tidx);
}
printf("\n");