Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
api: Move event id generation to protocol manager
Browse files Browse the repository at this point in the history
  • Loading branch information
flynd committed Jul 17, 2012
1 parent 696d426 commit 4b66a32
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 51 deletions.
6 changes: 6 additions & 0 deletions licq/include/licq/protocolmanager.h
Expand Up @@ -39,6 +39,12 @@ class ProtocolManager : private boost::noncopyable
public:
static const char* const KeepAutoResponse;

/**
* Get next available id to use for an event
* For use by protocols only
*/
virtual unsigned long getNextEventId() = 0;

/**
* Update user alias on server contact list
* Alias is taken from local contact list
Expand Down
13 changes: 0 additions & 13 deletions licq/src/daemon.cpp
Expand Up @@ -42,7 +42,6 @@
#include <licq/proxy.h>
#include <licq/socket.h>
#include <licq/statistics.h>
#include <licq/thread/mutexlocker.h>
#include <licq/translator.h>
#include <licq/userevents.h>

Expand Down Expand Up @@ -164,9 +163,6 @@ void Daemon::initialize()

// start GPG helper
LicqDaemon::gGpgHelper.Start();

// Init event id counter
myNextEventId = 1;
}

const char* Daemon::Version() const
Expand Down Expand Up @@ -323,15 +319,6 @@ Licq::Proxy* Licq::Daemon::createProxy()
return Proxy;
}

unsigned long Daemon::getNextEventId()
{
Licq::MutexLocker eventIdGuard(myNextEventIdMutex);
unsigned long eventId = myNextEventId;
if (++myNextEventId == 0)
++myNextEventId;
return eventId;
}

bool Daemon::addUserEvent(Licq::User* u, Licq::UserEvent* e)
{
int filteraction = gFilterManager.filterEvent(u, e);
Expand Down
8 changes: 0 additions & 8 deletions licq/src/daemon.h
Expand Up @@ -46,12 +46,6 @@ class Daemon : public Licq::Daemon
*/
void initialize();

/**
* Get next available id to use for an event
* TODO: Move to ProtocolManager when no longer used directy by ICQ code
*/
unsigned long getNextEventId();

