Skip to content

Commit eb23524

Browse files
committed
Access class fields and methods through this
1 parent b32f8b4 commit eb23524

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

pctest/test_publish_websocket.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -101,41 +101,41 @@ class pythd_websocket
101101

102102
pythd_websocket::pythd_websocket( QObject* parent, std::string pythd_websocket_endpoint )
103103
{
104-
pythd_websocket_endpoint_ = pythd_websocket_endpoint;
105-
rpc_client_ = new jcon::JsonRpcWebSocketClient(parent);
104+
this->pythd_websocket_endpoint_ = pythd_websocket_endpoint;
105+
this->rpc_client_ = new jcon::JsonRpcWebSocketClient(parent);
106106

107107
// Set up the handler for notify_price_sched
108-
rpc_client_->enableReceiveNotification(true);
108+
this->rpc_client_->enableReceiveNotification(true);
109109
QObject::connect(rpc_client_, &jcon::JsonRpcClient::notificationReceived, parent, [this](const QString& key, const QVariant& value){
110110
if (key == "notify_price_sched") {
111-
on_notify_price_sched( value.toMap()["subscription"].toInt() );
111+
this->on_notify_price_sched( value.toMap()["subscription"].toInt() );
112112
}
113113
});
114114

115115
// Continually check the connection and reconnect if dropped
116116
QTimer *timer = new QTimer( parent );
117117
QObject::connect(timer, &QTimer::timeout, parent, [this](){
118-
if ( !rpc_client_->isConnected() ) {
118+
if ( !this->rpc_client_->isConnected() ) {
119119
// Reset the subscription state
120-
subscription_to_account_.clear();
121-
account_to_subscription_.clear();
120+
this->subscription_to_account_.clear();
121+
this->account_to_subscription_.clear();
122122

123123
// Reconnect
124-
connect();
125-
get_product_list_and_subscribe();
124+
this->connect();
125+
this->get_product_list_and_subscribe();
126126
}
127127
});
128128
timer->start(1000);
129129
}
130130

131131
void pythd_websocket::connect()
132132
{
133-
rpc_client_->connectToServer(QUrl(QString::fromStdString(pythd_websocket_endpoint_)));
133+
this->rpc_client_->connectToServer(QUrl(QString::fromStdString(pythd_websocket_endpoint_)));
134134
}
135135

136136
void pythd_websocket::get_product_list_and_subscribe( )
137137
{
138-
auto req = rpc_client_->callAsync("get_product_list");
138+
auto req = this->rpc_client_->callAsync("get_product_list");
139139

140140
req->connect(req.get(), &jcon::JsonRpcRequest::result, [this](const QVariant& result){
141141
// Loop over all the products
@@ -150,13 +150,13 @@ void pythd_websocket::get_product_list_and_subscribe( )
150150
symbol_t symbol = attr_dict["symbol"].toString().toStdString();
151151

152152
// If this is a new symbol, associate the symbol with the account
153-
if (symbol_to_account_.find(account) == symbol_to_account_.end() || symbol_to_account_[symbol] != account) {
154-
symbol_to_account_[symbol] = account;
153+
if (this->symbol_to_account_.find(account) == this->symbol_to_account_.end() || this->symbol_to_account_[symbol] != account) {
154+
this->symbol_to_account_[symbol] = account;
155155
}
156156

157157
// If we don't already have a subscription for this account, subscribe to it
158158
if (account_to_subscription_.find(account) == account_to_subscription_.end()) {
159-
subscribe_price_sched(account);
159+
this->subscribe_price_sched(account);
160160
}
161161
}
162162
});
@@ -168,7 +168,7 @@ void pythd_websocket::get_product_list_and_subscribe( )
168168

169169
void pythd_websocket::subscribe_price_sched( account_pubkey_t account )
170170
{
171-
auto req = rpc_client_->callAsyncNamedParams("subscribe_price_sched",
171+
auto req = this->rpc_client_->callAsyncNamedParams("subscribe_price_sched",
172172
QVariantMap{
173173
{"account", QString::fromStdString(account)},
174174
});
@@ -187,7 +187,7 @@ void pythd_websocket::subscribe_price_sched( account_pubkey_t account )
187187

188188
void pythd_websocket::update_price( account_pubkey_t account, int price, uint conf, status_t status )
189189
{
190-
auto req = rpc_client_->callAsyncNamedParams("update_price",
190+
auto req = this->rpc_client_->callAsyncNamedParams("update_price",
191191
QVariantMap{
192192
{"account", QString::fromStdString(account)},
193193
{"price", price},
@@ -203,17 +203,17 @@ void pythd_websocket::update_price( account_pubkey_t account, int price, uint co
203203
void pythd_websocket::on_notify_price_sched( subscription_id_t subscription_id )
204204
{
205205
// Fetch the account associated with the subscription
206-
if (subscription_to_account_.find(subscription_id) == subscription_to_account_.end()) {
206+
if (this->subscription_to_account_.find(subscription_id) == this->subscription_to_account_.end()) {
207207
return;
208208
}
209209
account_pubkey_t account = subscription_to_account_[subscription_id];
210210

211211
// Fetch any price update we have for this account
212-
if (pending_updates_.find(account) == pending_updates_.end()) {
212+
if (this->pending_updates_.find(account) == this->pending_updates_.end()) {
213213
return;
214214
}
215215
update_t update = pending_updates_[account];
216-
pending_updates_.erase(account);
216+
this->pending_updates_.erase(account);
217217

218218
// Check that the update is not stale
219219
if ( (std::time(nullptr) - update.timestamp) > update_staleness_threshold_secs_) {
@@ -225,7 +225,7 @@ void pythd_websocket::on_notify_price_sched( subscription_id_t subscription_id )
225225
}
226226

227227
void pythd_websocket::add_price_update( symbol_t symbol, int64_t price, uint64_t conf, status_t status ) {
228-
if (symbol_to_account_.find(symbol) == symbol_to_account_.end()) {
228+
if (this->symbol_to_account_.find(symbol) == this->symbol_to_account_.end()) {
229229
return;
230230
}
231231
account_pubkey_t account = symbol_to_account_[symbol];
@@ -260,12 +260,12 @@ test_publish::test_publish(
260260
std::string pythd_websocket_endpoint )
261261
{
262262
pythd_websocket_ = new pythd_websocket( parent, pythd_websocket_endpoint );
263-
symbols_to_publish_.insert(symbols_to_publish_.end(), symbols_to_publish.begin(), symbols_to_publish.end());
263+
this->symbols_to_publish_.insert(this->symbols_to_publish_.end(), symbols_to_publish.begin(), symbols_to_publish.end());
264264

265265
// Continually generate new values for the symbols
266266
QTimer *timer = new QTimer( parent );
267267
QObject::connect(timer, &QTimer::timeout, parent, [this](){
268-
update_symbols();
268+
this->update_symbols();
269269
});
270270
timer->start(1000);
271271
}
@@ -277,8 +277,8 @@ void test_publish::update_symbols() {
277277
int64_t next_price = std::rand();
278278
uint64_t next_conf = (uint64_t) std::rand();
279279

280-
pythd_websocket_->add_price_update(
281-
symbols_to_publish_[i], next_price, next_conf, "trading" );
280+
this->pythd_websocket_->add_price_update(
281+
this->symbols_to_publish_[i], next_price, next_conf, "trading" );
282282
}
283283

284284
}

0 commit comments

Comments
 (0)