mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-28 12:30:58 +00:00
clang-format *ALL* the things!
PUBLISHED_FROM=faf0beb7545eb426c941fc366b6f87667723eb4c
This commit is contained in:
1 parent
dcf1cedec9
commit
183fc7ced9
22 files changed
+96
-88
No files matched your search
@@ -34,8 +34,10 @@ static void push_frame_to_clients(struct mg_mgr *mgr,
|
||||
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
|
||||
if (!(nc->flags & MG_F_USER_2)) continue; // Ignore un-marked requests
|
||||
|
||||
mg_printf(nc, "--w00t\r\nContent-Type: image/jpeg\r\n"
|
||||
"Content-Length: %lu\r\n\r\n", (unsigned long) wm->size);
|
||||
mg_printf(nc,
|
||||
"--w00t\r\nContent-Type: image/jpeg\r\n"
|
||||
"Content-Length: %lu\r\n\r\n",
|
||||
(unsigned long) wm->size);
|
||||
mg_send(nc, wm->data, wm->size);
|
||||
mg_send(nc, "\r\n", 2);
|
||||
printf("Image pushed to %p\n", nc);
|
||||
@@ -50,7 +52,8 @@ static void send_command_to_the_device(struct mg_mgr *mgr,
|
||||
const struct mg_str *cmd) {
|
||||
struct mg_connection *nc;
|
||||
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
|
||||
if (!(nc->flags & MG_F_IS_WEBSOCKET)) continue; // Ignore non-websocket requests
|
||||
if (!(nc->flags & MG_F_IS_WEBSOCKET))
|
||||
continue; // Ignore non-websocket requests
|
||||
|
||||
mg_send_websocket_frame(nc, WEBSOCKET_OP_TEXT, cmd->p, cmd->len);
|
||||
printf("Sent API command [%.*s] to %p\n", (int) cmd->len, cmd->p, nc);
|
||||
@@ -75,15 +78,15 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
switch (ev) {
|
||||
case MG_EV_HTTP_REQUEST:
|
||||
if (mg_vcmp(&hm->uri, "/mjpg") == 0) {
|
||||
nc->flags |= MG_F_USER_2; /* Set a mark on image requests */
|
||||
nc->flags |= MG_F_USER_2; /* Set a mark on image requests */
|
||||
mg_printf(nc, "%s",
|
||||
"HTTP/1.0 200 OK\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Type: multipart/x-mixed-replace; "
|
||||
"boundary=--w00t\r\n\r\n");
|
||||
"HTTP/1.0 200 OK\r\n"
|
||||
"Cache-Control: no-cache\r\n"
|
||||
"Pragma: no-cache\r\n"
|
||||
"Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
|
||||
"Connection: close\r\n"
|
||||
"Content-Type: multipart/x-mixed-replace; "
|
||||
"boundary=--w00t\r\n\r\n");
|
||||
} else if (mg_vcmp(&hm->uri, "/api") == 0 && hm->body.len > 0) {
|
||||
/*
|
||||
* RESTful API call. HTTP message body should be a JSON message.
|
||||
@@ -129,13 +132,13 @@ int main(int argc, char *argv[]) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
mg_set_protocol_http_websocket(nc);
|
||||
web_root_opts.document_root = "./web_root";
|
||||
web_root_opts.document_root = "./web_root";
|
||||
|
||||
/*
|
||||
* We explicitly hand over control to the Mongoose manager
|
||||
* in this event loop and we can easily multiplex other activities.
|
||||
*/
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 1000);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ static void send_mjpg_frame(struct mg_connection *nc, const char *file_path) {
|
||||
|
||||
/* Send those buffer through the websocket connection */
|
||||
mg_send_websocket_frame(nc, WEBSOCKET_OP_BINARY, buf, sizeof(buf));
|
||||
printf("Sent mjpg frame, %lu bytes after skippping %d frames\n", (unsigned long) sizeof(buf), skipped_frames);
|
||||
printf("Sent mjpg frame, %lu bytes after skippping %d frames\n",
|
||||
(unsigned long) sizeof(buf), skipped_frames);
|
||||
skipped_frames = 0;
|
||||
}
|
||||
}
|
||||
@@ -64,8 +65,10 @@ static void send_mjpg_frame(struct mg_connection *nc, const char *file_path) {
|
||||
*/
|
||||
static void set_led(int v) {
|
||||
char cmd[512];
|
||||
snprintf(cmd, sizeof(cmd), "for i in 22 23 24; do"
|
||||
" echo %d >/sys/class/gpio/gpio$i/value; done", v);
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"for i in 22 23 24; do"
|
||||
" echo %d >/sys/class/gpio/gpio$i/value; done",
|
||||
v);
|
||||
system(cmd);
|
||||
}
|
||||
|
||||
@@ -73,7 +76,7 @@ static void set_led(int v) {
|
||||
* Parse control JSON and perform command:
|
||||
* for now only LED on/off is supported.
|
||||
*/
|
||||
static void perform_control_command(const char* data, size_t len) {
|
||||
static void perform_control_command(const char *data, size_t len) {
|
||||
struct json_token toks[200], *onoff;
|
||||
parse_json(data, len, toks, sizeof(toks));
|
||||
onoff = find_json_token(toks, "onoff");
|
||||
@@ -86,16 +89,16 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
|
||||
switch (ev) {
|
||||
case MG_EV_CONNECT:
|
||||
printf("Reconnect: %s\n", * (int *) ev_data == 0 ? "ok" : "failed");
|
||||
if (* (int *) ev_data == 0) {
|
||||
printf("Reconnect: %s\n", *(int *) ev_data == 0 ? "ok" : "failed");
|
||||
if (*(int *) ev_data == 0) {
|
||||
/*
|
||||
* Tune the tcp send buffer size, so that we can skip frames
|
||||
* when the connection is congested. This helps maintaining a
|
||||
* reasonable latency.
|
||||
*/
|
||||
int sndbuf_size = 512;
|
||||
if(setsockopt(nc->sock, SOL_SOCKET, SO_SNDBUF,
|
||||
(void *) &sndbuf_size, sizeof(int)) == -1) {
|
||||
if (setsockopt(nc->sock, SOL_SOCKET, SO_SNDBUF, (void *) &sndbuf_size,
|
||||
sizeof(int)) == -1) {
|
||||
perror("failed to tune TCP send buffer size\n");
|
||||
}
|
||||
|
||||
@@ -111,7 +114,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
break;
|
||||
case MG_EV_WEBSOCKET_FRAME:
|
||||
printf("Got control command: [%.*s]\n", (int) wm->size, wm->data);
|
||||
perform_control_command((const char*)wm->data, wm->size);
|
||||
perform_control_command((const char *) wm->data, wm->size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -124,11 +127,13 @@ static void *generate_mjpg_data_thread_func(void *param) {
|
||||
char cmd[400];
|
||||
(void) param;
|
||||
|
||||
snprintf(cmd, sizeof(cmd), "raspistill -w %d -h %d -n -q 100 -tl %d "
|
||||
"-t 999999999 -v %s -o %s >/dev/null 2>&1", s_width, s_height,
|
||||
s_still_period, s_vertical_flip ? "-vf" : "", s_mjpg_file);
|
||||
snprintf(cmd, sizeof(cmd),
|
||||
"raspistill -w %d -h %d -n -q 100 -tl %d "
|
||||
"-t 999999999 -v %s -o %s >/dev/null 2>&1",
|
||||
s_width, s_height, s_still_period, s_vertical_flip ? "-vf" : "",
|
||||
s_mjpg_file);
|
||||
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
int ret = system(cmd);
|
||||
if (WIFSIGNALED(ret)) exit(1);
|
||||
sleep(1);
|
||||
@@ -152,7 +157,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
mg_mgr_init(&mgr, NULL);
|
||||
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, s_poll_interval_ms);
|
||||
|
||||
/* Reconnect if disconnected */
|
||||
|
||||
Reference in new issue
Block a user