1 
2 
3 module mars.protoupd;
4 
5 import mars.client;
6 import mars.msg;
7 import mars.server;
8 
9 /**
10 Handle a request for update coming form the client, originating from on optimistic update.
11 
12 Params:
13     client = the mars client, the sender.
14     socket = socket like object, as a transport.
15 */
16 void protoOptUpdate(S)(MarsClient* client, S socket) 
17 {
18     auto state = RequestState.executed;
19 
20     auto req = socket.binaryAs!OptUpdateReq;
21     if( req.tableIndex < 0 || req.tableIndex > marsServer.tables.length ){
22         state = RequestState.rejectedAsWrongParameter;
23     }
24 
25     if( state == state.init ){
26         client.vueUpdateRecord(req.tableIndex, req.keys, req.record, state);
27     }
28 
29     final switch(state) with(RequestState){
30         case rejectedAsWrongParameter: assert(false);
31         case internalServerError:
32         case rejectedAsDecodingFailed:
33         case rejectedAsForeignKeyViolation:
34         case rejectedAsNotAuthorised:
35         case rejectedAsPGSqlError:
36             socket.sendReply(req, OptUpdateRep(state));
37             break;
38         case executed:
39             socket.sendReply(req, OptUpdateRep(state));
40             break;
41     }
42 }
43 
44 void protoPesUpdate(S)(MarsClient* client, S socket) 
45 {
46     auto state = RequestState.executed;
47 
48     auto req = socket.binaryAs!PesUpdateReq;
49     if( req.tableIndex < 0 || req.tableIndex > marsServer.tables.length ){
50         state = RequestState.rejectedAsWrongParameter;
51     }
52 
53     if( state == state.init ){
54         client.vueUpdateRecord(req.tableIndex, req.keys, req.record, state);
55     }
56 
57     final switch(state) with(RequestState){
58         case rejectedAsWrongParameter: assert(false);
59         case internalServerError:
60         case rejectedAsDecodingFailed:
61         case rejectedAsForeignKeyViolation:
62         case rejectedAsNotAuthorised:
63         case rejectedAsPGSqlError:
64             socket.sendReply(req, PesUpdateRep(state));
65             break;
66         case executed:
67             socket.sendReply(req, PesUpdateRep(state));
68             break;
69     }
70 }