API Support Forum
OEC API > API Support > OnDisconnectedEvent and other events are not called
Author Topic: OnDisconnectedEvent and other events are not called
(6 messages, Page 1 of 1)
Moderators: VPfau
AAnatoly
Posts: 22
Joined: Jul 01, 2010


Posted: Jul 01, 2010 @ 10:37 AM             Msg. 1 of 6
Hello!

We are using OEC.API.OECClient in C++ Windows Application (not WinForm) using managed C++.

The problem is that for some reason all callbacks are not called.
( For example, OEC::API::OnDisconnectedEvent event is never called as in simple WinForm application)

I have another .Net dll and it works properly ( events are called as expected)
There is no difference in client application, so i believe that there are special requirements
to subscribe for events of OECAPI.

What can be reason?

The WinForms C# example is working properly.
I changed applcation to contain main thread and create OECClient object in separate thread.
Still events are not fired.

Here is a pseudocode:

COECWorkingThread thread;

thread.start(); // call COECWorkingThread::svc() below
thread.connect();

class COECWorkingThread : public ACE_Task<ACE_MT_SYNCH>
{
public:
COECWorkingThread();
virtual ~COECWorkingThread();

virtual int svc();

virtual void start();
virtual void stop();

void connect();
};

COECWorkingThread::connect()
{
this->_moAPI = gcnew OEC::API::OECClient();

this->_moAPI->OnLoginFailed += gcnew OEC::API::OnLoginFailedEvent(this, &OECAPI::moAPI_OnLoginFailed);

this->_moAPI->OnError += gcnew OEC::API::OnErrorEvent(this, &OECAPI::moAPI_OnError);

this->_moAPI->OnDisconnected += gcnew OEC::API::OnDisconnectedEvent(this, &OECAPI::moAPI_OnDisconnected);

this->_moAPI->OnLoginComplete += gcnew OEC::API::OnLoginCompleteEvent(this,&OECAPI::moAPI_OnLoginComplete);

this->_moAPI->Connect( "api.openecry.com", 9200, "test", "test", false );
}

int COECWorkingThread::svc()
{
MSG msg;
BOOL bRet;

while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return 0;
}



public ref class OECAPI
{
private:
OECAPI();
public:
static OECAPI^ instance()
{
if(_instance == nullptr)
_instance = gcnew OECAPI();
return _instance;
}

// destructor
~OECAPI();
long connect()
public:

void moAPI_OnLoginFailed(OEC::Data::FailReason Reason ){};
void moAPI_OnDisconnected( bool Unexpected ) {};
void moAPI_OnError(System::Exception^ ex ) {};
void moAPI_OnLoginComplete();

private:
static OECAPI^ _instance = nullptr;
OEC::API::OECClient^ _moAPI; //
};


Thanks,
Anatoly

Edited by AAnatoly on Jul 2, 2010 at 01:46:36
AAnatoly
Posts: 22
Joined: Jul 01, 2010


Posted: Jul 01, 2010 @ 04:00 PM             Msg. 2 of 6
I created my own thread for OECClient, and have message loop in it. Like below.
But still callbacks are not called (At least OnDisconnected must be called! like in C#WinForms application)

What can be done?

int COECWorkingThread::svc()
{
MSG msg;
BOOL bRet;

while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return 0;
}


Anatoly Gutnick
Edited by AAnatoly on Jul 1, 2010 at 16:22:20
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jul 02, 2010 @ 08:15 AM             Msg. 3 of 6
Hello, I'm not familiar with ACE_Task, but OECAPI instance should be created and connected in the same thread that has message loop.

Victor Vins
Software Developer
AAnatoly
Posts: 22
Joined: Jul 01, 2010


Posted: Jul 03, 2010 @ 06:05 AM             Msg. 4 of 6
Thanks.

I checked that OECAPI instance craeted and connected in the same thread as message loop.

But still events are not fired.

What esle can be cheked in our application?
OECClient wtire some logs to trace issues?

(But the way, why you required from client to have message loop and thread limitation.
Why standard .Net delagate/event mehanism can be used to implement callbacks without limitation to client)



Anatoly Gutnick

Edited by AAnatoly on Jul 3, 2010 at 09:43:55
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Jul 06, 2010 @ 08:43 AM             Msg. 5 of 6
Will thread.start() start another thread?

Victor Vins
Software Developer
AAnatoly
Posts: 22
Joined: Jul 01, 2010


Posted: Jul 06, 2010 @ 10:00 AM             Msg. 6 of 6
It was some ACE Thread related issue.
It is resolved.


Thanks.
Anatoly

Anatoly Gutnick