Compare commits

..

221 Commits

Author SHA1 Message Date
Adrien Bourmault a1b1bf772e
Cleanup 2021-11-03 18:44:37 +01:00
Jean Sirmai 72a979afe4
Merge branch 'master' of git.a-lec.org:gem-graph/gem-graph-server 2021-10-23 17:13:42 +02:00
Jean Sirmai 42a0f9ca2b
WIP: Changing names (node_id, condition, transition) 2021-10-23 17:13:25 +02:00
Jean Sirmai 562e2177e6
Changing names (node_id, condition, transition) 2021-10-23 16:56:11 +02:00
Jean Sirmai c1754a8928
Changing names (node_id, condition, transition) 2021-10-23 16:55:56 +02:00
Jean Sirmai f1062f2c05
Merge branch 'master' of git.a-lec.org:gem-graph/gem-graph-server 2021-10-23 16:29:55 +02:00
Jean Sirmai bd3bd0ffc9
random walk written with two rules using global coord. These rules must be sequentially evaluated. The conditions tree is not yet encoded. 2021-10-19 05:14:58 +02:00
Jean Sirmai 4228ebd2b8
random walk written with two rules using global coord. 2021-10-18 11:03:31 +02:00
Jean Sirmai 8a91a5988a
two rules moving a dimer toward east or west 2021-10-17 18:48:11 +02:00
Jean Sirmai 7fc13837f5
two rules moving a dimer toward east or west 2021-10-17 16:33:20 +02:00
Jean Sirmai 89b4cac52a
two rules moving a dimer toward east or west 2021-10-17 16:27:28 +02:00
Adrien Bourmault 6db8075c9b
Cleanup 2021-10-14 11:27:48 +02:00
Adrien Bourmault 0cc24b8a65
Cleanup 2021-10-14 09:11:38 +02:00
Adrien Bourmault f9187c3b28
Cleanup 2021-10-14 09:11:12 +02:00
Adrien Bourmault 1c09678635
Some cleanup 2021-10-14 08:34:19 +02:00
Adrien Bourmault dec98d4d0b
Changed legal notice to reflect reality 2021-10-13 09:44:00 +02:00
Adrien Bourmault bed06c74cb
Parsing arrows 2021-10-05 14:35:10 +02:00
Jean Sirmai c9912d2df6
<xs:element name="then" substitutionGroup="if"/> 2021-09-30 18:49:17 +02:00
Adrien Bourmault 942c2db6ba
Corrected incorrect thread exiting in server.c 2021-09-29 17:53:01 +02:00
Adrien Bourmault 0b0ecbff6b
Parsing model continued 2021-09-28 18:54:37 +02:00
Jean Sirmai da6c223e92
types missing added in XMLSchema + attributeGroup x_y_z 2021-09-28 18:15:17 +02:00
Adrien Bourmault 55d3d3f130
WIP: Arrows can be created 2021-09-28 17:40:34 +02:00
Adrien Bourmault 6125043513
Corrected memory and printing errors 2021-09-22 16:43:01 +02:00
Adrien Bourmault 982db3a2ad
Moved to schema folder 2021-09-22 15:42:57 +02:00
Jean Sirmai 7ebc255392
re-introducing example xmls with attributeGroup id-date-author 2021-09-22 10:24:18 +02:00
Adrien Bourmault fb7ae07506
WIP: some memory problems 2021-09-21 23:28:19 +02:00
Adrien Bourmault a3aa232121
Corrected a forgotten free 2021-09-21 23:09:38 +02:00
Adrien Bourmault b2a3508f08
WIP: New XML schemas used in gem-graph 2021-09-21 22:39:24 +02:00
Adrien Bourmault 33da3fee8d
Moved schema to a new folder 2021-09-21 22:26:18 +02:00
Adrien Bourmault 4a6191c07d
Moved schema to a new folder 2021-09-21 22:21:48 +02:00
Jean Sirmai c4197bdb01
WIP: XML schema validated except no ref at toplevel 2021-09-21 21:13:51 +02:00
Adrien Bourmault 3194a2ecf8
New model format (and filename!) 2021-09-21 15:57:56 +02:00
Adrien Bourmault 242d6a9cd6
New model format (reforged) 2021-09-21 15:55:18 +02:00
Jean Sirmai 299ca225a0
learning XMLSchema (comments) 2021-09-20 18:36:05 +02:00
Jean Sirmai 7bde01ebad
learning XMLSchema (comments) 2021-09-20 18:21:31 +02:00
Jean Sirmai 29fbf905d2
XML Schema States OK and Transitions first approach ! 2021-09-20 11:25:27 +02:00
Jean Sirmai b70a940f36
XML Schema States OK (before Transitions) 2021-09-20 07:03:36 +02:00
Jean Sirmai 4fc99aee92
XMLSchema > Attributes : introducung the type arrow 2021-09-19 23:12:36 +02:00
Jean Sirmai 7d0719a227
XMLSchema > Attributes : a small step 2021-09-19 22:58:37 +02:00
Jean Sirmai 2383f21e7b
XMLSchema > Attributes : a small step 2021-09-19 22:39:47 +02:00
Adrien Bourmault e910a2958f
Arrows readable. Got a space soon 2021-09-19 19:13:10 +02:00
Jean Sirmai c26ad4d3e9
XMLSchema recherche (suite) 2021-09-18 19:50:06 +02:00
Jean Sirmai e18df35372
XMLSchema recherche (suite) 2021-09-18 19:32:29 +02:00
Jean Sirmai d3f52853d5
Learning XMLSchema 2021-09-18 17:01:53 +02:00
Jean Sirmai ae296cdcf9
Learning XMLSchema 2021-09-18 16:46:39 +02:00
Jean Sirmai 49871fef04
learning XMLSchema 2021-09-18 16:44:10 +02:00
Adrien Bourmault efb3bfd64c
Header refactor, more XML parsing and stuff 2021-09-18 01:00:48 +02:00
Adrien Bourmault fc10d5de14
Global parsing sucessfull; lack of arrows now 2021-09-17 18:40:42 +02:00
Adrien Bourmault 048857a9af
Some quote 2021-09-17 16:22:51 +02:00
Adrien Bourmault 5ee70f6c44
Progressing into parsing and model file syntax 2021-09-17 16:14:04 +02:00
Adrien Bourmault 1342b445af
Merge branch 'master' of git.a-lec.org:gem-graph/gem-graph-server 2021-09-16 21:30:49 +02:00
Adrien Bourmault 89a93152d5
New parsing module 2021-09-16 21:30:43 +02:00
Jean Sirmai e3b35c3b24
Merge branch 'master' of git.a-lec.org:gem-graph/gem-graph-server 2021-09-16 12:54:47 +02:00
Jean Sirmai 5e06de413d
example II creation 2021-09-16 12:54:28 +02:00
Adrien Bourmault f6ad08702f
WIP: Crushing and rebuilding from the ground an XML parser 2021-09-15 18:26:57 +02:00
Adrien Bourmault b267fc5a09
WIP: Crushing and rebuilding from the ground an XML parser 2021-09-15 18:25:59 +02:00
Adrien Bourmault 7d17cd00fb
Minor modifications 2021-09-14 23:36:25 +02:00
Adrien Bourmault d8f83d86c5 Merge branch 'master-amend' into 'master'
Mass renaming of symbols/functions

See merge request gem-graph/gem-graph-server!1
2021-09-14 09:20:33 +00:00
Adrien Bourmault 130c602ecb Mass renaming of symbols/functions 2021-09-14 09:20:33 +00:00
Adrien Bourmault 3b04e4c01b
Renamming/changing vocabulary and signatures 2021-09-02 16:54:42 +02:00
Adrien Bourmault eb3f2c29cf
refactoring xml structure parsing 2021-08-31 01:03:02 +02:00
Adrien Bourmault 2bae3c1f3a
WIP: [BUG] Unloading models 2021-08-24 19:39:53 +02:00
Adrien Bourmault 768366d626
Server get arguments from command line 2021-08-24 18:25:44 +02:00
Adrien Bourmault b8787a9f5f
Model XML parsing without specific order 2021-08-24 12:40:51 +02:00
Adrien Bourmault 88f0c6a7b9
XML parsing sucessful 2021-08-24 12:09:54 +02:00
Adrien Bourmault d6538985b8
WIP: [BUG] parsing without order constraint 2021-08-24 01:39:00 +02:00
Adrien Bourmault 991b2ec549
Parse and add model 2021-08-24 01:14:48 +02:00
Adrien Bourmault d36242933d
First XML parsing 2021-08-24 00:41:49 +02:00
Adrien Bourmault 459da14781
XML model file 2021-08-21 22:22:58 +02:00
Adrien Bourmault 44c2f4d867
XML model file 2021-08-21 21:37:29 +02:00
Adrien Bourmault ce299ebc87
XML parsing 2021-08-20 17:33:41 +02:00
Adrien Bourmault 16753c7eff
Ready to parse 2021-08-20 16:41:58 +02:00
Adrien Bourmault 876b0deb8b
Detect xml models 2021-08-20 16:10:18 +02:00
Adrien Bourmault 5ba60afe7b
Server /etc parameters embryon, clean shutdown (&signals), model storage dir 2021-08-20 15:19:14 +02:00
Adrien Bourmault da226b3cfa
Server /etc parameters embryon, clean shutdown (&signals), model storage dir 2021-08-20 15:19:08 +02:00
Adrien Bourmault 1251b2dcbb
XML has been chosen 2021-08-12 16:43:30 +02:00
Adrien Bourmault ead56534d1
Some tests 2021-08-12 16:43:11 +02:00
Adrien Bourmault 7ba450380f
refactored terminal primitives to header; more cosmetics 2021-08-07 01:14:17 +02:00
Adrien Bourmault c8d1cb1038
Better cli monitor layout 2021-08-06 01:12:01 +02:00
Adrien Bourmault 8500cddbf3
New monitor layout 2021-08-05 15:14:59 +02:00
Adrien Bourmault d2a3f7cbf0
tests & makefile 2021-08-05 13:22:30 +02:00
Adrien Bourmault d7caf04b65
WIP: detect resizing 2021-07-22 01:27:40 +02:00
Jean Sirmai 26e93c2f04
touche suppr essai 2 2021-07-21 20:58:14 +02:00
Jean Sirmai 97114192d5
Merge branch 'master' of git.a-lec.org:gem-graph/gem-graph-server 2021-07-21 20:31:18 +02:00
Jean Sirmai 1d0e33e4fd
WIP: del key 2021-07-21 20:30:35 +02:00
Adrien Bourmault 7561ae646d
CLI : monitor command; get terminal size and print screen 2021-07-15 23:28:28 +02:00
Adrien Bourmault a95279b7ef
CLI : monitor command 2021-07-15 23:05:55 +02:00
Adrien Bourmault dee272db72
Add CLI in deb package 2021-07-15 16:31:53 +02:00
Adrien Bourmault 89219f40c6
Better CLI : colors! 2021-07-14 00:50:07 +02:00
Adrien Bourmault 452bb52394
Better Makefile : headers are now dependencies
Better CLI : there are colors !
2021-07-14 00:41:44 +02:00
Adrien Bourmault c6d99559b5
Better cli : arrows and edition 2021-07-12 19:58:09 +02:00
Adrien Bourmault 2774726c65
Blank line in history 2021-07-12 18:10:25 +02:00
Adrien Bourmault 4c1763f6c4
Model can be run and stop 2021-07-12 17:54:57 +02:00
Adrien Bourmault 1d5463c1c5
Model can be run 2021-07-12 17:09:38 +02:00
Adrien Bourmault 442c76e96c
Errno is useful 2021-07-12 15:12:29 +02:00
Adrien Bourmault dd59e34110
Disconnection detection 2021-07-09 22:44:29 +02:00
Adrien Bourmault 8ae1f2f65f
Server return value 2021-07-09 20:42:44 +02:00
Adrien Bourmault 5ec6e86f6e
Multiclient with IP:port detection 2021-07-09 20:34:32 +02:00
Adrien Bourmault 742b05de74
MULTIPLE CLIENTS WORKING! 2021-07-09 18:34:54 +02:00
Adrien Bourmault 2aa5c2814f
WIP: multiclient server 2021-07-09 15:58:47 +02:00
Adrien Bourmault ad685d528b
Multiple clients ! 2021-07-09 02:57:26 +02:00
Adrien Bourmault 428ac5ff4f
Multiple clients ! 2021-07-09 02:53:54 +02:00
Adrien Bourmault 48ca39577a
ids don't need to be allocated dynamically 2021-07-09 00:56:35 +02:00
Adrien Bourmault 3b26597bd6
History and correction 2021-07-09 00:37:03 +02:00
Adrien Bourmault 439a0b0bb2
WIP: [BUGGY] cli history 2021-07-08 20:30:09 +02:00
Adrien Bourmault 9566a3c74e
getch() ! 2021-07-08 19:14:45 +02:00
Adrien Bourmault e5ba2b9303
getch ! 2021-07-08 19:11:56 +02:00
Adrien Bourmault b5be741617
Invalid command! 2021-07-08 18:49:27 +02:00
Adrien Bourmault ca7cb9294d
WIP: Rollback threaded server 2021-07-08 18:35:14 +02:00
Adrien Bourmault 8fe9e2125f
WIP: server communicator 2021-07-08 18:14:46 +02:00
Adrien Bourmault 3d56a4ec61
Cleaned commands 2021-07-08 17:26:13 +02:00
Adrien Bourmault 8e6f99ecb7
New network code (better buffer sizes) 2021-07-08 00:35:22 +02:00
Adrien Bourmault 89a8defde6
New network code (better buffers) 2021-07-08 00:30:58 +02:00
Adrien Bourmault fa3efd69e5
New network code (better buffers) 2021-07-08 00:30:25 +02:00
Adrien Bourmault 9933c41a1e
New network code 2021-07-08 00:28:34 +02:00
Adrien Bourmault 4e9b368a72
WIP: [BUG] new network code 2021-07-08 00:10:36 +02:00
Adrien Bourmault 636758324f
models create and run 2021-07-07 19:46:23 +02:00
Adrien Bourmault e0a7cfe0b3
WIP: (BUG) model run/load/create + typos corrected 2021-07-02 15:19:08 +02:00
Adrien Bourmault aa4bd4478c
WIP: (BUG) model run/load/create 2021-07-02 15:06:11 +02:00
Adrien Bourmault 2d34d38a28
Model loading 2021-06-30 16:14:18 +02:00
Adrien Bourmault 67d78dfaec
make run-cli 2021-06-30 15:50:39 +02:00
Adrien Bourmault 97868beb39
Model create + load cmd 2021-06-30 15:46:18 +02:00
Adrien Bourmault e6ac4a3e91
cli model command (create) 2021-06-23 21:44:51 +02:00
Adrien Bourmault cca06c9ec6
new arrows for testing purposes 2021-06-23 20:23:37 +02:00
Jean Sirmai 44bae3d1c8
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-06-23 17:43:26 +02:00
Adrien Bourmault dfc5549043
some typo 2021-06-23 17:33:46 +02:00
Jean Sirmai 7eb70501b4
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-06-23 17:12:33 +02:00
Adrien Bourmault 4440075d7f
Better CLI 2021-06-23 17:07:43 +02:00
Jean Sirmai 160d514213
first rule : dimers random walk in 1D space 2021-06-23 15:06:33 +02:00
Adrien Bourmault 29e43c2f18
Model_t + lisibility 2021-06-23 14:16:45 +02:00
Adrien Bourmault cd9285e898
some lisibility improvements 2021-06-23 11:37:47 +02:00
Adrien Bourmault 18077df85b
some lisibility improvements 2021-06-23 11:06:36 +02:00
Adrien Bourmault 7c4c43b996
bugs resolved 2021-06-23 10:55:35 +02:00
Adrien Bourmault 2be99a944f
deleting history 2021-06-23 10:53:26 +02:00
Adrien Bourmault 9e737f24ab
test and arrows 2021-06-23 10:16:48 +02:00
Adrien Bourmault cdacbc0fb6
locked arrowArray in scheduler! 2021-06-23 09:13:46 +02:00
Adrien Bourmault 8c48856994
arrows have orientations 2021-06-21 14:26:09 +02:00
Adrien Bourmault 349b851f48
arrows have orientations 2021-06-21 12:03:06 +02:00
Adrien Bourmault 669e87f459
A simple model 2021-06-21 11:00:15 +02:00
Adrien Bourmault 10827abb56
Cleaning some typos 2021-06-21 10:57:58 +02:00
Adrien Bourmault f0743ec795
Cleaning some unused things 2021-06-21 10:34:11 +02:00
Adrien Bourmault 322f90b20c
Worker has now access to space 2021-06-19 16:32:39 +02:00
Adrien Bourmault 093c3cc0ea
Test 2021-06-18 15:05:15 +02:00
Adrien Bourmault ca1e959861
First command! 2021-06-17 21:34:50 +02:00
Adrien Bourmault 1256c65f62
WIP: server commands 2021-06-17 12:05:03 +02:00
Adrien Bourmault 057cad2bfb
We have a server ! (2) 2021-06-16 19:49:41 +02:00
Adrien Bourmault 3046f41506
We have a server ! 2021-06-16 19:44:48 +02:00
Adrien Bourmault 1842e1cebd
tcp server 2021-06-16 18:10:26 +02:00
Adrien Bourmault 2804fb42af
tcp server 2021-06-16 18:10:04 +02:00
Adrien Bourmault c5d0568578
space dimension 2021-06-16 13:15:26 +02:00
Adrien Bourmault de284948d7
space dimension 2021-06-16 13:06:23 +02:00
Adrien Bourmault bff453bb33
space is now Space_t 2021-06-16 12:44:51 +02:00
Adrien Bourmault 2531db992a
space is now Space_t 2021-06-16 12:42:19 +02:00
Adrien Bourmault 93adea1fa8
arrowList is majored 2021-06-16 12:17:00 +02:00
Adrien Bourmault 967f68ab25
Space is ArrowArray_t 2021-06-16 12:04:47 +02:00
Adrien Bourmault c7cb91a077
Space is ArrowArray_t 2021-06-16 12:02:51 +02:00
Adrien Bourmault 77909af0c5
Space is ArrowArray_t 2021-06-16 12:01:29 +02:00
Adrien Bourmault ab64d8f557
Some quotes & renaming 2021-06-16 11:33:36 +02:00
Adrien Bourmault 4f54f3030b
Corrected logic of scheduler.c/findWorkArea() 2021-06-16 10:06:05 +02:00
Adrien Bourmault 51a3fc3719
Scheduler working at maximum perfs 2021-06-16 00:09:35 +02:00
Adrien Bourmault 5862b207ce
Prepare arrows module 2021-06-15 23:46:18 +02:00
Adrien Bourmault f98e51bf4a
Scheduler working ! 2021-06-15 23:26:27 +02:00
Adrien Bourmault 70bff11041
Rebuild/refactoring of scheduler main func 2021-06-15 00:56:01 +02:00
Adrien Bourmault 17166e59f6
First unit tests for scheduler 2021-06-14 20:24:12 +02:00
Adrien Bourmault 46c024efe6
First unit tests for scheduler 2021-06-14 20:22:26 +02:00
Adrien Bourmault 0319676d7e
First unit tests for scheduler 2021-06-14 20:22:11 +02:00
Adrien Bourmault 6c7a46d3cd
center_t operations 2021-06-14 19:00:44 +02:00
Adrien Bourmault 9248f8176b
More 'objective' definitions 2021-06-14 18:33:13 +02:00
Adrien Bourmault 02c42045c2
builder is happy 2021-06-11 19:34:00 +02:00
Adrien Bourmault 0e734bd4e8
we find some centers 2021-06-11 17:39:34 +02:00
Jean Sirmai af433e8a90
findWorkArea 2021-06-11 17:14:40 +02:00
Jean Sirmai dd45f7794a
findWorkArea 2021-06-11 16:53:43 +02:00
Jean Sirmai 3316b0d338
findWorkArea 2021-06-11 16:52:40 +02:00
Adrien Bourmault 2182233068
Center list 2021-06-11 16:51:07 +02:00
Adrien Bourmault b73a9a8091
Center list 2021-06-11 16:50:38 +02:00
Adrien Bourmault f4711dab25
printLog macro 2021-06-11 15:11:06 +02:00
Jean Sirmai 4982a214da
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-06-11 14:50:38 +02:00
Adrien Bourmault 9f3d21ac20
Worker has parameters 2021-06-11 14:30:26 +02:00
Jean Sirmai debbc40432
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-06-11 14:23:08 +02:00
Adrien Bourmault bf35b1c705
Cleanup 2021-06-11 14:22:56 +02:00
Jean Sirmai bd8c5c6bce
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-06-11 14:18:04 +02:00
Adrien Bourmault c1e8c4cc9a
Tests files 2021-06-11 14:14:45 +02:00
Adrien Bourmault 2924428bdf
Local worker 2021-06-11 14:07:13 +02:00
Adrien Bourmault 4219ae2888
Local worker 2021-06-11 14:02:40 +02:00
Jean Sirmai 65628bc569
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-06-11 13:58:48 +02:00
Adrien Bourmault cbfcdb389f
cleanup inlines 2021-06-11 13:56:52 +02:00
Adrien Bourmault 61ceb36028
Thread -> worker 2021-06-11 13:40:59 +02:00
Jean Sirmai f43445f320
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-06-11 12:53:49 +02:00
Adrien Bourmault b21478ca46
Scheduler Crash test 2021-06-11 12:52:36 +02:00
Jean Sirmai 2db4558b5c
mon premier commit ! (super modif !!!!) 2021-06-11 12:29:43 +02:00
Adrien Bourmault e42534dc90
Some types 2021-06-11 12:23:16 +02:00
Adrien Bourmault 7829fb1457
Structure to pass parameters to Scheduler 2021-06-11 11:39:42 +02:00
Adrien Bourmault 0d796ff599
A real init/destroy 2021-06-09 23:56:42 +02:00
Adrien Bourmault 10ab0d01cd
Threaded ! 2021-06-09 14:40:23 +02:00
Adrien Bourmault e35b4b3725
Cleaned unused variable 2021-06-09 12:26:34 +02:00
Adrien Bourmault 8cecf6d145
Cleaned warnings 2021-06-09 12:23:42 +02:00
Adrien Bourmault 1194c2b59c
Cleaned warnings 2021-06-09 12:16:27 +02:00
Adrien Bourmault 6c29dd435b
Includes corrected 2021-06-09 11:54:58 +02:00
Adrien Bourmault 727e760dc0
Switch to C 2021-06-09 11:35:47 +02:00
Adrien Bourmault f134ecc8ec
Debian package working 2021-06-08 20:20:27 +02:00
Adrien Bourmault 736e556945
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-06-08 20:16:38 +02:00
Adrien Bourmault 4f6448a2ba
Switching to C 2021-06-08 20:15:47 +02:00
Adrien Bourmault f19d82a9e5 Update AUTHORS 2021-06-08 16:15:12 +00:00
Adrien Bourmault 6540aeadd2
Makefile at toplevel 2021-06-08 18:05:32 +02:00
Adrien Bourmault f35f7659a0
Cleaned Makefile 2021-04-10 23:23:41 +02:00
Adrien Bourmault cbcd402c4c
Detecting how many CPUs to use automatically 2021-04-10 23:14:59 +02:00
Adrien Bourmault 4486026d23
Improved intermediate *.c generation 2021-04-10 23:02:40 +02:00
Adrien Bourmault 17fdb7bed0
bin folder 2021-04-10 22:46:47 +02:00
Adrien Bourmault dc5b9b7daf
Program executable now with the correct mimetype 2021-04-10 22:42:10 +02:00
Adrien Bourmault ab780ea237
Better separate compilation 2021-04-10 22:03:38 +02:00
Adrien Bourmault 9f57a59f18
Ignore binaries 2021-04-10 21:26:59 +02:00
Adrien Bourmault 2f9cedb857
Merge branch 'master' of ssh://gitlab.os-k.eu:222/gem-graph-team/gem-graph-server 2021-04-10 21:25:59 +02:00
Jean Sirmai 950ebd6237
add Authors 2021-04-10 21:25:31 +02:00
Adrien Bourmault 156d7ccc49
Ignore binaries 2021-04-10 21:21:19 +02:00
Jean Sirmai 63c0b33451
Separate compilation with Cython works ! 2021-04-09 19:59:52 +02:00
Jean Sirmai fd78079ea2
all cpu working 2021-04-09 18:14:56 +02:00
Jean Sirmai ffbd6d2d63
Multiprocessing! (clean) 2021-04-09 18:01:45 +02:00
Jean Sirmai bfb625d2c0
Multiprocessing! 2021-04-09 18:01:29 +02:00
Jean Sirmai 0153fc300c
Using Cython ! 2021-04-09 16:16:44 +02:00
Jean Sirmai 912d818c4e
Initial commit 2021-04-08 19:44:43 +02:00
Adrien Bourmault 720f83b0db Add LICENSE 2021-03-28 15:26:21 +00:00
50 changed files with 4997 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.so
*.o
*.deb
bin/**

661
LICENSE Normal file
View File

@ -0,0 +1,661 @@
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Gem-graph server
Copyright (C) 2021 The Gem-Graph Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.

139
Makefile Normal file
View File

@ -0,0 +1,139 @@
#=----------------------------------------------------------------------------=#
# Makefile #
# #
# Copyright © 2021 Libre en Communs (contact@a-lec.org) #
# Copyright © 2021 Adrien Bourmault (neox@a-lec.org) #
# #
# This file is part of gem-graph. #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program 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 Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=#
CCOPTS=-pthread -Wall -g -Os -I/usr/include/libxml2
LDFLAGS= -lc -lpthread -lxml2
BINDIR=bin
INCDIR=include
SRCDIR=src
DEBDIR=debian
SERVEROBJ= $(BINDIR)/scheduler.o $(BINDIR)/server.o $(BINDIR)/worker.o \
$(BINDIR)/centers.o $(BINDIR)/cmds.o $(BINDIR)/model.o \
$(BINDIR)/main.o $(BINDIR)/arrows.o $(BINDIR)/parsing.o
CLIOBJ= $(BINDIR)/cli.o
SRCS=$(patsubst $(BINDIR)/%.o,$(SRCDIR)/%.c,$(SERVEROBJ)) \
$(patsubst $(BINDIR)/%.o,$(SRCDIR)/%.c,$(CLIOBJ))
DEPS=$(patsubst $(BINDIR)/%.o,$(BINDIR)/%.d,$(SERVEROBJ)) \
$(patsubst $(BINDIR)/%.o,$(BINDIR)/%.d,$(CLIOBJ))
.DEFAULT_GOAL:= all
.PHONY: all clean deb tests install run run-cli run-tests dependencies
# ---- Dependencies enumeration ---------------------------------------------- #
dependencies: $(DEPS)
$(BINDIR)/%.d: $(BINDIR)/%.o $(SRCDIR)/%.c
@$(CC) $(CFLAGS) -MM -MT $< $(word 2,$^) -MF $@
# ---- Tests enumeration ----------------------------------------------------- #
TEST_SCHEDULER=$(BINDIR)/tests/centers
TESTS=$(TEST_SCHEDULER)
$(BINDIR)/tests/centers: $(SRCDIR)/tests/centers.c
@echo "Compiling $<"
@$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) $(LDFLAGS) -o $@ $<
# ---- General recipes ------------------------------------------------------- #
$(BINDIR)/%.o: $(SRCDIR)/%.c
@echo "Compiling $<"
@$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) -c -o $@ $<
# ---- Main recipe ----------------------------------------------------------- #
$(BINDIR)/main.o: $(SRCDIR)/main.c
@echo "Compiling $<"
@$(CC) $(CCINCLUDES) $(CCOPTS) $(CCFLAGS) -c -o $@ $<
$(BINDIR)/gem-graph-server: $(SERVEROBJ)
@echo "Building program to $@"
@$(CC) -o $@ $(SERVEROBJ) $(LDFLAGS)
@echo "Success!"
$(BINDIR)/gem-graph-ctl: $(CLIOBJ)
@echo "Building program to $@"
@$(CC) -o $@ $(CLIOBJ) $(LDFLAGS)
@echo "Success!"
# ---- Misc recipes ---------------------------------------------------------- #
clean:
-rm -f $(SRCDIR)/*.o $(BINDIR)/* $(BINDIR)/tests/* *.deb
all: dependencies $(BINDIR)/gem-graph-server $(BINDIR)/gem-graph-ctl
tests: $(TESTS)
# ---- Build debian package -------------------------------------------------- #
$(BINDIR)/gem-graph-server.deb: all $(DEBDIR)/control \
$(DEBDIR)/conffiles \
$(DEBDIR)/etc/server.conf \
$(DEBDIR)/copyright
mkdir -p gem-graph-server/usr/bin
mkdir -p gem-graph-server/var/lib/gem-graph-server/models
mkdir -p gem-graph-server/var/lib/gem-graph-server/users
mkdir -p gem-graph-server/etc/gem-graph-server
mkdir -p gem-graph-server/usr/share/doc/gem-graph-server
mkdir -p gem-graph-server/DEBIAN
cp $(DEBDIR)/control gem-graph-server/DEBIAN/control
cp $(DEBDIR)/conffiles gem-graph-server/DEBIAN/conffiles
cp $(DEBDIR)/etc/* gem-graph-server/etc/gem-graph-server
cp $(BINDIR)/gem-graph-server gem-graph-server/usr/bin
cp $(BINDIR)/gem-graph-ctl gem-graph-server/usr/bin
cp $(DEBDIR)/copyright \
gem-graph-server/usr/share/doc/gem-graph-server/copyright
dpkg-deb --build gem-graph-server
rm -rf gem-graph-server
deb: $(BINDIR)/gem-graph-server.deb
# ---- Builder will call this to install the application before running ------ #
install:
echo "Installing is not supported"
# ---- Builder uses this target to run the application ----------------------- #
run: all
@bin/gem-graph-server -C debian/etc -M debian/var/models \
-U debian/var/users
run-gdb: all
@gdb bin/gem-graph-server \
-ex "set args -C debian/etc -M debian/var/models -U debian/var/users"
run-valgrind: all
@valgrind --leak-check=full --show-leak-kinds=all -s \
bin/gem-graph-server -C debian/etc -M debian/var/models \
-U debian/var/users
run-both: all
@bin/gem-graph-server -C debian/etc -M debian/var/models \
-U debian/var/users & sleep 1 && bin/gem-graph-ctl
run-server: all
@bin/gem-graph-server -C debian/etc -M debian/var/models \
-U debian/var/users
run-cli: all
@bin/gem-graph-ctl
run-tests: tests
@bin/tests/scheduler

View File

@ -1,2 +1,13 @@
# gem-graph-server
Build & execute the program:
```
make
make run
```
Build & execute tests
```
make tests
make run-tests
```

0
bin/.placeholder Normal file
View File

0
bin/tests/.placeholder Normal file
View File

1
debian/conffiles vendored Normal file
View File

@ -0,0 +1 @@
/etc/gem-graph-server/server.conf

10
debian/control vendored Normal file
View File

@ -0,0 +1,10 @@
Package: gem-graph-server
Version: 0.0.1
Section: custom
Priority: optional
Depends: libxml2
Architecture: amd64
Essential: no
Installed-Size: 112760
Maintainer: Libre en Communs (contact@a-lec.org)
Description: The wonderful gem-graph computation server

13
debian/copyright vendored Normal file
View File

@ -0,0 +1,13 @@
This is a packacked upstream version of gem-graph-server
The sources may be found at <https://gitlab.os-k.eu/gem-graph-team/gem-graph-server>.
Copyright © 2021 Libre en Communs (contact@a-lec.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/#AGPL>.

2
debian/etc/server.conf vendored Normal file
View File

@ -0,0 +1,2 @@
# CECI EST UN FICHIER DE CONFIGURATION
server_enabled=true

0
debian/var/models/.placeholder vendored Normal file
View File

111
debian/var/models/example_0.2.xml vendored Normal file
View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<gem-graph-model version="0.2">
<!-- Model identity informations -->
<identity>
<name>Modèle de test</name>
<owner>Gaston Lagaffe</owner>
<owner_id>2</owner_id>
<date>1629830000</date>
<version>1.0</version>
<g_ref id="texte" date="1629830000" author="Jean" lang="en">Ref</g_ref>
</identity>
<!-- Model parameters -->
<parameters id="texte" date="0" author="Gaston Lagaffe">
<simulation>
<max_thread>0</max_thread>
<max_cycles>9</max_cycles>
</simulation>
<space-param>
<dimension>1</dimension>
<size x="29" y="0" z="0"/>
<site_multiplicity>3</site_multiplicity>
</space-param>
</parameters>
<!-- Model objects definition -->
<objects id="texte" date="1629830000" author="Jean Sirmai">
<object id="dimer 1-1" date="1629830000" author="Jean Sirmai">
<arrow x="0" y="0" z="0" site="1" weight="1"/>
<arrow x="1" y="0" z="0" site="2" weight="1"/>
</object>
<object id="dimer 2-2" date="1629830000" author="Jean Sirmai">
<arrow x="0" y="0" z="0" site="1" weight="2"/>
<arrow x="1" y="0" z="0" site="2" weight="2"/>
</object>
<object id="dimer 3-3" date="1629830000" author="Jean Sirmai">
<arrow x="0" y="0" z="0" site="1" weight="3"/>
<arrow x="1" y="0" z="0" site="2" weight="3"/>
</object>
</objects>
<!-- Saved space description (initial space is sequence 0) -->
<savestates id="texte" date="1629830000" author="THE MATRIX">
<space id="initial" date="1629830000" author="Jean Sirmai" sequence="0">
<arrow x="0" y="0" z="0" site="1" weight="1"/>
<arrow x="1" y="0" z="0" site="2" weight="1"/>
<arrow x="10" y="0" z="0" site="1" weight="1"/>
<arrow x="11" y="0" z="0" site="2" weight="1"/>
<arrow x="20" y="0" z="0" site="1" weight="1"/>
<arrow x="21" y="0" z="0" site="2" weight="1"/>
</space>
</savestates>
<!-- Model transitions definition (rules) -->
<!-- In this version : <xs:sequence minOccurs="0" maxOccurs="unbounded">-->
<!-- As long as there is no client, transitions have to be edited by hand
and should be written using a 'human-readable' format -->
<conditions id="random walk of dimers" date="1629822222" author="Jean">
<condition x= "0" y="0" z="0" site="1" weight="1" node_id="1" parent="0"/>
<condition x= "1" y="0" z="0" site="2" weight="1" node_id="2" parent="1"/>
<condition x= "2" y="0" z="0" site="1" weight="0" node_id="3" parent="2"/>
<condition x="-1" y="0" z="0" site="2" weight="0" node_id="4" parent="2"/>
</conditions>
<transitions>
<transition id="move_a_dimer_to_east" date="1629811111" author="Jean"
parent="3" probability="1">
<arrow x="0" y="0" z="0" site="1" weight="0"/>
<arrow x="1" y="0" z="0" site="2" weight="0"/>
<arrow x="1" y="0" z="0" site="1" weight="1"/>
<arrow x="2" y="0" z="0" site="2" weight="1"/>
</transition>
<transition id="move_a_dimer_to_west" date="1629811112" author="Jean"
parent="4" probability="1">
<arrow x= "0" y="0" z="0" site="1" weight="0"/>
<arrow x= "1" y="0" z="0" site="2" weight="0"/>
<arrow x= "0" y="0" z="0" site="2" weight="1"/>
<arrow x="-1" y="0" z="0" site="1" weight="1"/>
</transition>
</transitions>
</gem-graph-model>

View File

199
debian/var/models/schemas/model_0.2.xmls vendored Normal file
View File

@ -0,0 +1,199 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- https://www.freeformatter.com/xml-validator-xsd.html -->
<!-- https://www.w3schools.com/xml/el_attribute.asp -->
<xs:attribute name="id" type="xs:string"/>
<xs:attribute name="node_id" type="xs:integer"/>
<xs:attribute name="date" type="xs:integer"/>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="lang" type="xs:string"/>
<xs:attribute name="owner" type="xs:string"/>
<xs:attribute name="owner_id" type="xs:integer"/>
<xs:attribute name="author" type="xs:string"/>
<xs:attribute name="version" type="xs:float"/>
<xs:attribute name="sequence" type="xs:integer"/>
<xs:attribute name="probability" type="xs:integer"/>
<xs:attribute name="parent" type="xs:integer"/>
<xs:attribute name="x" type="xs:integer" default="0"/>
<xs:attribute name="y" type="xs:integer" default="0"/>
<xs:attribute name="z" type="xs:integer" default="0"/>
<xs:attribute name="site" type="xs:integer" default="0"/>
<xs:attribute name="weight" type="xs:integer" default="0"/>
<xs:attributeGroup name="id_date_author">
<xs:attribute ref="id"/>
<xs:attribute ref="date"/>
<xs:attribute ref="author"/>
</xs:attributeGroup>
<xs:attributeGroup name="xyz_site_nb">
<xs:attribute ref="x"/>
<xs:attribute ref="y"/>
<xs:attribute ref="z"/>
<xs:attribute ref="site"/>
<xs:attribute ref="weight"/>
</xs:attributeGroup>
<xs:element name="g_ref">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attributeGroup ref="id_date_author"/>
<xs:attribute ref="lang" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="quote" substitutionGroup="g_ref"/>
<xs:element name="arrow">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="quote"/>
</xs:sequence>
<xs:attributeGroup ref="xyz_site_nb"/>
</xs:complexType>
</xs:element>
<xs:element name="condition">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="quote"/>
</xs:sequence>
<xs:attributeGroup ref="xyz_site_nb"/>
<xs:attribute ref="node_id" use="required"/>
<xs:attribute ref="parent" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="state">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element ref="arrow"/>
</xs:sequence>
<xs:attributeGroup ref="id_date_author"/>
</xs:complexType>
</xs:element>
<xs:element name="object" substitutionGroup="state"/>
<xs:element name="space">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element ref="arrow"/>
</xs:sequence>
<xs:attributeGroup ref="id_date_author"/>
<xs:attribute ref="sequence" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="transition">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element minOccurs="0" ref="quote"/>
<xs:element ref="arrow"/>
</xs:sequence>
<xs:attributeGroup ref="id_date_author"/>
<xs:attribute ref="parent" use="required"/>
<xs:attribute ref="probability" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="gem-graph-model">
<xs:complexType>
<xs:sequence>
<xs:element name="identity">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="owner" type="xs:string"/>
<xs:element name="owner_id" type="xs:integer"/>
<xs:element name="date" type="xs:integer"/>
<xs:element name="version" type="xs:float"/>
<xs:element minOccurs="0" ref="g_ref"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="parameters">
<xs:complexType>
<xs:sequence>
<xs:element name="simulation">
<xs:complexType>
<xs:sequence>
<xs:element name="max_thread" type="xs:integer"/>
<xs:element name="max_cycles" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="space-param">
<xs:complexType>
<xs:sequence>
<xs:element name="dimension" type="xs:integer"/>
<xs:element name="size">
<xs:complexType>
<xs:attributeGroup ref="xyz_site_nb"/>
</xs:complexType>
</xs:element>
<xs:element name="site_multiplicity" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attributeGroup ref="id_date_author"/>
</xs:complexType>
</xs:element>
<xs:element name="objects">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element ref="state"/>
</xs:sequence>
<xs:attributeGroup ref="id_date_author"/>
</xs:complexType>
</xs:element>
<xs:element name="savestates">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="space"/>
</xs:sequence>
<xs:attributeGroup ref="id_date_author"/>
</xs:complexType>
</xs:element>
<xs:element name="conditions">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element minOccurs="0" ref="quote"/>
<xs:element ref="condition"/>
</xs:sequence>
<xs:attributeGroup ref="id_date_author"/>
</xs:complexType>
</xs:element>
<xs:element name="transitions">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="transition"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute ref="version" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

0
debian/var/users/.placeholder vendored Normal file
View File

59
include/arrows.h Normal file
View File

@ -0,0 +1,59 @@
//=-------------------------------------------------------------------------=//
// Local workers definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
/* -------------------------------------------------------------------------- */
static inline int ArrowsInitLock(ArrowArray_t *arrowArray)
{
return pthread_spin_init(&arrowArray->lock, PTHREAD_PROCESS_SHARED);
}
static inline int ArrowsDestroyLock(ArrowArray_t *arrowArray)
{
return pthread_spin_destroy(&arrowArray->lock);
}
static inline int ArrowsAcquireLock(ArrowArray_t *arrowArray)
{
return pthread_spin_lock(&arrowArray->lock);
}
static inline int ArrowsAcquireNonBlockingLock(ArrowArray_t *arrowArray)
{
return pthread_spin_trylock(&arrowArray->lock);
}
static inline int ArrowsReleaseLock(ArrowArray_t *arrowArray)
{
return pthread_spin_unlock(&arrowArray->lock);
}
Arrow_t *ArrowAdd(Scheduler_t *scheduler, int x, int y, int z, int siteId,
int weight);
bool ArrowRemove(Scheduler_t *scheduler, int x, int y, int z, int siteId,
int weight);

