I've got the following code, trying to access functions that go beyond my base class..
When I do the compiler states it doesn't see my derived class functions such as my public member TestCPPClient
nor querySymbols
function.. leading me to believe it can only see the Super class.. is my factory not setup correctly?
cpool::ConnectionPool::ConnectionProxy proxy_conn = this->tma_conn_pool->get_connection();
TMAConnection* x = dynamic_cast<TMAConnection&>(*proxy_conn);
x->is_healthy();
x->querySymbols(empty_contract_vect, queries_list);
/home/server.cpp:48:24: error: cannot convert ‘TWSConnection’ to ‘TWSConnection*’ in initialization
48 | TWSConnection* x = dynamic_cast<TWSConnection&>(*proxy_conn);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| TWSConnection
#pragma once
#ifndef TMAConnection_H
#define TMAConnection_H
#include "TMAConnection.h"
#include <connection-pool/pool.h>
#include "tma-client/TestCppClient.h"
class TMAConnection final : public cpool::Connection {
public:
TMAConnection(const char* hostname, const int port){
this->gateway_host=hostname;
this->gateway_port=port;
}
bool heart_beat() override { return connected; }
bool is_healthy() override { return connected; }
bool connect() override {
connected = true;
return connected;
}
void disconnect() override {
connected = false;
}
// cannot call this function
void querySymbols(std::vector<tmaapithrift::ContractDescription> & empty_contract_vect, std::vector<std::string> & queries_list) {
this->tma_client.query_matching_tickers(empty_contract_vect, queries_list);
std::vector<std::string> empty_vec;
}
TestCppClient tma_client; // cannot see this
private:
TMAConnection(){ }
friend cpool::ConnectionPoolFactory<TMAConnection>;
bool connected = false;
const char* gateway_host;
int gateway_port;
uint16_t tma_client_id;
};
template <>
class cpool::ConnectionPoolFactory<TMAConnection> {
public:
static std::unique_ptr<cpool::ConnectionPool> create( const std::uint16_t num_connections, const char* tma_gw_host, const int tma_gw_port) {
std::vector< std::unique_ptr<cpool::Connection> > connections;
for ( std::uint16_t k = 0; k < num_connections; ++k ) {
// cannot use std::make_unique, because constructor is hidden
connections.emplace_back( std::unique_ptr<TMAConnection>( new TMAConnection{tma_gw_host, tma_gw_port} ) );
}
return std::unique_ptr<cpool::ConnectionPool>( new cpool::ConnectionPool{std::move( connections )} );
}
};
#endif
Main.cpp
auto tma_conn_pool = cpool::ConnectionPoolFactory<TMAConnection>::create(32, target_gateway_host, gateway_port);
I store the reference to this tma_conn_pool
throughout my server code as
cpool::ConnectionPool * const tws_conn_pool;
When I tried adding Templates to the ConnectionPool pointer i get more errors that this is not a template..
All other things with override
work as expected with my customized code from the derived class TMAConnection
.. just nothing beyond override
functions... any hints appreciated.. I am guessing I need to modify the Factory ?
Aucun commentaire:
Enregistrer un commentaire