Browse Source

Add submodules and project sceleton

Ilja Kartašov 2 months ago
parent
commit
06a69f0edd
18 changed files with 763 additions and 0 deletions
  1. 7
    0
      .gitignore
  2. 6
    0
      .gitmodules
  3. 77
    0
      Makefile
  4. 1
    0
      cStuff
  5. 3
    0
      data/arcd.config
  6. 77
    0
      project.mk
  7. 1
    0
      sdk
  8. 37
    0
      src/agent.c
  9. 31
    0
      src/agent.h
  10. 58
    0
      src/config.h
  11. 37
    0
      src/end-points.h
  12. 33
    0
      src/html.c
  13. 26
    0
      src/html.h
  14. 26
    0
      src/log.h
  15. 142
    0
      src/main.c
  16. 155
    0
      src/observer.c
  17. 34
    0
      src/observer.h
  18. 12
    0
      todo.txt

+ 7
- 0
.gitignore View File

@@ -0,0 +1,7 @@
1
+build/
2
+*.tar.gz
3
+*.zip
4
+*.rar
5
+*.gz
6
+*.bz2
7
+*.vgcore

+ 6
- 0
.gitmodules View File

@@ -0,0 +1,6 @@
1
+[submodule "sdk"]
2
+	path = sdk
3
+	url = git@lowenware.com:lowenware/aisl-sdk.git
4
+[submodule "cStuff"]
5
+	path = cStuff
6
+	url = git@lowenware.com:lowenware/cStuff.git

+ 77
- 0
Makefile View File

@@ -0,0 +1,77 @@
1
+#
2
+# Makefile
3
+# Ilja Kartašov, 2019-03-02 17:32
4
+#
5
+.POSIX:
6
+
7
+# Project directories
8
+SRC_DIR ?= src
9
+SDK_DIR ?= sdk
10
+CSTUFF_DIR ?= cStuff
11
+OUT_DIR ?= ./build
12
+
13
+# Project definition
14
+include project.mk
15
+
16
+# CFLAGS
17
+
18
+CFLAGS := \
19
+  $(PROJECT_INCLUDES) \
20
+  -std=c99 \
21
+  -pedantic \
22
+  -Wall \
23
+  -Wmissing-prototypes \
24
+  -Wstrict-prototypes \
25
+  -Wold-style-definition \
26
+  -O2 \
27
+  -s \
28
+  -fvisibility=hidden \
29
+  -DVERSION_MAJOR=$(PROJECT_VERSION_MAJOR) \
30
+  -DVERSION_MINOR=$(PROJECT_VERSION_MINOR) \
31
+  -DVERSION_TWEAK=$(PROJECT_VERSION_TWEAK) \
32
+  -DVERSION_LABEL=$(PROJECT_VERSION_LABEL) \
33
+  $(PROJECT_CFLAGS) \
34
+  $(CFLAGS) \
35
+
36
+
37
+LDFLAGS := \
38
+  $(PROJECT_LIBRARIES) \
39
+  $(LDFLAGS) \
40
+  $(PROJECT_LDFLAGS) \
41
+
42
+
43
+SOURCE_LIST := $(wildcard $(PROJECT_SOURCES))
44
+OBJECT_FILES := $(addprefix $(OUT_DIR)/o_, ${SOURCE_LIST:.c=.o})
45
+
46
+
47
+project: dirs $(OBJECT_FILES)
48
+	$(info linking target: $@)
49
+	@$(CC) -o $(OUT_DIR)/$(PROJECT_NAME) $(OBJECT_FILES) $(LDFLAGS)
50
+	$(info done: $@)
51
+
52
+
53
+build/o_%.o: %.c
54
+	$(info compiling file: $<)
55
+	@$(CC) $(CFLAGS) -c $< -o $@
56
+
57
+dirs:
58
+	$(info preparing: build folders)
59
+	@mkdir -p $(OUT_DIR)/o_$(SRC_DIR)
60
+	@mkdir -p $(OUT_DIR)/o_$(CSTUFF_DIR)
61
+	@mkdir -p $(OUT_DIR)/o_$(SDK_DIR)/components
62
+	@mkdir -p $(OUT_DIR)/o_$(SDK_DIR)/mods
63
+
64
+
65
+clean:
66
+	$(info cleaning: build files)
67
+	@rm -Rf $(OUT_DIR)
68
+	@rm -Rf ./vgcore.*
69
+
70
+
71
+all: project
72
+
73
+default: project
74
+.PHONY:  all dirs clean
75
+
76
+# vim:ft=make
77
+#

