1994-09-19 09:50:07 +00:00
|
|
|
#ifndef __MAILBOX_H
|
|
|
|
#define __MAILBOX_H
|
|
|
|
|
|
|
|
#ifndef __STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TMessage flags
|
|
|
|
#define MSG_READ (0x01)
|
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1996-09-05 09:54:52 +00:00
|
|
|
// @class TMessage | Classe per il passaggio dei messaggi base tra applicazioni
|
1996-01-31 17:19:02 +00:00
|
|
|
// e linea di comando
|
1995-06-27 10:18:49 +00:00
|
|
|
//
|
|
|
|
// @base public | TObject
|
1994-09-19 09:50:07 +00:00
|
|
|
class TMessage : public TObject
|
1996-02-05 19:00:53 +00:00
|
|
|
|
1998-03-13 10:31:30 +00:00
|
|
|
// @author:(INTERNAL) Villa
|
1996-02-05 19:00:53 +00:00
|
|
|
|
|
|
|
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
1995-07-21 17:27:58 +00:00
|
|
|
// @cfriend TMailbox
|
1996-02-05 19:00:53 +00:00
|
|
|
friend class TMailbox;
|
1995-06-27 10:18:49 +00:00
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @access:(INTERNAL) Private Member
|
1995-07-21 17:27:58 +00:00
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Applicazione che lancia il messaggio
|
1998-03-13 10:31:30 +00:00
|
|
|
TString _from;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Applicazione che deve ricevere il messaggio
|
1998-03-13 10:31:30 +00:00
|
|
|
TString _to;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Oggetto del messaggio
|
1998-03-13 10:31:30 +00:00
|
|
|
TString _subject;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Testo del messaggio
|
1994-09-28 10:36:08 +00:00
|
|
|
TString _text;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Flag di controllo del messaggio
|
1995-06-27 10:18:49 +00:00
|
|
|
byte _flags;
|
|
|
|
// #cmember Numero (non si sa cosa faccia)
|
1995-06-28 07:55:54 +00:00
|
|
|
// int _number;
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @access Protected Member
|
1994-10-24 15:06:49 +00:00
|
|
|
protected:
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Indica che il messaggio e' stato letto
|
|
|
|
void setread()
|
|
|
|
{ _flags |= MSG_READ; }
|
|
|
|
// @cmember Controlla se il messaggio e' stato letto (TRUE se e' stato letto)
|
|
|
|
bool isread()
|
|
|
|
{ return _flags & MSG_READ; }
|
|
|
|
// #cmember Setta il numero. Se viene passato -1 ritorna il valore attuale
|
1995-06-28 07:55:54 +00:00
|
|
|
// int number(int n = -1)
|
|
|
|
// { return (n == -1 ? _number : (_number = n)); }
|
1995-06-27 10:18:49 +00:00
|
|
|
|
|
|
|
// @access Public Member
|
1994-09-19 09:50:07 +00:00
|
|
|
public:
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Ritorna il nome dell'applicazione che lancia il messaggio
|
|
|
|
const TString& from() const
|
|
|
|
{ return _from; }
|
|
|
|
// @cmember Ritorna il nome dell'applicazione che deve ricevere il messaggio
|
|
|
|
const TString& to() const
|
|
|
|
{ return _to; }
|
|
|
|
// @cmember Ritorna l'oggetto del messaggio
|
|
|
|
const TString& subject() const
|
|
|
|
{ return _subject; }
|
|
|
|
// @cmember Ritorna il testo del messaggio
|
|
|
|
const TString& body() const
|
|
|
|
{ return _text; }
|
|
|
|
|
|
|
|
// @cmember Assegna il nome dell'applicazione che lancia il messaggio
|
|
|
|
const TString& from(const char* f)
|
|
|
|
{ return _from = f; }
|
|
|
|
// @cmember Assegna il nome dell'applicazione che deve ricevere il messaggio
|
|
|
|
const TString& to(const char* t)
|
|
|
|
{ return _to = t; }
|
|
|
|
// @cmember Assegna l'oggetto del messaggio
|
|
|
|
const TString& subject(const char* s)
|
|
|
|
{ return _subject = s; }
|
|
|
|
// @cmember Assegna il testo del messaggio
|
|
|
|
const TString& body(const char* b)
|
|
|
|
{ return _text = b; }
|
1994-10-24 15:06:49 +00:00
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Manda il messaggio
|
1994-09-28 10:36:08 +00:00
|
|
|
void send();
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Costruttore
|
|
|
|
TMessage(const char* to, const char* sub, const char* text, const char* from = NULL);
|
1997-11-17 10:28:04 +00:00
|
|
|
virtual ~TMessage() { }
|
1994-09-19 09:50:07 +00:00
|
|
|
};
|
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @class TMailbox | Classe per controllare i messaggi ricevuti da una applicazione
|
|
|
|
//
|
|
|
|
// @base public | TObject
|
1994-09-19 09:50:07 +00:00
|
|
|
class TMailbox : public TObject
|
1996-02-05 19:00:53 +00:00
|
|
|
|
|
|
|
// @author:(INTERNAL) Villa
|
|
|
|
|
|
|
|
// @access:(INTERNAL) Private Member
|
1994-09-19 09:50:07 +00:00
|
|
|
{
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Nome del file che contiene i messaggi
|
1995-06-27 10:18:49 +00:00
|
|
|
TFilename _path;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Array di messaggi ricevuti
|
1995-06-27 10:18:49 +00:00
|
|
|
TArray _msgs;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Numero dell'ultimo messaggio letto
|
1995-06-27 10:18:49 +00:00
|
|
|
int _lastread;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Numero di messaggi in attesa di lettura
|
1995-06-27 10:18:49 +00:00
|
|
|
int n_new;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Posizione nel file dell'ultimo messaggio letto
|
1995-06-27 10:18:49 +00:00
|
|
|
long _lastpos;
|
1996-02-05 19:00:53 +00:00
|
|
|
// @cmember:(INTERNAL) Indice dei messaggi letti e non letti
|
1995-06-27 10:18:49 +00:00
|
|
|
int _cnt;
|
|
|
|
|
|
|
|
// @access Protected Member
|
1994-09-19 09:50:07 +00:00
|
|
|
protected:
|
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Legge un nuovo messaggio dalla mailbox. Crea messaggi, mette i
|
|
|
|
// messaggi nell'array in ordine cronologico
|
1994-09-19 09:50:07 +00:00
|
|
|
void reread();
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Ritorna il prossimo messaggio letto (NULL se non e' stato letto)
|
1994-09-19 09:50:07 +00:00
|
|
|
TMessage* next_read();
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Ritorna il prossimo messaggio non letto
|
1994-09-28 10:36:08 +00:00
|
|
|
TMessage* next_unread();
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @access Public Member
|
1994-09-19 09:50:07 +00:00
|
|
|
public:
|
1995-06-27 10:18:49 +00:00
|
|
|
|
|
|
|
// @cmember Ritorna il numero di messaggi in attesa
|
|
|
|
int check()
|
|
|
|
{ reread(); return n_new; }
|
1996-09-05 09:54:52 +00:00
|
|
|
// @cmember Reinizializza la fase di lettura
|
1995-06-27 10:18:49 +00:00
|
|
|
void restart()
|
|
|
|
{ _cnt = 0;}
|
|
|
|
// @cmember Ritorna in numero di messaggi, letti e da leggere, presenti nella mailbox
|
|
|
|
int items()
|
|
|
|
{ return _msgs.items(); }
|
|
|
|
// @cmember Ritorna il prossimo messaggio
|
|
|
|
TMessage* next(bool read = FALSE);
|
|
|
|
// @cmember Ritorna il prossimo messaggio con lo stesso oggetto
|
1996-06-18 13:33:27 +00:00
|
|
|
TMessage* next_s(const char* s, bool read = FALSE);
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Ritorna il prossimo messaggio con lo stesso mandante
|
|
|
|
TMessage* next_f(char* f, bool read = FALSE);
|
|
|
|
// @cmember Manda un messaggio
|
|
|
|
void send(TMessage& m);
|
|
|
|
// @cmember Trasforma gli argomenti della command line in messaggi mail (NON IMPLEMENTATA)
|
|
|
|
void sendcmd(int argc, char* argv[],char* to);
|
|
|
|
// @cmember Trasforma una mailbox in parametri per la command line per la
|
|
|
|
// chaimata di applicazioni non compilanti (NON IMPLEMENTATA)
|
|
|
|
char* readcmd(char* to = NULL);
|
|
|
|
// @cmember Ritorna l'<p n>-esimo messaggio
|
|
|
|
TMessage* get(int n)
|
1994-09-28 10:36:08 +00:00
|
|
|
{ return (TMessage*)_msgs.objptr(n); }
|
1994-09-19 09:50:07 +00:00
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Costruttore
|
1994-09-19 09:50:07 +00:00
|
|
|
TMailbox::TMailbox(const char* appname = NULL);
|
1995-06-27 10:18:49 +00:00
|
|
|
// @cmember Distruttore
|
1994-09-19 09:50:07 +00:00
|
|
|
virtual ~TMailbox();
|
|
|
|
};
|
|
|
|
|
1995-06-27 10:18:49 +00:00
|
|
|
// @todo Da implementare in futuro
|
|
|
|
//
|
1994-09-19 09:50:07 +00:00
|
|
|
// instead of using commandline args directly, user posts
|
|
|
|
// messages to application, then calls it without arguments
|
|
|
|
// If the application is called by the user with command_line
|
|
|
|
// arguments, sendcmd parses them and translates to messages
|
|
|
|
// according to the following rules:
|
|
|
|
//
|
|
|
|
// from is "cmdline"
|
|
|
|
//
|
|
|
|
// subject comes from arguments of type -opt=value
|
|
|
|
// (opt becomes subject and value becomes body)
|
|
|
|
//
|
|
|
|
// args like -opt="val, val, val" create
|
|
|
|
// one message for each val, with the same subject=opt
|
|
|
|
//
|
|
|
|
// -opt arg creates subject=opt and empty body
|
|
|
|
//
|
|
|
|
// one-word arguments create a message with "null" subject
|
|
|
|
//
|
|
|
|
// A mailbox should be member of applicat and sendcmd should be
|
|
|
|
// called automatically upon startup
|
|
|
|
// Non compliant applications (which do not use mailbox) can be
|
|
|
|
// called consistently by sending messages,
|
|
|
|
// appending TMailbox::readcmd(appname) to
|
|
|
|
// their name and doing an exec()
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|