|
From: Linus A. <lin...@sm...> - 2002-03-26 20:35:38
|
Hi,
Changes to the Protocol Add-on:
--------------
=09status_t GotMessage( const char *aId, const char *aMessage );
=09status_t SendMessage( const char *aId, const char *aMessage );
--------------
changed to:
--------------
=09status_t ReceivedEvent( BIMEvent *aEvent );
=09status_t SendEvent( BIMEvent *aEvent )=3D0;
--------------
Where BIMEvent is:
--------------
class BIMEvent: public BMessage {
=09protected:
=09=09BIMEvent( uint32 aWhat ): BMessage(aWhat) {}
=09=09~BIMEvent();
=09public:
=09=09status_t SetTo( const char *aId );
=09=09status_t SetFrom( const char *aId );
=09=09status_t To( const char **aId );
=09=09status_t From( const char **aId );
};
--------------
For example:
--------------
class BIMMessage: public BIMEvent {
=09protected:
=09=09BIMMessage( uint32 aWhat ): BEvent( aWhat ) {}
=09public:
=09=09BIMMessage():BEvent( B_IM_MESSAGE ) {}
=09=09~BIMMessage();
=09=09status_t SetMessage( const char *aMessage );
=09=09status_t Message( const char **aMessage );
};
--------------
I have also added functions for errors and info in the Protocol Add-on:
--------------
status_t ReceivedError( BIMError *aError );
status_t ReveivedInfo( BIMInfo *aInfo );
--------------
Both BIMError and BIMInfo works as BIMEvent, but perhaps BIMInfo is a
bad name because I consider it to be mostly used for logging certain events=
.
This turned out to be a pretty long mail.
Comments on the code?
Regards
/Procton
PS: Below are the complete declaration of the classes.
--------------------------------- IMProtocol.h ---------------------------
#ifndef BIMPROTOCOL_H
#define BIMPROTOCOL_H
#include <OS.h>
class BIMProtocol {
=09public:
=09=09BIMProtocol( const char *aName );
=09=09virtual ~BIMProtocol();
=09=09//void GotMessage( const char *aId, const char *aMessage );
=09=09void ReceivedEvent( BIMEvent *aEvent );
=09=09void ReceivedError( BIMError *aError );
=09=09void ReceivedInfo( BIMInfo *aInfo );
=09=09void LoggedIn();
=09=09void ContactAdded( const char *aId );
=09=09void ContactRemoved( const char *aId );
=09=09void AddReadSocket( int aSocket );
=09=09void AddWriteSocket( int aSocket );
=09=09void RemoveReadSocket( int aSocket );
=09=09void RemoveWriteSocket( int aSocket );
=09=09/* Functions that need to be implemented by derived classes. */
=09=09virtual void SetServer( const char *aHost, int32 aPort )=3D0;
=09=09virtual void SetUser( const char *aUserId,
const char *aPassword=3DNULL )=3D0;
=09=09virtual void SetPassword(const char *aPassword)=3D0;
=09=09virtual void Login()=3D0;
=09=09virtual void ReadEvent( int aSocket )=3D0;
=09=09virtual void WriteEvent( int aSocket )=3D0;
=09=09virtual void SendEvent( BIMEvent *aEvent )=3D0;
=09private:
=09=09char *fName;
};
typedef BIMProtocol *(*InstantiateProtocol)();
typedef const char *(*ShortDescr)();
typedef const char *(*LongDescr)();
/*
=09Add-on functions.
=09BIMProtocol *instantiate_protocol();
=09const char *short_description();
=09const char *long_description();
*/
#endif
---------------------------------------- IMEvent.h ------------------------
#ifndef IMEVENT_H
#define IMEVENT_H
#include <Message.h>
class BIMEvent: public BMessage {
=09protected:
=09=09BIMEvent( uint32 aWhat ): BMessage(aWhat) {}
=09=09~BIMEvent();
=09public:
=09=09status_t SetTo( const char *aId );
=09=09status_t SetFrom( const char *aId );
=09=09status_t To( const char **aId );
=09=09status_t From( const char **aId );
};
class BIMMessage: public BIMEvent {
=09protected:
=09=09BIMMessage( uint32 aWhat ): BEvent( aWhat ) {}
=09public:
=09=09BIMMessage():BEvent( B_IM_MESSAGE ) {}
=09=09~BIMMessage();
=09=09status_t SetMessage( const char *aMessage );
=09=09status_t Message( const char **aMessage );
};
class BIMUrl: public BIMMessage {
=09public:
=09=09BIMUrl(): BIMMessage( B_IM_URL ) {}
=09=09~BIMUrl();
=09=09status_t SetUrl( const char *aUrl );
=09=09status_t Url( const char **aUrl );
};
class BIMAuthRequest: public BIMEvent {
=09public:
=09=09BIMAuthRequest():BEvent( B_AUTH_REQUEST ) {}
=09=09~BIMAuthRequest();
};
class BIMAuthResponce: public BIMEvent {
=09public:
=09=09BIMAuthResponce(): BEvent( B_AUTH_RESPONCE ) {}
=09=09~BIMAuthResponce();
=09=09status_t SetConfirmed( bool aAllow );
=09=09status_t Confirmed( bool *aAllow );
};
#endif
------------------------------------- IMError.h ---------------------------
#ifndef IMERROR_H
#define IMERROR_H
#include <Message.h>
class BIMError: public BMessage {
=09protected:
=09=09BIMError( uint32 aWhat ): BMessage( aWhat ) {}
=09public:
=09=09/* Unspecified error */
=09=09BIMError(): BMessage( B_ERROR ) {}
=09=09~BIMError();
=09=09status_t SetErrorMessage( const char *aMessage );
=09=09status_t ErrorMessage( const char **aMessage );
};
class BIMLoginError: public BIMError {
=09public:
=09=09BIMLoginError(): BIMError( B_IM_LOGIN_ERROR ) {}
};
#endif
|