206
include/base.h Normal file
View File

@ -0,0 +1,206 @@
//=-------------------------------------------------------------------------=//
// base definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include <sys/param.h>
#include <stdbool.h>
#include <pthread.h>
#include <unistd.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <netinet/in.h>
#define BASE_H
/* -------------------------------------------------------------------------- */
#define LOGMSG "[%s]"
#define printLog(FORMAT, ...) printf("\e[0m" LOGMSG " " FORMAT "\e[0m", \
__func__, ##__VA_ARGS__)
#define printErr(FORMAT,...) fprintf(stderr, "\e[0m" LOGMSG " " FORMAT "\e[0m",\
__func__, ##__VA_ARGS__)
#define LEN(x) (sizeof(x) / sizeof((x)[0]))
/* -------------------------------------------------------------------------- */
struct IntArray_t {
size_t size;
int *space;
} typedef IntArray_t;
struct Arrow_t {
int x;
int y;
int z;
int siteId;
int weight;
} typedef Arrow_t;
struct ArrowArray_t {
size_t size;
unsigned int freeSlotCount;
Arrow_t **freeSlots;
pthread_spinlock_t lock;
Arrow_t *array;
} typedef ArrowArray_t;
struct Site_t {
char *label;
int nArrow;
Arrow_t *arrowsPtr;
} typedef Site_t;
struct SpaceUnit_t {
int nSite;
char *label;
Site_t *sites;
} typedef SpaceUnit_t;
struct Space_t {
int xMax;
int yMax;
int zMax;
size_t size;
SpaceUnit_t *space;
} typedef Space_t;
/* -------------------------------------------------------------------------- */
//
// Scheduler
//
struct Scheduler_t {
pthread_t id;
bool pleaseStop;
Space_t *globalDrawingSpace;
IntArray_t *conditionTree;
ArrowArray_t *arrowArray;
int nMaxThread;
int nMaxCycles;
int ruleRadius;
} typedef Scheduler_t;
/* -------------------------------------------------------------------------- */
//
// Local threads
//
struct Center_t {
int x;
int y;
int z;
struct Center_t *next;
struct Center_t *prev;
} typedef Center_t;
struct Worker_t {
pthread_t id;
Center_t *localWorkAreaCenter;
Space_t *globalDrawingSpace;
IntArray_t *conditionTree; // XXX
ArrowArray_t *arrowArray;
bool pleaseStop;
bool terminated;
int returnValue;
} typedef Worker_t;
/* -------------------------------------------------------------------------- */
//
// Server
//
struct Server_t {
pthread_t id;
bool pleaseStop;
int returnValue;
int sockfd; // Socket file descriptor
} typedef Server_t;
struct ServerCommunication_t {
pthread_t id;
bool pleaseStop;
Server_t *associatedServer;
int sockfd; // Socket file descriptor
struct sockaddr_in clientAddr;
socklen_t sockLen;
} typedef ServerCommunication_t;
/* -------------------------------------------------------------------------- */
//
// Supervisor
//
struct Supervisor_t {
pthread_t id;
bool pleaseStop;
int *workerCreationOccurency; // XXX ???
} typedef Supervisor_t;
/* -------------------------------------------------------------------------- */
//
// Model
//
struct Model_t {
// Identity
int id;
bool validated; // true if model has been correctly parsed
char *name;
char *owner;
char *owner_id;
time_t date;
char *version;
char *filename;
// Parameters
int space_xMax; // TODO more than 3 dimension ?
int space_yMax;
int space_zMax;
int nmaxThread;
int nmaxCycles;
int siteNumber;
// Model instance
bool isRunning;
Scheduler_t *scheduler;
Supervisor_t *supervisor;
} typedef Model_t;
struct ModelField_t {
bool mandatory; // true if field must exist in file
char tag[25]; // XML tag attached to that field
char *destination; // data destination of that field
size_t size; // max size of data allowed
struct ModelField_t *son; // son in XML tree
struct ModelField_t *next; // brother in XML tree
} typedef ModelField_t;
/* -------------------------------------------------------------------------- */
//
// Parameters
//
struct Parameters_t {
char *configDir;
char *modelDir;
char *userDir;
} typedef Parameters_t;

38
include/centers.h Normal file
View File

@ -0,0 +1,38 @@
//=-------------------------------------------------------------------------=//
// Local workers definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Add a center to the center list //
// -------------------------------------------------------------------------- //
Center_t *CenterAdd(Center_t *anyCenter, Center_t *newCenter);
// -------------------------------------------------------------------------- //
// Remove a center from the center list //
// -------------------------------------------------------------------------- //
void CenterRemove(Center_t *oldCenter);

50
include/cmds.h Normal file
View File

@ -0,0 +1,50 @@
//=-------------------------------------------------------------------------=//
// Server supported commands definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
/* -------------------------------------------------------------------------- */
#define LINE_LENGTH 80
#define LINE_NUMBER 24
/* -------------------------------------------------------------------------- */
struct Command_t {
const char *name;
char* (*execute)(char*, char**, Server_t*);
const char *help;
} typedef Command_t;
/* -------------------------------------------------------------------------- */
//
// Existing commands
//
char *CmdModel(char*, char**, Server_t*);
char *CmdShutdown(char*, char**, Server_t*);
char *CmdHelp(char*, char**, Server_t*);
/* -------------------------------------------------------------------------- */

90
include/model.h Normal file
View File

