PSP Networking refactor
This commit is contained in:
@@ -6,83 +6,82 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "dusk.h"
|
||||
#include "network/networkhttprequest.h"
|
||||
#include "thread/thread.h"
|
||||
#include <psputility.h>
|
||||
#include "error/error.h"
|
||||
#include "system/systempsp.h"
|
||||
#include <psphttp.h>
|
||||
#include <pspnet.h>
|
||||
#include <pspnet_inet.h>
|
||||
#include <pspnet_apctl.h>
|
||||
#include <pspssl.h>
|
||||
#include <pspnet_resolver.h>
|
||||
#include <psphttp.h>
|
||||
|
||||
#define NETWORK_HTTP_PENDING_MAX 4
|
||||
#define NETWORK_HTTP_URL_MAX 512
|
||||
#define NETWORK_HTTP_BODY_MAX 2048
|
||||
#define NETWORK_HTTP_RESPONSE_MAX 16384
|
||||
#define NETWORK_HTTP_HEADER_MAX 8
|
||||
#define NETWORK_HTTP_HEADER_KEY_MAX 64
|
||||
#define NETWORK_HTTP_HEADER_VAL_MAX 256
|
||||
#define NETWORK_ERROR_MESSAGE_MAX 256
|
||||
#define NETWORK_PSP_AGENT "DuskEngine/1.0"
|
||||
#define NETWORK_PSP_HTTP_HEAP_SIZE 0x25800
|
||||
|
||||
typedef enum {
|
||||
NETWORK_PSP_STATE_DISCONNECTED, /* Init done, no connection requested yet */
|
||||
NETWORK_PSP_STATE_DIALOG, /* WiFi netconf dialog is active */
|
||||
NETWORK_PSP_STATE_CONNECTED, /* AP connected, HTTP ready */
|
||||
NETWORK_PSP_STATE_FAILED, /* Connection attempt failed or cancelled */
|
||||
} networkpspstate_t;
|
||||
// #define NETWORK_HTTP_PENDING_MAX 4
|
||||
// #define NETWORK_HTTP_URL_MAX 512
|
||||
// #define NETWORK_HTTP_BODY_MAX 2048
|
||||
// #define NETWORK_HTTP_RESPONSE_MAX 16384
|
||||
// #define NETWORK_HTTP_HEADER_MAX 8
|
||||
// #define NETWORK_HTTP_HEADER_KEY_MAX 64
|
||||
// #define NETWORK_HTTP_HEADER_VAL_MAX 256
|
||||
// #define NETWORK_ERROR_MESSAGE_MAX 256
|
||||
// #define NETWORK_PSP_AGENT "DuskEngine/1.0"
|
||||
|
||||
typedef struct {
|
||||
bool_t used;
|
||||
volatile bool_t resultReady;
|
||||
bool_t isError;
|
||||
char_t url[NETWORK_HTTP_URL_MAX];
|
||||
networkhttprequestmethod_t method;
|
||||
char_t body[NETWORK_HTTP_BODY_MAX];
|
||||
bool_t hasBody;
|
||||
char_t headerKeys[NETWORK_HTTP_HEADER_MAX][NETWORK_HTTP_HEADER_KEY_MAX];
|
||||
char_t headerVals[NETWORK_HTTP_HEADER_MAX][NETWORK_HTTP_HEADER_VAL_MAX];
|
||||
uint32_t headerCount;
|
||||
networkhttpcallback_t callback;
|
||||
networkhttperrorcallback_t errorCallback;
|
||||
void *user;
|
||||
uint16_t status;
|
||||
char_t responseBody[NETWORK_HTTP_RESPONSE_MAX];
|
||||
char_t errorMessage[NETWORK_ERROR_MESSAGE_MAX];
|
||||
thread_t thread;
|
||||
} networkhttppendingitem_t;
|
||||
|
||||
typedef struct {
|
||||
networkpspstate_t state;
|
||||
pspUtilityNetconfData dialogData;
|
||||
struct pspUtilityNetconfAdhoc dialogAdhoc;
|
||||
|
||||
// Used during establishing connection
|
||||
void *onConnectedUser;
|
||||
void (*onConnected)(void *user);
|
||||
void (*onFailed)(errorret_t error, void *user);
|
||||
void *connectionUser;
|
||||
networkhttppendingitem_t requests[NETWORK_HTTP_PENDING_MAX];
|
||||
threadmutex_t resultsMutex;
|
||||
|
||||
// Used during disconnecting
|
||||
void *onCompelteUser;
|
||||
void (*onComplete)(void *user);
|
||||
} networkpsp_t;
|
||||
|
||||
errorret_t networkPspInit();
|
||||
/**
|
||||
* Initializes the PSP Network manager. This will NOT do network connecting,
|
||||
* only prep it for being able to connect in future.
|
||||
*
|
||||
* @return Error state (if any).
|
||||
*/
|
||||
errorret_t networkPSPInit();
|
||||
|
||||
errorret_t networkPspUpdate();
|
||||
/**
|
||||
* Called each frame for handling PSP requests, basically this is where all
|
||||
* communication between the HTTP thread and the main thread happens.
|
||||
*
|
||||
* @return Error state (if any).
|
||||
*/
|
||||
errorret_t networkPSPUpdate();
|
||||
|
||||
errorret_t networkPspDispose();
|
||||
/**
|
||||
* Disposes the PSP Network manager, this will clean all resources and, if the
|
||||
* network is connected, it will disconnect it safely.
|
||||
*
|
||||
* @return Error state (if any).
|
||||
*/
|
||||
errorret_t networkPSPDispose();
|
||||
|
||||
bool_t networkPspIsConnected();
|
||||
/**
|
||||
* Checks if the PSP network is connected.
|
||||
*
|
||||
* @return True if the PSP is connected to a network, false otherwise.
|
||||
*/
|
||||
bool_t networkPSPIsConnected();
|
||||
|
||||
void networkPspRequestConnection(
|
||||
/**
|
||||
* Requests the PSP to connect to a network (Shows the Wi-Fi connected).
|
||||
*
|
||||
* @param onConnected Callback connected successfully.
|
||||
* @param onFailed Callback if the connection failed.
|
||||
* @param onDisconnect Callback when connection is lost.
|
||||
* @param user User data to pass to the callbacks.
|
||||
*/
|
||||
void networkPSPRequestConnection(
|
||||
void (*onConnected)(void *user),
|
||||
void (*onFailed)(errorret_t error, void *user),
|
||||
void (*onDisconnect)(errorret_t error, void *user),
|
||||
void *user
|
||||
);
|
||||
|
||||
void networkPspHTTPRequest(
|
||||
const char_t *url,
|
||||
const networkhttprequestmethod_t method,
|
||||
const char_t *bodyOrNull,
|
||||
const networkhttpheader_t *headers,
|
||||
const uint32_t headerCount,
|
||||
void *user,
|
||||
networkhttpcallback_t callback,
|
||||
networkhttperrorcallback_t errorCallback
|
||||
);
|
||||
|
||||
bool_t networkPspIsConnectionModalOpen();
|
||||
);
|
||||
Reference in New Issue
Block a user