project_files/frontlib/ipc/mapconn.c
changeset 7576 65d29988fd3d
parent 7316 f7b49b2c5d84
child 10017 de822cd3df3a
equal deleted inserted replaced
7574:b9ec869e624a 7576:65d29988fd3d
    28 #include <stdlib.h>
    28 #include <stdlib.h>
    29 
    29 
    30 typedef enum {
    30 typedef enum {
    31 	AWAIT_CONNECTION,
    31 	AWAIT_CONNECTION,
    32 	AWAIT_REPLY,
    32 	AWAIT_REPLY,
       
    33 	AWAIT_CLOSE,
    33 	FINISHED
    34 	FINISHED
    34 } mapconn_state;
    35 } mapconn_state;
    35 
    36 
    36 struct _flib_mapconn {
    37 struct _flib_mapconn {
    37 	uint8_t mapBuffer[IPCBASE_MAPMSG_BYTES];
    38 	uint8_t mapBuffer[IPCBASE_MAPMSG_BYTES];
   158 		}
   159 		}
   159 	}
   160 	}
   160 
   161 
   161 	if(conn->progress == AWAIT_REPLY) {
   162 	if(conn->progress == AWAIT_REPLY) {
   162 		if(flib_ipcbase_recv_map(conn->ipcBase, conn->mapBuffer) >= 0) {
   163 		if(flib_ipcbase_recv_map(conn->ipcBase, conn->mapBuffer) >= 0) {
   163 			conn->progress = FINISHED;
   164 			conn->progress = AWAIT_CLOSE;
   164 			conn->onSuccessCb(conn->onSuccessCtx, conn->mapBuffer, conn->mapBuffer[IPCBASE_MAPMSG_BYTES-1]);
       
   165 			return;
       
   166 		} else if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
   165 		} else if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
   167 			conn->progress = FINISHED;
   166 			conn->progress = FINISHED;
   168 			conn->onFailureCb(conn->onSuccessCtx, "Engine connection closed unexpectedly.");
   167 			conn->onFailureCb(conn->onSuccessCtx, "Engine connection closed unexpectedly.");
       
   168 			return;
       
   169 		}
       
   170 	}
       
   171 
       
   172 	if(conn->progress == AWAIT_CLOSE) {
       
   173 		// Just do throwaway reads so we find out when the engine disconnects
       
   174 		uint8_t buf[256];
       
   175 		flib_ipcbase_recv_message(conn->ipcBase, buf);
       
   176 		if(flib_ipcbase_state(conn->ipcBase) != IPC_CONNECTED) {
       
   177 			conn->progress = FINISHED;
       
   178 			conn->onSuccessCb(conn->onSuccessCtx, conn->mapBuffer, conn->mapBuffer[IPCBASE_MAPMSG_BYTES-1]);
   169 			return;
   179 			return;
   170 		}
   180 		}
   171 	}
   181 	}
   172 }
   182 }
   173 
   183