/**
* Set dir variable
* Only called once during startup
Expand Down Expand Up @@ -90,8 +84,6 @@ class Daemon : public Licq::Daemon
void rejectEvent(const Licq::UserId& userId, Licq::UserEvent* e);

private:
unsigned long myNextEventId;
Licq::Mutex myNextEventIdMutex;
std::string myRejectFile;
unsigned myErrorTypes;
std::string myErrorFile;
Expand Down
9 changes: 5 additions & 4 deletions licq/src/icq/icq-srv.cpp
Expand Up @@ -38,20 +38,21 @@
#include <licq/byteorder.h>
#include <licq/contactlist/group.h>
#include <licq/contactlist/usermanager.h>
#include <licq/daemon.h>
#include <licq/event.h>
#include <licq/icq/chat.h>
#include <licq/icq/filetransfer.h>
#include <licq/oneventmanager.h>
#include <licq/plugin/pluginmanager.h>
#include <licq/pluginsignal.h>
#include <licq/protocolmanager.h>
#include <licq/proxy.h>
#include <licq/statistics.h>
#include <licq/translator.h>
#include <licq/userevents.h>
#include <licq/logging/log.h>
#include <licq/version.h>

#include "../daemon.h"
#include "../gettext.h"
#include "oscarservice.h"
#include "owner.h"
Expand All @@ -61,15 +62,15 @@

using namespace std;
using namespace LicqIcq;
using Licq::Daemon;
using Licq::Log;
using Licq::OnEventData;
using Licq::StringList;
using Licq::gDaemon;
using Licq::gLog;
using Licq::gPluginManager;
using Licq::gOnEventManager;
using Licq::gTranslator;
using LicqDaemon::Daemon;
using LicqDaemon::gDaemon;

//-----icqAddUser----------------------------------------------------------
void IcqProtocol::icqAddUser(const Licq::UserId& userId, bool _bAuthRequired)
Expand Down Expand Up @@ -1532,7 +1533,7 @@ void IcqProtocol::icqLogoff()
if (nSD != -1)
{
CPU_Logoff p;
unsigned long eventId = gDaemon.getNextEventId();
unsigned long eventId = Licq::gProtocolManager.getNextEventId();
cancelledEvent = new Licq::Event(eventId, nSD, &p, Licq::Event::ConnectServer);
cancelledEvent->m_pPacket = NULL;
cancelledEvent->m_bCancelled = true;
Expand Down
11 changes: 6 additions & 5 deletions licq/src/icq/icq-tcp.cpp
Expand Up @@ -35,21 +35,22 @@

#include <licq/byteorder.h>
#include <licq/contactlist/usermanager.h>
#include <licq/daemon.h>
#include <licq/event.h>
#include <licq/gpghelper.h>
#include <licq/icq/chat.h>
#include <licq/icq/filetransfer.h>
#include <licq/oneventmanager.h>
#include <licq/plugin/pluginmanager.h>
#include <licq/pluginsignal.h>
#include <licq/protocolmanager.h>
#include <licq/protocolsignal.h>
#include <licq/statistics.h>
#include <licq/translator.h>
#include <licq/userevents.h>
#include <licq/logging/log.h>
#include <licq/version.h>

#include "../daemon.h"
#include "../gettext.h"
#include "oscarservice.h"
#include "owner.h"
Expand All @@ -60,14 +61,14 @@

using namespace std;
using namespace LicqIcq;
using Licq::Daemon;
using Licq::Log;
using Licq::OnEventData;
using Licq::StringList;
using Licq::gDaemon;
using Licq::gLog;
using Licq::gOnEventManager;
using Licq::gTranslator;
using LicqDaemon::Daemon;
using LicqDaemon::gDaemon;


void IcqProtocol::icqSendMessage(unsigned long eventId, const Licq::UserId& userId, const string& message,
Expand Down Expand Up @@ -168,7 +169,7 @@ void IcqProtocol::icqSendMessage(unsigned long eventId, const Licq::UserId& user

unsigned long IcqProtocol::icqFetchAutoResponse(const Licq::UserId& userId, bool bServer)
{
unsigned long eventId = gDaemon.getNextEventId();
unsigned long eventId = Licq::gProtocolManager.getNextEventId();
if (Licq::gUserManager.isOwner(userId))
return 0;

Expand Down Expand Up @@ -358,7 +359,7 @@ void IcqProtocol::icqFileTransfer(unsigned long eventId, const Licq::UserId& use
unsigned long IcqProtocol::icqSendContactList(const Licq::UserId& userId,
const StringList& users, unsigned flags, const Licq::Color* pColor)
{
unsigned long eventId = gDaemon.getNextEventId();
unsigned long eventId = Licq::gProtocolManager.getNextEventId();
if (Licq::gUserManager.isOwner(userId))
return 0;

Expand Down
17 changes: 9 additions & 8 deletions licq/src/icq/icq.cpp
Expand Up @@ -31,19 +31,20 @@

#include <licq/contactlist/group.h>
#include <licq/contactlist/usermanager.h>
#include <licq/daemon.h>
#include <licq/event.h>
#include <licq/inifile.h>
#include <licq/logging/log.h>
#include <licq/statistics.h>
#include <licq/oneventmanager.h>
#include <licq/plugin/pluginmanager.h>
#include <licq/pluginsignal.h>
#include <licq/protocolmanager.h>
#include <licq/proxy.h>
#include <licq/translator.h>
#include <licq/userevents.h>
#include <licq/utility.h>

#include "../daemon.h"
#include "../gettext.h"
#include "defines.h"
#include "oscarservice.h"
Expand All @@ -55,14 +56,14 @@

using namespace std;
using namespace LicqIcq;
using Licq::Daemon;
using Licq::Log;
using Licq::OnEventData;
using Licq::gDaemon;
using Licq::gLog;
using Licq::gOnEventManager;
using Licq::gPluginManager;
using Licq::gTranslator;
using LicqDaemon::Daemon;
using LicqDaemon::gDaemon;


// list of plugins we currently support
Expand Down Expand Up @@ -319,7 +320,7 @@ void IcqProtocol::SendEvent_Server(CPacket *packet, unsigned long eventId)
{
#if 1
if (eventId == 0)
eventId = gDaemon.getNextEventId();
eventId = Licq::gProtocolManager.getNextEventId();
Licq::Event* e = new Licq::Event(eventId, m_nTCPSrvSocketDesc, packet, Licq::Event::ConnectServer);
e->myCommand = eventCommandFromPacket(packet);

Expand Down Expand Up @@ -352,7 +353,7 @@ Licq::Event* IcqProtocol::SendExpectEvent_Server(unsigned long eventId, const Li
}

if (eventId == 0)
eventId = gDaemon.getNextEventId();
eventId = Licq::gProtocolManager.getNextEventId();

Licq::Event* e = new Licq::Event(eventId, m_nTCPSrvSocketDesc, packet, Licq::Event::ConnectServer, userId, ue);
e->myCommand = eventCommandFromPacket(packet);
Expand Down Expand Up @@ -1665,17 +1666,17 @@ bool IcqProtocol::waitForReverseConnection(unsigned short id, const Licq::UserId

Licq::Event* IcqProtocol::SendExpectEvent_Server(const Licq::UserId& userId, CSrvPacketTcp* packet, Licq::UserEvent* ue, bool extendedEvent)
{
return SendExpectEvent_Server(gDaemon.getNextEventId(), userId, packet, ue, extendedEvent);
return SendExpectEvent_Server(Licq::gProtocolManager.getNextEventId(), userId, packet, ue, extendedEvent);
}

Licq::Event* IcqProtocol::SendExpectEvent_Server(CSrvPacketTcp* packet, Licq::UserEvent* ue, bool extendedEvent)
{
return SendExpectEvent_Server(gDaemon.getNextEventId(), Licq::UserId(), packet, ue, extendedEvent);
return SendExpectEvent_Server(Licq::gProtocolManager.getNextEventId(), Licq::UserId(), packet, ue, extendedEvent);
}

Licq::Event* IcqProtocol::SendExpectEvent_Client(const Licq::User* user, CPacketTcp* packet, Licq::UserEvent* ue)
{
return SendExpectEvent_Client(gDaemon.getNextEventId(), user, packet, ue);
return SendExpectEvent_Client(Licq::gProtocolManager.getNextEventId(), user, packet, ue);
}

string CICQDaemon::getXmlTag(const string& xmlSource, const string& tagName)
Expand Down
4 changes: 2 additions & 2 deletions licq/src/icq/oscarservice.cpp
Expand Up @@ -31,13 +31,13 @@
#include <licq/buffer.h>
#include <licq/contactlist/usermanager.h>
#include <licq/byteorder.h>
#include <licq/daemon.h>
#include <licq/event.h>
#include <licq/plugin/pluginmanager.h>
#include <licq/pluginsignal.h>
#include <licq/proxy.h>
#include <licq/logging/log.h>

#include "../daemon.h"
#include "../gettext.h"
#include "icq.h"
#include "packet-srv.h"
Expand All @@ -47,7 +47,7 @@
using namespace std;
using namespace LicqIcq;
using Licq::gLog;
using LicqDaemon::gDaemon;
using Licq::gDaemon;

COscarService::COscarService(unsigned short Fam)
{
Expand Down
5 changes: 2 additions & 3 deletions licq/src/icq/threads.cpp
Expand Up @@ -29,9 +29,9 @@
#include <licq/event.h>
#include <licq/plugin/pluginmanager.h>
#include <licq/pluginsignal.h>
#include <licq/protocolmanager.h>
#include <licq/logging/log.h>

#include "../daemon.h"
#include "../gettext.h"
#include "buffer.h"
#include "defines.h"
Expand All @@ -58,7 +58,6 @@ void* UpdateUsers_tep(void* p);

using namespace std;
using namespace LicqIcq;
using LicqDaemon::gDaemon;
using Licq::gLog;

void cleanup_mutex(void *m)
Expand Down Expand Up @@ -969,7 +968,7 @@ void* LicqIcq::UpdateUsers_tep(void* /* p */)
if (useBart && autoInfo && pUser->buddyIconHash().size() > 0 &&
pUser->buddyIconHash() != pUser->ourBuddyIconHash())
{
unsigned long eventId = gDaemon.getNextEventId();
unsigned long eventId = Licq::gProtocolManager.getNextEventId();
gIcqProtocol.m_xBARTService->SendEvent(eventId, pUser->id(), ICQ_SNACxBART_DOWNLOADxREQUEST, true);
bSent = true;
bBART = true;
Expand Down
11 changes: 8 additions & 3 deletions licq/src/protocolmanager.cpp
Expand Up @@ -26,6 +26,7 @@
#include <licq/plugin/pluginmanager.h>
#include <licq/pluginsignal.h>
#include <licq/protocolsignal.h>
#include <licq/thread/mutexlocker.h>
#include <licq/userid.h>

#include "contactlist/user.h"
Expand Down Expand Up @@ -58,6 +59,7 @@ const char* const Licq::ProtocolManager::KeepAutoResponse = "__unset__";


ProtocolManager::ProtocolManager()
: myNextEventId(1)
{
// Empty
}
Expand All @@ -67,10 +69,13 @@ ProtocolManager::~ProtocolManager()
// Empty
}