+ 1
- 0
cStuff

@@ -0,0 +1 @@
1
+Subproject commit 4ba00ca17a6a86a9309fe8426220cc378d8f4579

+ 3
- 0
data/arcd.config View File

@@ -0,0 +1,3 @@
1
+agent:
2
+	surgard-1 = surgard-serial:///dev/ttyUSB0/?speed=9600
3
+	osm-1 = osm://127.0.0.1/

+ 77
- 0
project.mk View File

@@ -0,0 +1,77 @@
1
+#
2
+# config.mk
3
+# Löwenware Makefile Config, 2019-03-02 17:35
4
+#
5
+
6
+PREFIX = /usr/
7
+PKG_CONFIG = pkg-config
8
+
9
+PROJECT_NAME = arcd
10
+
11
+# Version
12
+
13
+PROJECT_VERSION_MAJOR = 1
14
+PROJECT_VERSION_MINOR = 0
15
+PROJECT_VERSION_TWEAK = 0
16
+PROJECT_VERSION_LABEL = 0
17
+
18
+# Override default paths
19
+#SRC_DIR = src
20
+#SDK_DIR = sdk
21
+#OUT_DIR = ./build
22
+
23
+
24
+# Source files
25
+
26
+PROJECT_SOURCES := \
27
+  $(SRC_DIR)/main.c \
28
+  $(SRC_DIR)/observer.c \
29
+  $(SRC_DIR)/agent.c \
30
+  \
31
+  $(CSTUFF_DIR)/log.c \
32
+  $(CSTUFF_DIR)/string.c \
33
+  $(CSTUFF_DIR)/list.c \
34
+  $(CSTUFF_DIR)/file.c \
35
+  \
36
+  $(SDK_DIR)/components/query.c \
37
+  $(SDK_DIR)/components/quick.c \
38
+  $(SDK_DIR)/components/validate.c \
39
+  $(SDK_DIR)/components/mail.c \
40
+  $(SDK_DIR)/components/log.c \
41
+  $(SDK_DIR)/components/todo.c \
42
+  \
43
+  $(SDK_DIR)/mods/context.c \
44
+  $(SDK_DIR)/mods/module.c \
45
+
46
+
47
+
48
+# includes
49
+PROJECT_INCLUDES = \
50
+  -I./ \
51
+  -I./$(SDK_DIR) \
52
+  `$(PKG_CONFIG) --cflags libaisl` \
53
+  `$(PKG_CONFIG) --cflags libcurl` \
54
+  `$(PKG_CONFIG) --cflags uuid` \
55
+
56
+# libraries
57
+PROJECT_LIBRARIES = \
58
+  `$(PKG_CONFIG) --libs libaisl` \
59
+  `$(PKG_CONFIG) --libs libcurl` \
60
+  `$(PKG_CONFIG) --libs uuid` \
61
+	-lpthread \
62
+
63
+# compilation macro options:
64
+
65
+# flags
66
+PROJECT_CFLAGS  = -D_POSIX_C_SOURCE=200809L
67
+PROJECT_CFLAGS += -D_ISOC99_SOURCE
68
+PROJECT_CFLAGS += -D_XOPEN_SOURCE=500
69
+PROJECT_CFLAGS += -D_GNU_SOURCE
70
+# PROJECT_CFLAGS += -DDEBUG
71
+
72
+
73
+# PROJECT_LDFLAGS = -L
74
+
75
+
76
+# vim:ft=make
77
+#

+ 1
- 0
sdk

@@ -0,0 +1 @@
1
+Subproject commit e00ffe6f708f1460ca1d2b00d94c739ebb2cb184

+ 37
- 0
src/agent.c View File

@@ -0,0 +1,37 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file agent.c
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief 
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#include "agent.h"
17
+
18
+
19
+int
20
+agent_init(void)
21
+{
22
+	return 0;
23
+}
24
+
25
+
26
+void
27
+agent_release(void)
28
+{
29
+
30
+}
31
+
32
+
33
+int
34
+agent_run_cycle(void)
35
+{
36
+	return 1;
37
+}

+ 31
- 0
src/agent.h View File

@@ -0,0 +1,31 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file agent.h
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief 
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#ifndef AGENT_H_D0CDB429_AC49_4BC6_83FA_9163404D387E
17
+#define AGENT_H_D0CDB429_AC49_4BC6_83FA_9163404D387E
18
+
19
+
20
+int
21
+agent_init(void);
22
+
23
+
24
+void
25
+agent_release(void);
26
+
27
+
28
+int
29
+agent_run_cycle(void);
30
+
31
+#endif /* !AGENT_H */

+ 58
- 0
src/config.h View File

@@ -0,0 +1,58 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file config.h
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief 
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#ifndef CONFIG_H_18E4DCB3_B446_424F_9E5E_06DC15FA40BA
17
+#define CONFIG_H_18E4DCB3_B446_424F_9E5E_06DC15FA40BA
18
+
19
+/** Default HTTP server port */
20
+#ifndef CONFIG_HTTP_PORT
21
+#define CONFIG_HTTP_PORT 8080
22
+#endif
23
+
24
+#ifndef CONFIG_LOG_TARGET 
25
+#define CONFIG_LOG_TARGET "output.log"
26
+#endif
27
+
28
+#ifndef CONFIG_SMTP_SERVER
29
+#define CONFIG_SMTP_SERVER "mx.lowenware.com"
30
+#endif
31
+
32
+#ifndef CONFIG_SMTP_PORT
33
+#define CONFIG_SMTP_PORT 465
34
+#endif
35
+
36
+#ifndef CONFIG_SMTP_USER
37
+#define CONFIG_SMTP_USER "robot@lowenware.com"
38
+#endif
39
+
40
+#ifndef CONFIG_SMTP_PASS
41
+#define CONFIG_SMTP_PASS "3HFzxiQYY9QJ6LN3" /* +){xA8}(mNF43B(~" */
42
+#endif
43
+
44
+#ifndef CONFIG_MAIL_FROM
45
+#define CONFIG_MAIL_FROM CONFIG_SMTP_USER
46
+#endif
47
+
48
+#ifndef CONFIG_MAIL_TO
49
+#define CONFIG_MAIL_TO "ik@lowenware.com"
50
+#endif
51
+
52
+#ifndef CONFIG_MAIL_SUBJECT
53
+#define CONFIG_MAIL_SUBJECT "Feedback from website"
54
+#endif
55
+
56
+
57
+
58
+#endif /* !CONFIG_H */

+ 37
- 0
src/end-points.h View File

@@ -0,0 +1,37 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file end-points.h
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief Header-file only module with end-points URI macroses
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#ifndef END_POINTS_H_406472C7_FC75_41D5_8988_AA12455597EC
17
+#define END_POINTS_H_406472C7_FC75_41D5_8988_AA12455597EC
18
+
19
+
20
+#define ROOT_URI "/"
21
+#define HOOK_URI "/hook/"
22
+#define BLOG_URI "/blog/"
23
+#define TODO_URI "/todo/"
24
+
25
+/* Pages */
26
+
27
+/* Blog */
28
+
29
+/* Static */
30
+
31
+/* ToDo */
32
+#define TODO_END_POINT TODO_URI
33
+
34
+/* Hooks */
35
+#define FEEDBACK_END_POINT HOOK_URI "feedback/"
36
+
37
+#endif /* !END_POINTS_H */

+ 33
- 0
src/html.c View File

@@ -0,0 +1,33 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file html.c
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief 
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#include "html.h"
17
+
18
+typedef enum {
19
+
20
+	HTML_HEADER = 0,
21
+	HTML_MENU = 20,
22
+	HTML_FOOTER = 100
23
+
24
+} HtmlSequence;
25
+
26
+
27
+const struct html html[] = {
28
+	  {7, 0, 0, "<html>\n"}
29
+	, {7, 1, 0, "<head>\n"}
30
+	, {7, 2, 0, "<title>"},
31
+	, {9, 2, 0, "</title>\n"},
32
+	, {8, 1, 0, "</head>\n"},
33
+};

+ 26
- 0
src/html.h View File

@@ -0,0 +1,26 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file html.h
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief 
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#ifndef HTML_H_43FF7C60_6224_40DF_B3C6_6E4E18350871
17
+#define HTML_H_43FF7C60_6224_40DF_B3C6_6E4E18350871
18
+
19
+struct html {
20
+	uint32_t size;
21
+	uint16_t offset;
22
+	uint16_t reserve;
23
+	const char *data;
24
+};
25
+
26
+#endif /* !HTML_H */

+ 26
- 0
src/log.h View File

@@ -0,0 +1,26 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file log.h
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief 
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#ifndef LOG_H_33B3B660_C0F7_455F_A17D_AB4FD0C0FD2C
17
+#define LOG_H_33B3B660_C0F7_455F_A17D_AB4FD0C0FD2C
18
+
19
+#include <components/log.h>
20
+
21
+#define LOG_DEBUG(...) AX_LOG_DEBUG(__VA_ARGS__)
22
+#define LOG_STATE(...) AX_LOG_STATE(__VA_ARGS__)
23
+#define LOG_ALERT(...) AX_LOG_ALERT(__VA_ARGS__)
24
+#define LOG_ERROR(...) AX_LOG_ERROR(__VA_ARGS__)
25
+
26
+#endif /* !LOG_H */

+ 142
- 0
src/main.c View File

@@ -0,0 +1,142 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file main.c
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief Lowenware.com backend main source code file
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#include <stdio.h>
17
+#include <stdlib.h>
18
+#include <string.h>
19
+#include <unistd.h>
20
+#include <errno.h>
21
+#include <locale.h>
22
+
23
+/* Include library meta header */
24
+#include <aisl/aisl.h>
25
+#include "log.h"
26
+#include "config.h"
27
+#include "observer.h"
28
+#include "agent.h"
29
+
30
+
31
+static const struct aisl_cfg_srv m_srv[] = {{
32
+  .host   = "0.0.0.0",
33
+  .port   = CONFIG_HTTP_PORT,
34
+  .secure = false
35
+}};
36
+
37
+
38
+static const struct aisl_cfg m_cfg = {
39
+	  AISL_CFG_DEFAULTS
40
+	, .srv = m_srv
41
+	, .srv_cnt = sizeof (m_srv) / sizeof (m_srv[0])
42
+	, .ssl = NULL
43
+	, .ssl_cnt = 0
44
+	, .callback = observer_on_aisl_event
45
+};
46
+
47
+
48
+static int
49
+process_args(int argc, char **argv)
50
+{
51
+	int i;
52
+	char c = 0;
53
+
54
+	for (i = 1; i < argc; i++) {
55
+		switch (c) {
56
+		case 'd':
57
+			if (chdir(argv[i]) != 0) {
58
+				LOG_ERROR("Failed to set working directory `%s`: %s", argv[i],
59
+						strerror(errno));
60
+				return -1;
61
+			}
62
+			break;
63
+
64
+		default:
65
+			if (strcmp(argv[i], "-d") == 0) {
66
+				c = 'd';
67
+			} else if (strcmp(argv[i], "-h") == 0) {
68
+				printf("arcd %d.%d.%d\n\n", VERSION_MAJOR, VERSION_MINOR, VERSION_TWEAK);
69
+				printf("USAGE: arcd [ARGUMENTS]\n");
70
+				printf("ARGUMENTS:\n");
71
+				printf("\t-h      - show this information\n");
72
+				printf("\t-d :dir - set custom working directory\n");
73
+				printf("\n");
74
+				exit(0);
75
+			}
76
+			continue;
77
+		}
78
+		c = 0;
79
+	}
80
+
81
+	if (c) {
82
+		LOG_ERROR("No value for -%c argument", c);
83
+		return -1;
84
+	}
85
+
86
+	return 0;
87
+}
88
+
89
+
90
+int
91
+main(int argc, char **argv)
92
+{
93
+	AislInstance aisl;    /**< AISL instance pointer */
94
+	char cwd[64];
95
+
96
+	AX_LOG_INIT(CSTUFF_LOG_ALL);
97
+
98
+	if (!setlocale(LC_ALL, "C")) {
99
+		LOG_ERROR("Failed to set C locale");
100
+		return -1;
101
+	}
102
+
103
+	if (process_args(argc, argv)) {
104
+		return -1;
105
+	}
106
+
107
+	LOG_STATE("working directory: `%s`", getcwd(cwd, sizeof(cwd)));
108
+
109
+	/* Initialize instance */
110
+	if ((aisl = aisl_new(&m_cfg)) != NULL) {
111
+		if (observer_init() == 0) {
112
+			if (agent_init() == 0) {
113
+				/* launch application loop */
114
+				fprintf(stdout, "Entering main loop");
115
+				for(;;) {
116
+					int rc, do_sleep = 1;
117
+
118
+					if ((rc = aisl_run_cycle(aisl)) == AISL_SUCCESS)
119
+						do_sleep = 0;
120
+
121
+					if ((rc = agent_run_cycle()) == 0)
122
+						do_sleep = 0;
123
+
124
+					if (!do_sleep)
125
+						continue;
126
+
127
+					aisl_sleep(aisl, 500);
128
+				}
129
+				agent_release();
130
+			}
131
+			observer_release();
132
+		}
133
+		aisl_free(aisl);
134
+	} else {
135
+		fprintf(stderr, "Failed to initialize AISL");
136
+	}
137
+
138
+	AX_LOG_RELEASE();
139
+
140
+	return 0;
141
+}
142
+

