blob: 8a939d5615a6ad115312b3d904758c542295df58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/*
* File Name: trigger_fan.c
* Workflow: on click send msg to MQ
* Return Value: 0 always
*/
/* Header files */
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/types.h>
#include "cgic.h"
#include "proto.h"
/* cgiMain, main in cgic.h */
int cgiMain() {
char fan_switch_bit = '0';
MQ_STRUCT *p_mq_struct = malloc(sizeof(MQ_STRUCT));
key_t msg_key;
int msg_id;
cgiFormString("fan_switch", &fan_switch_bit, 1);
memset(p_mq_struct, '\0', sizeof(MQ_STRUCT));
p_mq_struct->mtype = 20L;
switch (fan_switch_bit) {
case '0':
p_mq_struct->tswitch = 0;
break;
case '1':
p_mq_struct->tswitch = 1;
break;
}
msg_key = ftok("/usr/bin/boa", 'q');
msg_id = msgget(msg_key, 0600);
msgsnd(msg_id, p_mq_struct, sizeof(MQ_STRUCT) - sizeof(long), 0);
free(p_mq_struct);
return 0;
}
|