publish final code

Dependencies:   Pubnub_c_core_mbed2_pal2

Fork of Pubnub_mbed2_sync by Srdjan Veljkovic

Files at this revision

API Documentation at this revision

Comitter:
sveljko
Date:
Thu Nov 10 22:25:17 2016 +0000
Child:
1:9fbec3606b08
Commit message:
Initial commit of the Pubnub library for MBed2 with the "sync" interface.

Changed in this revision

pubnub_ntf_sync.cpp Show annotated file Show diff for this revision Revisions of this file
pubnub_ntf_sync.h Show annotated file Show diff for this revision Revisions of this file
pubnub_sync.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_ntf_sync.cpp	Thu Nov 10 22:25:17 2016 +0000
@@ -0,0 +1,106 @@
+/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
+#include "pubnub_ntf_sync.h"
+
+#include "pbpal.h"
+#include "pubnub_internal.h"
+#include "pubnub_assert.h"
+#include "pubnub_log.h"
+
+#include "pbntf_trans_outcome_common.h"
+
+
+int pbntf_init(void)
+{
+    return 0;
+}
+
+
+int pbntf_got_socket(pubnub_t *pb, pb_socket_t socket)
+{
+    PUBNUB_UNUSED(socket);
+    if (PUBNUB_BLOCKING_IO_SETTABLE) {
+        pbpal_set_blocking_io(pb);
+    }
+    return +1;
+}
+
+
+void pbntf_update_socket(pubnub_t *pb, pb_socket_t socket)
+{
+    PUBNUB_UNUSED(socket);
+    PUBNUB_UNUSED(pb);
+}
+
+
+void pbntf_lost_socket(pubnub_t *pb, pb_socket_t socket)
+{
+    PUBNUB_UNUSED(socket);
+    PUBNUB_UNUSED(pb);
+}
+
+
+void pbntf_trans_outcome(pubnub_t *pb)
+{
+    PBNTF_TRANS_OUTCOME_COMMON(pb);
+}
+
+
+int pbntf_enqueue_for_processing(pubnub_t *pb)
+{
+    PUBNUB_UNUSED(pb);
+    return 0;
+}
+
+
+int pbntf_requeue_for_processing(pubnub_t *pb)
+{
+    PUBNUB_UNUSED(pb);
+    
+    return 0;
+}
+
+
+int pbntf_watch_in_events(pubnub_t *pbp)
+{
+    PUBNUB_UNUSED(pbp);
+    return 0;
+}
+
+
+int pbntf_watch_out_events(pubnub_t *pbp)
+{
+    PUBNUB_UNUSED(pbp);
+    return 0;
+}
+
+
+enum pubnub_res pubnub_last_result(pubnub_t *pb)
+{
+    enum pubnub_res result;
+    PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
+
+    pubnub_mutex_lock(pb->monitor);
+    if (pb->state != PBS_IDLE) {
+        pbnc_fsm((pubnub_t*)pb);
+    }
+    result = pb->core.last_result;
+    pubnub_mutex_unlock(pb->monitor);
+
+    return result;
+}
+
+
+enum pubnub_res pubnub_await(pubnub_t *pb)
+{
+    enum pubnub_res result;
+    PUBNUB_ASSERT(pb_valid_ctx_ptr(pb));
+
+    pubnub_mutex_lock(pb->monitor);
+    while (pb->state != PBS_IDLE) {
+        pbnc_fsm(pb);
+    }
+    result = pb->core.last_result;
+    pubnub_mutex_unlock(pb->monitor);
+
+    return result;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pubnub_ntf_sync.h	Thu Nov 10 22:25:17 2016 +0000
@@ -0,0 +1,39 @@
+/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
+#if !defined INC_PUBNUB_NTF_SYNC
+#define	INC_PUBNUB_NTF_SYNC
+
+
+#include "pubnub_api_types.h"
+
+
+/** @file pubnub_ntf_sync.h 
+    This is the "sync" notification interface.
+
+    Pubnub client library offers two "mostly portable" interfaces for
+    getting notification about the outcome of a Pubnub transaction.
+    Those are:
+    - sync (this one)
+    - callback
+
+    There are others, which are specific to a platform (like process
+    events for Contiki OS). Also, not all platforms support the
+    two "mostly portable" interfaces mentioned above.
+
+    Sync interfaces is the simplest. You just check for the (last)
+    result of a context (by using pubnub_last_result()) and when it
+    becomes something other than #PNR_STARTED, you have your
+    outcome. 
+
+    Since pubnub_last_result() is part of the "Core API", this
+    interface only provides one additional, helper function, which
+    will wait in a loop for the transaction to finish.  While
+    pubnub_last_result() is available in all Pubnub client libraries,
+    pubnub_await() is not.
+*/
+
+
+/** Waits, in a loop, for the current transaction to finish. */
+enum pubnub_res pubnub_await(pubnub_t *p);
+
+
+#endif        /* defined INC_PUBNUB_NTF_CONTIKI */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pubnub_sync.h	Thu Nov 10 22:25:17 2016 +0000
@@ -0,0 +1,38 @@
+/* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */
+#if !defined INC_PUBNUB_MBED_SYNC
+#define	INC_PUBNUB_MBED_SYNC
+
+/** @mainpage The MBed Pubnub client library - sync interface
+
+    This is the "sync" interface of the Pubnub client library for
+    MBed. 
+
+    The "sync" interface has these characteristics:
+    - There is no "callback" on the end of a transaction. Instead,
+    you should check (via pubnub_last_result()) to see if the 
+    transaction completed, or if you don't need to do anything
+    else on the thread until the transaction is completed (including
+    possible thread shutdown), you can call pubnub_await() which
+    will do it for you (and return the final result).
+
+    You can have multiple pubnub contexts established; in each
+    context, at most one Pubnub API call/transaction may be ongoing
+    (typically a "publish" or a "subscribe").
+    
+ */
+
+/** @file pubnub_sync.h */
+
+#include "pubnub_config.h"
+
+/* -- You should not change anything below this line -- */
+
+#include "pubnub_alloc.h"
+#include "pubnub_assert.h"
+#include "pubnub_coreapi.h"
+#include "pubnub_ntf_sync.h"
+//#include "pubnub_generate_uuid.h"
+#include "pubnub_blocking_io.h"
+
+
+#endif /* !defined INC_PUBNUB_MBED_SYNC */