Home /Modules/telephony-skya/Servers.sleela

Servers.sleela

lib/telephony-skya/Servers.sleela · 124 line(s) · sleela

<< lib/telephony-skya/Servers.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines Servers, the Skya server-side-presence Master Class —
     the listeners the node holds open and the roles they serve.
   
   Servers is an emblematic Skya module and a NATURAL / LOADABLE MODULE sharing
   the common module contract (load / loaded / moduleName / describe). It can
   hold the always-open local comm listener (the local SLeeLa comm server) and
   answers a basic PING so a peer can confirm the node is alive. Networking uses
   the same portable VM socket primitives as SkyaServer (listen / accept /
   sockread / sockwrite) across the explicit SLeeLa VM/OS bridge. The runnable
   orchestration example lives in telephony-skya/sleela/Servers.sleela.
   
   Family: telephony-skya. Native VM/OS work crosses an explicit bridge. >>
#sleela 2.5
material;
< Unified SLeeLa SDK front-end object. >
class Servers {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10406;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-07";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }

  static final String MODULE = "Servers";

  int loadedFlag;
  < always-open local comm listener handle (-1 = none) >
  int commListener;
  < port the comm listener holds open >
  int commPort;
  < listeners currently held open >
  int openCount;
  < requests served >
  int served;

  void load() {
    loadedFlag = 1;
    commListener = -1;
    commPort = 0;
    openCount = 0;
    served = 0;
  }
  boolean loaded() { return loadedFlag == 1; }
  String moduleName() { return MODULE; }

  void openComm(int port) {
    commPort = port;
    commListener = listen(port);
    openCount = openCount + 1;
  }

  boolean commOpen() { return commListener >= 0; }
  int listenersOpen() { return openCount; }
  int port() { return commPort; }

  boolean serveOne() {
    if (commListener < 0) { return false; }
    int client = accept(commListener);
    String request = sockread(client);
    boolean isPing = request != null && request.length() >= 4
                     && request.substring(0, 4) == "PING";
    if (isPing) {
      sockwrite(client, "SKYA/1 PONG port=" + commPort);
    } else {
      sockwrite(client, "SKYA/1 server-ready port=" + commPort);
    }
    sockclose(client);
    served = served + 1;
    return isPing;
  }

  void closeComm() {
    if (commListener >= 0) {
      sockclose(commListener);
      commListener = -1;
      if (openCount > 0) { openCount = openCount - 1; }
    }
  }

  int servedCount() { return served; }

  String describe() {
    return MODULE + " commOpen=" + commOpen() + " port=" + commPort
         + " listeners=" + openCount + " served=" + served;
  }
}