@ -0,0 +1,90 @@
//=-------------------------------------------------------------------------=//
// Model definitions //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
#include <dirent.h>
#include <signal.h>
/* -------------------------------------------------------------------------- */
#define MODEL_STRING_SIZE 64
#define MAX_MODEL_NUMBER 1
#define ARROW_NUMBER 6
#define SITE_NUMBER 2
#define MAX_CYCLES 10
#define MAX_THREAD 0
#define XMAX 39
#define YMAX 0
#define ZMAX 0
#define SPACE_SIZE (XMAX+1) * (YMAX+1) * (ZMAX+1)
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Model init function (and model discovery) //
// -------------------------------------------------------------------------- //
void ModelSystemInit(Parameters_t *parameters);
// -------------------------------------------------------------------------- //
// Model stopping function //
// -------------------------------------------------------------------------- //
void ModelSystemDestroy(void);
// -------------------------------------------------------------------------- //
// Load a model ready to execute //
// -------------------------------------------------------------------------- //
int ModelLoad(int id);
// -------------------------------------------------------------------------- //
// Unload a model //
// -------------------------------------------------------------------------- //
int ModelUnload(int id);
// -------------------------------------------------------------------------- //
// Add a model to the known model list //
// -------------------------------------------------------------------------- //
void ModelAddToKnown(Model_t **newModel);
// -------------------------------------------------------------------------- //
// Print informations about all models (known and loaded) to the client //
// -------------------------------------------------------------------------- //
void printModels(char *buf);
// -------------------------------------------------------------------------- //
// Launch a model execution //
// -------------------------------------------------------------------------- //
int ModelRun(int id);
// -------------------------------------------------------------------------- //
// Stop a model execution //
// -------------------------------------------------------------------------- //
int ModelStop(int id);
// -------------------------------------------------------------------------- //
// Stop and unload all loaded or running model //
// -------------------------------------------------------------------------- //
void ModelShutdown(void);

73
include/parsing.h Normal file
View File

@ -0,0 +1,73 @@
//=-------------------------------------------------------------------------=//
// XML parsing module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
#include <string.h>
#include <stdlib.h>
#include <libxml/parser.h>
#include <libxml/xmlschemas.h>
/* -------------------------------------------------------------------------- */
#define NO_DESTINATION NULL
/* -------------------------------------------------------------------------- */
struct ModelParserTableXML_t;
struct ParserTableXML_t
{
const xmlChar *tag;
int (*parse) (xmlDoc*,
struct ModelParserTableXML_t*,
int currentParser,
xmlNode*);
void *destination;
} typedef ParserTableXML_t;
struct ModelParserTableXML_t
{
size_t len;
ParserTableXML_t *table;
} typedef ModelParserTableXML_t;
/* -------------------------------------------------------------------------- */
int parseParentFieldXML(xmlDocPtr,
ModelParserTableXML_t*,
int,
xmlNodePtr);
int parseTextField(xmlDocPtr,
ModelParserTableXML_t*,
int,
xmlNodePtr);
int ParseModelXML(Model_t*);
int ParseModelIdentityXML(Model_t*, Parameters_t*);
/* -------------------------------------------------------------------------- */

78
include/scheduler.h Normal file
View File

@ -0,0 +1,78 @@
//=-------------------------------------------------------------------------=//
// Scheduler definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
#include <sys/sysinfo.h>
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Scheduler init function //
// -------------------------------------------------------------------------- //
void SchedInit(Scheduler_t *scheduler);
// -------------------------------------------------------------------------- //
// Scheduler content destructor function //
// -------------------------------------------------------------------------- //
static inline void SchedContentDestroy(Scheduler_t *scheduler)
{
if (scheduler) {
if (scheduler->globalDrawingSpace) {
if (scheduler->globalDrawingSpace->space) {
free(scheduler->globalDrawingSpace->space);
scheduler->globalDrawingSpace->space = NULL;
}
free(scheduler->globalDrawingSpace);
scheduler->globalDrawingSpace = NULL;
}
if (scheduler->arrowArray) {
if (scheduler->arrowArray->array) {
free(scheduler->arrowArray->array);
scheduler->arrowArray->array = NULL;
}
free(scheduler->arrowArray);
scheduler->arrowArray = NULL;
}
}
}
// -------------------------------------------------------------------------- //
// Scheduler destructor function //
// -------------------------------------------------------------------------- //
static inline void SchedDestroy(Scheduler_t *scheduler)
{
if (scheduler) {
free(scheduler);
}
}
// -------------------------------------------------------------------------- //
// Scheduler wait function //
// -------------------------------------------------------------------------- //
static inline void SchedWait(Scheduler_t *scheduler)
{
pthread_join(scheduler->id, NULL);
}

48
include/server.h Normal file
View File

@ -0,0 +1,48 @@
//=-------------------------------------------------------------------------=//
// Server definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
#include <netdb.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <errno.h>
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Server init function //
// -------------------------------------------------------------------------- //
void ServerInit(Server_t *server);
// -------------------------------------------------------------------------- //
// Server wait function //
// -------------------------------------------------------------------------- //
static inline void ServerWait(Server_t *server)
{
pthread_join(server->id, NULL);
}

48
include/supervisor.h Normal file
View File

@ -0,0 +1,48 @@
//=-------------------------------------------------------------------------=//
// Supervisor definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Supervisor init function //
// -------------------------------------------------------------------------- //
void SupervisorInit(Supervisor_t *supervisor);
// -------------------------------------------------------------------------- //
// Supervisor destructor function //
// -------------------------------------------------------------------------- //
static inline void SupervisorDestroy(Supervisor_t *supervisor)
{
}
// -------------------------------------------------------------------------- //
// Supervisor wait function //
// -------------------------------------------------------------------------- //
static inline void SupervisorWait(Supervisor_t *supervisor)
{
pthread_join(supervisor->id, NULL);
}

181
include/terminal.h Normal file
View File

@ -0,0 +1,181 @@
//=-------------------------------------------------------------------------=//
// Terminal management tools //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
/* -------------------------------------------------------------------------- */
#include <sys/ioctl.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#define C_CLEARSCREEN "\e[2J"
#define C_CLEARLINE "\e[2K"
#define C_CURSORLEFT "\e[1D"
#define C_CURSORRIGHT "\e[1C"
#define C_SAVE_CURSORPOS "\e7"
#define C_RESTORE_CURSORPOS "\e8"
#define C_COLOR_RED "\e[01;31m"
#define C_COLOR_YELLOW "\e[00;33m"
#define C_COLOR_GREEN "\e[00;32m"
#define C_COLOR_BLUE "\e[01;34m"
#define C_COLOR_REVERSE "\e[7m"
#define C_COLOR_NORMAL "\e[0m"
#define C_COLOR_BLACK_ON_GREEN "\e[30;42m"
#define C_COLOR_LIGHTWHITE_ON_GREEN "\e[47;42m"
#define C_COLOR_LIGHTWHITE_ON_GREY "\e[47;100m"
#define C_COLOR_BLACK_ON_LIGHTGREY "\e[30;102m"
#define C_COLOR_WHITE_ON_BLUE "\e[107;44m"
#define NON_BLOCKING 1
/* -------------------------------------------------------------------------- */
volatile struct winsize TermWindowSize;
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Get a character code from the keyboard //
// -------------------------------------------------------------------------- //
static inline int TermGetch(bool nonBlocking)
{
int buf = 0;
// old terminal
struct termios old = {0};
// force flush stdout
fflush(stdout);
// Set non-blocking mode if asked
if(nonBlocking)
fcntl(0, F_SETFL, O_NONBLOCK);
if(tcgetattr(0, &old) < 0) {
printErr("%sError getting terminal settings! (%s)\n",
C_COLOR_RED,
strerror(errno));
return -1;
}
old.c_lflag &= ~ICANON; // disable buffered I/O
old.c_lflag &= ~ECHO; // set no echo mode
if(tcsetattr(0, TCSANOW, &old) < 0) {
printErr("%sError setting terminal settings! (%s)\n",
C_COLOR_RED,
strerror(errno));
return -1;
}
buf = getchar();
if(buf < 0) {
// Check target busy (try again)
if(errno == EAGAIN)
return 0;
printErr("%sError reading character! (%s)\n",
C_COLOR_RED,
strerror(errno));
return -1;
}
old.c_lflag |= ICANON; // enable buffered I/O
old.c_lflag |= ECHO; // set echo mode
if(tcsetattr(0, TCSADRAIN, &old) < 0) {
printErr("%sError resetting terminal settings! (%s)\n",
C_COLOR_RED,
strerror(errno));
return -1;
}
// Reset blocking mode
if(nonBlocking)
fcntl(0, F_SETFL, 0);
return buf;
}
// -------------------------------------------------------------------------- //
// Get the screen size //
// -------------------------------------------------------------------------- //
static inline void TermGetScreenSize(int signum)
{
// Get current terminal size
ioctl(STDOUT_FILENO, TIOCGWINSZ, &TermWindowSize);
}
// -------------------------------------------------------------------------- //
// Set cursor location //
// -------------------------------------------------------------------------- //
static inline void TermSetCursorLocation(char x, char y)
{
printf("\x1b[%d;%dH", y, x);
}
// -------------------------------------------------------------------------- //
// Save cursor location //
// -------------------------------------------------------------------------- //
static inline void TermSaveCursorLocation(void)
{
printf(C_SAVE_CURSORPOS);
}
// -------------------------------------------------------------------------- //
// Restore cursor location //
// -------------------------------------------------------------------------- //
static inline void TermRestoreCursorLocation(void)
{
printf(C_RESTORE_CURSORPOS);
}
// -------------------------------------------------------------------------- //
// Move cursor location to the right //
// -------------------------------------------------------------------------- //
static inline void TermMoveCursorForward(void)
{
printf(C_CURSORRIGHT);
}
// -------------------------------------------------------------------------- //
// Move cursor location to the left //
// -------------------------------------------------------------------------- //
static inline void TermMoveCursorBackward(void)
{
printf(C_CURSORLEFT);
}
// -------------------------------------------------------------------------- //
// Clear screen //
// -------------------------------------------------------------------------- //
static inline void TermClearScreen(void)
{
printf(C_CLEARSCREEN);
TermSetCursorLocation(1,1);
fflush(stdout);
}

55
include/worker.h Normal file
View File

@ -0,0 +1,55 @@
//=-------------------------------------------------------------------------=//
// Local workers definition //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Worker init function //
// -------------------------------------------------------------------------- //
void WorkerInit(Worker_t *worker);
// -------------------------------------------------------------------------- //
// Worker destructor function //
// -------------------------------------------------------------------------- //
static inline void WorkerDestroy(Worker_t *worker)
{
worker->pleaseStop = false;
worker->terminated = false;
worker->returnValue = false;
worker->id = 0;
free(worker->localWorkAreaCenter);
worker->localWorkAreaCenter = NULL;
}
// -------------------------------------------------------------------------- //
// Worker wait function //
// -------------------------------------------------------------------------- //
static inline void WorkerWait(Worker_t *worker)
{
pthread_join(worker->id, NULL);
}

35
include/xml.h Normal file
View File

@ -0,0 +1,35 @@
//=-------------------------------------------------------------------------=//
// XML management tools //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#pragma once
#ifndef BASE_H
#include "../include/base.h"
#endif
/* -------------------------------------------------------------------------- */
#include <string.h>
#include <stdlib.h>
#include <libxml2/libxml/xmlmemory.h>
#include <libxml2/libxml/parser.h>

31
src/arrows.c Normal file
View File

@ -0,0 +1,31 @@
//=-------------------------------------------------------------------------=//
// Arrows management module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/arrows.h"
/* -------------------------------------------------------------------------- */
static inline int location(Space_t *space, int x, int y, int z) {
return x + y * (space->xMax+1) + z * (space->xMax+1) * (space->zMax+1);
}

54
src/centers.c Normal file
View File

@ -0,0 +1,54 @@
//=-------------------------------------------------------------------------=//
// Centers management module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/centers.h"
/* -------------------------------------------------------------------------- */
Center_t *CenterAdd(Center_t *anyCenter, Center_t *newCenter)
{
if (!newCenter) return NULL;
if (anyCenter->next) {
anyCenter->next->prev = newCenter;
}
newCenter->next = anyCenter->next;
anyCenter->next = newCenter;
newCenter->prev = anyCenter;
return newCenter;
}
void CenterRemove(Center_t *oldCenter)
{
register Center_t *prev;
register Center_t *next;
//printLog("Removing center %p\n", oldCenter);
if (!oldCenter) return;
prev = oldCenter->prev;
next = oldCenter->next;
if (prev) prev->next = oldCenter->next;
if (next) next->prev = oldCenter->prev;
}

480
src/cli.c Normal file
View File

