mqtt: allow daisy-chaining subscriptions (#2638)
This commit is contained in:
parent
56f19e44c3
commit
2b006e2f9a
|
@ -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
|
||||||
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
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue