Only a lot of debug printouts, but this version is working for SwitchKing at least
This commit is contained in:
parent
4af5c5b658
commit
0d8bf77a45
6 changed files with 58 additions and 5 deletions
|
@ -61,6 +61,8 @@ int CallbackMainDispatcher::registerCallback(CallbackStruct::CallbackType type,
|
|||
callback->id = id;
|
||||
callback->context = context;
|
||||
d->callbackList.push_back(callback);
|
||||
//logga callbackprenumeration lades till
|
||||
debuglog(id, "Callback added");
|
||||
return id;
|
||||
}
|
||||
|
||||
|
@ -69,9 +71,11 @@ int CallbackMainDispatcher::unregisterCallback(int callbackId) {
|
|||
{
|
||||
TelldusCore::MutexLocker locker(&d->mutex);
|
||||
for(CallbackList::iterator callback_it = d->callbackList.begin(); callback_it != d->callbackList.end(); ++callback_it) {
|
||||
//logga, avregistrering av callback
|
||||
if ( (*callback_it)->id != callbackId ) {
|
||||
continue;
|
||||
}
|
||||
debuglog(callbackId, "Callback unregistered");
|
||||
newEventList.splice(newEventList.begin(), d->callbackList, callback_it);
|
||||
break;
|
||||
}
|
||||
|
@ -102,9 +106,16 @@ void CallbackMainDispatcher::run(){
|
|||
if (!cbd) {
|
||||
continue;
|
||||
}
|
||||
//logga här, att den fortfarande körs, ev till fil bara för att det kan bli så mkt...
|
||||
//om för mkt, kolla att viss tid gått sedan förra ggn eller ngt...
|
||||
debuglog(333, "Callbackevent, signalled");
|
||||
TelldusCore::MutexLocker locker(&d->mutex);
|
||||
//logga, har låst
|
||||
debuglog(333, "Callbackevent, locked");
|
||||
for(CallbackList::iterator callback_it = d->callbackList.begin(); callback_it != d->callbackList.end(); ++callback_it) {
|
||||
if ( (*callback_it)->type == cbd->type ) {
|
||||
//ev logga här också, att det finns ngnstans att skicka till
|
||||
debuglog((*callback_it)->id, "Callbackevent, sending");
|
||||
std::tr1::shared_ptr<TelldusCore::TDEventDispatcher> ptr(new TelldusCore::TDEventDispatcher(eventData, *callback_it, d->janitor));
|
||||
d->eventThreadList.push_back(ptr);
|
||||
}
|
||||
|
|
|
@ -73,6 +73,8 @@ std::wstring Client::getWStringFromService(const Message &msg) {
|
|||
}
|
||||
|
||||
int Client::registerEvent( CallbackStruct::CallbackType type, void *eventFunction, void *context ) {
|
||||
//LOGGA, client is registering callback
|
||||
debuglog(555, "Client, Registering callback");
|
||||
return d->callbackMainDispatcher.registerCallback(type, eventFunction, context );
|
||||
}
|
||||
|
||||
|
@ -83,6 +85,8 @@ void Client::run(){
|
|||
while(d->running){
|
||||
|
||||
if(!d->eventSocket.isConnected()){
|
||||
//LOGGA trying to (re)connect to TelldusEvents
|
||||
debuglog(555, "Client, Trying to (re)connect to TelldusEvents");
|
||||
d->eventSocket.connect(L"TelldusEvents"); //try to reconnect to service
|
||||
if(!d->eventSocket.isConnected()){
|
||||
//reconnect didn't succeed, wait a while and try again
|
||||
|
@ -186,6 +190,8 @@ void Client::stopThread(){
|
|||
}
|
||||
|
||||
int Client::unregisterCallback( int callbackId ) {
|
||||
//LOGGA, client correctly unregistering callback
|
||||
debuglog(555, "Client, correctly unregistering callback");
|
||||
return d->callbackMainDispatcher.unregisterCallback(callbackId);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "Socket.h"
|
||||
|
||||
#include "common.h"
|
||||
#include <windows.h>
|
||||
#include <AccCtrl.h>
|
||||
#include <Aclapi.h>
|
||||
|
@ -120,6 +120,9 @@ std::wstring Socket::read(int timeout){
|
|||
|
||||
if (!fSuccess) {
|
||||
DWORD err = GetLastError();
|
||||
if(err != ERROR_OPERATION_ABORTED){ //gets this "error" always when nothing was reads
|
||||
debuglog((int)err, "Socket read error");
|
||||
}
|
||||
|
||||
if(err == ERROR_MORE_DATA){
|
||||
moreData = true;
|
||||
|
@ -127,7 +130,8 @@ std::wstring Socket::read(int timeout){
|
|||
else{
|
||||
buf[0] = 0;
|
||||
}
|
||||
if (err == ERROR_BROKEN_PIPE) {
|
||||
if (err == ERROR_BROKEN_PIPE){
|
||||
debuglog(222, "Got an error, close this socket");
|
||||
d->connected = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include <string>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
inline void msleep( const int msec) {
|
||||
#ifdef _WINDOWS
|
||||
Sleep(msec);
|
||||
|
@ -40,11 +42,11 @@ inline void dlog(const char *fmt, ...) {
|
|||
fflush(stdout);
|
||||
}
|
||||
|
||||
inline void debuglog(const int intMessage, const std::string strMessage){
|
||||
inline void debuglogfilename(const int intMessage, const std::string strMessage, const std::string filename){
|
||||
#ifdef _WINDOWS
|
||||
static bool firstRun = true;
|
||||
std::ofstream file;
|
||||
std::string filename("C:/log_locks.txt");
|
||||
|
||||
if (firstRun) {
|
||||
file.open(filename.c_str(), std::ios::out);
|
||||
firstRun = false;
|
||||
|
@ -52,7 +54,14 @@ inline void debuglog(const int intMessage, const std::string strMessage){
|
|||
file.open(filename.c_str(), std::ios::out | std::ios::app);
|
||||
}
|
||||
|
||||
file << "[" << GetCurrentThreadId() << "] " << intMessage << " - " << strMessage << "\n";
|
||||
time_t now = time(0);
|
||||
|
||||
// Convert now to tm struct for local timezone
|
||||
tm* localtm = localtime(&now);
|
||||
char* thetime = asctime(localtm);
|
||||
thetime[strlen(thetime)-1] = '\0';
|
||||
|
||||
file << thetime << " [" << GetCurrentThreadId() << "] " << intMessage << " - " << strMessage << "\n";
|
||||
file.flush();
|
||||
file.close();
|
||||
|
||||
|
@ -65,6 +74,16 @@ inline void debuglog(const int intMessage, const std::string strMessage){
|
|||
#endif
|
||||
}
|
||||
|
||||
inline void debuglogservice(const int intMessage, const std::string strMessage){
|
||||
std::string filename("C:/telldus_service_debug.txt");
|
||||
debuglogfilename(intMessage, strMessage, filename);
|
||||
}
|
||||
|
||||
inline void debuglog(const int intMessage, const std::string strMessage){
|
||||
std::string filename("C:/telldus_client_debug.txt");
|
||||
debuglogfilename(intMessage, strMessage, filename);
|
||||
}
|
||||
|
||||
inline char *wrapStdString( const std::string &string) {
|
||||
#ifdef _WINDOWS
|
||||
return (char *)SysAllocStringByteLen(string.c_str(), (unsigned int)string.size());
|
||||
|
|
|
@ -5,6 +5,11 @@
|
|||
#include "Message.h"
|
||||
#include "Socket.h"
|
||||
|
||||
#include "common.h" //debug
|
||||
#include <iostream> //debug
|
||||
#include <sstream> //debug
|
||||
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
|
@ -119,8 +124,13 @@ void EventUpdateManager::sendMessageToClients(EventUpdateData *data){
|
|||
}
|
||||
else{
|
||||
//connection is dead, remove it
|
||||
debuglogservice(0, "Lost connection, removing it");
|
||||
delete *it;
|
||||
it = d->clients.erase(it);
|
||||
}
|
||||
}
|
||||
//printf("Sent message to %d connected clients", connected)
|
||||
std::stringstream strMessage;
|
||||
strMessage << "Sent message to " << connected << " clients" << std::endl;
|
||||
debuglogservice(0, strMessage.str());
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "EventUpdateManager.h"
|
||||
#include "Timer.h"
|
||||
#include "Log.h"
|
||||
#include "common.h" //debug
|
||||
|
||||
#include <stdio.h>
|
||||
#include <list>
|
||||
|
@ -57,6 +58,8 @@ void TelldusMain::suspend() {
|
|||
}
|
||||
|
||||
void TelldusMain::start(void) {
|
||||
//Logga, starta service
|
||||
debuglogservice(0, "Starting service");
|
||||
TelldusCore::EventRef clientEvent = d->eventHandler.addEvent();
|
||||
TelldusCore::EventRef dataEvent = d->eventHandler.addEvent();
|
||||
TelldusCore::EventRef janitor = d->eventHandler.addEvent(); //Used for regular cleanups
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue