aboutsummaryrefslogtreecommitdiff
path: root/shared.h
blob: f02c0a4d013a0380b319da281244b588f5104326 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 *
 * Copyright (C) 2022 Jeremias Stotter <jeremias@stotter.eu>
 *
 * This file is part of network-simulator.
 *
 * network-simulator is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * network-simulator is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with network-simulator. If not, see <https://www.gnu.org/licenses/>. 
*/

#ifndef NETSIM_STRUCTS
#define NETSIM_STRUCTS

#include <lua.h>
#include <gtk/gtk.h>

#define SLL_HEAD(t) t* next
#define LL_HEAD(t) t* next; t* prev
#define LL_FOR(t, start, item) for(t* item = start; item; item = item->next)
// get the last item of a linked list
#define LL_LAST(start, last) for(last = start; last && last->next; last = last->next)

#define AREA_TEXT_SIZE 14

extern unsigned long timestamp;
extern int actions_since_save;

struct send_queue_entry {
	SLL_HEAD(struct send_queue_entry);
	struct interface* parent_interface;
	const char* data;
	int data_length;
	// The index the entry got in the gui packet list
	int gui_index;
	unsigned long timestamp;
	double color[3];
	char data_type[256];
};

struct cmd_history{
	LL_HEAD(struct cmd_history);
	char* text;
};

struct device {
	SLL_HEAD(struct device);
	// An array of size template->slots pointing to all the installed interfaces
	struct interface* interfaces;
	char* name;
	lua_State* lua_vm;
	struct dev_template* template;
	// Coordinates on the map
	double X;
	double Y;
	// The command line buffer
	GtkTextBuffer* cmd_buffer;
	bool deleted;
	
	struct cmd_history* history;
	int cmdline_current_index;
};

struct interface {
	// Points to a connection if this interface is connected or to NULL if it is not
	struct connection* connection; 
	struct device* parent_device;
	int parent_index;
	lua_State* lua_vm;
	struct interface_template* template;
	struct send_queue_entry* start_queue;
};

struct connection {
	struct interface* interface1;
	struct interface* interface2;
	struct connection_template* template;
};

struct dev_template {
	const char* name;
	int slots;
	// The default interfaces, an array of strings containing the names with the size slots
	char** interfaces;
	// The path to the lua file
	const char* kernel;
	// The path of the icon
	char* icon_path;
	GdkPixbuf* icon;
	// The size of the icon in pixels
	int icon_size;
	// Documentation html file
	char* docs;
};

struct interface_template {
	const char* name;
	const char* port_type;
	const char* firmware;
};

struct connection_template {
	const char* name;
	const char* plug;
	double color[3];
};

struct lib_template {
	const char* name;
	const char* lua_file;
};

enum deco_type {
	deco_type_text,
	deco_type_rect,
	deco_type_circle
};

struct deco {
	LL_HEAD(struct deco);
	int type;
	char* text;
	double X;
	double Y;
	double width;
	double height;
	int refs;
};

#endif
Jeremias Stotters git repositories generated by CGIT