inline unsigned long ProtocolManager::getNextEventId()
unsigned long ProtocolManager::getNextEventId()
{
// Event id generation is still owned by daemon as it's used directly by some ICQ functions
return gDaemon.getNextEventId();
Licq::MutexLocker eventIdGuard(myNextEventIdMutex);
unsigned long eventId = myNextEventId;
if (++myNextEventId == 0)
++myNextEventId;
return eventId;
}

bool ProtocolManager::isProtocolConnected(const UserId& userId)
Expand Down
11 changes: 6 additions & 5 deletions licq/src/protocolmanager.h
Expand Up @@ -22,6 +22,8 @@

#include <licq/protocolmanager.h>

#include <licq/thread/mutex.h>

namespace Licq
{
class ProtocolSignal;
Expand Down Expand Up @@ -55,6 +57,7 @@ class ProtocolManager : public Licq::ProtocolManager
void removeUser(const Licq::UserId& userId);

// From Licq::ProtocolManager
unsigned long getNextEventId();
void updateUserAlias(const Licq::UserId& userId);
unsigned long setStatus(const Licq::UserId& ownerId,
unsigned newStatus, const std::string& message = KeepAutoResponse);
Expand Down Expand Up @@ -87,17 +90,15 @@ class ProtocolManager : public Licq::ProtocolManager
void ignoreListSet(const Licq::UserId& userId, bool ignore);

private:
/**
* Get next available id to use for an event
*/
unsigned long getNextEventId();

/**
* @return true if the protocol is connected
*/
bool isProtocolConnected(const Licq::UserId& userId);

void pushProtoSignal(Licq::ProtocolSignal* s, const Licq::UserId& userId);

unsigned long myNextEventId;
Licq::Mutex myNextEventIdMutex;
};

extern ProtocolManager gProtocolManager;
Expand Down

0 comments on commit 4b66a32

Please sign in to comment.