Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Eclipse Foundation
paho.mqtt.python
提交
4af8776b
P
paho.mqtt.python
项目概览
镜像
/
Eclipse Foundation
/
paho.mqtt.python
11 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
paho.mqtt.python
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4af8776b
编写于
4月 20, 2016
作者:
J
Jason Swails
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Restore backwards compatibliity to MQTTClient.
Signed-off-by:
N
Jason Swails
<
jason.swails@gmail.com
>
上级
9a5f892e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
110 addition
and
61 deletion
+110
-61
src/paho/mqtt/client.py
src/paho/mqtt/client.py
+110
-61
未找到文件。
src/paho/mqtt/client.py
浏览文件 @
4af8776b
...
...
@@ -479,6 +479,14 @@ class Client(object):
self
.
_tls_ciphers
=
None
self
.
_tls_version
=
tls_version
self
.
_tls_insecure
=
False
# No default callbacks
self
.
_on_log
=
None
self
.
_on_connect
=
None
self
.
_on_subscribe
=
None
self
.
_on_message
=
None
self
.
_on_publish
=
None
self
.
_on_unsubscribe
=
None
self
.
_on_disconnect
=
None
def
__del__
(
self
):
pass
...
...
@@ -1134,9 +1142,10 @@ class Client(object):
rc
=
MQTT_ERR_SUCCESS
else
:
rc
=
1
self
.
_in_callback
=
True
self
.
on_disconnect
(
self
,
self
.
_userdata
,
rc
)
self
.
_in_callback
=
False
if
self
.
on_disconnect
:
self
.
_in_callback
=
True
self
.
on_disconnect
(
self
,
self
.
_userdata
,
rc
)
self
.
_in_callback
=
False
self
.
_callback_mutex
.
release
()
return
MQTT_ERR_CONN_LOST
...
...
@@ -1312,9 +1321,9 @@ class Client(object):
self
.
_thread
.
join
()
self
.
_thread
=
None
def
on_log
(
self
,
client
,
userdata
,
level
,
buf
):
"""Called when the client has log information.
This function may be overridden by sub-classes
.
@
property
def
on_log
(
self
):
"""Called when the client has log information if implemented
.
Define to allow debugging.
...
...
@@ -1323,11 +1332,15 @@ class Client(object):
MQTT_LOG_DEBUG.
buf: the message itself
"""
pass
return
self
.
_on_log
def
on_connect
(
self
,
client
,
userdata
,
flag
,
rc
):
"""Called when the broker responds to our connection request.
This function may be overridden by sub-classes.
@
on_log
.
setter
def
on_log
(
self
,
func
):
self
.
_on_log
=
func
@
property
def
on_connect
(
self
):
"""Called when the broker responds to our connection request if implemented.
self: the client instance for this callback
userdata: the private user data as set in ``Client()`` or ``userdata_set()``
...
...
@@ -1350,23 +1363,31 @@ class Client(object):
5: Connection refused - not authorised
6-255: Currently unused.
"""
pass
return
self
.
_on_connect
def
on_subscribe
(
self
,
client
,
userdata
,
mid
,
granted_qos
):
"""Called when the broker responds to a subscribe request.
This function may be overridden by sub-classes.
@
on_connect
.
setter
def
on_connect
(
self
,
func
):
self
.
_on_connect
=
func
@
property
def
on_subscribe
(
self
):
"""Called when the broker responds to a subscribe request if implemented.
mid: matches the mid variable returned from the corresponding
subscribe() call.
granted_qos: list of integers that give the QoS level the broker has
granted for each of the different subscription requests.
"""
pass
return
self
.
_on_subscribe
@
on_subscribe
.
setter
def
on_subscribe
(
self
,
func
):
self
.
_on_subscribe
=
func
def
on_message
(
self
,
client
,
userdata
,
message
):
@
property
def
on_message
(
self
):
"""Called when a message has been received on a topic that the client
subscribes to.
This function may be overridden by sub-classes.
subscribes to if implemented.
This callback will be called for every message received. Use
``message_callback_add()`` to define multiple callbacks that will be called for
...
...
@@ -1377,9 +1398,14 @@ class Client(object):
message: an instance of MQTTMessage.
This is a class with members topic, payload, qos, retain.
"""
pass
return
self
.
_on_message
@
on_message
.
setter
def
on_message
(
self
,
func
):
self
.
_on_message
=
func
def
on_publish
(
self
,
client
,
userdata
,
mid
):
@
property
def
on_publish
(
self
):
"""Called when a message that was to be sent using the publish() call
has completed transmission to the broker.
This function may be overridden by sub-classes.
...
...
@@ -1393,18 +1419,28 @@ class Client(object):
mid: matches the mid variable returned from the corresponding
publish() call, to allow outgoing messages to be tracked.
"""
pass
return
self
.
_on_publish
@
on_publish
.
setter
def
on_publish
(
self
,
func
):
self
.
_on_publish
=
func
def
on_unsubscribe
(
self
,
client
,
userdata
,
mid
):
@
property
def
on_unsubscribe
(
self
):
"""Called when the broker responds to an unsubscribe request.
This function may be overridden by sub-classes.
mid: matches the mid variable returned from the corresponding
unsubscribe() call.
"""
pass
return
self
.
_on_unsubscribe
@
on_unsubscribe
.
setter
def
on_unsubscribe
(
self
,
func
):
self
.
_on_unsubscribe
=
func
def
on_disconnect
(
self
,
client
,
userdata
,
rc
):
@
property
def
on_disconnect
(
self
):
"""Called when the client disconnects from the broker.
This function may be overridden by sub-classes.
...
...
@@ -1417,7 +1453,11 @@ class Client(object):
other value the disconnection was unexpected, such as might be caused by
a network error.
"""
pass
return
self
.
_on_disconnect
@
on_disconnect
.
setter
def
on_disconnect
(
self
,
func
):
self
.
_on_disconnect
=
func
def
message_callback_add
(
self
,
sub
,
callback
):
"""Register a message callback for a specific topic.
...
...
@@ -1476,9 +1516,10 @@ class Client(object):
rc
=
MQTT_ERR_SUCCESS
self
.
_state_mutex
.
release
()
self
.
_callback_mutex
.
acquire
()
self
.
_in_callback
=
True
self
.
on_disconnect
(
self
,
self
.
_userdata
,
rc
)
self
.
_in_callback
=
False
if
self
.
on_disconnect
:
self
.
_in_callback
=
True
self
.
on_disconnect
(
self
,
self
.
_userdata
,
rc
)
self
.
_in_callback
=
False
self
.
_callback_mutex
.
release
()
return
rc
...
...
@@ -1618,9 +1659,10 @@ class Client(object):
if
packet
[
'to_process'
]
==
0
:
if
(
packet
[
'command'
]
&
0xF0
)
==
PUBLISH
and
packet
[
'qos'
]
==
0
:
self
.
_callback_mutex
.
acquire
()
self
.
_in_callback
=
True
self
.
on_publish
(
self
,
self
.
_userdata
,
packet
[
'mid'
])
self
.
_in_callback
=
False
if
self
.
on_publish
:
self
.
_in_callback
=
True
self
.
on_publish
(
self
,
self
.
_userdata
,
packet
[
'mid'
])
self
.
_in_callback
=
False
self
.
_callback_mutex
.
release
()
...
...
@@ -1632,9 +1674,10 @@ class Client(object):
self
.
_msgtime_mutex
.
release
()
self
.
_callback_mutex
.
acquire
()
self
.
_in_callback
=
True
self
.
on_disconnect
(
self
,
self
.
_userdata
,
0
)
self
.
_in_callback
=
False
if
self
.
on_disconnect
:
self
.
_in_callback
=
True
self
.
on_disconnect
(
self
,
self
.
_userdata
,
0
)
self
.
_in_callback
=
False
self
.
_callback_mutex
.
release
()
if
self
.
_ssl
:
...
...
@@ -1663,7 +1706,8 @@ class Client(object):
return
MQTT_ERR_SUCCESS
def
_easy_log
(
self
,
level
,
buf
):
self
.
on_log
(
self
,
self
.
_userdata
,
level
,
buf
)
if
self
.
on_log
:
self
.
on_log
(
self
,
self
.
_userdata
,
level
,
buf
)
def
_check_keepalive
(
self
):
if
self
.
_keepalive
==
0
:
...
...
@@ -1694,9 +1738,10 @@ class Client(object):
else
:
rc
=
1
self
.
_callback_mutex
.
acquire
()
self
.
_in_callback
=
True
self
.
on_disconnect
(
self
,
self
.
_userdata
,
rc
)
self
.
_in_callback
=
False
if
self
.
on_disconnect
:
self
.
_in_callback
=
True
self
.
on_disconnect
(
self
,
self
.
_userdata
,
rc
)
self
.
_in_callback
=
False
self
.
_callback_mutex
.
release
()
def
_mid_generate
(
self
):
...
...
@@ -2091,20 +2136,21 @@ class Client(object):
self
.
_easy_log
(
MQTT_LOG_DEBUG
,
"Received CONNACK ("
+
str
(
flags
)
+
", "
+
str
(
result
)
+
")"
)
self
.
_callback_mutex
.
acquire
()
self
.
_in_callback
=
True
if
self
.
on_connect
:
self
.
_in_callback
=
True
if
sys
.
version_info
[
0
]
<
3
:
argcount
=
self
.
on_connect
.
func_code
.
co_argcount
else
:
argcount
=
self
.
on_connect
.
__code__
.
co_argcount
if
sys
.
version_info
[
0
]
<
3
:
argcount
=
self
.
on_connect
.
func_code
.
co_argcount
else
:
argcount
=
self
.
on_connect
.
__code__
.
co_argcount
if
argcount
==
3
:
self
.
on_connect
(
self
,
self
.
_userdata
,
result
)
else
:
flags_dict
=
dict
()
flags_dict
[
'session present'
]
=
flags
&
0x01
self
.
on_connect
(
self
,
self
.
_userdata
,
flags_dict
,
result
)
self
.
_in_callback
=
False
if
argcount
==
3
:
self
.
on_connect
(
self
,
self
.
_userdata
,
result
)
else
:
flags_dict
=
dict
()
flags_dict
[
'session present'
]
=
flags
&
0x01
self
.
on_connect
(
self
,
self
.
_userdata
,
flags_dict
,
result
)
self
.
_in_callback
=
False
self
.
_callback_mutex
.
release
()
if
result
==
0
:
rc
=
0
...
...
@@ -2168,9 +2214,10 @@ class Client(object):
granted_qos
=
struct
.
unpack
(
pack_format
,
packet
)
self
.
_callback_mutex
.
acquire
()
self
.
_in_callback
=
True
self
.
on_subscribe
(
self
,
self
.
_userdata
,
mid
,
granted_qos
)
self
.
_in_callback
=
False
if
self
.
on_subscribe
:
self
.
_in_callback
=
True
self
.
on_subscribe
(
self
,
self
.
_userdata
,
mid
,
granted_qos
)
self
.
_in_callback
=
False
self
.
_callback_mutex
.
release
()
return
MQTT_ERR_SUCCESS
...
...
@@ -2307,9 +2354,10 @@ class Client(object):
mid
=
mid
[
0
]
self
.
_easy_log
(
MQTT_LOG_DEBUG
,
"Received UNSUBACK (Mid: "
+
str
(
mid
)
+
")"
)
self
.
_callback_mutex
.
acquire
()
self
.
_in_callback
=
True
self
.
on_unsubscribe
(
self
,
self
.
_userdata
,
mid
)
self
.
_in_callback
=
False
if
self
.
on_unsubscribe
:
self
.
_in_callback
=
True
self
.
on_unsubscribe
(
self
,
self
.
_userdata
,
mid
)
self
.
_in_callback
=
False
self
.
_callback_mutex
.
release
()
return
MQTT_ERR_SUCCESS
...
...
@@ -2328,11 +2376,12 @@ class Client(object):
if
self
.
_out_messages
[
i
].
mid
==
mid
:
# Only inform the client the message has been sent once.
self
.
_callback_mutex
.
acquire
()
self
.
_out_message_mutex
.
release
()
self
.
_in_callback
=
True
self
.
on_publish
(
self
,
self
.
_userdata
,
mid
)
self
.
_in_callback
=
False
self
.
_out_message_mutex
.
acquire
()
if
self
.
on_publish
:
self
.
_out_message_mutex
.
release
()
self
.
_in_callback
=
True
self
.
on_publish
(
self
,
self
.
_userdata
,
mid
)
self
.
_in_callback
=
False
self
.
_out_message_mutex
.
acquire
()
self
.
_callback_mutex
.
release
()
self
.
_out_messages
.
pop
(
i
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录