Repository navigation
Network system basic (HPNS::Internal::Base_NetworkObject)
Half People edited this page Jan 7, 2025
·
1 revision
class Base_NetworkObject
{
public:
//-----------------------------------------------------------------------------------------
// main
virtual void Start(bool thread_activate = false);
virtual void Close();
inline bool IsWorking() { return working; }
inline CallbackIO& SetupCallback() { return callbacks; }
virtual void Update() {};
//-----------------------------------------------------------------------------------------
//command
virtual void push_command(const char* command_name, std::function<void(nlohmann::json&, HPNS::Internal::Base_NetworkObject*, HPNS::ConnectDevice)> function, bool cover = false);
virtual void erase_command(const char* command_name);
virtual bool command_is_exist(const char* command_name);
virtual bool call_command(std::string command_name, nlohmann::json& data, HPNS::Internal::Base_NetworkObject* network_system, HPNS::ConnectDevice device);
virtual void insert_commands(Base_NetworkObject* network_object, bool cover = false);
virtual void clear_command();
//-----------------------------------------------------------------------------------------
//message - server
virtual bool MSG_SendMessageToClient(HPNS::ConnectDevice device, const char* command_name, nlohmann::json data = nlohmann::json()) { return false; }
virtual const char* MSG_GetDeviceIP(HPNS::ConnectDevice device) { return "null"; }
virtual bool MSG_CloseClientConnet(HPNS::ConnectDevice device) { return false; }
virtual bool MSG_IsConnected(HPNS::ConnectDevice device) { return false; }
//message - client
#if HPNS_CLIENT_ACTIVATE virtual bool Client_SendMessageToServer(const char* command_name, nlohmann::json data = nlohmann::json()) { return false; } virtual const char* Client_GetDeviceIP() { return "null"; } virtual bool Client_CloseClientConnet() { return false; } virtual bool Client_IsConnected() { return false; } #endif // HPNS_CLIENT_ACTIVATE void* message_buffer = nullptr;//Reserved for users to save information (will be automatically deleted) protected: void* network_context = nullptr; void* command_list = nullptr; void* working_thread = nullptr; bool working = false; CallbackIO callbacks; void init_command_list(); void release_command_list(); };