Witam,
Mój problem wygląda tak:
- mam klasę, która zajmuje się rejestracją callbacków i ich obsługą.
- chcę, żeby po wywołaniu danego callbacka mieć dostęp do składowych tej klasy, więc przy rejestracji przypisuję instancję klasy do globalnej zmiennej instance
- przy jednej instancji klasy wszystko działa poprawnie, lecz jak mam dwie instancje tej klasy, to mam dostęp do zmiennych tylko z tej drugiej klasy, ponieważ to w jej instancja została ostatnio przypisana do zmiennej instance.
Mój cel jest taki, żeby każdy callback był wywoływany w kontekście swojej klasy. Jak to zrealizować z poziomu kodu, niestety callbacki nie dostają żadnych informacji w parametrach, a ja nie mogę zmienić parametrów callbacka.
Trochę kodu:
/*******************************************************************************
* Copyright © 2016 Rafał Babiarz *
* *
* This file is part of GG plugin *
* *
* GG plugin is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3, or (at your option) *
* any later version. *
* *
* GG is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with GNU Radio. If not, see <http://www.gnu.org/licenses/>. *
******************************************************************************/
#include "GaduStateChangeService.h"
#include "SDK\PluginLink.h"
#include "SDK\IconManager.h"
#include <map>
void* instance;
CGaduStateChangeService::CGaduStateChangeService(CGaduStateChange *gaduStateChange)
{
this->gaduStateChange = gaduStateChange;
this->CreateServices();
}
CGaduStateChangeService::~CGaduStateChangeService()
{
this->DestroyServices();
}
void CGaduStateChangeService::CreateServices()
{
instance = this;
this->hOnline = this->RegisterService(gaduStateChange->GetPopupServiceName("Online"), this->Online);
this->hFFC = this->RegisterService(gaduStateChange->GetPopupServiceName("FFC"), this->FFC);
this->hAway = this->RegisterService(gaduStateChange->GetPopupServiceName("Away"), this->Away);
this->hDND = this->RegisterService(gaduStateChange->GetPopupServiceName("DND"), this->DND);
this->hInvisible = this->RegisterService(gaduStateChange->GetPopupServiceName("Invisible"), this->Invisible);
this->hOffline = this->RegisterService(gaduStateChange->GetPopupServiceName("Offline"), this->Offline);
this->hChangeDesc = this->RegisterService(gaduStateChange->GetPopupServiceName("ChangeDesc"), this->ChangeDesc);
}
void CGaduStateChangeService::DestroyServices()
{
this->UnregisterService(this->hOnline);
this->UnregisterService(this->hFFC);
this->UnregisterService(this->hAway);
this->UnregisterService(this->hDND);
this->UnregisterService(this->hInvisible);
this->UnregisterService(this->hOffline);
this->UnregisterService(this->hChangeDesc);
instance = NULL;
}
HANDLE CGaduStateChangeService::RegisterService(UnicodeString name, TAQQService serviceProc)
{
return CPluginLink::instance()->getLink().CreateServiceFunction(name.c_str(), serviceProc);
}
INT_PTR CGaduStateChangeService::UnregisterService(HANDLE hService)
{
return CPluginLink::instance()->getLink().DestroyServiceFunction(hService);
}
INT_PTR CGaduStateChangeService::Online(WPARAM wParam, LPARAM lParam)
{
CGaduStateChangeService *gaduStateChangeService = (CGaduStateChangeService*)instance;
int onlineIcon = CIconManager::instance()->GetIconByName("GG_ONLINE");
gaduStateChangeService->gaduStateChange->stateButton->blinkStopIcon = onlineIcon;
gaduStateChangeService->gaduStateChange->stateButton->setIcon(onlineIcon);
}
INT_PTR CGaduStateChangeService::FFC(WPARAM wParam, LPARAM lParam)
{
CGaduStateChangeService *gaduStateChangeService = (CGaduStateChangeService*)instance;
int ffcIcon = CIconManager::instance()->GetIconByName("GG_FFC");
gaduStateChangeService->gaduStateChange->stateButton->blinkStopIcon = ffcIcon;
gaduStateChangeService->gaduStateChange->stateButton->setIcon(ffcIcon);
}
INT_PTR CGaduStateChangeService::Away(WPARAM wParam, LPARAM lParam)
{
CGaduStateChangeService *gaduStateChangeService = (CGaduStateChangeService*)instance;
int awayIcon = CIconManager::instance()->GetIconByName("GG_AWAY");
gaduStateChangeService->gaduStateChange->stateButton->blinkStopIcon = awayIcon;
gaduStateChangeService->gaduStateChange->stateButton->setIcon(awayIcon);
}
INT_PTR CGaduStateChangeService::DND(WPARAM wParam, LPARAM lParam)
{
CGaduStateChangeService *gaduStateChangeService = (CGaduStateChangeService*)instance;
int dndIcon = CIconManager::instance()->GetIconByName("GG_DND");
gaduStateChangeService->gaduStateChange->stateButton->blinkStopIcon = dndIcon;
gaduStateChangeService->gaduStateChange->stateButton->setIcon(dndIcon);
}
INT_PTR CGaduStateChangeService::Invisible(WPARAM wParam, LPARAM lParam)
{
CGaduStateChangeService *gaduStateChangeService = (CGaduStateChangeService*)instance;
int invisibleIcon = CIconManager::instance()->GetIconByName("GG_INVISIBLE");
gaduStateChangeService->gaduStateChange->stateButton->blinkStopIcon = invisibleIcon;
gaduStateChangeService->gaduStateChange->stateButton->setIcon(invisibleIcon);
}
INT_PTR CGaduStateChangeService::Offline(WPARAM wParam, LPARAM lParam)
{
CGaduStateChangeService *gaduStateChangeService = (CGaduStateChangeService*)instance;
int offlineIcon = CIconManager::instance()->GetIconByName("GG_OFFLINE");
gaduStateChangeService->gaduStateChange->stateButton->blinkStopIcon = offlineIcon;
gaduStateChangeService->gaduStateChange->stateButton->setIcon(offlineIcon);
}
INT_PTR CGaduStateChangeService::ChangeDesc(WPARAM wParam, LPARAM lParam)
{
//ShowMessage("Desc");
}