This is the Pubnub library for MBed2 ("classic") with the "sync" interface. It is based on the Pubnub C-core library.
Dependencies: Pubnub_c_core_mbed2_pal
Dependents: Pubnub_ATT_IoT_SK_WNC_sync pubnub_sync
srand_from_pubnub_time.cpp
00001 #include "srand_from_pubnub_time.h" 00002 00003 #include "pubnub_coreapi.h" 00004 #include "pubnub_ntf_sync.h" 00005 00006 #include <stdlib.h> 00007 #include <string.h> 00008 00009 00010 int srand_from_pubnub_time(pubnub_t *pbp) 00011 { 00012 pubnub_res rslt = pubnub_time(pbp); 00013 if (rslt != PNR_STARTED) { 00014 return -1; 00015 } 00016 rslt = pubnub_await(pbp); 00017 if (rslt != PNR_OK) { 00018 return -1; 00019 } 00020 char const* pbtime = pubnub_get(pbp); 00021 if (0 == pbtime) { 00022 return -1; 00023 } 00024 size_t length_of_time = strlen(pbtime); 00025 if (0 == length_of_time) { 00026 return -1; 00027 } 00028 char const *s = pbtime + length_of_time - 1; 00029 unsigned int val_for_srand = 0; 00030 for (int i = 0; (i < 10) && (s > pbtime); ++i, --s) { 00031 val_for_srand = val_for_srand * 10 + *s - '0'; 00032 } 00033 00034 srand(val_for_srand); 00035 00036 return 0; 00037 }
Generated on Thu Jul 28 2022 01:33:33 by 1.7.2