Adding waitFor(...) method

This commit is contained in:
Rodrigo Alfonso 2024-08-18 23:31:55 -03:00
parent c3ed1114a9
commit b7f5288d4c
2 changed files with 16 additions and 4 deletions

View File

@ -453,6 +453,7 @@ Name | Return type | Description
`openConnection(ip, port, type, result)` | **bool** | Opens a TCP/UDP (`type`) connection at the given `ip` (4-byte address) on the given `port`. The `result` is a pointer to a `LinkMobile::OpenConn` struct that will be filled with the result. When the request is completed, the `completed` field will be `true`. If the connection was successful, the `success` field will be `true` and the `connectionId` field can be used when calling the `transfer(...)` method. Only `2` connections can be opened at the same time.
`closeConnection(connectionId, type, result)` | **bool** | Closes an active TCP/UDP (`type`) connection. The `result` is a pointer to a `LinkMobile::CloseConn` struct that will be filled with the result. When the request is completed, the `completed` field will be `true`. If the connection was closed correctly, the `success` field will be `true`.
`transfer(dataToSend, result, [connectionId])` | **bool** | Requests a data transfer (up to `254` bytes) and responds the received data. The transfer can be done with the other node in a P2P connection, or with any open TCP/UDP connection if an ISP session is active. In the case of a TCP/UDP connection, the `connectionId` must be provided. The `result` is a pointer to a `LinkMobile::DataTransfer` struct that will be filled with the received data. It can also point to `dataToSend` to reuse the struct. When the request is completed, the `completed` field will be `true`. If the transfer was successful, the `success` field will be `true`. If not, you can assume that the connection was closed.
`waitFor(asyncRequest)` | **bool** | Waits for `asyncRequest` to be completed. Returns `true` if the request was completed && successful, and the adapter session is still alive. Otherwise, it returns `false`. The `asyncRequest` is a pointer to a `LinkMobile::DNSQuery`, `LinkMobile::OpenConn`, `LinkMobile::CloseConn`, or `LinkMobile::DataTransfer`.
`hangUp()` | **bool** | Hangs up the current P2P or ISP call. Closes all connections.
`readConfiguration(configurationData)` | **bool** | Retrieves the adapter configuration, and puts it in the `configurationData` struct. If the adapter has an active session, the data is already loaded, so it's instantaneous.
`getState()` | **LinkMobile::State** | Returns the current state (one of `LinkMobile::State::NEEDS_RESET`, `LinkMobile::State::PINGING`, `LinkMobile::State::WAITING_TO_START`, `LinkMobile::State::STARTING_SESSION`, `LinkMobile::State::ACTIVATING_SIO32`, `LinkMobile::State::WAITING_32BIT_SWITCH`, `LinkMobile::State::READING_CONFIGURATION`, `LinkMobile::State::SESSION_ACTIVE`, `LinkMobile::State::CALL_REQUESTED`, `LinkMobile::State::CALLING`, `LinkMobile::State::CALL_ESTABLISHED`, `LinkMobile::State::ISP_CALL_REQUESTED`, `LinkMobile::State::ISP_CALLING`, `LinkMobile::State::ISP_LOGIN`, `LinkMobile::State::ISP_ACTIVE`, `LinkMobile::State::SHUTDOWN_REQUESTED`, `LinkMobile::State::ENDING_SESSION`, `LinkMobile::State::WAITING_8BIT_SWITCH`, or `LinkMobile::State::SHUTDOWN`).

View File

@ -197,10 +197,6 @@ class LinkMobile {
struct AsyncRequest {
volatile bool completed = false;
bool success = false;
void waitForCompletion() {
// TODO: ASD
}
};
struct DNSQuery : public AsyncRequest {
@ -517,6 +513,21 @@ class LinkMobile {
return true;
}
/**
* @brief Waits for `asyncRequest` to be completed. Returns `true` if the
* request was completed && successful, and the adapter session is still
* alive. Otherwise, it returns `false`.
* @param asyncRequest A pointer to a `LinkMobile::DNSQuery`,
* `LinkMobile::OpenConn`, `LinkMobile::CloseConn`, or
* `LinkMobile::DataTransfer`.
*/
bool waitForCompletion(AsyncRequest* asyncRequest) {
while (isSessionActive() && !asyncRequest->completed)
Link::_IntrWait(1, Link::_IRQ_SERIAL | Link::_IRQ_VBLANK);
return isSessionActive() && asyncRequest->completed &&
asyncRequest->success;
}
/**
* @brief Hangs up the current P2P or ISP call. Closes all connections.
* \warning Non-blocking. Returns `true` immediately, or `false` if there's no