Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
Continue to improve network module abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
AlixANNERAUD committed Aug 7, 2023
1 parent 689f643 commit e1a032b
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 127 deletions.
2 changes: 1 addition & 1 deletion lib/Xila/include/Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// - Xila's modules
#include "Account/Accounts.hpp"
#include "Clipboard/Clipboard.hpp"
#include "Communication/Communication.hpp"
#include "Network/Network.hpp"
#include "Display/Display.hpp"
#include "Drive/Drive.hpp"
#include "Flash/Flash.hpp"
Expand Down
7 changes: 3 additions & 4 deletions lib/Xila/include/Network/Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace Xila_Namespace
// - - Constructors / destructors

Client_Class();
~Client_Class();

virtual Result_Type Connect(const char* Host, Word_Type Port, int32_t Timeout = 30000) = 0;

Expand Down Expand Up @@ -53,10 +52,10 @@ namespace Xila_Namespace

virtual operator bool() = 0;

virtual operator==(Client_Class& Client) = 0;
virtual operator==(Client_Class& Client) = 0;
virtual bool operator==(Client_Class& Client) = 0;
virtual bool operator!=(Client_Class& Client) = 0;

private:
protected:

void* Data;
} Client_Type;
Expand Down
121 changes: 61 additions & 60 deletions lib/Xila/include/Network/HTTP_Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,64 @@ namespace Xila_Namespace
{
enum class HTTP_Code_Type
{
Continue = HTTP_CODE_CONTINUE,
Switching_Protocols = HTTP_CODE_SWITCHING_PROTOCOLS,
Processing = HTTP_CODE_PROCESSING,
OK = HTTP_CODE_OK,
Created = HTTP_CODE_CREATED,
Accepted = HTTP_CODE_ACCEPTED,
Non_Authoritative_Information = HTTP_CODE_NON_AUTHORITATIVE_INFORMATION,
No_Content = HTTP_CODE_NO_CONTENT,
Reset_Content = HTTP_CODE_RESET_CONTENT,
Partial_Content = HTTP_CODE_PARTIAL_CONTENT,
Multi_Status = HTTP_CODE_MULTI_STATUS,
Already_Reported = HTTP_CODE_ALREADY_REPORTED,
I_M_Used = HTTP_CODE_IM_USED,
Multiple_Choices = HTTP_CODE_MULTIPLE_CHOICES,
Moved_Permanently = HTTP_CODE_MOVED_PERMANENTLY,
Found = HTTP_CODE_FOUND,
See_Other = HTTP_CODE_SEE_OTHER,
Not_Modified = HTTP_CODE_NOT_MODIFIED,
Use_Proxy = HTTP_CODE_USE_PROXY,
Temporary_Redirect = HTTP_CODE_TEMPORARY_REDIRECT,
Permanent_Redirect = HTTP_CODE_PERMANENT_REDIRECT,
Bad_Request = HTTP_CODE_BAD_REQUEST,
Unauthorized = HTTP_CODE_UNAUTHORIZED,
Payment_Required = HTTP_CODE_PAYMENT_REQUIRED,
Forbidden = HTTP_CODE_FORBIDDEN,
Not_Found = HTTP_CODE_NOT_FOUND,
Method_Not_Allowed = HTTP_CODE_METHOD_NOT_ALLOWED,
Not_Acceptable = HTTP_CODE_NOT_ACCEPTABLE,
Proxy_Authentication_Required = HTTP_CODE_PROXY_AUTHENTICATION_REQUIRED,
Request_Timeout = HTTP_CODE_REQUEST_TIMEOUT,
Conflict = HTTP_CODE_CONFLICT,
Gone = HTTP_CODE_GONE,
Length_Required = HTTP_CODE_LENGTH_REQUIRED,
Precondition_Failed = HTTP_CODE_PRECONDITION_FAILED,
Payload_Too_Large = HTTP_CODE_PAYLOAD_TOO_LARGE,
URI_Too_Long = HTTP_CODE_URI_TOO_LONG,
Unsupported_Media_Type = HTTP_CODE_UNSUPPORTED_MEDIA_TYPE,
Range_Not_Satisfiable = HTTP_CODE_RANGE_NOT_SATISFIABLE,
Expectation_Failed = HTTP_CODE_EXPECTATION_FAILED,
Misdirected_Request = HTTP_CODE_MISDIRECTED_REQUEST,
Unprocessable_Entity = HTTP_CODE_UNPROCESSABLE_ENTITY,
Locked = HTTP_CODE_LOCKED,
Failed_Dependency = HTTP_CODE_FAILED_DEPENDENCY,
Upgrade_Required = HTTP_CODE_UPGRADE_REQUIRED,
Precondition_Required = HTTP_CODE_PRECONDITION_REQUIRED,
Too_Many_Requests = HTTP_CODE_TOO_MANY_REQUESTS,
Request_Header_Fields_Too_Large = HTTP_CODE_REQUEST_HEADER_FIELDS_TOO_LARGE,
Internal_Server_Error = HTTP_CODE_INTERNAL_SERVER_ERROR,
Not_Implemented = HTTP_CODE_NOT_IMPLEMENTED,
Bad_Gateway = HTTP_CODE_BAD_GATEWAY,
Service_Unavailable = HTTP_CODE_SERVICE_UNAVAILABLE,
Gateway_Timeout = HTTP_CODE_GATEWAY_TIMEOUT,
HTTP_Version_Not_Supported = HTTP_CODE_HTTP_VERSION_NOT_SUPPORTED,
Variant_Also_Negotiates = HTTP_CODE_VARIANT_ALSO_NEGOTIATES,
Insufficient_Storage = HTTP_CODE_INSUFFICIENT_STORAGE,
Loop_Detected = HTTP_CODE_LOOP_DETECTED,
Not_Extended = HTTP_CODE_NOT_EXTENDED,
Network_Authentication_Required = HTTP_CODE_NETWORK_AUTHENTICATION_REQUIRED
Continue,
Switching_Protocols,
Processing,
OK,
Created,
Accepted,
Non_Authoritative_Information,
No_Content,
Reset_Content,
Partial_Content,
Multi_Status,
Already_Reported,
I_M_Used,
Multiple_Choices,
Moved_Permanently,
Found,
See_Other,
Not_Modified,
Use_Proxy,
Temporary_Redirect,
Permanent_Redirect,
Bad_Request,
Unauthorized,
Payment_Required,
Forbidden,
Not_Found,
Method_Not_Allowed,
Not_Acceptable,
Proxy_Authentication_Required,
Request_Timeout,
Conflict,
Gone,
Length_Required,
Precondition_Failed,
Payload_Too_Large,
URI_Too_Long,
Unsupported_Media_Type,
Range_Not_Satisfiable,
Expectation_Failed,
Misdirected_Request,
Unprocessable_Entity,
Locked,
Failed_Dependency,
Upgrade_Required,
Precondition_Required,
Too_Many_Requests,
Request_Header_Fields_Too_Large,
Internal_Server_Error,
Not_Implemented,
Bad_Gateway,
Service_Unavailable,
Gateway_Timeout,
HTTP_Version_Not_Supported,
Variant_Also_Negotiates,
Insufficient_Storage,
Loop_Detected,
Not_Extended,
Network_Authentication_Required
};

typedef class HTTPS_Client_Class
Expand Down Expand Up @@ -137,8 +137,9 @@ namespace Xila_Namespace

String_Type &Get_String(String_Type &String);

private:
HTTPClient Client;
protected:

void* Data;
} HTTPS_Client_Type;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Xila/include/Network/IP_Address.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef IP_Address_Hpp_Included
#define IP_Address_Hpp_Included
#ifndef Xila_Network_IP_Address_Hpp_Included
#define Xila_Network_IP_Address_Hpp_Included

