Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
2b006e2f
Commit
2b006e2f
authored
Jan 31, 2019
by
Javier Peletier
Committed by
Arnim Läuger
Jan 31, 2019
Browse files
mqtt: allow daisy-chaining subscriptions (#2638)
parent
56f19e44
Changes
1
Show whitespace changes
Inline
Side-by-side
components/modules/mqtt.c
View file @
2b006e2f
...
@@ -180,11 +180,10 @@ static void event_subscribed(lua_State* L, mqtt_context_t* mqtt_context, esp_mqt
...
@@ -180,11 +180,10 @@ static void event_subscribed(lua_State* L, mqtt_context_t* mqtt_context, esp_mqt
ESP_LOGD
(
TAG
,
"CB:subscribe: calling registered one-shot subscribe callback"
);
ESP_LOGD
(
TAG
,
"CB:subscribe: calling registered one-shot subscribe callback"
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
mqtt_context
->
subscribed_ok_cb
);
// push the function reference on the stack
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
mqtt_context
->
subscribed_ok_cb
);
// push the function reference on the stack
luaX_push_weak_ref
(
L
,
mqtt_context
->
self
);
// push the client object on the stack
luaX_push_weak_ref
(
L
,
mqtt_context
->
self
);
// push the client object on the stack
luaX_unset_ref
(
L
,
&
mqtt_context
->
subscribed_ok_cb
);
// forget the callback since it is one-shot
int
res
=
lua_pcall
(
L
,
1
,
0
,
0
);
//call the connect callback with one parameter: function(client)
int
res
=
lua_pcall
(
L
,
1
,
0
,
0
);
//call the connect callback with one parameter: function(client)
if
(
res
!=
0
)
if
(
res
!=
0
)
ESP_LOGD
(
TAG
,
"CB:subscribe: Error when calling one-shot subscribe callback - (%d) %s"
,
res
,
luaL_checkstring
(
L
,
-
1
));
ESP_LOGD
(
TAG
,
"CB:subscribe: Error when calling one-shot subscribe callback - (%d) %s"
,
res
,
luaL_checkstring
(
L
,
-
1
));
luaX_unset_ref
(
L
,
&
mqtt_context
->
subscribed_ok_cb
);
// forget the callback since it is one-shot
}
}
//event_published is called when a publish operation completes
//event_published is called when a publish operation completes
...
@@ -194,11 +193,10 @@ static void event_published(lua_State* L, mqtt_context_t* mqtt_context, esp_mqtt
...
@@ -194,11 +193,10 @@ static void event_published(lua_State* L, mqtt_context_t* mqtt_context, esp_mqtt
ESP_LOGD
(
TAG
,
"CB:publish: calling registered one-shot publish callback"
);
ESP_LOGD
(
TAG
,
"CB:publish: calling registered one-shot publish callback"
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
mqtt_context
->
published_ok_cb
);
// push the callback function reference to the stack
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
mqtt_context
->
published_ok_cb
);
// push the callback function reference to the stack
luaX_push_weak_ref
(
L
,
mqtt_context
->
self
);
// push the client reference to the stack
luaX_push_weak_ref
(
L
,
mqtt_context
->
self
);
// push the client reference to the stack
luaX_unset_ref
(
L
,
&
mqtt_context
->
published_ok_cb
);
// forget this callback since it is one-shot
int
res
=
lua_pcall
(
L
,
1
,
0
,
0
);
//call the connect callback with 1 parameter: function(client)
int
res
=
lua_pcall
(
L
,
1
,
0
,
0
);
//call the connect callback with 1 parameter: function(client)
if
(
res
!=
0
)
if
(
res
!=
0
)
ESP_LOGD
(
TAG
,
"CB:publish: Error when calling one-shot publish callback - (%d) %s"
,
res
,
luaL_checkstring
(
L
,
-
1
));
ESP_LOGD
(
TAG
,
"CB:publish: Error when calling one-shot publish callback - (%d) %s"
,
res
,
luaL_checkstring
(
L
,
-
1
));
luaX_unset_ref
(
L
,
&
mqtt_context
->
published_ok_cb
);
// forget this callback since it is one-shot
}
}
// event_unsubscribed is called when a subscription is successful
// event_unsubscribed is called when a subscription is successful
...
@@ -208,11 +206,10 @@ static void event_unsubscribed(lua_State* L, mqtt_context_t* mqtt_context, esp_m
...
@@ -208,11 +206,10 @@ static void event_unsubscribed(lua_State* L, mqtt_context_t* mqtt_context, esp_m
ESP_LOGD
(
TAG
,
"CB:unsubscribe: calling registered one-shot unsubscribe callback"
);
ESP_LOGD
(
TAG
,
"CB:unsubscribe: calling registered one-shot unsubscribe callback"
);
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
mqtt_context
->
unsubscribed_ok_cb
);
// push callback function reference on the stack
lua_rawgeti
(
L
,
LUA_REGISTRYINDEX
,
mqtt_context
->
unsubscribed_ok_cb
);
// push callback function reference on the stack
luaX_push_weak_ref
(
L
,
mqtt_context
->
self
);
// push a reference to the client
luaX_push_weak_ref
(
L
,
mqtt_context
->
self
);
// push a reference to the client
luaX_unset_ref
(
L
,
&
mqtt_context
->
unsubscribed_ok_cb
);
// forget callback as it is one-shot
int
res
=
lua_pcall
(
L
,
1
,
0
,
0
);
//call the connect callback with one parameter: function(client)
int
res
=
lua_pcall
(
L
,
1
,
0
,
0
);
//call the connect callback with one parameter: function(client)
if
(
res
!=
0
)
if
(
res
!=
0
)
ESP_LOGD
(
TAG
,
"CB:unsubscribe: Error when calling one-shot unsubscribe callback - (%d) %s"
,
res
,
luaL_checkstring
(
L
,
-
1
));
ESP_LOGD
(
TAG
,
"CB:unsubscribe: Error when calling one-shot unsubscribe callback - (%d) %s"
,
res
,
luaL_checkstring
(
L
,
-
1
));
luaX_unset_ref
(
L
,
&
mqtt_context
->
unsubscribed_ok_cb
);
// forget callback as it is one-shot
}
}
//event_data_received is called when data is received on a subscribed topic
//event_data_received is called when data is received on a subscribed topic
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment