Print the different strucutures.
parent
9d16d6f2b8
commit
c14148ef35
|
@ -61,7 +61,7 @@ test "Message - creation and display" {
|
||||||
var m = Message.init(1, MessageType.DATA, 3, s);
|
var m = Message.init(1, MessageType.DATA, 3, s);
|
||||||
|
|
||||||
print("\n", .{});
|
print("\n", .{});
|
||||||
print("message:\t{}\n", .{m});
|
print("message:\t[{}]\n", .{m});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const Messages = std.ArrayList(Message);
|
pub const Messages = std.ArrayList(Message);
|
||||||
|
@ -155,36 +155,111 @@ pub const Event = struct {
|
||||||
self.m = null;
|
self.m = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn format(
|
||||||
|
self: Self,
|
||||||
|
comptime _: []const u8, // No need.
|
||||||
|
_: std.fmt.FormatOptions, // No need.
|
||||||
|
out_stream: anytype,
|
||||||
|
) !void {
|
||||||
|
try std.fmt.format(out_stream
|
||||||
|
, "type {}, origin: {}, index {}, message: [{}]"
|
||||||
|
, .{ self.@"type", self.origin, self.index, self.m} );
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//test {
|
test "Event - creation and display" {
|
||||||
// //m = Message.init
|
var s = "hello!!";
|
||||||
// //e = Event.init(Event.available_types.EXTRA_SOCKET, 0, 0, m);
|
// fd type usertype payload
|
||||||
//}
|
var m = Message.init(1, MessageType.DATA, 3, s);
|
||||||
|
// type index origin message
|
||||||
|
var e = Event.init(EventType.CONNECTION, 5, 8, &m);
|
||||||
|
|
||||||
|
print("\n", .{});
|
||||||
|
print("event:\t[{}]\n", .{e});
|
||||||
|
}
|
||||||
|
|
||||||
pub const ConnectionType = enum {
|
pub const ConnectionType = enum {
|
||||||
IPC, // Standard connection.
|
IPC, // Standard connection.
|
||||||
EXTERNAL, // ??
|
EXTERNAL, // Non IPC connection (TCP, UDP, etc.).
|
||||||
SERVER, // Messages received = new connections.
|
SERVER, // Messages received = new connections.
|
||||||
SWITCHED, // IO operations should go through registered callbacks.
|
SWITCHED, // IO operations should go through registered callbacks.
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Connection = struct {
|
pub const Connection = struct {
|
||||||
|
@"type": ConnectionType,
|
||||||
@"type": Connection.ConnectionType,
|
|
||||||
more_to_read: bool,
|
more_to_read: bool,
|
||||||
path: *const []u8,
|
path: ?[] const u8, // Not always needed.
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
pub fn init(@"type": ConnectionType, path: ?[] const u8) Self {
|
||||||
|
return Self {
|
||||||
|
.@"type" = @"type",
|
||||||
|
.more_to_read = false,
|
||||||
|
.path = path,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format(
|
||||||
|
self: Self,
|
||||||
|
comptime _: []const u8, // No need.
|
||||||
|
_: std.fmt.FormatOptions, // No need.
|
||||||
|
out_stream: anytype,
|
||||||
|
) !void {
|
||||||
|
try std.fmt.format(out_stream
|
||||||
|
, "connection type {}, more_to_read {}, path {s}"
|
||||||
|
, .{ self.@"type", self.more_to_read, self.path} );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test "Connection - creation and display" {
|
||||||
|
// origin destination
|
||||||
|
var path = "/some/path";
|
||||||
|
var c1 = Connection.init(ConnectionType.EXTERNAL, path);
|
||||||
|
var c2 = Connection.init(ConnectionType.IPC , null);
|
||||||
|
print("\n", .{});
|
||||||
|
print("connection 1:\t[{}]\n", .{c1});
|
||||||
|
print("connection 2:\t[{}]\n", .{c2});
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: callbacks.
|
||||||
pub const Switch = struct {
|
pub const Switch = struct {
|
||||||
orig : usize,
|
origin : usize,
|
||||||
dest : usize,
|
destination : usize,
|
||||||
// enum ipccb (*orig_in) (int origin_fd, struct ipc_message *m, short int *more_to_read);
|
// enum ipccb (*orig_in) (int origin_fd, struct ipc_message *m, short int *more_to_read);
|
||||||
// enum ipccb (*orig_out) (int origin_fd, struct ipc_message *m);
|
// enum ipccb (*orig_out) (int origin_fd, struct ipc_message *m);
|
||||||
// enum ipccb (*dest_in) (int origin_fd, struct ipc_message *m, short int *more_to_read);
|
// enum ipccb (*dest_in) (int origin_fd, struct ipc_message *m, short int *more_to_read);
|
||||||
// enum ipccb (*dest_out) (int origin_fd, struct ipc_message *m);
|
// enum ipccb (*dest_out) (int origin_fd, struct ipc_message *m);
|
||||||
|
|
||||||
|
const Self = @This();
|
||||||
|
|
||||||
|
pub fn init(origin: usize, destination: usize) Self {
|
||||||
|
return Self {
|
||||||
|
.origin = origin,
|
||||||
|
.destination = destination,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn format(
|
||||||
|
self: Self,
|
||||||
|
comptime _: []const u8, // No need.
|
||||||
|
_: std.fmt.FormatOptions, // No need.
|
||||||
|
out_stream: anytype,
|
||||||
|
) !void {
|
||||||
|
try std.fmt.format(out_stream
|
||||||
|
, "switch {} <-> {}"
|
||||||
|
, .{ self.origin, self.destination} );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test "Switch - creation and display" {
|
||||||
|
// origin destination
|
||||||
|
var s = Switch.init(3,8);
|
||||||
|
print("\n", .{});
|
||||||
|
print("switch:\t[{}]\n", .{s});
|
||||||
|
}
|
||||||
|
|
||||||
pub const Switches = std.ArrayList(Switch);
|
pub const Switches = std.ArrayList(Switch);
|
||||||
|
|
||||||
pub const Connections = std.ArrayList(Connection);
|
pub const Connections = std.ArrayList(Connection);
|
||||||
|
|
Reference in New Issue