+ 155
- 0
src/observer.c View File

@@ -0,0 +1,155 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file observer.c
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief AISL event observer source code file
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+#include <string.h>
16
+/* modules */
17
+#include <mods/module.h>
18
+/* commons */
19
+#include "config.h"
20
+#include "end-points.h"
21
+#include "log.h"
22
+#include "observer.h"
23
+
24
+
25
+/* static struct ax_feedback m_feedback = {0}; */
26
+
27
+AislStatus
28
+observer_init(void)
29
+{
30
+	AislStatus result = AISL_SUCCESS;
31
+
32
+	/* struct ax_feedback_cfg feedback_cfg; */
33
+
34
+	/*
35
+	memset(&feedback_cfg, 0, sizeof(struct ax_feedback_cfg));
36
+	feedback_cfg.end_point    = FEEDBACK_END_POINT;
37
+	feedback_cfg.smtp.host    = CONFIG_SMTP_SERVER;
38
+	feedback_cfg.smtp.user    = CONFIG_SMTP_USER;
39
+	feedback_cfg.smtp.pass    = CONFIG_SMTP_PASS;
40
+	feedback_cfg.smtp.port    = CONFIG_SMTP_PORT;
41
+	feedback_cfg.mail_from    = CONFIG_MAIL_FROM;
42
+	feedback_cfg.mail_to      = CONFIG_MAIL_TO;
43
+	feedback_cfg.mail_subject = CONFIG_MAIL_SUBJECT;
44
+	feedback_cfg.name_email   = "email";
45
+	feedback_cfg.name_msg     = "msg";
46
+
47
+	if ((result = ax_feedback_init(&m_feedback, &feedback_cfg)) != 0)
48
+		return result;
49
+		*/
50
+
51
+	return result;
52
+}
53
+
54
+
55
+void
56
+observer_release(void)
57
+{
58
+	/* ax_feedback_release(&m_feedback); */
59
+}
60
+
61
+
62
+static void
63
+observer_on_stream_event(const struct aisl_evt *evt)
64
+{
65
+	AxModule mods[] = { /* AX_MODULE(&m_feedback) */ NULL };
66
+
67
+	int i, c = sizeof (mods) / sizeof (mods[0]);
68
+
69
+	for (i = 0; i < c; i++) {
70
+
71
+		/* TODO: remove !!!! */
72
+		if (!mods[i])
73
+			continue;
74
+
75
+		AislStatus status = ax_module_on_event(mods[i], evt);
76
+
77
+		switch(status) {
78
+		case AISL_IDLE:
79
+			continue;
80
+
81
+		case AISL_SUCCESS:
82
+			return;
83
+
84
+		default:
85
+			LOG_ALERT("Module error: %s", aisl_status_to_string(status));
86
+			return;
87
+		}
88
+	}
89
+}
90
+
91
+
92
+static void
93
+observer_on_server_event(const struct aisl_evt *evt)
94
+{
95
+	struct sockaddr_in srv_addr;
96
+	AislServer srv = (AislServer) evt->source;
97
+	AislStatus status = evt->status;
98
+
99
+	aisl_server_get_address(srv, &srv_addr);
100
+
101
+	LOG_STATE("HTTP%s server %s:%d: %s", (aisl_server_get_ssl(srv) ? "s" : ""),
102
+	  inet_ntoa(srv_addr.sin_addr), ntohs(srv_addr.sin_port),
103
+	  (status ? aisl_status_to_string(status) : "ready"));
104
+}
105
+
106
+
107
+static void
108
+observer_on_client_event(const struct aisl_evt *evt, const char *msg)
109
+{
110
+	struct sockaddr_in cli_addr;
111
+	AislClient cli = (AislClient) evt->source;
112
+
113
+	aisl_client_get_address(cli, &cli_addr);
114
+	if (evt->status == AISL_IDLE)
115
+		msg = "timeout";
116
+
117
+	LOG_STATE( "HTTP%s client %s:%d: %s",
118
+    (aisl_client_is_secure(cli) ? "s" : ""),
119
+    inet_ntoa(cli_addr.sin_addr),
120
+    ntohs(cli_addr.sin_port),
121
+    msg
122
+  );
123
+}
124
+
125
+
126
+void
127
+observer_on_aisl_event(const struct aisl_evt *evt, void *p_ctx)
128
+{
129
+	switch(evt->code) {
130
+	case AISL_EVENT_SERVER_READY:
131
+	case AISL_EVENT_SERVER_ERROR:
132
+		observer_on_server_event(evt);
133
+		break;
134
+
135
+	case AISL_EVENT_CLIENT_CONNECT:
136
+		observer_on_client_event(evt, "connected");
137
+		break;
138
+
139
+
140
+	case AISL_EVENT_CLIENT_DISCONNECT:
141
+		observer_on_client_event(evt, "disconnected");
142
+		break;
143
+
144
+	case AISL_EVENT_STREAM_OPEN:
145
+	case AISL_EVENT_STREAM_HEADER:
146
+	case AISL_EVENT_STREAM_INPUT:
147
+	case AISL_EVENT_STREAM_REQUEST:
148
+	case AISL_EVENT_STREAM_OUTPUT:
149
+	case AISL_EVENT_STREAM_CLOSE:
150
+	case AISL_EVENT_STREAM_ERROR:
151
+		observer_on_stream_event(evt);
152
+		break;
153
+	}
154
+}
155
+

