Program Listing for File Router.h

Program Listing for File Router.h#

Return to documentation for file (include/Karana/WebUI/Router.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"Karana/KCore/SharedPointer.h"
#include"Karana/WebUI/HttpWsServer.h"

namespaceKarana::WebUI{

classRouter{
public:
Router(constKarana::Core::ks_ptr<HttpWsServer>&server);

Router(constRouter&)=delete;
Router&operator=(constRouter&)=delete;

virtual~Router();

Karana::Core::ks_ptr<class Channel>channel(std::string_viewesm);

Karana::Core::ks_ptr<class Channel>channel(conststd::filesystem::path&esm);

inlineKarana::Core::ks_ptr<class Channel>channel(conststd::string&esm){
//Defaultingtostring_view(sourcecode)
returnchannel(std::string_view(esm));
}

private:
std::unique_ptr<structRouterState>_state;
};

classChannel{
public:
Channel(constChannel&)=delete;
Channel&operator=(constChannel&)=delete;

virtual~Channel();

std::string_viewuuid()const;

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);

voiddefer(std::function<void()>callback);

voidsync();

private:
friendclassRouter;
explicitChannel(constKarana::Core::ks_ptr<HttpWsServer>&server,
std::string_viewesm_hash);

std::unique_ptr<structChannelState>_state;
};

}//namespaceKarana::WebUI