Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeuz committed Sep 19, 2024
1 parent ae904a8 commit ac3ea97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 5 additions & 6 deletions wiring/inc/spark_wiring_cloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ enum class ContentType: int {
TEXT = (int)protocol::CoapContentFormat::TEXT_PLAIN, ///< `text/plain; charset=utf-8`.
JPEG = (int)protocol::CoapContentFormat::IMAGE_JPEG, ///< `image/jpeg`.
PNG = (int)protocol::CoapContentFormat::IMAGE_PNG, ///< `image/png`.
BINARY = (int)protocol::CoapContentFormat::APPLICATION_OCTET_STREAM, ///< `application/octet-stream`.
JSON_AS_CBOR = (int)protocol::CoapContentFormat::PARTICLE_JSON_AS_CBOR ///< `application/vnd.particle.json+cbor` (vendor-specific).
BINARY = (int)protocol::CoapContentFormat::APPLICATION_OCTET_STREAM ///< `application/octet-stream`.
};

typedef void (*EventHandlerWithContentType)(const char* name, const char* data, size_t size, ContentType type);
Expand Down Expand Up @@ -294,7 +293,7 @@ class CloudClass {

inline particle::Future<bool> publish(const char *eventName, const char *eventData, int ttl, PublishFlags flags1, PublishFlags flags2 = PublishFlags())
{
return publish_event(eventName, eventData, eventData ? std::strlen(eventData) : 0, particle::ContentType::TEXT, ttl, flags1 | flags2);
return publish_event(eventName, eventData, eventData ? std::strlen(eventData) : 0, static_cast<int>(particle::ContentType::TEXT), ttl, flags1 | flags2);
}

particle::Future<bool> publish(const char* name);
Expand All @@ -312,7 +311,7 @@ class CloudClass {
}

particle::Future<bool> publish(const char* name, const char* data, size_t size, particle::ContentType type, PublishFlags flags = PublishFlags()) {
return publish_event(name, data, size, type, DEFAULT_CLOUD_EVENT_TTL, flags);
return publish_event(name, data, size, static_cast<int>(type), DEFAULT_CLOUD_EVENT_TTL, flags);
}

particle::Future<bool> publish(const char* name, const particle::EventData& data, PublishFlags flags = PublishFlags());
Expand Down Expand Up @@ -547,8 +546,8 @@ class CloudClass {

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

static particle::Future<bool> publish_event(const char* name, const char* data, size_t size, particle::ContentType type,
int ttl, PublishFlags flags);
static particle::Future<bool> publish_event(const char* name, const char* data, size_t size, int type, int ttl,
PublishFlags flags);

bool subscribe_wiring(const char *eventName, wiring_event_handler_t handler, Spark_Subscription_Scope_TypeDef scope, const char *deviceID = NULL)
{
Expand Down
5 changes: 3 additions & 2 deletions wiring/src/spark_wiring_cloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ bool CloudClass::register_function(cloud_function_t fn, void* data, const char*
return spark_function(NULL, (user_function_int_str_t*)&desc, NULL);
}

Future<bool> CloudClass::publish_event(const char* name, const char* data, size_t size, ContentType type, int ttl,
Future<bool> CloudClass::publish_event(const char* name, const char* data, size_t size, int type, int ttl,
PublishFlags flags) {
if (!connected()) {
return Future<bool>(Error::INVALID_STATE);
Expand Down Expand Up @@ -159,7 +159,8 @@ Future<bool> CloudClass::publish(const char* name, const Variant& data, PublishF
if (r < 0) {
return Future<bool>((Error::Type)r);
}
return publish(name, s.c_str(), s.length(), ContentType::JSON_AS_CBOR, flags);
return publish_event(name, s.c_str(), s.length(), static_cast<int>(protocol::CoapContentFormat::PARTICLE_JSON_AS_CBOR),
DEFAULT_CLOUD_EVENT_TTL, flags);
}

int CloudClass::publishVitals(system_tick_t period_s_) {
Expand Down

0 comments on commit ac3ea97

Please sign in to comment.