+ 34
- 0
src/observer.h View File

@@ -0,0 +1,34 @@
1
+/******************************************************************************
2
+ *
3
+ *                Copyright (c) 2017-2019 by Löwenware Ltd
4
+ *             Please, refer LICENSE file for legal information
5
+ *
6
+ ******************************************************************************/
7
+
8
+/**
9
+ * @file observer.h
10
+ * @author Ilja Kartašov <ik@lowenware.com>
11
+ * @brief AISL event observer header file
12
+ *
13
+ * @see https://lowenware.com/
14
+ */
15
+
16
+#ifndef OBSERVER_H_C0DE24F7_EC8D_4C89_B253_15F0BB5BF7B5
17
+#define OBSERVER_H_C0DE24F7_EC8D_4C89_B253_15F0BB5BF7B5
18
+
19
+#include <aisl/aisl.h>
20
+
21
+
22
+AislStatus
23
+observer_init(void);
24
+
25
+
26
+void
27
+observer_release(void);
28
+
29
+
30
+void
31
+observer_on_aisl_event(const struct aisl_evt *evt, void *p_ctx);
32
+
33
+
34
+#endif /* !OBSERVER_H */

+ 12
- 0
todo.txt View File

@@ -0,0 +1,12 @@
1
+Port templight to SDK
2
+Implement authentication UI
3
+Implement authentication modules in SDK
4
+Implement serial surgard receiver
5
+Implement EBS OSM receiver
6
+Define device file format
7
+Implement device logs
8
+Implement ARC journal
9
+Implement device cards
10
+Implement routes
11
+x Create project repository
12
+

Loading…
Cancel
Save