Made available to dub.

This commit is contained in:
Tristan B. Kildaire 2020-05-04 18:27:12 +02:00
parent f35f371380
commit d8b85be2bc
3 changed files with 82 additions and 0 deletions

13
dub.json Normal file
View File

@ -0,0 +1,13 @@
{
"authors": [
"Tristan B. Kildaire"
],
"copyright": "Copyright © 2020, Tristan B. Kildaire",
"dependencies": {
"bformat": "~>1.0.4"
},
"description": "A minimal D application.",
"license": "proprietary",
"name": "libinformer",
"targetType": "library"
}

6
dub.selections.json Normal file
View File

@ -0,0 +1,6 @@
{
"fileVersion": 1,
"versions": {
"bformat": "1.0.4"
}
}

63
source/libinformer.d Normal file
View File

@ -0,0 +1,63 @@
module libinformer;
import std.socket;
import bmessage;
import std.json;
import std.string;
public final class BesterInformerClient
{
/* The informer socket */
private Socket informerSocket;
this(string socketPath)
{
try
{
informerSocket = new Socket(AddressFamily.UNIX, SocketType.STREAM);
informerSocket.connect(new UnixAddress(socketPath));
}
catch(AddressException e)
{
}
catch(SocketException e)
{
}
}
public string[] getClients()
{
string[] clientList;
JSONValue message;
JSONValue commandBlock;
commandBlock["type"] = "listClients";
message["command"] = commandBlock;
sendMessage(informerSocket, message);
JSONValue response;
receiveMessage(informerSocket, response);
string statusCode = response["status"].str();
if(cmp(statusCode, "0") == 0)
{
JSONValue[] clientListJSON = response["data"].array();
for(ulong i = 0; i < clientListJSON.length; i++)
{
clientList ~= clientListJSON[i].str();
}
}
else
{
/* error */
}
return clientList;
}
}