@ -0,0 +1,480 @@
//=-------------------------------------------------------------------------=//
// Command line interface main file //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/terminal.h"
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#define SEND_BUFFER_SIZE 80
#define RECEIVE_BUFFER_SIZE 80 * 24
#define NHISTORY 25
#define SERVER_IP_ADDR "127.0.0.1"
#define SERVER_PORT 9000
#define KEY_ESCAPE_1 27
#define KEY_ESCAPE_2 91
#define KEY_ESCAPE_3 51
#define KEY_ARROW_UP 65 // accessible after sequence KEY_ESCAPE_1, 2
#define KEY_ARROW_DOWN 66 // accessible after sequence KEY_ESCAPE_1, 2
#define KEY_ARROW_RIGHT 67 // accessible after sequence KEY_ESCAPE_1, 2
#define KEY_ARROW_LEFT 68 // accessible after sequence KEY_ESCAPE_1, 2
#define KEY_BACKSPACE 127
#define KEY_DELETE 126 // accessible after sequence KEY_ESCAPE_1, 2, 3
/* -------------------------------------------------------------------------- */
//
// Print monitor screen
//
void CliDecorateMonitor(int signum)
{
const char titleText[] = "GEM-GRAPH MONITOR";
const char screenTitleText[] = "Model view";
const char infosTitleText[] = "Model informations";
const char infosNameText[] = "Name ";
const char infosStatusText[] = "Status ";
const char infosOwnerText[] = "Owner ";
const char infosSchedulerText[] = "Scheduler id";
const char infosScThreadsText[] = "+ threads ";
TermGetScreenSize(signum);
TermClearScreen();
TermSetCursorLocation(1,1);
printf(C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE);
for (int i = 0; i < TermWindowSize.ws_col; i++) {
printf(" ");
}
TermSetCursorLocation(1,1);
printf("%s%s",
C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE,
titleText
);
TermSetCursorLocation(1,2);
printf(C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN);
for (int i = 0; i < TermWindowSize.ws_col; i++) {
printf(" ");
}
TermSetCursorLocation(1,2);
printf("%s%s",
C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN,
screenTitleText
);
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 2);
printf("%s%s",
C_COLOR_NORMAL C_COLOR_BLACK_ON_GREEN,
infosTitleText
);
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 4);
printf("%s%s%s (void)",
C_COLOR_NORMAL C_COLOR_BLACK_ON_LIGHTGREY,
infosNameText,
C_COLOR_NORMAL
);
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 6);
printf("%s%s%s (void)",
C_COLOR_BLACK_ON_GREEN,
infosStatusText,
C_COLOR_NORMAL
);
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 8);
printf("%s%s%s (void)",
C_COLOR_BLACK_ON_LIGHTGREY,
infosOwnerText,
C_COLOR_NORMAL
);
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 10);
printf("%s%s%s (void)",
C_COLOR_BLACK_ON_GREEN,
infosSchedulerText,
C_COLOR_NORMAL
);
TermSetCursorLocation(TermWindowSize.ws_col / 3 * 2, 12);
printf("%s%s%s (void)",
C_COLOR_BLACK_ON_LIGHTGREY,
infosScThreadsText,
C_COLOR_NORMAL
);
TermSetCursorLocation(1, TermWindowSize.ws_row - 1);
printf(C_COLOR_NORMAL C_COLOR_WHITE_ON_BLUE);
for (int i = 0; i < TermWindowSize.ws_col; i++) {
printf(" ");
}
TermSetCursorLocation(1, TermWindowSize.ws_row);
printf(C_COLOR_NORMAL);
for (int i = 0; i < TermWindowSize.ws_col; i++) {
printf(" ");
}
TermSetCursorLocation(1, TermWindowSize.ws_row);
printf("%sQ%s Quit\t%sS%s Start/Stop",
C_COLOR_NORMAL C_COLOR_REVERSE,
C_COLOR_NORMAL,
C_COLOR_REVERSE,
C_COLOR_NORMAL);
TermSetCursorLocation(1, 3);
fflush(stdout);
}
//
// Monitor mode main loop
//
int CliConnectedMonitor(int sockfd)
{
char sendBuff[SEND_BUFFER_SIZE] = {0};
char receiveBuff[RECEIVE_BUFFER_SIZE] = {0};
int pleaseStop = 0;
char curChar;
int answerLength;
signal(SIGWINCH ,CliDecorateMonitor);
CliDecorateMonitor(0);
while (!pleaseStop) {
// Zeroing buffer
bzero(sendBuff, sizeof(sendBuff));
// Read command from terminal
curChar = TermGetch(NON_BLOCKING);
switch (curChar) {
case 'q':
pleaseStop = true;
break;
}
/* // Otherwise send command to server */
/* send(sockfd, sendBuff, sizeof(sendBuff), 0); */
/* // Zeroing buffer */
/* bzero(receiveBuff, sizeof(receiveBuff)); */
/* // Reading server answer */
/* answerLength = recv(sockfd, receiveBuff, sizeof(receiveBuff), 0); */
/* // Detect disconnection */
/* if (answerLength == 0) { */
/* break; */
/* } */
/* // Detect null-string returned */
/* if (receiveBuff[0] == '\0') { */
/* // Invalid command */
/* } */
}
TermClearScreen();
printf("%sEnd of monitoring session\n\e[0m", C_COLOR_YELLOW);
return 0;
}
//
// Main CLI loop
//
void CliConnectedCommandLine(int sockfd)
{
char sendBuff[SEND_BUFFER_SIZE] = {0};
char receiveBuff[RECEIVE_BUFFER_SIZE] = {0};
char historyBuff[SEND_BUFFER_SIZE * NHISTORY + 1] = {0};
int historyIndex = 0, historyModifier;
char curChar;
int curLineLength, curPosition, continueReadLine, answerLength,
promptLength;
const char *exitCommand = "exit";
const char *monitorCommand = "monitor";
const char *promptString = C_COLOR_BLUE "gem-graph console" C_COLOR_NORMAL "> ";
promptLength = strlen("gem-graph console");
for (;;) {
// Zeroing buffer
bzero(sendBuff, sizeof(sendBuff));
printf("%s", promptString);
// Read command from terminal
curLineLength = 0;
curPosition = 0;
continueReadLine = 1;
historyModifier = -1;
while (continueReadLine && (curChar = TermGetch(0))) {
switch (curChar) {
case '\n':
printf("%c", curChar);
continueReadLine = 0;
break;
case KEY_BACKSPACE:
if (strlen(sendBuff) == 0)
break;
// Delete last char
sendBuff[--curPosition] = 0;
curLineLength--;
if (curLineLength >= 0) {
TermSaveCursorLocation();
memmove(sendBuff + curPosition, sendBuff + curPosition + 1,
SEND_BUFFER_SIZE);
printf("%s\r%s%s",
C_CLEARLINE,
promptString,
sendBuff
);
TermRestoreCursorLocation();
TermMoveCursorBackward();
}
break;
case KEY_ESCAPE_1:
if (TermGetch(0) == KEY_ESCAPE_2) {
switch(TermGetch(0)) {
case KEY_ARROW_UP:
if (historyIndex <= 0)
break;
historyModifier = (historyModifier + 1)
% (historyIndex + 1);
printf("%s\r%s%s",
C_CLEARLINE,
promptString,
&historyBuff[
(historyIndex - historyModifier - 1)
* SEND_BUFFER_SIZE
]
);
memcpy(sendBuff, &historyBuff[
(historyIndex - historyModifier - 1)
* SEND_BUFFER_SIZE
], SEND_BUFFER_SIZE);
curLineLength = strlen(sendBuff);
curPosition = curLineLength;
break;
case KEY_ARROW_DOWN:
if (historyIndex <= 0)
break;
historyModifier = (historyModifier + historyIndex)
% (historyIndex + 1);
printf("%s\r%s%s",
C_CLEARLINE,
promptString,
&historyBuff[
(historyIndex - historyModifier - 1)
* SEND_BUFFER_SIZE
]
);
memcpy(sendBuff, &historyBuff[
(historyIndex - historyModifier - 1)
* SEND_BUFFER_SIZE
], SEND_BUFFER_SIZE);
curLineLength = strlen(sendBuff);
curPosition = curLineLength;
break;
case KEY_ARROW_LEFT:
if (curPosition > 0) {
TermMoveCursorBackward();
curPosition--;
}
break;
case KEY_ARROW_RIGHT:
if (curPosition < curLineLength) {
TermMoveCursorForward();
curPosition++;
}
break;
case KEY_ESCAPE_3:
if (TermGetch(0) == KEY_DELETE) {
if (strlen(sendBuff) == 0)
break;
// Delete next char
sendBuff[curPosition] = 0;
curLineLength--;
if (curLineLength >= 0) {
TermSaveCursorLocation();
memmove(sendBuff + curPosition, sendBuff + curPosition + 1,
SEND_BUFFER_SIZE);
printf("%s\r%s%s",
C_CLEARLINE,
promptString,
sendBuff
);
TermRestoreCursorLocation();
}
else {
TermMoveCursorForward(); // XXX
}
}
break;
}
}
break;
default:
if (curLineLength < MIN(SEND_BUFFER_SIZE,
TermWindowSize.ws_col - promptLength - 3)
&& curChar > 0) {
TermSaveCursorLocation();
memmove(sendBuff + curPosition + 1, sendBuff + curPosition,
SEND_BUFFER_SIZE);
sendBuff[curPosition++] = curChar;
curLineLength++;
printf("%s\r%s%s",
C_CLEARLINE,
promptString,
sendBuff
);
TermRestoreCursorLocation();
TermMoveCursorForward();
}
break;
}
fflush(stdout);
}
// Do not send null-string
if (curLineLength == 0)
continue;
// Update history
memcpy(&historyBuff[historyIndex * SEND_BUFFER_SIZE], sendBuff,
SEND_BUFFER_SIZE);
historyIndex = (historyIndex + 1) % NHISTORY;
// Quit if asked
if (strcmp(exitCommand, sendBuff) == 0) {
break;
}
// Launch monitor mode if asked
if (strcmp(monitorCommand, sendBuff) == 0) {
CliConnectedMonitor(sockfd);
continue;
}
// Otherwise send command to server
send(sockfd, sendBuff, sizeof(sendBuff), 0);
// Zeroing buffer
bzero(receiveBuff, sizeof(receiveBuff));
// Reading server answer
answerLength = recv(sockfd, receiveBuff, sizeof(receiveBuff), 0);
// Detect disconnection
if (answerLength == 0) {
break;
}
// Detect null-string returned
if (receiveBuff[0] == '\0') {
printf("%sInvalid command!\n\e[0m", C_COLOR_YELLOW);
}
printf("%s\n", receiveBuff);
}
printf("%sDisconnected\n\e[0m", C_COLOR_YELLOW);
}
//
// main
//
int main(void)
{
int sockfd;
struct sockaddr_in servaddr;
// Socket creation
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
printErr("%sSocket creation failed! (%s)\n",
C_COLOR_RED,
strerror(errno));
return 1;
}
bzero(&servaddr, sizeof(servaddr));
// Assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr(SERVER_IP_ADDR);
servaddr.sin_port = htons(SERVER_PORT);
// Connect to the server
if (connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) != 0) {
printErr("%sConnection failed! (%s)\n",
C_COLOR_RED,
strerror(errno));
return 2;
}
printLog("%sConnected to server!\n\n", C_COLOR_GREEN);
signal(SIGWINCH, TermGetScreenSize);
TermGetScreenSize(0);
CliConnectedCommandLine(sockfd);
// close the socket
close(sockfd);
return 0;
}

222
src/cmds.c Normal file
View File

@ -0,0 +1,222 @@
//=-------------------------------------------------------------------------=//
// Server management module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/cmds.h"
#include "../include/scheduler.h"
#include "../include/model.h"
#include <sys/socket.h>
/* -------------------------------------------------------------------------- */
char *CmdModel(char *buf, char **argv, Server_t *args)
{
int id, eid;
Model_t *newModel;
// invalid use
if (!argv[1]) {
strcat(buf, "{create | delete | load | unload | run | stop | list |"
"info}\n");
goto CmdModelEnd;
}
if (strcmp(argv[1], "create") == 0) {
if (!argv[2] || !argv[3]) {
goto createEnd;
}
if (strncmp(argv[2], "name=", 5) == 0) {
if (strncmp(argv[3], "file=", 5) == 0) {
// TODO get the file content (sent by the client) from args
// Creating model
ModelAddToKnown(&newModel);
// TODO modify model according to things in file
// Write name
strcpy(newModel->name, argv[2] + 5);
// Write filename
strcpy(newModel->filename, argv[3] + 5);
sprintf(buf + strlen(buf), "Model %s created with id %d\n",
newModel->name, newModel->id);
goto CmdModelEnd;
} else {
goto createEnd;
}
} else {
goto createEnd;
}
createEnd:
// invalid use
strcat(buf, "Creates a model structure\n");
strcat(buf, "Usage: model create name=NAME file=FILENAME\n");
goto CmdModelEnd;
}
else if (strcmp(argv[1], "load") == 0) {
if (!argv[2]) {
goto loadEnd;
}
id = (int) strtol(argv[2] + 3, NULL, 10);
if (id == 0 || (eid = ModelLoad(id)) <= 0) {
sprintf(buf + strlen(buf), "Failed to load model id %d\n", id);
goto CmdModelEnd;
}
sprintf(buf + strlen(buf), "Model id %d loaded with effective "
"id %d\n", id, eid);
goto CmdModelEnd;
loadEnd:
// invalid use
strcat(buf, "Loads a model structure\n");
strcat(buf, "Usage: model load id=ID\n");
goto CmdModelEnd;
}
else if (strcmp(argv[1], "unload") == 0) {
if (!argv[2]) {
goto unloadEnd;
}
id = (int) strtol(argv[2] + 3, NULL, 10);
if (id == 0 || ModelUnload(id) < 0) {
printErr("Failed to unload model id %d\n", id);
sprintf(buf + strlen(buf), "Failed to unload model id %d\n", id);
goto CmdModelEnd;
}
sprintf(buf + strlen(buf), "Model id %d unloaded\n", id);
goto CmdModelEnd;
unloadEnd:
// invalid use
strcat(buf, "Unloads a model structure\n");
strcat(buf, "Usage: model unload id=ID\n");
goto CmdModelEnd;
}
else if (strcmp(argv[1], "delete") == 0) {
if (!argv[2]) {
goto deleteEnd;
}
// TODO delete model
deleteEnd:
// invalid use
strcat(buf, "Deletes a model structure\n");
strcat(buf, "Usage: model delete id=ID\n");
goto CmdModelEnd;
}
else if (strcmp(argv[1], "run") == 0) {
if (!argv[2]) {
goto runEnd;
}
id = (int) strtol(argv[2] + 3, NULL, 10);
if (id == 0 || (!ModelRun(id))) {
sprintf(buf + strlen(buf), "Failed to run model id %d\n", id);
goto CmdModelEnd;
}
sprintf(buf + strlen(buf), "Model id %d is running\n", id);
goto CmdModelEnd;
runEnd:
// invalid use
strcat(buf, "Run a model simulation\n");
strcat(buf, "Usage: model run id=ID\n");
goto CmdModelEnd;
}
else if (strcmp(argv[1], "stop") == 0) {
if (!argv[2]) {
goto stopEnd;
}
id = (int) strtol(argv[2] + 3, NULL, 10);
if (id == 0 || (!ModelStop(id))) {
sprintf(buf + strlen(buf), "Failed to stop model id %d\n", id);
goto CmdModelEnd;
}
sprintf(buf + strlen(buf), "Model id %d is running\n", id);
goto CmdModelEnd;
stopEnd:
// invalid use
strcat(buf, "Stop a model simulation\n");
strcat(buf, "Usage: model stop id=ID\n");
goto CmdModelEnd;
}
else if (strcmp(argv[1], "list") == 0) {
strcat(buf, "You asked for us to list models\n");
printModels(buf);
}
else if (strcmp(argv[1], "info") == 0) {
if (!argv[2]) {
goto infoEnd;
}
// TODO info model
infoEnd:
// invalid use
strcat(buf, "Print info about a model\n");
strcat(buf, "Usage: model info id=ID\n");
goto CmdModelEnd;
}
// invalid use
else strcat(buf, "{create | delete | load | unload | run | stop | list |"
"info}\n");
CmdModelEnd:
return buf;
}
char *CmdShutdown(char *buf, char **argv, Server_t *args)
{
args->pleaseStop = true;
strcat(buf, "Server stopping\n");
ModelShutdown();
strcat(buf, "All model shutted down\n");
return buf;
}
char *CmdHelp(char *buf, char **argv, Server_t *args)
{
strcat(buf, "List of known commands:\n");
return buf;
}

141
src/main.c Normal file
View File

@ -0,0 +1,141 @@
//=-------------------------------------------------------------------------=//
// Main //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/base.h"
#include "../include/server.h"
#include "../include/model.h"
/* -------------------------------------------------------------------------- */
static Server_t *server;
static void sigtermHandler(int signum)
{
server->pleaseStop = true;
printLog("Server stopping\n");
ModelShutdown();
printLog("All model shutted down\n");
}
int main(int argc, char **argv)
{
int options;
time_t t;
int returnValue = 0;
Parameters_t parameters;
while ((options = getopt(argc, argv, ":C:M:U:")) != -1) {
switch (options) {
case 'C':
printLog("Config : %s\n", optarg);
parameters.configDir = calloc(1, strlen(optarg) + 1);
strcpy(parameters.configDir, optarg);
break;
case 'M':
printLog("Models : %s\n", optarg);
parameters.modelDir = calloc(1, strlen(optarg) + 1);
strcpy(parameters.modelDir, optarg);
break;
case 'U':
printLog("Users : %s\n", optarg);
parameters.userDir = calloc(1, strlen(optarg) + 1);
strcpy(parameters.userDir, optarg);
break;
case ':':
printErr("Option missing argument : %c\n", optopt);
if (parameters.configDir)
free(parameters.configDir);
if (parameters.modelDir)
free(parameters.modelDir);
if (parameters.userDir)
free(parameters.userDir);
return ENOSYS;
break;
case '?':
printErr("Unknown option : %c\n", optopt);
if (parameters.configDir)
free(parameters.configDir);
if (parameters.modelDir)
free(parameters.modelDir);
if (parameters.userDir)
free(parameters.userDir);
return ENOSYS;
break;
}
}
if (!parameters.configDir | !parameters.modelDir | !parameters.userDir) {
printErr("Missing arguments\n");
if (parameters.configDir)
free(parameters.configDir);
if (parameters.modelDir)
free(parameters.modelDir);
if (parameters.userDir)
free(parameters.userDir);
return ENOSYS;
}
// Go!
printLog("Starting gem-graph-server...\n");
// Register new interrupt handler
signal(SIGINT, sigtermHandler);
signal(SIGTERM, sigtermHandler);
// Initializing random generator
t = time(&t);
srand((unsigned) t);
server = calloc(1, sizeof(*server));
// Initializing model system
ModelSystemInit(&parameters);
// Launching server
ServerInit(server);
// Waiting for termination
ServerWait(server);
// Exiting
returnValue |= server->returnValue;
ModelSystemDestroy();
free(server);
server = NULL;
free(parameters.userDir);
free(parameters.modelDir);
free(parameters.configDir);
return returnValue;
}

310
src/model.c Normal file
View File

@ -0,0 +1,310 @@
//=-------------------------------------------------------------------------=//
// Model management module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/model.h"
#include "../include/parsing.h"
#include "../include/arrows.h"
#include "../include/scheduler.h"
static Model_t **loadedModel;
static int loadedModelSize; // begins to 1
static Model_t **knownModel;
static int knownModelSize; // begins to 1
Model_t *lastModel;
Model_t **lastModelAddr;
/* -------------------------------------------------------------------------- */
void printModels(char *buf)
{
sprintf(buf + strlen(buf),"Known models\n");
for (int i = 0; i <= knownModelSize-1; i++) {
sprintf(buf + strlen(buf), "id: %d, addr: %p, name: %s, date: %lu, "
"owner: %s\n",
knownModel[i]->id,
knownModel[i],
knownModel[i]->name,
knownModel[i]->date,
knownModel[i]->owner
);
}
sprintf(buf + strlen(buf), "\nLoaded models\n");
for (int i = 0; i <= loadedModelSize-1; i++) {
sprintf(buf + strlen(buf), "id: %d, addr: %p, name: %s\n",
loadedModel[i]->id, loadedModel[i], loadedModel[i]->name);
}
}
int ModelLoad(int id)
{
if (id <= 0 || id > knownModelSize) {
return -1;
}
printLog("Loading model id %d (/%d models)...\n", id, knownModelSize);
// Creating structure for the Scheduler
knownModel[id-1]->scheduler =
calloc(1, sizeof(*knownModel[id-1]->scheduler));
loadedModelSize++;
loadedModel =
(Model_t**) realloc(loadedModel, loadedModelSize * sizeof(Model_t*));
loadedModel[loadedModelSize-1] = knownModel[id-1];
// Parse model
ParseModelXML(loadedModel[loadedModelSize-1]);
return loadedModelSize;
}
int ModelUnload(int id)
{
// Destroy scheduler
if (id > loadedModelSize)
return -1;
SchedContentDestroy(loadedModel[id-1]->scheduler);
SchedDestroy(loadedModel[id-1]->scheduler);
loadedModel[id-1]->scheduler = NULL;
// Prevent fragmentation by moving data in the newly freed slot
if (id-1 < loadedModelSize) {
memmove(&loadedModel[id-1],
&loadedModel[id-1] + sizeof(Model_t*),
loadedModelSize - id);
}
// Decrement loaded model index
loadedModelSize--;
// Resize loaded model list
loadedModel =
(Model_t**) realloc(loadedModel, loadedModelSize * sizeof(Model_t*));
return 0;
}
/* -------------------------------------------------------------------------- */
int ModelRun(int id)
{
if (id <= 0 || id > loadedModelSize)
return -1;
if (!loadedModel[id-1]->scheduler)
return -2;
if (loadedModel[id-1]->isRunning)
return -3;
loadedModel[id-1]->scheduler->nMaxThread = knownModel[id-1]->nmaxThread;
loadedModel[id-1]->scheduler->nMaxCycles = knownModel[id-1]->nmaxCycles;
loadedModel[id-1]->scheduler->pleaseStop = false;
loadedModel[id-1]->isRunning = true;
SchedInit(loadedModel[id-1]->scheduler);
printLog("Model %d launched\n", id);
return 0;
}
int ModelStop(int id)
{
if (id <= 0 || id > loadedModelSize) {
return -1;
}
if (!loadedModel[id-1]->scheduler) {
return -2;
}
if (!loadedModel[id-1]->isRunning) {
return -3;
}
// Stop model scheduler
loadedModel[id-1]->scheduler->pleaseStop = true;
printLog("Model %d stop bit set\n", id);
// Wait for Shceduler to stop
SchedWait(loadedModel[id-1]->scheduler);
// Disable running bit
loadedModel[id-1]->isRunning = false;
return 0;
}
/* -------------------------------------------------------------------------- */
void ModelAddToKnown(Model_t **newModel)
{
// increment index
knownModelSize++;
// create socket
knownModel =
(Model_t**) realloc(knownModel, knownModelSize * sizeof(*knownModel));
// populate socket
knownModel[knownModelSize-1] = calloc(1, sizeof(**knownModel));
// populate model
knownModel[knownModelSize-1]->id = knownModelSize;
// return value
*newModel = knownModel[knownModelSize-1];
lastModel = knownModel[knownModelSize-1];
lastModelAddr = &knownModel[knownModelSize-1];
// continue. model population
knownModel[knownModelSize-1]->name =
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
knownModel[knownModelSize-1]->filename =
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
knownModel[knownModelSize-1]->owner =
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
knownModel[knownModelSize-1]->version =
calloc(1, sizeof(char) * MODEL_STRING_SIZE);
knownModel[knownModelSize-1]->space_xMax = XMAX;
knownModel[knownModelSize-1]->space_yMax = YMAX;
knownModel[knownModelSize-1]->space_zMax = ZMAX;
knownModel[knownModelSize-1]->nmaxThread = MAX_THREAD;
knownModel[knownModelSize-1]->nmaxCycles = MAX_CYCLES;
knownModel[knownModelSize-1]->siteNumber = 0;
}
void ModelDelete(int id) //XXX fragmentation
{
// Free a model structure
free(knownModel[id-1]->name);
knownModel[id-1]->name = NULL;
free(knownModel[id-1]->filename);
knownModel[id-1]->filename = NULL;
free(knownModel[id-1]->owner);
knownModel[id-1]->owner = NULL;
free(knownModel[id-1]->version);
knownModel[id-1]->version = NULL;
free(knownModel[id-1]);
knownModel[id-1] = NULL;
}
void ModelShutdown(void)
{
// Stop each model from running
for (int i = 0; i < loadedModelSize; i++) {
ModelStop(i);
ModelUnload(i);
}
}
/* -------------------------------------------------------------------------- */
void ModelSystemInit(Parameters_t *parameters)
{
struct dirent *modelDirEntry = NULL;
DIR *modelDir = NULL;
Model_t *newModel;
char *extensionPosition;
loadedModel = calloc(1, sizeof(*loadedModel));
knownModel = calloc(1, sizeof(*knownModel));
knownModelSize = 0;
loadedModelSize = 0;
printLog("Model system initiated with folder : %s\n", parameters->modelDir);
// Open model directory
if ((modelDir = opendir(parameters->modelDir)) <= 0) {
printErr("Could not open %s\n", parameters->modelDir);
ModelSystemDestroy();
kill(getpid(), SIGTERM);
return;
}
while ((modelDirEntry = readdir(modelDir)) != NULL) {
if ((extensionPosition = strstr(modelDirEntry->d_name, ".xml"))) {
// Creating model
ModelAddToKnown(&newModel);
// Write file path in filename
strncpy(newModel->filename, parameters->modelDir,
strlen(parameters->modelDir));
// Add a / separator
strcat(newModel->filename
+ strlen(parameters->modelDir),
"/");
// Add the file relative name
strncpy(newModel->filename
+ strlen(parameters->modelDir)
+ 1,
modelDirEntry->d_name,
strlen(modelDirEntry->d_name));
// Write model name
strncpy(newModel->name, modelDirEntry->d_name,
extensionPosition - modelDirEntry->d_name);
// Ask to parse the new model
if (ParseModelIdentityXML(newModel, parameters) != 0) {
printErr("Deleting invalid model %s from known list\n",
newModel->name);
ModelDelete(newModel->id);
continue;
};
// Check model is valid and/or parsed
if (newModel->validated == false) {
printErr("Deleting invalid model %s from known list\n",
newModel->name);
ModelDelete(newModel->id);
continue;
}
// Succeeded !
printLog("Loaded model %s\n", newModel->name);
}
}
free(modelDir);
}
void ModelSystemDestroy(void)
{
for (int i = 0; i < loadedModelSize; i++) {
ModelDelete(i);
}
free(loadedModel);
loadedModel = NULL;
free(knownModel);
knownModel = NULL;
}

583
src/parsing.c Normal file
View File

@ -0,0 +1,583 @@
//=-------------------------------------------------------------------------=//
// XML parsing module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/parsing.h"
#include "../include/arrows.h"
#include "../include/model.h"
// -------------------------------------------------------------------------- //
// Parsing NOTHING (but yeah that prints) //
// -------------------------------------------------------------------------- //
int parseStubFieldXML (xmlDocPtr doc,
ModelParserTableXML_t *ModelTable,
int currentParser,
xmlNodePtr currentNode)
{
xmlChar *content, *contentText, *contentValueAttribute;
contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
contentValueAttribute = xmlGetProp(currentNode,
(xmlChar*)"value");
if (contentText) {
content = contentText;
} else if (contentValueAttribute) {
content = contentValueAttribute;
// Detect children
if (currentNode->xmlChildrenNode) {
printLog("%s (stub) has children\n",
ModelTable->table[currentParser].tag);
}
}
printLog("%s (stub): %s\n", ModelTable->table[currentParser].tag,
content);
if (!content) {
xmlFree(contentText);
xmlFree(contentValueAttribute);
return -1;
}
xmlFree(contentText);
xmlFree(contentValueAttribute);
return 0;
}
// -------------------------------------------------------------------------- //
// Parsing an arrow (but yeah that prints) //
// -------------------------------------------------------------------------- //
int parseArrowFieldXML (xmlDocPtr doc,
ModelParserTableXML_t *ModelTable,
int currentParser,
xmlNodePtr currentNode)
{
Model_t *destination = ModelTable->table[currentParser].destination;
xmlChar *x, *y, *z, *siteId, *weight;
x = xmlGetProp(currentNode, (xmlChar*)"x");
y = xmlGetProp(currentNode, (xmlChar*)"y");
z = xmlGetProp(currentNode, (xmlChar*)"z");
siteId = xmlGetProp(currentNode, (xmlChar*)"siteId");
weight = xmlGetProp(currentNode, (xmlChar*)"weight");
// Detect children
if (currentNode->xmlChildrenNode) {
printLog("%s (stub) has children\n",
ModelTable->table[currentParser].tag);
}
printLog("%s: x:%s, y:%s, z:%s\n", ModelTable->table[currentParser].tag,
x, y, z);
if (!x || !y || !z) {
xmlFree(x);
xmlFree(y);
xmlFree(z);
return -1;
}
// Create arrow in model
if (destination->scheduler) {
ArrowAdd(destination->scheduler,
atoi((char*)x), atoi((char*)y), atoi((char*)z),
atoi((char*)siteId), atoi((char*)weight));
} else {
xmlFree(x);
xmlFree(y);
xmlFree(z);
return -1;
}
xmlFree(x);
xmlFree(y);
xmlFree(z);
return 0;
}
int parseSpaceSizeFieldXML (xmlDocPtr doc,
ModelParserTableXML_t *ModelTable,
int currentParser,
xmlNodePtr currentNode)
{
xmlChar *x, *y, *z;
Model_t *destination =
(Model_t*)ModelTable->table[currentParser].destination;
x = xmlGetProp(currentNode, (xmlChar*)"x");
y = xmlGetProp(currentNode, (xmlChar*)"y");
z = xmlGetProp(currentNode, (xmlChar*)"z");
// Detect children
if (currentNode->xmlChildrenNode) {
printLog("%s (stub) has children\n",
ModelTable->table[currentParser].tag);
}
printLog("%s: x:%s, y:%s, z:%s\n", ModelTable->table[currentParser].tag,
x, y, z);
if (!x || !y || !z) {
xmlFree(x);
xmlFree(y);
xmlFree(z);
return -1;
}
// Store space size
destination->space_xMax = atoi((const char*)x);
destination->space_yMax = atoi((const char*)y);
destination->space_zMax = atoi((const char*)z);
xmlFree(x);
xmlFree(y);
xmlFree(z);
return 0;
}
// -------------------------------------------------------------------------- //
// Parsing a text field //
// -------------------------------------------------------------------------- //
int parseTextFieldXML (xmlDocPtr doc,
ModelParserTableXML_t *ModelTable,
int currentParser,
xmlNodePtr currentNode)
{
xmlChar *content, *contentText, *contentValueAttribute;
char *destination = (char*)ModelTable->table[currentParser].destination;
contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
contentValueAttribute = xmlGetProp(currentNode,
(xmlChar*)"value");
if (contentText) {
content = contentText;
} else if (contentValueAttribute) {
content = contentValueAttribute;
// Detect children
if (currentNode->xmlChildrenNode) {
printLog("%s has children\n", ModelTable->table[currentParser].tag);
}
}
printLog("%s: %s\n", ModelTable->table[currentParser].tag,
content);
if (!content) {
xmlFree(contentText);
xmlFree(contentValueAttribute);
return -1;
}
strcat(destination, " ");
strncpy(destination + strlen(destination),
(char *)content, MODEL_STRING_SIZE - strlen(destination));
xmlFree(contentText);
xmlFree(contentValueAttribute);
return 0;
}
// -------------------------------------------------------------------------- //
// Parsing an integer field //
// -------------------------------------------------------------------------- //
int parseIntFieldXML (xmlDocPtr doc,
ModelParserTableXML_t *ModelTable,
int currentParser,
xmlNodePtr currentNode)
{
xmlChar *content, *contentText, *contentValueAttribute;
int *destination = (int*)ModelTable->table[currentParser].destination;
contentText = xmlNodeListGetString(doc, currentNode->xmlChildrenNode, 1);
contentValueAttribute = xmlGetProp(currentNode,
(xmlChar*)"value");
if (contentText) {
content = contentText;
} else if (contentValueAttribute) {
content = contentValueAttribute;
// Detect children
if (currentNode->xmlChildrenNode) {
printLog("%s has children\n", ModelTable->table[currentParser].tag);
}
}
printLog("%s: %s\n", ModelTable->table[currentParser].tag,
content);
if (!content) {
xmlFree(contentText);
xmlFree(contentValueAttribute);
return -1;
}
*destination = (int)atoi((char*)content);
xmlFree(content);
return 0;
}
// -------------------------------------------------------------------------- //
// Parsing a field that contains children fields //
// -------------------------------------------------------------------------- //
int parseParentFieldXML (xmlDocPtr doc,
ModelParserTableXML_t *ModelTable,
int currentParser,
xmlNodePtr currentNode)
{
printLog("%s parsed\n",
ModelTable->table[currentParser].tag);
// Getting children content
currentNode = currentNode->xmlChildrenNode;
while (currentNode != NULL) {
for (int i = 0; i < ModelTable->len; i++) {
if ((!xmlStrcmp(currentNode->name,
ModelTable->table[i].tag))) {
ModelTable->table[i].parse(doc,
ModelTable,
i,
currentNode);
break;
}
}
currentNode = currentNode->next;
}
return 0;
}
// -------------------------------------------------------------------------- //
// Parsing a field that contains children fields with props //
// -------------------------------------------------------------------------- //
int parseParentFieldPropsXML (xmlDocPtr doc,
ModelParserTableXML_t *ModelTable,
int currentParser,
xmlNodePtr currentNode)
{
xmlChar *id, *date, *author;
// (truc*)destination = (truc*)ModelTable->table[currentParser].destination;
// Getting field identity
id = xmlGetProp(currentNode, (xmlChar*)"id");
date = xmlGetProp(currentNode, (xmlChar*)"date");
author = xmlGetProp(currentNode, (xmlChar*)"author");
printLog("%s parsed (id=%s, date=%s, author=%s)\n",
ModelTable->table[currentParser].tag, id, date, author);
// Getting children content
currentNode = currentNode->xmlChildrenNode;
while (currentNode != NULL) {
for (int i = 0; i < ModelTable->len; i++) {
if ((!xmlStrcmp(currentNode->name,
ModelTable->table[i].tag))) {
ModelTable->table[i].parse(doc,
ModelTable,
i,
currentNode);
break;
}
}
currentNode = currentNode->next;
}
free(id);
free(date);
free(author);
return 0;
}
// -------------------------------------------------------------------------- //
// Preparsing a model file //
// -------------------------------------------------------------------------- //
int ParseModelIdentityXML(Model_t *model, Parameters_t *params)
{
xmlDocPtr xmlDocument;
xmlNodePtr currentNode;
xmlChar *version = NULL;
xmlSchemaPtr schemPtr;
xmlSchemaValidCtxtPtr schemValidator;
xmlSchemaParserCtxtPtr schemFile;
char *schemPath;
ParserTableXML_t table[] =
{
// IDENTITY
{(const xmlChar *)"identity", parseParentFieldXML, NULL},
{(const xmlChar *)"name", parseTextFieldXML, model->name},
{(const xmlChar *)"owner", parseTextFieldXML, model->owner},
// TODO lacking implementation (model side)
{(const xmlChar *)"owner_id", parseStubFieldXML, model->owner_id},
{(const xmlChar *)"date", parseIntFieldXML, &model->date},
{(const xmlChar *)"version", parseTextFieldXML, model->version},
// PARAMETERS
{(const xmlChar *)"parameters", parseParentFieldPropsXML, model},
// MODELIZATION
{(const xmlChar *)"modelization", parseParentFieldXML, model},
{(const xmlChar *)"max_thread", parseStubFieldXML, model},
{(const xmlChar *)"max_cycles", parseStubFieldXML, model},
// SPACE
{(const xmlChar *)"space_param", parseParentFieldXML, model},
{(const xmlChar *)"dimension", parseStubFieldXML, model},
{(const xmlChar *)"size", parseSpaceSizeFieldXML, model},
{(const xmlChar *)"site_multiplicity", parseIntFieldXML,
&model->siteNumber},
// TODO lacking implementation (model side)
{(const xmlChar *)"boundaries", parseStubFieldXML, model},
};
ModelParserTableXML_t identityParserTable =
{
LEN(table),
&table[0]
};
// Allocating space for schema file path
schemPath = calloc(1, strlen(params->modelDir)
+ strlen("/schemas/model_ .xmls"));
printLog("Preparsing model %s\n", model->name);
// Opening document
xmlDocument = xmlReadFile(model->filename, NULL, 0);
if (xmlDocument == NULL) {
printErr("Can't parse model file at '%s'.\n", model->filename);
return -1;
}
// Getting root from XML model file
currentNode = xmlDocGetRootElement(xmlDocument);
if (currentNode == NULL) {
printErr("Invalid model file at '%s', document empty !\n",
model->filename);
xmlFreeDoc(xmlDocument);
free(schemPath);
return -2;
}
// Checking that XML file is actually a model
if (xmlStrcmp(currentNode->name, (const xmlChar *) "gem-graph-model")) {
printErr("Invalid model file at '%s', "
"root node is not <gem-graph-model> !\n",
model->filename);
xmlFreeDoc(xmlDocument);
free(schemPath);
return -3;
}
// Get gem-graph model version to parse
version = xmlGetProp(currentNode, (xmlChar*)"version");
// Check version is present
if (!version) {
printErr("Missing version for model %s \n", model->name);
xmlFreeDoc(xmlDocument);
free(schemPath);
return -4;
} else if (strlen((char*)version) > MODEL_STRING_SIZE) {
printErr("Invalid version number for model %s \n", model->name);
free(version);
xmlFreeDoc(xmlDocument);
free(schemPath);
}
printLog("Gem-graph model version %s detected\n", version);
// Retrieving schema file
sprintf(schemPath, "%s/schemas/model_%s.xmls", params->modelDir, version);
printLog("Loading schema %s\n", schemPath);
// Loading schema file
schemFile = xmlSchemaNewParserCtxt(schemPath);
if (schemFile == NULL) {
printErr("Invalid gem-graph version %s in model %s: no schema present",
version, model->name);
free(version);
xmlFreeDoc(xmlDocument);
free(schemPath);
return -5;
}
// Loading schema file content
schemPtr = xmlSchemaParse(schemFile);
if (schemPtr == NULL) {
printErr("Invalid schema file, version %s\n", version);
xmlSchemaFreeParserCtxt(schemFile);
free(version);
xmlFreeDoc(xmlDocument);
free(schemPath);
return -6;
}
// Creating validating context
schemValidator = xmlSchemaNewValidCtxt(schemPtr);
if (schemValidator == NULL) {
xmlSchemaFreeParserCtxt(schemFile);
xmlSchemaFree(schemPtr);
free(version);
xmlFreeDoc(xmlDocument);
free(schemPath);
printErr("An error occured preparing schema file, version %s\n", version);
return -7;
}
// Validate (and print errors) !
xmlSchemaSetValidErrors(schemValidator,
(xmlSchemaValidityErrorFunc) fprintf,
(xmlSchemaValidityWarningFunc) fprintf, stderr);
// Get the validation status
model->validated =
xmlSchemaValidateDoc(schemValidator, xmlDocument) == 0 ? true : false;
// Reset node
currentNode = xmlDocGetRootElement(xmlDocument);
// Parsing identity
currentNode = currentNode->xmlChildrenNode;
while (currentNode != NULL) {
for (int i = 0; i < identityParserTable.len; i++) {
if ((!xmlStrcmp(currentNode->name,
identityParserTable.table[i].tag))) {
identityParserTable.table[i].parse(xmlDocument,
&identityParserTable,
i,
currentNode);
}
}
currentNode = currentNode->next;
}
xmlSchemaFreeParserCtxt(schemFile);
xmlSchemaFreeValidCtxt(schemValidator);
xmlSchemaFree(schemPtr);
free(version);
xmlFreeDoc(xmlDocument);
free(schemPath);
xmlCleanupParser();
return 0;
}
// -------------------------------------------------------------------------- //
// Parsing a model file //
// -------------------------------------------------------------------------- //
int ParseModelXML(Model_t *model)
{
xmlDocPtr xmlDocument;
xmlNodePtr currentNode;
ParserTableXML_t table[] =
{
// OBJECTS
// {(const xmlChar *)"objects", parseParentFieldXML, model},
// {(const xmlChar *)"object", parseParentFieldPropsXML, model},
// SAVESTATES
{(const xmlChar *)"savestates", parseParentFieldPropsXML, model},
// SPACE
{(const xmlChar *)"space", parseParentFieldPropsXML, model},
// TRANSITIONS
{(const xmlChar *)"transitions", parseParentFieldPropsXML, model},
// TRANSITION
// TODO probability
{(const xmlChar *)"transition", parseParentFieldPropsXML, model},
{(const xmlChar *)"if", parseParentFieldXML, model},
{(const xmlChar *)"then", parseParentFieldXML, model},
// ARROW
{(const xmlChar *)"arrow", parseArrowFieldXML, model},
// REF
{(const xmlChar *)"ref", parseStubFieldXML, model},
// QUOTE
{(const xmlChar *)"quote", parseStubFieldXML, model},
};
ModelParserTableXML_t modelParserTable =
{
LEN(table),
&table[0]
};
printLog("Parsing model %s\n", model->name);
xmlDocument = xmlReadFile(model->filename, NULL, 0);
if (xmlDocument == NULL) {
printErr("Can't parse model file at '%s'.\n", model->filename);
return -1;
}
currentNode = xmlDocGetRootElement(xmlDocument);
if (currentNode == NULL) {
printErr("Invalid model file at '%s', document empty !\n",
model->filename);
xmlFreeDoc(xmlDocument);
return -2;
}
if (xmlStrcmp(currentNode->name, (const xmlChar *) "gem-graph-model")) {
printErr("Invalid model file at '%s', "
"root node is not <gem-graph-model> !\n",
model->filename);
xmlFreeDoc(xmlDocument);
return -3;
}
currentNode = currentNode->xmlChildrenNode;
while (currentNode != NULL) {
for (int i = 0; i < modelParserTable.len; i++) {
if ((!xmlStrcmp(currentNode->name,
modelParserTable.table[i].tag))) {
modelParserTable.table[i].parse(xmlDocument,
&modelParserTable,
i,
currentNode);
}
}
currentNode = currentNode->next;
}
xmlFreeDoc(xmlDocument);
xmlCleanupParser();
return 0;
}

