summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2020-05-14 10:07:34 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-06-02 12:32:36 +0200
commit16e45fa83efed48547d93deaddbbec7a79cd7793 (patch)
tree7142eb15cc1b3a4cf9cb8cce7f69477ff658ddc2
parenta63ec0ba7fa08b4f6e9c209d1f42e2d33366575a (diff)
#980 add procedure auto execution
Users can configure clients to execute a procedure at start. This commit adapt this functionality to new functions and behaviour of the ogAdmServer.
-rw-r--r--sources/ogAdmServer.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/sources/ogAdmServer.c b/sources/ogAdmServer.c
index 7537931..dbc46ef 100644
--- a/sources/ogAdmServer.c
+++ b/sources/ogAdmServer.c
@@ -185,6 +185,7 @@ struct og_client {
enum og_client_status status;
enum og_cmd_type last_cmd;
unsigned int last_cmd_id;
+ bool autorun;
};
static inline int og_client_socket(const struct og_client *cli)
@@ -1523,6 +1524,7 @@ struct og_computer {
unsigned int center;
unsigned int room;
char name[OG_COMPUTER_NAME_MAXLEN + 1];
+ unsigned int procedure_id;
};
#define OG_REST_PARAM_ADDR (1UL << 0)
@@ -4809,6 +4811,7 @@ static int og_dbi_get_computer_info(struct og_computer *computer,
"SELECT ordenadores.idordenador,"
" ordenadores.nombreordenador,"
" ordenadores.idaula,"
+ " ordenadores.idproautoexec,"
" centros.idcentro FROM ordenadores "
"INNER JOIN aulas ON aulas.idaula=ordenadores.idaula "
"INNER JOIN centros ON centros.idcentro=aulas.idcentro "
@@ -4831,6 +4834,7 @@ static int og_dbi_get_computer_info(struct og_computer *computer,
computer->id = dbi_result_get_uint(result, "idordenador");
computer->center = dbi_result_get_uint(result, "idcentro");
computer->room = dbi_result_get_uint(result, "idaula");
+ computer->procedure_id = dbi_result_get_uint(result, "idproautoexec");
strncpy(computer->name,
dbi_result_get_string(result, "nombreordenador"),
OG_COMPUTER_NAME_MAXLEN);
@@ -5069,12 +5073,36 @@ static int og_json_parse_partition_array(json_t *value,
return 0;
}
+static int og_dbi_queue_autorun(uint32_t computer_id, uint32_t proc_id)
+{
+ struct og_task dummy_task = {
+ .scope = computer_id,
+ .type_scope = AMBITO_ORDENADORES,
+ .procedure_id = proc_id,
+ };
+ struct og_dbi *dbi;
+
+ dbi = og_dbi_open(&dbi_config);
+ if (!dbi) {
+ syslog(LOG_ERR, "cannot open connection database "
+ "(%s:%d)\n", __func__, __LINE__);
+ return -1;
+ }
+ if (og_dbi_queue_procedure(dbi, &dummy_task)) {
+ og_dbi_close(dbi);
+ return -1;
+ }
+ og_dbi_close(dbi);
+
+ return 0;
+}
+
static int og_resp_refresh(json_t *data, struct og_client *cli)
{
struct og_partition partitions[OG_PARTITION_MAX] = {};
const char *serial_number = NULL;
+ struct og_computer computer = {};
struct og_partition disk_setup;
- struct og_computer computer;
char cfg[1024] = {};
struct og_dbi *dbi;
const char *key;
@@ -5150,6 +5178,13 @@ static int og_resp_refresh(json_t *data, struct og_client *cli)
return -1;
}
+ if (!cli->autorun && computer.procedure_id) {
+ cli->autorun = true;
+
+ if (og_dbi_queue_autorun(computer.id, computer.procedure_id))
+ return -1;
+ }
+
return 0;
}