Modified the BMessageRunner to stop sending messages when it's unneeded, added connect/disconnect notifications code.

This commit is contained in:
barrett 2012-03-08 02:58:21 +00:00
parent fd546ea9ae
commit d237f75f61
2 changed files with 61 additions and 15 deletions

View File

@ -313,7 +313,8 @@ MSNP::Process(BMessage* msg)
Error("Empty Username!", NULL); Error("Empty Username!", NULL);
if (fPassword == "") if (fPassword == "")
Error("Empty Password!",NULL); Error("Empty Password!",NULL);
Progress("MSN Protocol: Login", "MSNP: Connecting...", 0.0f);
//Progress("MSN Protocol: Login", "MSNP: Connecting...", 0.0f);
MSN::Passport username; MSN::Passport username;
try { try {
username = MSN::Passport(fUsername.c_str()); username = MSN::Passport(fUsername.c_str());
@ -533,24 +534,46 @@ MSNP::Error(const char* message, const char* who)
msg.AddString("id", who); msg.AddString("id", who);
msg.AddString("error", message); msg.AddString("error", message);
fServerMsgr->SendMessage( &msg ); _SendMessage(&msg);
} }
void void
MSNP::Progress(const char* id, const char* message, float progress) MSNP::_NotifyProgress(const char* title, const char* message, float progress)
{ {
BMessage msg(IM_MESSAGE); BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_PROGRESS); msg.AddInt32("im_what", IM_PROGRESS);
msg.AddString("protocol", kProtocolSignature); msg.AddString("title", title);
msg.AddString("progressID", id);
msg.AddString("message", message); msg.AddString("message", message);
msg.AddFloat("progress", progress); msg.AddFloat("progress", progress);
msg.AddInt32("state", 11); //IM_impsConnecting ); _SendMessage(&msg);
fServerMsgr->SendMessage(&msg);
} }
void
MSNP::_Notify(notification_type type, const char* title, const char* message)
{
BMessage msg(IM_MESSAGE);
msg.AddInt32("im_what", IM_NOTIFICATION);
msg.AddInt32("type", (int32)type);
msg.AddString("title", title);
msg.AddString("message", message);
_SendMessage(&msg);
}
void
MSNP::_SendMessage(BMessage* msg)
{
// Skip invalid messages
if (!msg)
return;
msg->AddString("protocol", kProtocolSignature);
fServerMsgr->SendMessage(msg);
}
uint32 uint32
MSNP::Version() const MSNP::Version() const
{ {
@ -643,8 +666,7 @@ MSNP::AvatarQueueCheck() {
RequestBuddyIcon(item->second, item->first); RequestBuddyIcon(item->second, item->first);
fAvatarDone.AddItem(item); fAvatarDone.AddItem(item);
} else { } else {
fRunnerTime += 100000000; fAvatarRunner->SetCount(0);
fAvatarRunner->SetInterval(fRunnerTime);
} }
} }
@ -924,7 +946,12 @@ void MSNP::connectionReady(MSN::Connection * conn)
msg.AddString("protocol", kProtocolSignature); msg.AddString("protocol", kProtocolSignature);
msg.AddInt32("status", CAYA_ONLINE); msg.AddInt32("status", CAYA_ONLINE);
fServerMsgr->SendMessage(&msg); fServerMsgr->SendMessage(&msg);
Progress("MSN Protocol Login", "MSN Protocol: Logged in!", 1.00);
BString content(fUsername.c_str());
content << " has logged in!";
_Notify(B_INFORMATION_NOTIFICATION, "Connected",
content.String());
fMainConnection->setState(MSN::STATUS_AVAILABLE, fClientID); fMainConnection->setState(MSN::STATUS_AVAILABLE, fClientID);
} }
@ -1028,8 +1055,12 @@ void MSNP::buddyChangedStatus(MSN::NotificationServerConnection* conn, MSN::Pass
fAvatarDone.RemoveItemAt(i); fAvatarDone.RemoveItemAt(i);
} }
fAvatarQueue.AddItem(new pair<string, string>(buddy, msnobject)); fAvatarQueue.AddItem(new pair<string, string>(buddy, msnobject));
fRunnerTime = 40000000;
fAvatarRunner->SetInterval(fRunnerTime); bigtime_t time;
int32 count;
fAvatarRunner->GetInfo(&time, &count);
if (count == 0)
fAvatarRunner->SetCount(-1);
} else { } else {
for (uint32 i = 0; i < fAvatarDone.CountItems(); i++) { for (uint32 i = 0; i < fAvatarDone.CountItems(); i++) {
if (fAvatarDone.ItemAt(i)->first == buddy) if (fAvatarDone.ItemAt(i)->first == buddy)
@ -1223,6 +1254,15 @@ void MSNP::buddyChangedPersonalInfo(MSN::NotificationServerConnection* conn, MSN
void MSNP::closingConnection(MSN::Connection* conn) void MSNP::closingConnection(MSN::Connection* conn)
{ {
// TODO there should be a class that provide those
// strings, also in prevision of the localization support
if (conn->sock == fMainConnection->sock) {
BString content(fUsername.c_str());
content << " has logged out!";
_Notify(B_INFORMATION_NOTIFICATION, "Disconnected",
content.String());
}
printf ("MSNP::closingConnection : connection with socket %d\n", (int)conn->sock); printf ("MSNP::closingConnection : connection with socket %d\n", (int)conn->sock);
int x; int x;
int count = 0; int count = 0;

View File

@ -22,6 +22,7 @@
#include <Messenger.h> #include <Messenger.h>
#include <MessageRunner.h> #include <MessageRunner.h>
#include <Notification.h>
#include <OS.h> #include <OS.h>
#include <Path.h> #include <Path.h>
#include <String.h> #include <String.h>
@ -60,7 +61,6 @@ public:
virtual uint32 Version() const; virtual uint32 Version() const;
void Error(const char* message, const char* who); void Error(const char* message, const char* who);
void Progress(const char* id, const char* message, float progress);
void SendContactInfo(MSN::Buddy buddy); void SendContactInfo(MSN::Buddy buddy);
void MessageFromBuddy(const char* mess, const char* id); void MessageFromBuddy(const char* mess, const char* id);
@ -76,6 +76,12 @@ public:
BString FindSHA1D(string msnobject); BString FindSHA1D(string msnobject);
private: private:
void _NotifyProgress(const char* title,
const char* message, float progress);
void _Notify(notification_type type,
const char* title, const char* message);
void _SendMessage(BMessage* msg);
BPath fCachePath; BPath fCachePath;
thread_id fPollThread; thread_id fPollThread;
bool fLogged; bool fLogged;