228
src/scheduler.c Normal file
View File

@ -0,0 +1,228 @@
//=-------------------------------------------------------------------------=//
// Scheduler module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/scheduler.h"
#include "../include/centers.h"
#include "../include/worker.h"
#include "../include/arrows.h"
#include <sys/sysinfo.h>
/* -------------------------------------------------------------------------- */
static void *schedulerMain(void *scheduler);
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Scheduler init function //
// -------------------------------------------------------------------------- //
void SchedInit(Scheduler_t *scheduler)
{
pthread_create(&scheduler->id, NULL, schedulerMain, scheduler);
}
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Scheduler area finder function //
// -------------------------------------------------------------------------- //
static Center_t *findWorkArea(Center_t *centersList, Arrow_t *electedArrow,
int ruleRadius, int xmax, int ymax, int zmax)
{
register Center_t *currentCenter, *newCenter;
currentCenter = centersList->next;
newCenter = malloc(sizeof(Center_t));
while (currentCenter){
if ( (xmax && (abs(electedArrow->x - currentCenter->x) <= ruleRadius))
|| (ymax && (abs(electedArrow->y - currentCenter->y) <= ruleRadius))
|| (zmax && (abs(electedArrow->z - currentCenter->z) <= ruleRadius))
){
free(newCenter);
newCenter = NULL;
//printLog("Can't find a free area\n");
return NULL;
}
currentCenter = currentCenter->next;
}
newCenter->x = electedArrow->x;
newCenter->y = electedArrow->y;
newCenter->z = electedArrow->z;
return newCenter;
}
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Scheduler thread main function //
// -------------------------------------------------------------------------- //
static void *schedulerMain(void *scheduler)
{
Scheduler_t *args;
Worker_t *workerArray;
// A center is a structure that defines, with a radius, a cubic preempted
// area for a worker to operate on (as an approximation of a spheric one)
Center_t *centersList, *workArea;
Arrow_t *electedArrow;
int ncpu, nworker, err;
// Getting scheduler argument structure
args = (Scheduler_t*) scheduler;
printLog("Scheduler #%lu online\n", args->id);
if (!args->nMaxThread) { // nmaxthread = 0 => no minimum
ncpu = get_nprocs(); // allocating all the cpus available
} else { // n thread = min(cpu, nmaxthread)
ncpu = MIN(get_nprocs(), args->nMaxThread);
}
printLog("%d threads available.\n", ncpu);
// Data structures
workerArray = calloc(ncpu, sizeof(*workerArray));
nworker = 0;
centersList = calloc(1, sizeof(*centersList));
// Initiate the arrowArray lock
if (err = ArrowsInitLock(args->arrowArray), err != 0) {
printErr("Impossible to create the arrow array lock (error %d)\n", err);
return NULL;
}
//
// MAIN LOOP
//
while (!args->pleaseStop && 0 <= args->nMaxCycles) { //XXX count cycles
//printLog("Scheduler #%lu online: cycle %d\n", *args->id, ncycles);
//
// TODO statistics here
// Create a new thread
if (nworker < ncpu) {
workArea = NULL;
// Acquiring lock to consistently read the arrowArray
if (ArrowsAcquireNonBlockingLock(args->arrowArray)) {
// Random choice of an arrow
electedArrow =
&args->arrowArray->array[rand() % args->arrowArray->size]; // XXX
// Find a local area
workArea = findWorkArea(centersList,
electedArrow,
args->ruleRadius,
args->globalDrawingSpace->xMax,
args->globalDrawingSpace->yMax,
args->globalDrawingSpace->zMax
);
ArrowsReleaseLock(args->arrowArray);
}
// If a free area exists,
if (workArea) {
// preempt it,
CenterAdd(centersList, workArea);
// find a worker socket,
for (int i = 0; i < ncpu; i++) {
// if a location is empty
if (workerArray[i].id == 0) {
// prepare the worker for the area,
workerArray[i].localWorkAreaCenter = workArea;
workerArray[i].globalDrawingSpace =
args->globalDrawingSpace;
workerArray[i].conditionTree =
args->conditionTree;
workerArray[i].arrowArray =
args->arrowArray;
// create the worker,
WorkerInit(&workerArray[i]);
// and increment worker count.
nworker++;
printLog("Added worker at rank %d with center %p, now %d worker(s)\n",
i,
workArea,
nworker
);
// Increment partial cycle TODO
break;
}
}
}
}
// Delete finished workers
for (int i = 0; i < ncpu; i++) {
if (workerArray[i].id) {
//printLog("Checking termination of worker #%lu\n", *workerArray[i].id);
// Check worker termination
if (workerArray[i].terminated) {
// Join the thread to act his termination
WorkerWait(&workerArray[i]);
// Remove preemption on space
CenterRemove(workerArray[i].localWorkAreaCenter);
printLog("Worker #%lu terminated with return %d. Cleaning...\n",
workerArray[i].id,
workerArray[i].returnValue
);
// Remove Worker
WorkerDestroy(&workerArray[i]);
nworker--;
}
}
}
}
// Exiting scheduler properly
printLog("Stopping scheduler... (waiting for workers)\n");
// Waiting for remaining workers
for (int i = 0; i < ncpu; i++) {
if (workerArray[i].id) {
printLog("Waiting for termination of worker #%lu\n", workerArray[i].id);
// Join the thread to wait for his termination
WorkerWait(&workerArray[i]);
// Remove preemption on space
CenterRemove(workerArray[i].localWorkAreaCenter);
printLog("Worker #%lu terminated with return %d. Cleaning...\n",
workerArray[i].id,
workerArray[i].returnValue
);
// Remove Worker
WorkerDestroy(&workerArray[i]);
}
}
printLog("Scheduler #%lu offline\n", args->id);
ArrowsDestroyLock(args->arrowArray);
free(workerArray);
workerArray = NULL;
free(centersList);
centersList = NULL;
return NULL;
}

262
src/server.c Normal file
View File

