48 lines
1.7 KiB
C
48 lines
1.7 KiB
C
#include <pthread.h>
|
|
|
|
#include <msgba/core_controller.h>
|
|
#include <msgba/client_connection_data.h>
|
|
#include <msgba/packet/save_request.h>
|
|
|
|
struct msClientConnectionData *
|
|
msClientConnectionDataNew(size_t numberOfThread, int clientFd) {
|
|
struct msClientConnectionData *data = malloc (sizeof *data);
|
|
data->numberOfThread = numberOfThread;
|
|
data->clientFd = clientFd;
|
|
data->coreController = NULL;
|
|
data->mutexSendPacket = malloc(sizeof *data->mutexSendPacket);
|
|
data->mutexPressKey = malloc(sizeof *data->mutexPressKey);
|
|
data->mutexSaveRequests = malloc(sizeof *data->mutexSaveRequests);
|
|
data->saveRequests = NULL;
|
|
data->saveRequestsLen = 0;
|
|
data->lastFrameDate = calloc(sizeof *data->lastFrameDate, 1);
|
|
pthread_mutex_init(data->mutexSendPacket, NULL);
|
|
pthread_mutex_init(data->mutexPressKey, NULL);
|
|
pthread_mutex_init(data->mutexSaveRequests, NULL);
|
|
return data;
|
|
}
|
|
|
|
void
|
|
msClientConnectionDataDestroy(struct msClientConnectionData **data) {
|
|
if ((*data)->coreController) {
|
|
msCoreControllerDestroy(&(*data)->coreController);
|
|
}
|
|
pthread_mutex_destroy((*data)->mutexSendPacket);
|
|
pthread_mutex_destroy((*data)->mutexPressKey);
|
|
pthread_mutex_destroy((*data)->mutexSaveRequests);
|
|
free((*data)->mutexSendPacket);
|
|
free((*data)->mutexPressKey);
|
|
free((*data)->mutexSaveRequests);
|
|
if ((*data)->saveRequests) {
|
|
for (size_t i = 0; i<(*data)->saveRequestsLen; i++) {
|
|
msPacketSaveRequestDataDestroy(&(*data)->saveRequests[i]);
|
|
}
|
|
free((*data)->saveRequests);
|
|
}
|
|
(*data)->mutexSendPacket = NULL;
|
|
(*data)->mutexPressKey = NULL;
|
|
(*data)->mutexSaveRequests = NULL;
|
|
free(*data);
|
|
*data = NULL;
|
|
}
|