Skip to content

Commit 1857587

Browse files
committed
PR Changes
1 parent 5a85698 commit 1857587

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

examples/example_integration.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,26 @@
22
#include <chrono>
33
#include <random>
44
#include <iostream>
5-
using namespace std;
6-
7-
85
#include "countly.hpp"
96

7+
using namespace std;
8+
109
void printLog(Countly::LogLevel level, const string& msg) {
1110
string lvl = "[DEBUG]";
1211
switch (level) {
13-
case Countly::LogLevel::DEBUG/* constant-expression */:
12+
case Countly::LogLevel::DEBUG:
1413
lvl = "[Debug]";
1514
break;
1615
case Countly::LogLevel::INFO:
1716
lvl = "[INFO]";
1817
break;
19-
case Countly::LogLevel::WARNING:
18+
case Countly::LogLevel::WARNING:
2019
lvl = "[WARNING]";
2120
break;
22-
case Countly::LogLevel::ERROR:
21+
case Countly::LogLevel::ERROR:
2322
lvl = "[ERROR]";
2423
break;
25-
case Countly::LogLevel::FATAL:
24+
case Countly::LogLevel::FATAL:
2625
lvl = "[FATAL]";
2726
break;
2827

@@ -39,7 +38,7 @@ int main() {
3938
cout<<"Sample App"<<endl;
4039
Countly& ct = Countly::getInstance();
4140
ct.alwaysUsePost(true);
42-
ct.setDeviceID("zahidzafar");
41+
ct.setDeviceID("test-device-id");
4342

4443
void (*logger_function)(Countly::LogLevel level, const std::string& message);
4544
logger_function = printLog;
@@ -48,7 +47,7 @@ int main() {
4847
ct.SetMetrics("Windows 10", "10.22", "Mac", "800x600", "Carrier", "1.0");
4948
ct.setCustomUserDetails({{"Account Type", "Basic"}, {"Employer", "Company4"}});
5049
// Server and port
51-
ct.Start("8c1d653f8f474be24958b282d5e9b4c4209ee552", "https://master.count.ly", 443);
50+
ct.Start("YOUR_APP_KEY", "https://try.count.ly", 443);
5251
ct.SetMaxEventsPerMessage(10);
5352
ct.SetMinUpdatePeriod(10);
5453
ct.setUpdateInterval(15);
@@ -60,6 +59,7 @@ int main() {
6059
cout<<"2) Event with count and sum"<<endl;
6160
cout<<"3) Event with count, sum, duration"<<endl;
6261
cout<<"4) Event with sum, count, duration and segmentation"<<endl;
62+
cout<<"5) Update Session"<<endl;
6363
cout<<"0) Exit"<<endl;
6464
int a;
6565
cin>>a;
@@ -81,17 +81,20 @@ int main() {
8181
ct.RecordEvent("Event with sum, count, duration and segmentation", segmentation, 1, 0, 10);
8282
break;
8383
}
84+
case 5:
85+
ct.updateSession();
86+
break;
8487
case 0:
8588
flag = false;
8689
break;
87-
8890
default:
8991
cout<<"Option not found!"<<endl;
9092
break;
9193
}
9294
}
9395

9496
ct.updateSession();
97+
ct.stop();
9598

9699
return 0;
97100
}

include/countly.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using json = nlohmann::json;
2121

2222
#define COUNTLY_SDK_NAME "cpp-native-unknown"
2323
#define COUNTLY_SDK_VERSION "0.1.0"
24-
#define COUNTLY_API_VERSION "19.8.0"
24+
#define COUNTLY_API_VERSION "21.11.0"
2525
#define COUNTLY_POST_THRESHOLD 2000
2626
#define COUNTLY_KEEPALIVE_INTERVAL 3000
2727
#define COUNTLY_MAX_EVENTS_DEFAULT 200

src/countly.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void Countly::setDeviceID(const std::string& value, bool same_user) {
182182

183183
void Countly::start(const std::string& app_key, const std::string& host, int port, bool start_thread) {
184184
mutex.lock();
185-
log(Countly::LogLevel::DEBUG, "[Countly][start]");
185+
log(Countly::LogLevel::INFO, "[Countly][start]");
186186
this->host = host;
187187
if (host.find("http://") == 0) {
188188
use_https = false;
@@ -370,7 +370,7 @@ void Countly::flushEvents(std::chrono::seconds timeout) {
370370

371371
bool Countly::beginSession() {
372372
mutex.lock();
373-
log(Countly::LogLevel::DEBUG, "[Countly][beginSession]");
373+
log(Countly::LogLevel::INFO, "[Countly][beginSession]");
374374
if (began_session) {
375375
mutex.unlock();
376376
return true;
@@ -410,7 +410,7 @@ bool Countly::beginSession() {
410410
}
411411

412412
bool Countly::updateSession() {
413-
log(Countly::LogLevel::DEBUG, "[Countly][updateSession]");
413+
log(Countly::LogLevel::INFO, "[Countly][updateSession]");
414414

415415
mutex.lock();
416416
if (!began_session) {
@@ -490,7 +490,8 @@ bool Countly::updateSession() {
490490
mutex.unlock();
491491
return false;
492492
}
493-
last_sent = Countly::getTimestamp();
493+
494+
last_sent += duration;
494495
}
495496

496497
mutex.unlock();
@@ -509,7 +510,7 @@ bool Countly::updateSession() {
509510
return false;
510511
}
511512

512-
last_sent = Countly::getTimestamp();
513+
last_sent += duration;
513514

514515
#ifndef COUNTLY_USE_SQLITE
515516
event_queue.clear();
@@ -534,7 +535,7 @@ bool Countly::updateSession() {
534535
}
535536

536537
bool Countly::endSession() {
537-
log(Countly::LogLevel::DEBUG, "[Countly][endSession]");
538+
log(Countly::LogLevel::INFO, "[Countly][endSession]");
538539
const std::chrono::system_clock::time_point now = Countly::getTimestamp();
539540
const auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch());
540541
const auto duration = std::chrono::duration_cast<std::chrono::seconds>(getSessionDuration(now));
@@ -631,7 +632,7 @@ static size_t countly_curl_write_callback(void *data, size_t byte_size, size_t n
631632
Countly::HTTPResponse Countly::sendHTTP(std::string path, std::string data) {
632633
bool use_post = always_use_post || (data.size() > COUNTLY_POST_THRESHOLD);
633634

634-
log(Countly::LogLevel::INFO, "[Countly][sendHTTP] data: "+ data);
635+
log(Countly::LogLevel::DEBUG, "[Countly][sendHTTP] data: "+ data);
635636
if (!salt.empty()) {
636637
unsigned char checksum[SHA256_DIGEST_LENGTH];
637638
std::string salted_data = data + salt;
@@ -768,7 +769,7 @@ log(Countly::LogLevel::INFO, "[Countly][sendHTTP] data: "+ data);
768769
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data.c_str());
769770
}
770771

771-
log(Countly::LogLevel::INFO, "[Countly][sendHTTP] request: " + full_url_stream.str());
772+
log(Countly::LogLevel::DEBUG, "[Countly][sendHTTP] request: " + full_url_stream.str());
772773

773774
std::string full_url = full_url_stream.str();
774775
curl_easy_setopt(curl, CURLOPT_URL, full_url.c_str());
@@ -790,7 +791,7 @@ log(Countly::LogLevel::INFO, "[Countly][sendHTTP] data: "+ data);
790791
curl_easy_cleanup(curl);
791792
}
792793
#endif
793-
log(Countly::LogLevel::INFO, "[Countly][sendHTTP] response: " + response.data.dump());
794+
log(Countly::LogLevel::DEBUG, "[Countly][sendHTTP] response: " + response.data.dump());
794795
return response;
795796
#endif
796797

@@ -808,7 +809,7 @@ std::chrono::system_clock::duration Countly::getSessionDuration() {
808809
}
809810

810811
void Countly::updateLoop() {
811-
log(Countly::LogLevel::INFO, "[Countly][updateLoop]");
812+
log(Countly::LogLevel::DEBUG, "[Countly][updateLoop]");
812813
mutex.lock();
813814
running = true;
814815
mutex.unlock();

0 commit comments

Comments
 (0)