mirror of
https://github.com/deavmi/birchwood
synced 2024-09-20 02:03:27 +02:00
Client
- Updated imports - Moved `IRCEvent`, `IRCEventType` and `PongEvent` outside of the `Client` class - Made `engine`, `running` and `socket` package-level accessible Package - Fixed package for `client` Main package - Updated public imports for the `birchwood` package
This commit is contained in:
parent
586b80edbc
commit
d75d5407fd
@ -7,11 +7,14 @@ import std.container.slist : SList;
|
|||||||
import core.sync.mutex : Mutex;
|
import core.sync.mutex : Mutex;
|
||||||
import core.thread : Thread, dur;
|
import core.thread : Thread, dur;
|
||||||
import std.string;
|
import std.string;
|
||||||
import eventy;
|
import eventy : EventyEvent = Event, Engine, EventType, Signal;
|
||||||
import birchwood.client.conninfo : ConnectionInfo;
|
import birchwood.config : ConnectionInfo;
|
||||||
import birchwood.client.exceptions : BirchwoodException;
|
import birchwood.client.exceptions : BirchwoodException;
|
||||||
import birchwood.messages : Message, encodeMessage, decodeMessage, isValidText;
|
import birchwood.protocol.messages : Message, encodeMessage, decodeMessage, isValidText;
|
||||||
import birchwood.constants : ReplyType;
|
// import birchwood.protocol.constants : ReplyType;
|
||||||
|
import birchwood.client.receiver : ReceiverThread;
|
||||||
|
import birchwood.client.sender : SenderThread;
|
||||||
|
|
||||||
|
|
||||||
// TODO: Remove this import
|
// TODO: Remove this import
|
||||||
import std.stdio : writeln;
|
import std.stdio : writeln;
|
||||||
@ -24,43 +27,7 @@ __gshared static this()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public final enum IRCEventType : ulong
|
||||||
|
|
||||||
// TODO: Make abstract and for unit tests make a `DefaultClient`
|
|
||||||
// ... which logs outputs for the `onX()` handler functions
|
|
||||||
public class Client : Thread
|
|
||||||
{
|
|
||||||
/* Connection information */
|
|
||||||
private ConnectionInfo connInfo;
|
|
||||||
|
|
||||||
/* TODO: We should learn some info in here (or do we put it in connInfo)? */
|
|
||||||
private string serverName; //TODO: Make use of
|
|
||||||
|
|
||||||
|
|
||||||
private Socket socket;
|
|
||||||
|
|
||||||
/* Message queues (and handlers) */
|
|
||||||
private SList!(ubyte[]) recvQueue, sendQueue;
|
|
||||||
private Mutex recvQueueLock, sendQueueLock;
|
|
||||||
private Thread recvHandler, sendHandler;
|
|
||||||
|
|
||||||
/* Event engine */
|
|
||||||
private Engine engine;
|
|
||||||
|
|
||||||
private bool running = false;
|
|
||||||
|
|
||||||
this(ConnectionInfo connInfo)
|
|
||||||
{
|
|
||||||
super(&loop);
|
|
||||||
this.connInfo = connInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
~this()
|
|
||||||
{
|
|
||||||
//TODO: Do something here, tare downs
|
|
||||||
}
|
|
||||||
|
|
||||||
private final enum IRCEventType : ulong
|
|
||||||
{
|
{
|
||||||
GENERIC_EVENT = 1,
|
GENERIC_EVENT = 1,
|
||||||
PONG_EVENT
|
PONG_EVENT
|
||||||
@ -68,7 +35,7 @@ public class Client : Thread
|
|||||||
|
|
||||||
|
|
||||||
/* TODO: Move to an events.d class */
|
/* TODO: Move to an events.d class */
|
||||||
private final class IRCEvent : Event
|
public final class IRCEvent : EventyEvent
|
||||||
{
|
{
|
||||||
private Message msg;
|
private Message msg;
|
||||||
|
|
||||||
@ -91,7 +58,7 @@ public class Client : Thread
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: make PongEvent (id 2 buit-in) */
|
/* TODO: make PongEvent (id 2 buit-in) */
|
||||||
private final class PongEvent : Event
|
public final class PongEvent : EventyEvent
|
||||||
{
|
{
|
||||||
private string pingID;
|
private string pingID;
|
||||||
|
|
||||||
@ -107,6 +74,46 @@ public class Client : Thread
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Make abstract and for unit tests make a `DefaultClient`
|
||||||
|
// ... which logs outputs for the `onX()` handler functions
|
||||||
|
public class Client : Thread
|
||||||
|
{
|
||||||
|
/* Connection information */
|
||||||
|
private ConnectionInfo connInfo;
|
||||||
|
|
||||||
|
/* TODO: We should learn some info in here (or do we put it in connInfo)? */
|
||||||
|
private string serverName; //TODO: Make use of
|
||||||
|
|
||||||
|
|
||||||
|
package Socket socket;
|
||||||
|
|
||||||
|
/* Message queues (and handlers) */
|
||||||
|
private SList!(ubyte[]) recvQueue, sendQueue;
|
||||||
|
private Mutex recvQueueLock, sendQueueLock;
|
||||||
|
private Thread recvHandler, sendHandler;
|
||||||
|
|
||||||
|
private ReceiverThread receiver;
|
||||||
|
private SenderThread sender;
|
||||||
|
|
||||||
|
|
||||||
|
/* Event engine */
|
||||||
|
package Engine engine;
|
||||||
|
|
||||||
|
package bool running = false;
|
||||||
|
|
||||||
|
this(ConnectionInfo connInfo)
|
||||||
|
{
|
||||||
|
super(&loop);
|
||||||
|
this.connInfo = connInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
~this()
|
||||||
|
{
|
||||||
|
//TODO: Do something here, tare downs
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User overridable handler functions below
|
* User overridable handler functions below
|
||||||
*/
|
*/
|
||||||
@ -509,7 +516,7 @@ public class Client : Thread
|
|||||||
super(client, [IRCEventType.GENERIC_EVENT]);
|
super(client, [IRCEventType.GENERIC_EVENT]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void handler(Event e)
|
public override void handler(EventyEvent e)
|
||||||
{
|
{
|
||||||
/* TODO: Insert cast here to our custoim type */
|
/* TODO: Insert cast here to our custoim type */
|
||||||
IRCEvent ircEvent = cast(IRCEvent)e;
|
IRCEvent ircEvent = cast(IRCEvent)e;
|
||||||
@ -573,7 +580,7 @@ public class Client : Thread
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Send a PONG back with the received PING id */
|
/* Send a PONG back with the received PING id */
|
||||||
public override void handler(Event e)
|
public override void handler(EventyEvent e)
|
||||||
{
|
{
|
||||||
PongEvent pongEvent = cast(PongEvent)e;
|
PongEvent pongEvent = cast(PongEvent)e;
|
||||||
assert(pongEvent);
|
assert(pongEvent);
|
||||||
@ -762,7 +769,7 @@ public class Client : Thread
|
|||||||
|
|
||||||
/* TODO: Implement */
|
/* TODO: Implement */
|
||||||
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
|
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
|
||||||
Event pongEvent = new PongEvent(pingID);
|
EventyEvent pongEvent = new PongEvent(pingID);
|
||||||
engine.push(pongEvent);
|
engine.push(pongEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -784,7 +791,7 @@ public class Client : Thread
|
|||||||
curMsg = Message.parseReceivedMessage(messageNormal);
|
curMsg = Message.parseReceivedMessage(messageNormal);
|
||||||
|
|
||||||
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
|
// TODO: Remove the Eventy push and replace with a handler call (on second thought no)
|
||||||
Event ircEvent = new IRCEvent(curMsg);
|
EventyEvent ircEvent = new IRCEvent(curMsg);
|
||||||
engine.push(ircEvent);
|
engine.push(ircEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,4 +2,3 @@ module birchwood.client;
|
|||||||
|
|
||||||
public import birchwood.client.client;
|
public import birchwood.client.client;
|
||||||
public import birchwood.client.exceptions : BirchwoodException;
|
public import birchwood.client.exceptions : BirchwoodException;
|
||||||
public import birchwood.client.conninfo : ConnectionInfo;
|
|
@ -1,4 +1,5 @@
|
|||||||
module birchwood;
|
module birchwood;
|
||||||
|
|
||||||
public import birchwood.client;
|
public import birchwood.client;
|
||||||
public import birchwood.messages;
|
public import birchwood.config;
|
||||||
|
public import birchwood.protocol;
|
Loading…
Reference in New Issue
Block a user