-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSlot.h
105 lines (86 loc) · 3.6 KB
/
Slot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright Kabuki Starship� <kabukistarship.com>.
#pragma once
#ifndef SCRIPT2_SLOT_DECL
#define SCRIPT2_SLOT_DECL
#include <_Config.h>
#if SEAM >= SCRIPT2_CRABS
namespace _ {
struct BIn;
struct BOut;
struct Op;
/* A Slot in a Door in a Chinese Room to pass messages through.
A Slot is Ring Boofer Socket similar to a TCP port. The operation of the
Slot is similar to the Text class except that it introduces two more
pointers for the (socket) origin and (data) origin of the ring socket and
you may write packed data. */
struct Slot {
IUA* origin, //< First byte of the ring socket.
* start, //< Start of the data in the ring socket.
* stop, //< Stop of the data in the ring socket.
* end; //< End of the ring socket.
/* Initializes the ring socket with the given socket origin and size.
@param origin Pointer to the beginning of the ring socket.
@param size The size of the ring socket in bytes. */
Slot(IUW* socket, ISW size);
/* Initializes the slot from the BIn. */
Slot(BIn* bin);
/* Initializes the slot from the BIn. */
Slot(BOut* bout);
/* Sets the ring socket to the given socket origin and size.
@param origin Pointer to the beginning of the ring socket.
@param size The size of the ring socket in bytes. */
inline BOL Set(IUW* socket, IUW size) {
if (!socket) return true;
IUA* l_begin = reinterpret_cast<IUA*>(socket);
origin = origin = stop = l_begin;
stop = l_begin + size;
return false;
}
/* Checks if this slot contains the given address.
@return Returns inputed address if this Slot contains the given address
and nil else wise. */
void* Contains(void* address);
/* Clears the socket without zeroing it out. */
inline void Clear() { origin = stop = origin; }
/* Zeros out the Slot. */
void Wipe();
/* Checks if there is space in the socket.
@return True if the socket has space. */
BOL IsWritable();
/* Checks if there is data in the socket.
@return True if the socket has data. */
BOL IsReadable();
/* Reads the given Operation input parameters from the slot to the args.
@param slot The slot to read from.
@param op The Operation to get the in from.
@param args The args array of pointers to write to.
@return Nil upon success and an Error Operation upon failure. */
const Op* Read(const ISC* params, void** args);
/* Reads the given Operation input parameters from the slot to the args.
@param slot The slot to read from.
@param op The Operation to get the in from.
@param args The args array of pointers to write to.
@return Nil upon success and an Error Operation upon failure. */
const Op* Read(const Op& op, void** args);
/* Writes the given Operation output parameters from the slot to the args.
@param slot The slot to read from.
@param op The Operation to get the in from.
@param args The args array of pointers to write to.
@return Nil upon success and an Error Operation upon failure. */
const Op* Write(const ISC* params, void** args);
/* Writes the given Operation output parameters from the slot to the args.
@param slot The slot to read from.
@param op The Operation to get the in from.
@param args The args array of pointers to write to.
@return Nil upon success and an Error Operation upon failure. */
const Op* Write(const Op& op, void** args);
/* Writes a single to the slot socket.
@param message The message to send.
@return Nil upon success and an Error Operation upon failure. */
const Op* Write(const IUA* message);
/* Copies the contents of the target slot into the slot. */
const Op* Write(Slot& target);
};
} //< namespace _
#endif
#endif