#include "../Module/String.hpp"

Expand Down
4 changes: 2 additions & 2 deletions lib/Xila/include/Network/Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
///
/// @copyright Copyright (c) 2023

#ifndef Xila_Interface_Hpp_Included
#define Xila_Interface_Hpp_Included
#ifndef Xila_Network_Interface_Hpp_Included
#define Xila_Network_Interface_Hpp_Included

#include "IP_Address.hpp"
#include "Client.hpp"
Expand Down
6 changes: 3 additions & 3 deletions lib/Xila/include/Network/Network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
/// @copyright Copyright (c) 2022
///

#ifndef Communication_Hpp_Included
#define Communication_Hpp_Included
#ifndef Xila_Network_Hpp_Included
#define Xila_Network_Hpp_Included

#include "IP_Address.hpp"
#include "WiFi.hpp"
#include "WiFi/WiFi.hpp"
#include "HTTP_Client.hpp"

#include "Interface.hpp"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
/// @file WiFi_Client.hpp
/// @file Client.hpp
/// @author Alix ANNERAUD ([email protected])
/// @brief
/// @version 0.1.0
/// @date 16-05-2023
///
/// @copyright Copyright (c) 2023

#ifndef Communication_WiFi_Client_Hpp_Included
#define Communication_WiFi_Client_Hpp_Included
#ifndef Xila_Network_WiFi_Client_Hpp_Included
#define Xila_Network_WiFi_Client_Hpp_Included



#ifdef Xila_WiFi_Hardware_ESP32
#include <WiFiClientSecure.h>
#endif

#include "Module/Module.hpp"
#include "../Client.hpp"

