Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Particle.publish() API changes #1195

Merged
merged 1 commit into from
Dec 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/reference/firmware.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,18 @@ Particle.publish("t", temperature, ttl, PRIVATE, NO_ACK);

{{/if}}

*`WITH_ACK` flag*

This flag causes `Particle.publish()` to return only after receiving an acknowledgement that the published event has been received by the Cloud.

```C++
// SYNTAX

Particle.publish("motion-detected", NULL, WITH_ACK);
Particle.publish("motion-detected", NULL, PRIVATE, WITH_ACK);
Particle.publish("motion-detected", NULL, ttl, PRIVATE, WITH_ACK);
```


### Particle.subscribe()

Expand Down
12 changes: 5 additions & 7 deletions wiring/inc/spark_wiring_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "spark_protocol_functions.h"
#include "spark_wiring_system.h"
#include "spark_wiring_watchdog.h"
#include "spark_wiring_async.h"
#include "interrupts_hal.h"
#include "system_mode.h"
#include <functional>
Expand Down Expand Up @@ -222,23 +221,22 @@ class CloudClass {
return _function(funcKey, std::bind(func, instance, _1));
}

inline spark::Future<void> publish(const char *eventName, PublishFlag eventType=PUBLIC)
inline bool publish(const char *eventName, PublishFlag eventType=PUBLIC)
{
return publish(eventName, NULL, 60, PublishFlag::flag_t(eventType));
}

inline spark::Future<void> publish(const char *eventName, const char *eventData, PublishFlag eventType=PUBLIC)
inline bool publish(const char *eventName, const char *eventData, PublishFlag eventType=PUBLIC)
{
return publish(eventName, eventData, 60, PublishFlag::flag_t(eventType));
}

inline spark::Future<void> publish(const char *eventName, const char *eventData, PublishFlag f1, PublishFlag f2)
inline bool publish(const char *eventName, const char *eventData, PublishFlag f1, PublishFlag f2)
{
return publish(eventName, eventData, 60, f1.flag()+f2.flag());
}


inline spark::Future<void> publish(const char *eventName, const char *eventData, int ttl, PublishFlag eventType=PUBLIC)
inline bool publish(const char *eventName, const char *eventData, int ttl, PublishFlag eventType=PUBLIC)
{
return publish(eventName, eventData, ttl, PublishFlag::flag_t(eventType));
}
Expand Down Expand Up @@ -351,7 +349,7 @@ class CloudClass {

static void call_wiring_event_handler(const void* param, const char *event_name, const char *data);

static spark::Future<void> publish(const char *eventName, const char *eventData, int ttl, uint32_t flags);
static bool publish(const char *eventName, const char *eventData, int ttl, uint32_t flags);

static ProtocolFacade* sp()
{
Expand Down
10 changes: 7 additions & 3 deletions wiring/src/spark_wiring_cloud.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "spark_wiring_cloud.h"

#include "spark_wiring_async.h"

int CloudClass::call_raw_user_function(void* data, const char* param, void* reserved)
{
user_function_int_str_t* fn = (user_function_int_str_t*)(data);
Expand Down Expand Up @@ -30,7 +32,7 @@ bool CloudClass::register_function(cloud_function_t fn, void* data, const char*
return spark_function(NULL, (user_function_int_str_t*)&desc, NULL);
}

spark::Future<void> CloudClass::publish(const char *eventName, const char *eventData, int ttl, uint32_t flags) {
bool CloudClass::publish(const char *eventName, const char *eventData, int ttl, uint32_t flags) {
#ifndef SPARK_NO_CLOUD
spark_send_event_data d = { sizeof(spark_send_event_data) };

Expand All @@ -45,8 +47,10 @@ spark::Future<void> CloudClass::publish(const char *eventName, const char *event
p.fromDataPtr(d.handler_data); // Free wrapper object
}

return p.future();
// TODO: Return future object instead of synchronous waiting
spark::Future<void> f = p.future();
return f.wait().isSucceeded();
#else
return spark::Future<void>::makeFailed(spark::Error::NOT_SUPPORTED);
return false; // spark::Future<void>::makeFailed(spark::Error::NOT_SUPPORTED);
#endif
}