The Pubnub C-core library. It's home is on https://github.com/pubnub/c_core, this is a copy
Dependents: Pubnub_c_core_mbed2_pal Pubnub_c_core_mbed2_pal Pubnub_c_core_mbed2_pal2
Revision 2:d85e42c1125d, committed 2016-11-22
- Comitter:
- sveljko
- Date:
- Tue Nov 22 22:21:39 2016 +0000
- Parent:
- 1:929314a174af
- Commit message:
- Added `pubnub_helper` module
Changed in this revision
pubnub_helper.cpp | Show annotated file Show diff for this revision Revisions of this file |
pubnub_helper.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pubnub_helper.cpp Tue Nov 22 22:21:39 2016 +0000 @@ -0,0 +1,56 @@ +/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ +#include "pubnub_helper.h" + +#include "pubnub_assert.h" + +#include <string.h> + + +enum pubnub_publish_res pubnub_parse_publish_result(char const *result) +{ + PUBNUB_ASSERT_OPT(result != NULL); + + if (strcmp(result, "\"Sent\"") == 0) { + return PNPUB_SENT; + } + if (strcmp(result, "\"Invalid JSON\"") == 0) { + return PNPUB_INVALID_JSON; + } + if (strncmp(result, "\"Invalid Character in Channel Name", 34) == 0) { + return PNPUB_INVALID_CHAR_IN_CHAN_NAME; + } + if (strncmp(result, "\"Account quota exceeded", 23) == 0) { + return PNPUB_ACCOUNT_QUOTA_EXCEEDED; + } + if (strcmp(result, "\"Message Too Large\"") == 0) { + return PNPUB_MESSAGE_TOO_LARGE; + } + return PNPUB_UNKNOWN_ERROR; +} + + +char const* pubnub_res_2_string(enum pubnub_res e) +{ + switch (e) { + case PNR_OK: return "OK"; + case PNR_ADDR_RESOLUTION_FAILED: return "Pubnub host name resolution failed"; + case PNR_CONNECT_FAILED: return "Connecting to Pubnub server failed"; + case PNR_CONNECTION_TIMEOUT: return "A time-out happened in the network"; + case PNR_TIMEOUT: return "Timeout"; + case PNR_ABORTED: return "Aborted"; + case PNR_IO_ERROR: return "I/O (communication) error"; + case PNR_HTTP_ERROR: return "HTTP error received from server"; + case PNR_FORMAT_ERROR: return "Response format error"; + case PNR_CANCELLED: return "Pubnub API transaction cancelled"; + case PNR_STARTED: return "Pubnub API transaction started"; + case PNR_IN_PROGRESS: return "Pubnub API transaction already in progress"; + case PNR_RX_BUFF_NOT_EMPTY: return "Rx buffer not empty"; + case PNR_TX_BUFF_TOO_SMALL: return "Tx buffer too small for sending/publishing the message"; + case PNR_INVALID_CHANNEL: return "Invalid channel"; + case PNR_PUBLISH_FAILED: return "Publish failed"; + case PNR_CHANNEL_REGISTRY_ERROR: return "A transaction related to channel registry failed"; + case PNR_REPLY_TOO_BIG: return "Reply from Pubnub too big to fit in buffer"; + case PNR_INTERNAL_ERROR: return "Internal error in processing"; + default: return "!?!?!"; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pubnub_helper.h Tue Nov 22 22:21:39 2016 +0000 @@ -0,0 +1,45 @@ +/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ +#if !defined INC_PUBNUB_HELPER +#define INC_PUBNUB_HELPER + + +#include "pubnub_api_types.h" + + +/** @file pubnub_helper.h + This is a set of "Helper" functions of the Pubnub client library. + You don't need this to work with Pubnub client, but they may come + in handy. +*/ + + +/** Possible (known) publish results (outcomes) in the description + received from Pubnub. + */ +enum pubnub_publish_res { + /** Publish succeeded, message sent on the channel */ + PNPUB_SENT, + /** Publish failed, the message had invalid JSON */ + PNPUB_INVALID_JSON, + /** Publish failed, the channel had an invalid character in the name */ + PNPUB_INVALID_CHAR_IN_CHAN_NAME, + /** The publishing quota for this account was exceeded */ + PNPUB_ACCOUNT_QUOTA_EXCEEDED, + /** Message is too large to be published */ + PNPUB_MESSAGE_TOO_LARGE, + /** Publish failed, but we were not able to parse the error description */ + PNPUB_UNKNOWN_ERROR, +}; + +/** Parses the given publish @p result. You usually obtain this with + pubnub_last_publish_result(). + */ +enum pubnub_publish_res pubnub_parse_publish_result(char const *result); + +/** Returns a string (in English) describing a Pubnub result enum value + @p e. + */ +char const* pubnub_res_2_string(enum pubnub_res e); + + +#endif /* defined INC_PUBNUB_HELPER */