@ -0,0 +1,262 @@
//=-------------------------------------------------------------------------=//
// Server management module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/server.h"
#include "../include/cmds.h"
/* -------------------------------------------------------------------------- */
static Command_t cmdList[] =
{
{"help", CmdHelp, "Help command"},
{"model", CmdModel, "Model command"},
{"shutdown", CmdShutdown, "Shutdown command"},
};
static void *serverMain(void *server);
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Server init function //
// -------------------------------------------------------------------------- //
void ServerInit(Server_t *server)
{
pthread_create(&server->id, NULL, serverMain, server);
}
#define SEND_BUFFER_SIZE 80 * 24
#define RECEIVE_BUFFER_SIZE 80
void *serverCommunicationInstance(void *serverCom)
{
ServerCommunication_t *args;
char **argv = NULL;
char receiveBuff[RECEIVE_BUFFER_SIZE];
char sendBuff[SEND_BUFFER_SIZE];
int tokenIndex, bytesReceived, clientPort;
char clientIP[16];
args = (ServerCommunication_t*) serverCom;
// Get ip address from client
inet_ntop(AF_INET,
&args->clientAddr.sin_addr,
clientIP,
args->sockLen);
// Get port number from client
clientPort = ntohs(args->clientAddr.sin_port);
//Accept and incoming connection
while(!args->pleaseStop) {
// Zeroing buffer
bzero(receiveBuff, RECEIVE_BUFFER_SIZE);
//printLog("Waiting for commands...\n");
// Read the message from client and copy it in buffer
bytesReceived = recv(args->sockfd, receiveBuff, RECEIVE_BUFFER_SIZE, 0);
if (bytesReceived == -1) {
printErr("Could not receive data! (%s)\n", strerror(errno));
break;
};
// Ignore null-sized request
if (bytesReceived == 0)
break;
// Print buffer which contains the client request
printLog("Client %s:%d request : '%s'\n",
clientIP,
clientPort,
receiveBuff);
if (receiveBuff[0] == '\0') //XXX
break;
// get args in an array
tokenIndex = 0;
argv = (char**) realloc(argv, 1 * sizeof(char*));
argv[0] = strtok(receiveBuff, " ");
while (argv[tokenIndex]) {
tokenIndex++;
argv = (char**) realloc(argv, (tokenIndex+1) * sizeof(char*));
argv[tokenIndex] = strtok(NULL, " ");
}
// Zeroing buffer
bzero(sendBuff, RECEIVE_BUFFER_SIZE);
// Execute command by first arg in cmdList
for (int i = 0; i < LEN(cmdList); i++) {
if (strcmp(cmdList[i].name, argv[0]) == 0) {
cmdList[i].execute(sendBuff, argv, args->associatedServer);
}
}
// and send that buffer to client
send(args->sockfd, sendBuff, SEND_BUFFER_SIZE, 0);
}
close(args->sockfd);
if (argv) {
free(argv);
argv = NULL;
}
printLog("Disconnected from %s:%d\n", clientIP, clientPort);
return NULL;
}
// -------------------------------------------------------------------------- //
// Server main function //
// -------------------------------------------------------------------------- //
#define PORT 9000
#define MAX_CONNECTION 100
static void *serverMain(void *server)
{
Server_t *args;
ServerCommunication_t serverSlots[MAX_CONNECTION] = {0};
int connfd, flags, threadStatus, serverSlotIndex = 0;
uint socklen;
struct sockaddr_in servaddr;
char clientIP[16];
// Get args
args = (Server_t*) server;
args->returnValue = 0;
printLog("Server #%lu online\n", args->id);
// Create socket
args->sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (args->sockfd == -1) {
printErr("Socket creation failed! (%s)\n", strerror(errno));
args->returnValue = 1;
goto serverExiting;
}
// Get socket flags
flags = fcntl(args->sockfd, F_GETFL);
if (flags == -1) {
printErr("Socket parameters getting failed! (%s)\n", strerror(errno));
args->returnValue = 1;
goto serverExiting;
}
// Change socket flags to non-blocking
if (fcntl(args->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
printErr("Socket non-blocking setting failed! (%s)\n", strerror(errno));
args->returnValue = 1;
goto serverExiting;
}
// Prepare binding structure
bzero(&servaddr, sizeof(servaddr));
// Assign IP and PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(PORT);
// Binding newly created socket
if ((bind(args->sockfd, (struct sockaddr*)&servaddr,
sizeof(servaddr))) == -1) {
printErr("Socket bind failed! (%s)\n", strerror(errno));
args->returnValue = 1;
goto serverExiting;
}
// Now server is ready to listen and verification
if (listen(args->sockfd, MAX_CONNECTION) == -1) {
printErr("Socket listening failed! (%s)\n", strerror(errno));
args->returnValue = 1;
goto serverExiting;
}
socklen = sizeof(struct sockaddr_in);
// Get server socket address structure
if (getsockname(args->sockfd, (struct sockaddr *)&servaddr, &socklen)
== -1) {
printErr("Could not get socket structure! (%s)\n", strerror(errno));
args->returnValue = 1;
goto serverExiting;
}
printLog("Server listening...\n");
while (!args->pleaseStop) {
// Accept the data packet from client
connfd = accept(args->sockfd,
(struct sockaddr*) &serverSlots[serverSlotIndex].clientAddr,
&socklen);
if (connfd < 0) {
// If error is not due to lack of clients connecting, this is error
if (errno != EWOULDBLOCK && errno != EAGAIN) {
printErr("Server acccept failed! (%s)\n", strerror(errno));
goto serverExiting;
}
sleep(1);
} else {
// Client connected
// get IP addr from client
inet_ntop(AF_INET,
&(serverSlots[serverSlotIndex].clientAddr.sin_addr),
clientIP, socklen);
printLog("Client accepted from %s:%d\n",
clientIP,
ntohs(serverSlots[serverSlotIndex].clientAddr.sin_port)); // TODO envisager déplacement dans thread
// Populate communicator slot
serverSlots[serverSlotIndex].sockLen = socklen; // XXX
serverSlots[serverSlotIndex].sockfd = connfd;
serverSlots[serverSlotIndex].associatedServer = args;
// Create thread
threadStatus = pthread_create(&serverSlots[serverSlotIndex].id,
NULL,
serverCommunicationInstance,
(void*)&serverSlots[serverSlotIndex]);
if(threadStatus != 0) {
printErr("Error from pthread: %d (%s)\n",
threadStatus, strerror(errno));
args->returnValue = 1;
goto serverExiting;
}
serverSlotIndex++;
//printLog("Accepted connection. Server will now listen...\n");
}
}
serverExiting:
for (int i; i < serverSlotIndex; i++) {
serverSlots[i].pleaseStop = true;
usleep(10000);
pthread_cancel(serverSlots[i].id);
pthread_join(serverSlots[i].id, NULL);
}
close(args->sockfd);
printLog("Server #%lu offline\n", args->id);
return NULL;
}

45
src/supervisor.c Normal file
View File

@ -0,0 +1,45 @@
//=-------------------------------------------------------------------------=//
// Supervisor module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/supervisor.h"
/* -------------------------------------------------------------------------- */
static void *supervisorMain(void *supervisor);
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Supervisor init function //
// -------------------------------------------------------------------------- //
void SupervisorInit(Supervisor_t *supervisor)
{
pthread_create(&supervisor->id, NULL, supervisorMain, supervisor);
}
// -------------------------------------------------------------------------- //
// Supervisor thread main function //
// -------------------------------------------------------------------------- //
static void *supervisorMain(void *supervisor)
{
return NULL;
}

23
src/tests/arrows.c Normal file
View File

@ -0,0 +1,23 @@
//=-------------------------------------------------------------------------=//
// Arrows tests //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../centers.c"

177
src/tests/centers.c Normal file
View File

@ -0,0 +1,177 @@
//=-------------------------------------------------------------------------=//
// Centers tests //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../centers.c"
#include <assert.h>
//
// Tests for Center_t functions
//
void printCenters(Center_t *firstCenter)
{
while (firstCenter) {
printf("Center %p\n\tNext %p\n\tPrev %p\n\n",
firstCenter,
firstCenter->next,
firstCenter->prev
);
firstCenter = firstCenter->next;
}
}
bool TestCenterRemove
(void)
{
Center_t *anyCenter = NULL;
// adding a something to a bad pointer
CenterRemove(anyCenter);
//printf("* Status of centers list after deleting NULL\n");
//printCenters(anyCenter);
assert(anyCenter == NULL);
anyCenter = calloc(1, sizeof(*anyCenter));
//printf("* Initial status of centers list\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// Deleting a lonely pointer
CenterRemove(anyCenter);
//printf("* Status of centers list after deleting a lonely center\n");
//printCenters(anyCenter);
anyCenter = calloc(1, sizeof(*anyCenter));
Center_t *oldfirst = anyCenter->next;
Center_t *oldsecond = anyCenter->next->next;
// Deleting a the first pointer
CenterRemove(anyCenter->next);
//printf("* Status of centers list after deleting the head center\n");
//printCenters(anyCenter);
assert(anyCenter->next == oldsecond);
return true;
}
bool TestCenterAdd(void)
{
Center_t *anyCenter = NULL;
// adding a something to a bad pointer
CenterAdd(anyCenter, NULL);
//printf("* Status of centers list after adding something to NULL\n");
//printCenters(anyCenter);
assert(anyCenter == NULL);
anyCenter = calloc(1, sizeof(Center_t));
//printf("* Initial status of centers list\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// adding a bad pointer
CenterAdd(anyCenter, NULL);
//printf("* Status of centers list after adding NULL\n");
//printCenters(anyCenter);
assert(anyCenter->next == NULL);
assert(anyCenter->prev == NULL);
assert(anyCenter != NULL);
// adding a good pointer
Center_t *goodpointer = calloc(1, sizeof(Center_t));
CenterAdd(anyCenter, goodpointer);
//printf("* Status of centers list after adding a center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == goodpointer);
assert(anyCenter->prev == NULL);
assert(goodpointer->prev == anyCenter);
assert(goodpointer->next == NULL);
// adding another good pointer
Center_t *newgoodpointer = calloc(1, sizeof(Center_t));
CenterAdd(anyCenter, newgoodpointer);
//printf("* Status of centers list after adding another center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == newgoodpointer);
assert(anyCenter->prev == NULL);
assert(newgoodpointer->prev == anyCenter);
assert(newgoodpointer->next == goodpointer);
// adding another good pointer
Center_t *strangepointer = calloc(1, sizeof(Center_t));
strangepointer->next = (Center_t*)0xCAFEBABE;
strangepointer->prev = (Center_t*)0xCAFEBABE;
CenterAdd(anyCenter, strangepointer);
//printf("* Status of centers list after adding a strange center\n");
//printCenters(anyCenter);
assert(anyCenter != NULL);
assert(anyCenter->next == strangepointer);
assert(anyCenter->prev == NULL);
assert(strangepointer->prev != (Center_t*)0xCAFEBABE);
assert(strangepointer->next != (Center_t*)0xCAFEBABE);
return true;
}
int main(int argc, char **argv)
{
printf("\n==== Testing centers.c/CenterAdd() ====\n");
TestCenterAdd();
printf("\n==== Testing centers.c/CenterAdd() ==== : OK\n");
printf("\n==== Testing centers.c/CenterRemove() ====\n");
TestCenterRemove();
printf("\n==== Testing centers.c/CenterRemove() ==== : OK\n");
return 0;
}

BIN
src/tests/getchar Executable file

Binary file not shown.

104
src/tests/getchar.c Normal file
View File

@ -0,0 +1,104 @@
#include "../../include/base.h"
#include <sys/ioctl.h>
#include <unistd.h>
#include <termios.h>
#include <fcntl.h>
#define KEY_ESCAPE 27
#define KEY_DIRECTIONS 91
#define KEY_ARROW_UP 65
#define KEY_ARROW_DOWN 66
#define KEY_ARROW_RIGHT 67
#define KEY_ARROW_LEFT 68
#define KEY_DELETE 127
#define C_CLEARSCREEN "\e[2J"
#define C_CLEARLINE "\e[2K"
#define C_CURSORLEFT "\e[1D"
#define C_CURSORRIGHT "\e[1C"
#define C_SAVE_CURSORPOS "\e7"
#define C_RESTORE_CURSORPOS "\e8"
#define C_COLOR_RED "\e[01;31m"
#define C_COLOR_YELLOW "\e[00;33m"
#define C_COLOR_GREEN "\e[00;32m"
#define C_COLOR_BLUE "\e[01;34m"
#define C_COLOR_REVERSE "\e[7m"
#define C_COLOR_NORMAL "\e[0m"
//
// Get a character code from the keyboard
//
static inline int getch(bool nonBlocking)
{
int buf = 0;
// old terminal
struct termios old = {0};
// force flush stdout
fflush(stdout);
// Set non-blocking mode if asked
if(nonBlocking)
fcntl(0, F_SETFL, O_NONBLOCK);
if(tcgetattr(0, &old) < 0) {
printLog("%sError getting terminal settings! (%s)\n",
C_COLOR_RED,
strerror(errno));
return -1;
}
old.c_lflag &= ~ICANON; // disable buffered I/O
old.c_lflag &= ~ECHO; // set no echo mode
if(tcsetattr(0, TCSANOW, &old) < 0) {
printLog("%sError setting terminal settings! (%s)\n",
C_COLOR_RED,
strerror(errno));
return -1;
}
buf = getchar();
if(buf < 0) {
// Check target busy (try again)
if(errno == EAGAIN)
return 0;
printLog("%sError reading character! (%s)\n",
C_COLOR_RED,
strerror(errno));
return -1;
}
old.c_lflag |= ICANON; // enable buffered I/O
old.c_lflag |= ECHO; // set echo mode
if(tcsetattr(0, TCSADRAIN, &old) < 0) {
printLog("%sError resetting terminal settings! (%s)\n",
C_COLOR_RED,
strerror(errno));
return -1;
}
// Reset blocking mode
if(nonBlocking)
fcntl(0, F_SETFL, 0);
return buf;
}
int main(void)
{
while(1) {
int c = getch(1);
if (c > 0)
printf("touche %d\n", c);
}
return 0;
}

23
src/tests/localworker.c Normal file
View File

@ -0,0 +1,23 @@
//=-------------------------------------------------------------------------=//
// Local worker tests //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../localworker.c"

23
src/tests/scheduler.c Normal file
View File

@ -0,0 +1,23 @@
//=-------------------------------------------------------------------------=//
// Scheduler tests //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../scheduler.c"

23
src/tests/server.c Normal file
View File

@ -0,0 +1,23 @@
//=-------------------------------------------------------------------------=//
// Server tests //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../server.c"

BIN
src/tests/test_realloc Executable file

Binary file not shown.

13
src/tests/test_realloc.c Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int *a = malloc(7 * sizeof(int));
printf("Salut! Tableau d'entiers à l'adresse %p\n", a);
int *b = (int*) realloc(a, 8*sizeof(int));
printf("Salut! Tableau d'entiers à l'adresse %p\n", b);
}

BIN
src/tests/xml Executable file

Binary file not shown.

65
src/tests/xml.c Normal file
View File

@ -0,0 +1,65 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libxml2/libxml/xmlmemory.h>
#include <libxml2/libxml/parser.h>
void parseStory (xmlDocPtr doc, xmlNodePtr cur)
{
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"authors"))) {
printf("%s\n", xmlNodeListGetString(doc, cur->xmlChildrenNode, 1));
}
cur = cur->next;
}
return;
}
static void parseDoc(char *docname)
{
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(docname);
if (doc == NULL ) {
fprintf(stderr,"Document not parsed successfully. \n");
xmlFreeDoc(doc);
return;
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
fprintf(stderr,"empty document\n");
xmlFreeDoc(doc);
return;
}
if (xmlStrcmp(cur->name, (const xmlChar *) "story")) {
fprintf(stderr,"document of the wrong type, root node != story");
xmlFreeDoc(doc);
return;
}
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"storyinfo"))){
parseStory(doc, cur);
}
cur = cur->next;
}
xmlFreeDoc(doc);
return;
}
int main(int argc, char **argv)
{
char *docname;
if (argc <= 1) {
printf("Usage: %s docname\n", argv[0]);
return 1;
}
docname = argv[1];
parseDoc(docname);
return 0;
}

15
src/tests/xml.xml Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<story>
<storyinfo>
<author>John Fleck</author>
<datewritten>June 2, 2002</datewritten>
<keyword>example keyword</keyword>
</storyinfo>
<body>
<headline>This is the headline</headline>
<para>This is the body text.</para>
</body>
</story>

63
src/worker.c Normal file
View File

@ -0,0 +1,63 @@
//=-------------------------------------------------------------------------=//
// Local worker module //
// //
// Copyright © 2021 Libre en Communs (contact@a-lec.org) //
// Copyright © 2021 Adrien Bourmault (neox@a-lec.org) //
// //
// This file is part of gem-graph. //
// //
// This program is free software: you can redistribute it and/or modify //
// it under the terms of the GNU Affero General Public License as //
// published by the Free Software Foundation, either version 3 of the //
// License, or (at your option) any later version. //
// //
// This program 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 Affero General Public License for more details. //
// //
// You should have received a copy of the GNU Affero General Public License //
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
//=-------------------------------------------------------------------------=//
#include "../include/worker.h"
/* -------------------------------------------------------------------------- */
static void *WorkerMain(void *worker);
/* -------------------------------------------------------------------------- */
// -------------------------------------------------------------------------- //
// Worker init function //
// -------------------------------------------------------------------------- //
void WorkerInit(Worker_t *worker)
{
if (pthread_create(&worker->id, NULL, WorkerMain, worker)) {
printLog("Worker #%lu can't be initialized!\n", worker->id);
return;
}
}
// -------------------------------------------------------------------------- //
// Worker thread main function //
// -------------------------------------------------------------------------- //
static void *WorkerMain(void *worker)
{
Worker_t *args;
int a = rand()%__INT_MAX__;
args = (Worker_t*) worker;
printLog("Worker #%lu online\n", args->id);
int size = args->globalDrawingSpace->size;
// TODO execute rule comparison
args->returnValue = a;
args->terminated = true;
printLog("Worker #%lu offline\n", args->id);
return NULL;
}