namespace Xila_Namespace
{
namespace Communication_Types
namespace Network_Types
{
typedef class WiFi_Client_Class : public Xila_Namespace::Stream_Type
typedef class WiFi_Client_Class : public Client_Class
{
public:
// - Methods
Expand All @@ -32,21 +26,21 @@ namespace Xila_Namespace

// - - Operations

Result_Type Connect(const char *Host, uint16_t Port, int32_t Timeout = 30000);
Result_Type Connect(const char *Host, uint16_t Port, int32_t Timeout = 30000) override;

void Stop();
void Stop() override;

bool Connected();
String_Type &Last_Error(String_Type &Error_Buffer);
bool Connected() override;
String_Type &Last_Error(String_Type &Error_Buffer) override;

// - - Getters

// - - Setters

void Set_Insecure();
void Set_Insecure() override;

void Set_Handshake_Timeout(uint32_t Timeout);
void Set_Timeout(uint32_t Timeout);
void Set_Handshake_Timeout(uint32_t Timeout) override;
void Set_Timeout(uint32_t Timeout) override;

// - - - Overrided Stream_Type methods

Expand All @@ -63,21 +57,10 @@ namespace Xila_Namespace

// - - Operators

operator bool();

bool operator==(WiFi_Client_Class &Client);
bool operator!=(WiFi_Client_Class &Client);

/// @brief Cast operator to WiFiClientSecure (compatibility purpose)
operator WiFiClientSecure &()
{
return Client;
}
operator bool() override;

private:
#if defined(Xila_WiFi_Hardware_ESP32)
WiFiClientSecure Client;
#endif
bool operator==(WiFi_Client_Class &Client) override;
bool operator!=(WiFi_Client_Class &Client) override;
} WiFi_Client_Type;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Xila_Namespace
{

/// @brief WiFi types
namespace Communication_Types
namespace Network_Types
{
/// @brief WiFi status type
enum class Status_Type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
/// @file WiFi_Client.cpp
/// @author Alix ANNERAUD ([email protected])
/// @brief
/// @version 0.1.0
/// @date 16-05-2023
///
/// @copyright Copyright (c) 2023

/// @file Client.cpp
/// @author Alix ANNERAUD ([email protected])
/// @brief
/// @version 0.1.0
/// @date 16-05-2023
///
/// @copyright Copyright (c) 2023

#include "Communication/WiFi_Client.hpp"
#ifdef Xila_WiFi_Hardware_ESP32

#include <WiFiClientSecure.h>

#include "Network/WiFi/Client.hpp"

using namespace Xila_Namespace;
using namespace Communication_Types;
using namespace Network_Types;

WiFi_Client_Class::WiFi_Client_Class()
{
Data = new
}

Result_Type WiFi_Client_Class::Connect(const char* Host, uint16_t Port, int32_t Timeout)
Result_Type WiFi_Client_Class::Connect(const char *Host, uint16_t Port, int32_t Timeout)
{

return (Result_Type)Client.connect(Host, Port, Timeout);
}

Expand All @@ -31,18 +36,17 @@ bool WiFi_Client_Class::Connected()
return Client.connected();
}

String_Type& WiFi_Client_Class::Last_Error(String_Type& Error_Buffer)
String_Type &WiFi_Client_Class::Last_Error(String_Type &Error_Buffer)
{
if (!Error_Buffer)
return Error_Buffer;

if (Client.lastError((char*)Error_Buffer, Error_Buffer.Get_Size()) == 0)
if (Client.lastError((char *)Error_Buffer, Error_Buffer.Get_Size()) == 0)
Error_Buffer = "";

return Error_Buffer;
}


void WiFi_Client_Class::Set_Insecure()
{
Client.setInsecure();
Expand Down Expand Up @@ -83,7 +87,7 @@ String_Type &WiFi_Client_Class::Read_String(String_Type &String)
if (!String)
return String;

Client.read((uint8_t*)(char*)String, String.Get_Size());
Client.read((uint8_t *)(char *)String, String.Get_Size());
return String;
}

Expand All @@ -102,9 +106,9 @@ Size_Type WiFi_Client_Class::Write_Bytes(const Byte_Type *Buffer, Size_Type Leng
return Client.write(Buffer, Length);
}

Size_Type WiFi_Client_Class::Write_String(const char* String)
Size_Type WiFi_Client_Class::Write_String(const char *String)
{
return Client.write((uint8_t*)String, strlen(String));
return Client.write((uint8_t *)String, strlen(String));
}

WiFi_Client_Class::operator bool()
Expand All @@ -122,4 +126,4 @@ bool WiFi_Client_Class::operator!=(WiFi_Client_Class &Client)
return Client != Client;
}


#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
///
/// @copyright Copyright (c) 2023

#if Xila_WiFi_Hardware_ESP32
#ifdef Xila_WiFi_Hardware_ESP32

#include <WiFi.h>

Expand Down
Loading

0 comments on commit e1a032b

Please sign in to comment.