49 lines
1.1 KiB
C
49 lines
1.1 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "networkhttp.h"
|
|
#include "networkhttprequest.h"
|
|
#include "networkhttpthread.h"
|
|
|
|
networkhttp_t NETWORK_HTTP;
|
|
|
|
errorret_t networkHttpInit(void) {
|
|
networkHttpRequestPoolInit();
|
|
|
|
threadInit(&NETWORK_HTTP.thread, networkHttpThreadRun);
|
|
threadStart(&NETWORK_HTTP.thread);
|
|
|
|
errorOk();
|
|
}
|
|
|
|
errorret_t networkHttpUpdate(void) {
|
|
for(uint32_t i = 0; i < NETWORK_HTTP_REQUEST_COUNT_MAX; i++) {
|
|
networkhttprequest_t *request = &NETWORK_HTTP_REQUESTS[i];
|
|
|
|
threadMutexLock(&request->mutex);
|
|
const networkhttprequeststate_t state = request->state;
|
|
threadMutexUnlock(&request->mutex);
|
|
|
|
if(state == NETWORK_HTTP_REQUEST_STATE_DONE) {
|
|
eventInvoke(&request->onComplete, request);
|
|
} else if(state == NETWORK_HTTP_REQUEST_STATE_ERROR) {
|
|
eventInvoke(&request->onError, request);
|
|
} else {
|
|
continue;
|
|
}
|
|
|
|
networkHttpRequestReset(request);
|
|
}
|
|
|
|
errorOk();
|
|
}
|
|
|
|
errorret_t networkHttpDispose(void) {
|
|
threadStop(&NETWORK_HTTP.thread);
|
|
errorOk();
|
|
}
|