Skip to content

Commit dbed774

Browse files
author
Matthew Stern
committed
added id's and request failing flag
1 parent 40d7c65 commit dbed774

21 files changed

+104
-78
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ $(BISON_CPP): $(BISONPP)
6363
$(CXX) -fPIC -g -c $(BISON_CPP) -o $(BISON_OBJ_PP)
6464

6565
all:$(BIN)
66-
.PHONY : clean cpp python python2 rust csharp
66+
.PHONY : clean cpp
6767

6868
clean:
6969
rm -f libtopologic.a
70+
rm -f $(TEST_OBJ) $(TESTS)
7071
rm -f $(FLEX_C) $(FLEX_OBJ)
7172
rm -f $(BISON_C) $(BISON_OBJ) $(BISON_H)
7273
rm -f $(FLEX_CPP) $(FLEX_OBJ_PP)

include/edge.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct edge
2525
//will compare with other Edges in graph
2626
//Also unique, a la vertex
2727
//Perhaps @nanosecond level
28-
int (*f)(void *, void *, const void *const a_vars, const void *const b_vars);
28+
int (*f)(int, void *, void *, const void *const a_vars, const void *const b_vars);
2929
void *glbl;
3030
const void *const *a_vars; //To be shared among vertex a and shared edge
3131
const void *const *b_vars; //To be shared among vertex b. Will be NULL for context=SWITCH
@@ -40,7 +40,7 @@ struct edge_request
4040
{
4141
struct vertex *a;
4242
struct vertex *b;
43-
int (*f)(void *, void *, const void *const, const void *const);
43+
int (*f)(int, void *, void *, const void *const, const void *const);
4444
void *glbl;
4545
};
4646

include/graph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <signal.h>
1414
#include "./context.h"
15+
#include "./request.h"
1516

