Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a99b0ae5c1e40ccee1fe6a49f1b940a9ebe7b102 (plain) (blame)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>Target Communication Framework: Lua Integration</title>
</head>

<body lang='EN-US'>

<h1>Target Communication Framework: Lua Integration</h1>

<p>Copyright (c) 2007, 2012 Wind River Systems, Inc. Made available under the EPL v1.0
<p>Direct comments, questions to the <a href="https://dev.eclipse.org/mailman/listinfo/tcf-dev">tcf-dev@eclipse.org</a> mailing list

<h2><a name='TcfLua'>TCF Integration with Lua</a></h2>

<p>The TCF integration with Lua allows writing TCF client and server programs in the Lua programming language.
The integration is done so the main loop is the TCF event dispatch loop.
At startup a Lua program is invoked to allow an initial setup after which it should return to enter the TCF dispatch loop.</p>

<p>TCF functions are accessible from the Lua table named "tcf".  Accessible functions are:</p>

<table border=1 cellpadding=8>
    <tr>
        <th>Function
        <th>Callback
        <th>Description
    <tr>
        <td><code>read_command(read_command_callback)
        <td><code>read_command_callback(string)
        <td>Reads one line from stdin or if the -s command line option is specified from the specified file.
    <tr>
        <td><code>peer = peer_server_find(peer_name)
        <td>NA
        <td>Looks up peer object with the specified name.  Returns <code>nil</code> if not found.
    <tr>
        <td><code>peers = peer_server_list()
        <td>NA
        <td>Returns a table of discovered peer objects.
    <tr>
        <td><code>peer = peer_server_from_url(peer_url)
        <td>NA
        <td>Creates a peer object from the specified URL.
    <tr>
        <td><code>protocol = protocol_alloc()
        <td>NA
        <td>Created a new protocol object.
    <tr>
        <td><code>channel_connect(peer, protocol, connect_callback)
        <td><code>connect_callback(channel, errorString)
        <td>Creates connection to specified peer.
    <tr>
        <td><code>event = post_event(post_event_callback, micro_seconds)
        <td><code>post_event_callback()
        <td>The <code>micro_seconds</code> argument is optional.  Then not present the callback function will be invoked after currently pending event have been processed.
</table>

<p>Protocol object functions:</p>

<table border=1 cellpadding=8>
    <tr>
        <th>Function
        <th>Callback
        <th>Description
    <tr>
        <td><code>command_handler(protocol, service, name, command_callback)
        <td><code>command_callback(token, data)
        <td>Register command handler for <code>service</code> and <code>name</code> with <code>protocol</code>.  The <code>command_callback</code> function will be called each time a command of the specified name and service is received on a channel associated with the protocol object.
</table>

<p>Channel object functions:</p>

<table border=1 cellpadding=8>
    <tr>
        <th>Function
        <th>Callback
        <th>Description
    <tr>
        <td><code>close(channel)
        <td>NA
        <td>Disconnects the specified channel.
    <tr>
        <td><code>connecting_handler(channel, connecting_callback)
        <td><code>connecting_callback()
        <td>Register callback function which is called when the channel enters connecting state.
    <tr>
        <td><code>connected_handler(channel, connected_callback)
        <td><code>connected_callback()
        <td>Register callback function which is called when the channel enters connected state.
    <tr>
        <td><code>receive_handler(channel, receive_callback)
        <td><code>receive_callback()
        <td>Register callback function which is called when the channel receives a message.
    <tr>
        <td><code>disconnected_handler(channel, disconnected_callback)
        <td><code>disconnected_callback()
        <td>Register callback function which is called when the channel is disconnected.
    <tr>
        <td><code>event_handler(channel, service, name, event_callback)
        <td><code>event_callback(data)
        <td>Register callback function which is called when an event for <code>service</code> and <code>name</code> is received.
    <tr>
        <td><code>start(channel)
        <td>NA
        <td>Starts communication on channel.
    <tr>
        <td><code>send_command(channel, service, name, data, replay_callback)
        <td><code>replay_callback(data, error)
        <td>Send a command to channel and register callback when reply is received.
    <tr>
        <td><code>services = get_services(channel)
        <td>NA
        <td>Create a table of service names supported by remote peer.
</table>

<p>Peer object functions:</p>

<table border=1 cellpadding=8>
    <tr>
        <th>Function
        <th>Callback
        <th>Description
    <tr>
        <td><code>id = getid(peer)
        <td>NA
        <td>Return ID of peer.
    <tr>
        <td><code>getnames(peer)
        <td>NA
        <td>Return table of peer propery names.
    <tr>
        <td><code>getvalue(peer, name)
        <td>NA
        <td>Return value of propery <code>name</code>.
    <tr>
        <td><code>setvalue(peer, name, value)
        <td>NA
        <td>Set value of propery <code>name</code>.
    <tr>
        <td><code>getflags(peer)
        <td>NA
        <td>Return table of flags for peer.
    <tr>
        <td><code>setflags(peer, flags)
        <td>NA
        <td>Set flags for peer.
</table>

<p>Event object functions:</p>

<table border=1 cellpadding=8>
    <tr>
        <th>Function
        <th>Callback
        <th>Description
    <tr>
        <td><code>cancel(event)
        <td>NA
        <td>Cancel event created by <code>post_event()</code>.
</table>

<h3>Download and Build</h3>

The integration has only been tested on Linux at this point.

<p><code>cd &lt;<i>luadir</i>&gt;
<br>curl -O http://www.lua.org/ftp/lua-5.1.4.tar.gz
<br>tar zxf lua-5.1.4.tar.gz
<br>cd lua-5.1.4
<br>make linux
<br>make local
<br>cd &lt;<i>tcfdir</i>&gt;/agent
<br>make LUADIR=&lt;<i>luadir</i>&gt;/lua-5.1.4
</code>

<p><code>./obj/GNU/Linux/i686/Debug/tcflua tcf_example.lua
</code>

</body>
</html>

Back to the top