Program Listing for File HttpWsServer.h#
↰ Return to documentation for file (include/Karana/WebUI/HttpWsServer.h)
/*
*Copyright(c)2024-2026KaranaDynamicsPtyLtd.Allrightsreserved.
*
*NOTICETOUSER:
*
*Thissourcecodeand/ordocumentation(the"LicensedMaterials")is
*theconfidentialandproprietaryinformationofKaranaDynamicsInc.
*UseoftheseLicensedMaterialsisgovernedbythetermsandconditions
*ofaseparatesoftwarelicenseagreementbetweenKaranaDynamicsandthe
*Licensee("LicenseAgreement").Unlessexpresslypermittedunderthat
*agreement,anyreproduction,modification,distribution,ordisclosure
*oftheLicensedMaterials,inwholeorinpart,toanythirdparty
*withoutthepriorwrittenconsentofKaranaDynamicsisstrictlyprohibited.
*
*THELICENSEDMATERIALSAREPROVIDED"ASIS"WITHOUTWARRANTYOFANYKIND.
*KARANADYNAMICSDISCLAIMSALLWARRANTIES,EXPRESSORIMPLIED,INCLUDING
*BUTNOTLIMITEDTOWARRANTIESOFMERCHANTABILITY,NON-INFRINGEMENT,AND
*FITNESSFORAPARTICULARPURPOSE.
*
*INNOEVENTSHALLKARANADYNAMICSBELIABLEFORANYDAMAGESWHATSOEVER,
*INCLUDINGBUTNOTLIMITEDTOLOSSOFPROFITS,DATA,ORUSE,EVENIF
*ADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGES,WHETHERINCONTRACT,TORT,
*OROTHERWISEARISINGOUTOFORINCONNECTIONWITHTHELICENSEDMATERIALS.
*
*U.S.GovernmentEndUsers:TheLicensedMaterialsarea"commercialitem"
*asdefinedat48C.F.R.2.101,andareprovidedtotheU.S.Government
*onlyasacommercialenditemunderthetermsofthislicense.
*
*AnyuseoftheLicensedMaterialsinindividualorcommercialsoftwaremust
*include,intheuserdocumentationandinternalsourcecodecomments,
*thisNotice,Disclaimer,andU.S.GovernmentUseProvision.
*/
#pragmaonce
#include<filesystem>
#include<functional>
#include<memory>
#include<string>
namespaceKarana::WebUI{
classHttpWsServer{
public:
HttpWsServer(unsignedshortport);
virtual~HttpWsServer();
unsignedshortgetPort()const;
std::stringgetUrl()const;
voidserveFile(std::string_viewurl,
conststd::filesystem::path&path,
std::string_viewmime_type="");
voidserveData(std::string_viewurl,
std::string_viewcontent,
std::string_viewmime_type="application/octet-stream");
voidbroadcastMessage(std::string_viewmsg);
voidsendMessage(std::string_viewmsg,intclient_id);
voidsetOnConnect(std::function<void(int)>callback={});
voidsetOnMessage(std::function<void(std::string_view,int)>callback={});
voidsetOnDisconnect(std::function<void(int)>callback={});
boolwaitForClients(intclients=1,floattimeout_seconds=0);
voiddefer(std::function<void()>callback);
voidsync();
voidprintConnectionInfo();
voidclose();
private:
std::unique_ptr<structHttpWsServerImpl>_impl;
};
}//namespaceKarana::WebUI