1617
#ifdef __cplusplus
1718
extern "C" {
@@ -81,6 +82,7 @@ struct graph
8182
{
8283
enum CONTEXT context;
8384
enum MEM_OPTION mem_option;
85+
enum REQUEST_FLAG request_flag;
8486
struct AVLTree *vertices;
8587
struct stack *start;
8688
struct stack *modify;

include/request.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ enum REQUESTS
3232
GENERIC = 12
3333
};
3434

35+
/**
36+
Enum for handling failed requests
37+
NO_FAIL_REQUEST: All request must succeed else end the graph
38+
IGNORE_FAIL_REQUEST: Ignore a request if it fails
39+
**/
40+
enum REQUEST_FLAG
41+
{
42+
NO_FAIL_REQUEST = 0,
43+
IGNORE_FAIL_REQUEST = 1
44+
};
45+
3546
/** Request **/
3647
struct request
3748
{

include/topologic.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,20 @@
3434
extern "C" {
3535
#endif
3636

37+
/**
38+
@PARAM graph: the graph
39+
@PARAM vertex: a vertex in the graph
40+
@PARAM vertex_result: the vertex_results to copy
41+
@PARAM color: next vertices color
42+
@PARAM iloop: the count of the number of times the vertex has been called
43+
Create a fireable structure
44+
**/
3745
struct fireable *create_fireable(struct graph *graph, struct vertex *vertex, struct vertex_result *args, enum STATES color, int iloop);
46+
47+
/**
48+
@PARAM fireable: the fireable to destroy
49+
Frees the fireable struct
50+
**/
3851
int destroy_fireable(struct fireable *fireable);
3952

4053
/**
@@ -57,9 +70,10 @@ struct graph *graph_init(int max_state_changes,
5770
int max_loop,
5871
unsigned int lvl_verbose,
5972
enum CONTEXT context,
60-
enum MEM_OPTION mem_option);
73+
enum MEM_OPTION mem_option,
74+
enum REQUEST_FLAG request_flag);
6175
#define MAX_LOOPS 100
62-
#define GRAPH_INIT() graph_init(-1, START_STOP, MAX_LOOPS, VERTICES | EDGES | FUNCTIONS | GLOBALS, SINGLE, CONTINUE)
76+
#define GRAPH_INIT() graph_init(-1, START_STOP, MAX_LOOPS, VERTICES | EDGES | FUNCTIONS | GLOBALS, SINGLE, CONTINUE, IGNORE_FAIL_REQUEST)
6377

6478
/**
6579
@PARAM graph: the graph
@@ -73,7 +87,7 @@ NOTE: NULL glbl will mean no global variables.
7387
f cannot be NULL.
7488
**/
7589
struct vertex *create_vertex(struct graph *graph,
76-
void (*f)(struct graph *, struct vertex_result *, void *, void *),
90+
void (*f)(int, struct graph *, struct vertex_result *, void *, void *),
7791
int id,
7892
void *glbl);
7993
#define CREATE_VERTEX(graph, f, id) create_vertex(graph, f, id, NULL, PROTECT_B_VARS)
@@ -91,7 +105,7 @@ NOTE: NULL glbl will mean no global variables. f cannot be NULL.
91105
**/
92106
struct edge *create_edge(struct vertex *a,
93107
struct vertex *b,
94-
int (*f)(void *, void *, const void *const, const void *const),
108+
int (*f)(int, void *, void *, const void *const, const void *const),
95109
void *glbl);
96110
#define CREATE_EDGE(a, b, f) create_edge(a, b, f, NULL)
97111

@@ -106,7 +120,7 @@ If edge_a_to_b or edge_b_to_a is NULL it will not.
106120
**/
107121
int create_bi_edge(struct vertex *a,
108122
struct vertex *b,
109-
int (*f)(void *, void *, const void *const, const void *const),
123+
int (*f)(int, void *, void *, const void *const, const void *const),
110124
void *glbl,
111125
struct edge **edge_a_to_b,
112126
struct edge **edge_b_to_a);
@@ -174,7 +188,7 @@ NOTE: NULL f, or glbl will mean no change.
174188
Modifies the vertices function
175189
**/
176190
int modify_vertex(struct vertex *vertex,
177-
void (*f)(struct graph *, struct vertex_result *, void *, void *),
191+
void (*f)(int, struct graph *, struct vertex_result *, void *, void *),
178192
void *glbl);
179193
#define MODIFY_VERTEX(vertex, f) modify_vertex(vertex, f, NULL)
180194
#define MODIFY_VERTEX_GLOBALS(vertex, glbl) modify_vertex(vertex, NULL, glbl)
@@ -201,7 +215,7 @@ NOTE: NULL f, or glbl will mean no change.
201215
**/
202216
int modify_edge(struct vertex *a,
203217
struct vertex *b,
204-
int (*f)(void *, void *, const void *const, const void *const),
218+
int (*f)(int, void *, void *, const void *const, const void *const),
205219
void *glbl);
206220

207221
#define MODIFY_EDGE(a, b, f) modify_edge(a, b, f, NULL)
@@ -222,7 +236,7 @@ NOTE: NULL f, or glbl will mean no change.
222236
**/
223237
int modify_bi_edge(struct vertex *a,
224238
struct vertex *b,
225-
int (*f)(void *, void *, const void *const, const void *const),
239+
int (*f)(int, void *, void *, const void *const, const void *const),
226240
void *glbl);
227241
#define MODIFY_BI_EDGE(a, b, f) modify_bi_edge(a, b, f, NULL)
228242
#define MODIFY_BI_EDGE_GLOBALS(a, b, glbl) modify_bi_edge(a, b, NULL, glbl)

include/vertex.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct vertex
3636
//will compare with other vertices in graph
3737
//Must be unique. If non-unique ID, error
3838
int is_active;
39-
void (*f)(struct graph *, struct vertex_result *, void *, void *);
39+
void (*f)(int, struct graph *, struct vertex_result *, void *, void *);
4040
void *glbl;
4141
union shared_edge *shared;
4242
pthread_mutex_t lock;
@@ -51,14 +51,14 @@ struct vertex_request
5151
int id; //Hash for number passed in,
5252
//will compare with other vertices in graph
5353
//Must be unique. If non-unique ID, error
54-
void (*f)(struct graph *, struct vertex_result *, void *, void *);
54+
void (*f)(int, struct graph *, struct vertex_result *, void *, void *);
5555
void *glbl;
5656
};
5757

5858
struct mod_vertex_request
5959
{
6060
struct vertex *vertex;
61-
void (*f)(struct graph *, struct vertex_result *, void *, void *);
61+
void (*f)(int, struct graph *, struct vertex_result *, void *, void *);
6262
void *glbl;
6363
};
6464

parse/topologic_parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
%{
55
#include "../include/topologic.h"
6-
void f(struct graph *graph, struct vertex_result *args, void *glbl, void *edge_vars) {}
7-
int edge_f(void *args, void *glbl, const void *const edge_vars_a, const void *const edge_vars_b) {return 0;}
6+
void f(int id, struct graph *graph, struct vertex_result *args, void *glbl, void *edge_vars) {}
7+
int edge_f(int id, void *args, void *glbl, const void *const edge_vars_a, const void *const edge_vars_b) {return 0;}
88
void yyerror(struct graph** graph, const char *s);
99
extern FILE *yyin;
1010
int yylex(void);

src/edge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "../include/topologic.h"
55

6-
struct edge *create_edge(struct vertex *a, struct vertex *b, int (*f)(void *, void *, const void *const, const void *const), void *glbl)
6+
struct edge *create_edge(struct vertex *a, struct vertex *b, int (*f)(int, void *, void *, const void *const, const void *const), void *glbl)
77
{
88
topologic_debug("%s;a %p;b %p;f %p;glbl %p", "create_edge", a, b, f, glbl);
99
if (!a || !b)
@@ -102,7 +102,7 @@ struct edge *create_edge(struct vertex *a, struct vertex *b, int (*f)(void *, vo
102102
return NULL;
103103
}
104104

105-
int create_bi_edge(struct vertex *a, struct vertex *b, int (*f)(void *, void *, const void *const, const void *const), void *glbl, struct edge **edge_a_to_b, struct edge **edge_b_to_a)
105+
int create_bi_edge(struct vertex *a, struct vertex *b, int (*f)(int, void *, void *, const void *const, const void *const), void *glbl, struct edge **edge_a_to_b, struct edge **edge_b_to_a)
106106
{
107107
topologic_debug("%s;a %p;b %p;f %p;glbl %p", "create_edge", a, b, f, glbl);
108108
if (!a || !b || !f || a == b)
@@ -293,7 +293,7 @@ int remove_bi_edge(struct vertex *a, struct vertex *b)
293293
return ret;
294294
}
295295

296-
int modify_edge(struct vertex *a, struct vertex *b, int (*f)(void *, void *, const void *const, const void *const), void *glbl)
296+
int modify_edge(struct vertex *a, struct vertex *b, int (*f)(int, void *, void *, const void *const, const void *const), void *glbl)
297297
{
298298
topologic_debug("%s;a %p;b %p;f %p;glbl %p", "modify_edge", a, b, f, glbl);
299299
if (!a || !b)
@@ -333,7 +333,7 @@ int modify_edge(struct vertex *a, struct vertex *b, int (*f)(void *, void *, con
333333
return 0;
334334
}
335335

336-
int modify_bi_edge(struct vertex *a, struct vertex *b, int (*f)(void *, void *, const void *const, const void *const), void *glbl)
336+
int modify_bi_edge(struct vertex *a, struct vertex *b, int (*f)(int, void *, void *, const void *const, const void *const), void *glbl)
337337
{
338338
topologic_debug("%s;a %p;b %p;f %p;glbl %p", "modify_bi_edge", a, b, f, glbl);
339339
if (!a || !b || a == b)

src/graph.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "../include/topologic.h"
55

6-
struct graph *graph_init(int max_state_changes, int snapshot_timestamp, int max_loop, unsigned int lvl_verbose, enum CONTEXT context, enum MEM_OPTION mem_option)
6+
struct graph *graph_init(int max_state_changes, int snapshot_timestamp, int max_loop, unsigned int lvl_verbose, enum CONTEXT context, enum MEM_OPTION mem_option, enum REQUEST_FLAG request_flag)
77
{
88
topologic_debug("%s;max_state_chages %d;snapshot_timestamp %d;max_loop %d;lvl_verbose %d;context %d;mem_option %d", "graph_init", max_state_changes, snapshot_timestamp, max_loop, lvl_verbose, context, mem_option);
99
struct graph *graph = (struct graph *)malloc(sizeof(struct graph));
@@ -15,6 +15,7 @@ struct graph *graph_init(int max_state_changes, int snapshot_timestamp, int max_
1515
graph->max_state_changes = max_state_changes;
1616
graph->max_loop = max_loop;
1717
graph->snapshot_timestamp = snapshot_timestamp;
18+
graph->request_flag = request_flag;
1819
graph->lvl_verbose = lvl_verbose;
1920
graph->context = context;
2021
graph->state_count = 0;

src/request.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ int process_requests(struct graph *graph)
270270
{
271271
if (graph->context != SINGLE)
272272
pthread_mutex_unlock(&graph->lock);
273-
if (procces_request(req) < 0)
273+
if (procces_request(req) < 0 && graph->request_flag == NO_FAIL_REQUEST)
274274
{
275275
topologic_debug("%s;%s;%d", "process_requests", "failed to process general requests", -1);
276276
return -1;
@@ -282,7 +282,7 @@ int process_requests(struct graph *graph)
282282
{
283283
if (graph->context != SINGLE)
284284
pthread_mutex_unlock(&graph->lock);
285-
if (procces_request(req) < 0)
285+
if (procces_request(req) < 0 && graph->request_flag == NO_FAIL_REQUEST)
286286
{
287287
topologic_debug("%s;%s;%d", "process_requests", "failed to remove edges", -1);
288288
return -1;
@@ -294,7 +294,7 @@ int process_requests(struct graph *graph)
294294
{
295295
if (graph->context != SINGLE)
296296
pthread_mutex_unlock(&graph->lock);
297-
if (procces_request(req) < 0)
297+
if (procces_request(req) < 0 && graph->request_flag == NO_FAIL_REQUEST)
298298
{
299299
topologic_debug("%s;%s;%d", "process_requests", "failed to remove vertices", -1);
300300
return -1;

0 commit comments

Comments
 (0)