Repository navigation
Expand file tree
/
Copy pathcommand.py
More file actions
366 lines (321 loc) · 10.7 KB
/
Copy pathcommand.py
File metadata and controls
366 lines (321 loc) · 10.7 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-----------------------------------------------------------
# libTML: A BEEP based Messaging Suite
# Copyright (C) 2015 wobe-systems GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
#
# You may find a copy of the license under this software is released
# at COPYING file. This is LGPL software: you are welcome to develop
# proprietary applications using this library without any royalty or
# fee but returning back any change, improvement or addition in the
# form of source code, project image, documentation patches, etc.
#
# Homepage:
# http://www.libtml.org
#
# For professionel support contact us:
#
# wobe-systems GmbH
#-----------------------------------------------------------
from sidex.constants import *
import tml
import sidex.document
import sidex.variant
## @defgroup TMLCmdGroup TML Command
# @ingroup highLevelClasses
# @brief Commands, events and data exchange.
#
# The TMLCommand contains status information and carries the data of a command or event call.
# All parameters are accessable through a data property. If the command is used to call a remote
# function changes will be passed back to the caller.
## @brief TML Command Object.
# @ingroup TMLCmdGroup
#
# The TMLCmd object provides an interface to a TML command
# and its data.
class TMLCmd(object):
## @brief TMLCmd constructor.
#
# Passing a handle results in a wrapper around it.
# The command handle will not be freed on object destruction
# because it is not owned by the object.
# If not handle is passed the object will create a new one that
# is owned and freed on object destruction.
#
# @param aId : [\b int] [\em optional] Command Id
# @param aHandle : [\b int] [\em optional] handle of an existing command
#
# @sa tml_Cmd_Create()
def __init__(self, cmdid=None, handle=None):
if (PY3 and handle and isinstance(handle, int)) or \
(PY2 and handle and isinstance(handle, (long, int))):
self.__command_handle = handle
self.__thisown = False
else:
self.__command_handle = tml.tml_Cmd_Create()
self.__thisown = True
if cmdid:
self.command = cmdid
self.__sdoc = None # sidex document
self.__progress = 0 # last progress value
self.__show_progress = True
self.__tml_core = None
return
# ------------ properties ---------------------
# -- the code here is for documentation only --
self.data = None
self.command = None
self.error = None
self.errormsg = None
self.progress = None
self.command_handle = None
self.thisown = True
self.creation_time = None
self.show_progress = True
self.mode = None
self.reply_type = 0
self.reply_message = ''
self.tml_core = None
# ------------ end properties -----------------
## @brief Free command handle and release data.
#
# If the command handle is owned by the object it will be freed here.
# The data needs to be released to allow other threads to access it.
#
# @sa tml_Cmd_Free
def __del__(self):
self.release_data()
if self.__thisown:
tml.tml_Cmd_Free(self.__command_handle)
## @property tml_core
# @brief [\b tml.core.TMLCore] TML core handling this command.
#
# This property is None until, it was sent through a TML core.
#
# @par Access:
# read/write
# @cond NODOC
@property
def tml_core(self):
return self.__tml_core
@tml_core.setter
def tml_core(self, value):
self.__tml_core = value
# @endcond
## @property reply_message
# @brief [\b int] status reply message
#
# @par Access:
# read
#
# @sa tml_Cmd_Header_GetReplyMessage()
# @cond NODOC
@property
def reply_type(self):
return tml.tml_Cmd_Header_GetReplyMessage(self.__command_handle)
# @endcond
## @property reply_type
# @brief [\b int] status reply type
#
# @par Access:
# read
#
# @sa tml_Cmd_Header_GetReplyType()
# @cond NODOC
@property
def reply_type(self):
return tml.tml_Cmd_Header_GetReplyType(self.__command_handle)
# @endcond
## @property mode
# @brief [\b int] command mode
#
# @par Access:
# read
#
# @sa tml_Cmd_Header_GetMode()
# @cond NODOC
@property
def mode(self):
return tml.tml_Cmd_Header_GetMode(self.__command_handle)
# @endcond
## @property show_progress
# @brief [\b bool] call progress event
#
# Assigning false to show_progress will block the tml.profile.TMLProfile.on_progress event.
#
# @par Access:
# read/write
#
# @sa tml.profile.TMLProfile.on_progress
# @cond NODOC
@property
def show_progress(self):
return self.__show_progress
@show_progress.setter
def progress(self, value):
self.__show_progress = value
# @endcond
## @property creation_time
# @brief [\b sidex.variant.SDXDateTime] command creation time
#
# @par Access:
# read
#
# @sa tml_Cmd_Header_GetCreationTime()
# @cond NODOC
@property
def creation_time(self):
stime = tml.tml_Cmd_Header_GetCreationTime(self.__command_handle)
return sidex.variant.SDXDateTime(value=stime)
# @endcond
## @property data
# @brief [\b sidex.document.SDXDocument] A SIDEX Document representing the command data
#
# @par Access:
# read
# @cond NODOC
@property
def data(self):
return self.aquire_data()
# @endcond
## @property command
# @brief [\b int] command id of the command
#
# @par Access:
# read/write
#
# @sa tml_Cmd_Header_GetCommand(), tml_Cmd_Header_SetCommand()
# @cond NODOC
@property
def command(self):
return tml.tml_Cmd_Header_GetCommand(self.__command_handle)
@command.setter
def command(self, value):
tml.tml_Cmd_Header_SetCommand(self.__command_handle, value)
# @endcond
## @property error
# @brief [\b int] The error number
#
# @par Access:
# read/write
#
# @sa tml_Cmd_Header_GetError(), tml_Cmd_Header_SetError()
# @cond NODOC
@property
def error(self):
return tml.tml_Cmd_Header_GetError(self.__command_handle)
@error.setter
def error(self, value):
tml.tml_Cmd_Header_SetError(self.__command_handle, value)
# @endcond
## @property errormsg
# @brief [\b str] The error message
#
# @par Access:
# read/write
#
# @sa tml_Cmd_Header_GetErrorMessage(), tml_Cmd_Header_SetErrorMessage()
# @cond NODOC
@property
def errormsg(self):
return tml.tml_Cmd_Header_GetErrorMessage(self.__command_handle)
@errormsg.setter
def errormsg(self, value):
tml.tml_Cmd_Header_SetErrorMessage(self.__command_handle, value)
# @endcond
## @property progress
# @brief [\b int] progress between 0-100
#
# @par Access:
# read/write
#
# @sa tml_Send_AsyncProgressReply()
# @cond NODOC
@property
def progress(self):
return self.__progress
@progress.setter
def progress(self, value):
if self.__progress != value:
tml.tml_Send_AsyncProgressReply(self.__command_handle, value)
self.__progress = value
# @endcond
## @property command_handle
# @brief [\b int] TML command handle
#
# @par Access:
# read
# @cond NODOC
@property
def command_handle(self):
return self.__command_handle
# @endcond
## @property thisown
# @brief [\b bool] if True the handle is freed on object destruction
#
# Normally the command handle is freed on object destruction. If the TMLCmd
# is used to access a TML command handle from that was not created by the
# TMLCmd object constructor, thisown is False. Sometimes it makes sense
# to free the TMLCmd instance but leave the TML command handle untouched.
# In this case False can be assigned to the thisown property to prevent the
# handle from beeing freed.
#
# @par Access:
# read/write
# @cond NODOC
@property
def thisown(self):
return self.__thisown
@thisown.setter
def thisown(self, value):
self.__thisown = value
# @endcond
## @brief Aquire the SIDEX handle of the command data and return a SIDEX document.
#
# If the data property is read, aquire_data will be autmatically called. After using
# the data a call to release data is required.
#
# @note This a mechanism to protect the data from changes by another thread while
# used. If the call to release_data is missing, the system can be blocked.
#
# Using data in callback functions does not require a release_data call. This is
# handled by the calling class. The data will also be released by the TMLCmd destructor.
#
# @returns [sidex.document.SDXDocument] SIDEX document to access the data
#
# @sa release_data, tml_Cmd_Acquire_Sidex_Handle()
def aquire_data(self):
if self.__sdoc is None:
self.__sdoc = sidex.document.SDXDocument(tml.tml_Cmd_Acquire_Sidex_Handle(self.__command_handle))
return self.__sdoc
## @brief Release the handle of the SIDEX document representing the command data.
#
# @sa aquire_data, tml_Cmd_Release_Sidex_Handle()
def release_data(self):
if self.__sdoc is not None:
tml.tml_Cmd_Release_Sidex_Handle(self.__command_handle)
self.__sdoc = None
## @brief Send a status reply to the caller.
#
# @param rtype : [\b int] status reply type
# @param rmsg : [\b rmsg] status reply message
#
# @sa tml.core.on_status_reply, tml.profile.on_status_reply, tml_Send_AsyncStatusReply()
def send_status_reply(self, rtype, rmsg):
tml.tml_Send_AsyncStatusReply(self.__command_handle, rtype, rmsg)