Files correlati : Commento : Aggiunto oggetto TURL per verificare e scaricare un URL Aggiunta funzione get_date delle token string Aggiunta funzione fmove per spostare un file Aggiunte funzioni time_t atime(const char* file) // access time time_t ctime(const char* file) // creation time time_t mtime(const char* file) // modification time struct tm * altime(const char* file) // access local time struct tm * cltime(const char* file) // creation local time struct tm * mltime(const char* file); // creation local time TDate aldate(const char* file) // creation date TDate cldate(const char* file) // modification date TDate mldate(const char* file)// access date per le varie ddate di un file
119 lines
3.1 KiB
C++
Executable File
119 lines
3.1 KiB
C++
Executable File
#ifndef __NETUTILS_H__
|
|
#define __NETUTILS_H__
|
|
|
|
#ifndef __ASSOC_H
|
|
#include <assoc.h>
|
|
#endif
|
|
|
|
class TConnection;
|
|
typedef unsigned long CONNID;
|
|
|
|
typedef int (*ConnectionFunction)(TConnection& conn, void* pJolly);
|
|
|
|
class TLanManager : public TObject
|
|
{
|
|
TAssoc_array m_mapConn;
|
|
|
|
protected:
|
|
CONNID AddConnection(TConnection* pConn);
|
|
|
|
virtual TConnection* OnCreateConnection(CONNID id);
|
|
virtual bool OnRemoveConnection(CONNID id);
|
|
|
|
public:
|
|
virtual bool IsServer() const { return false; }
|
|
virtual bool IsClient() const { return false; }
|
|
virtual bool IsOk() const { return false; }
|
|
|
|
virtual bool Execute(CONNID id, const char* cmd);
|
|
virtual bool Request(CONNID id, const char* cmd);
|
|
|
|
int ForEachConnection(ConnectionFunction f, void* pJolly);
|
|
|
|
bool HasConnections() const;
|
|
TConnection* GetConnection(CONNID id) const;
|
|
|
|
bool RemoveConnection(CONNID id);
|
|
void RemoveAllConnections();
|
|
|
|
TLanManager();
|
|
virtual ~TLanManager();
|
|
};
|
|
|
|
class TLanServer : public TLanManager
|
|
{
|
|
TString m_strName;
|
|
|
|
public:
|
|
const TString& Name() const { return m_strName; }
|
|
|
|
virtual bool IsServer() const { return true; }
|
|
|
|
virtual byte* GetBuffer(unsigned int dwSize) pure;
|
|
byte* GetBufferSetString(const char* str);
|
|
byte* GetBufferSetBool(bool ok);
|
|
byte* GetBufferSetInteger(long n);
|
|
|
|
TLanServer(const char* name) : m_strName(name) { }
|
|
virtual ~TLanServer() { }
|
|
};
|
|
|
|
class TLanClient : public TLanManager
|
|
{
|
|
protected:
|
|
virtual TConnection* OnQueryConnection(const char* service, const char* server) pure;
|
|
|
|
public:
|
|
virtual bool IsClient() const { return true; }
|
|
|
|
CONNID QueryConnection(const char* service, const char* server = NULL);
|
|
|
|
virtual bool Execute(CONNID id, const char* cmd);
|
|
virtual bool Request(CONNID id, const char* cmd);
|
|
virtual byte* GetBuffer(unsigned int& dwSize) = 0;
|
|
virtual void ReleaseBuffer() = 0;
|
|
|
|
bool RequestString(CONNID id, const char* cmd, TString& res);
|
|
bool RequestInteger(CONNID id, const char* cmd, long& num);
|
|
bool RequestBool(CONNID id, const char* cmd, bool& ok);
|
|
};
|
|
|
|
class TConnection : public TObject
|
|
{
|
|
TLanManager* m_pManager;
|
|
CONNID m_dwId;
|
|
|
|
protected:
|
|
int ParseCommand(const char* cmd, TString_array& argv);
|
|
void SetId(CONNID id) { m_dwId = id; } // Internal use only
|
|
|
|
public:
|
|
CONNID Id() const { return m_dwId; }
|
|
|
|
TLanManager& Manager() const { return *m_pManager; }
|
|
TLanServer& Server() const;
|
|
|
|
virtual bool Execute(const char* cmd);
|
|
virtual bool Request(const char* cmd);
|
|
|
|
bool ReturnBool(bool b) const { return Server().GetBufferSetBool(b) != NULL; }
|
|
bool ReturnInteger(long n) const { return Server().GetBufferSetInteger(n) != NULL; }
|
|
bool ReturnString(const TString& s) const { return Server().GetBufferSetString(s) != NULL; }
|
|
|
|
TConnection(TLanManager* lm, CONNID id);
|
|
virtual ~TConnection();
|
|
};
|
|
|
|
class TURL : public TObject
|
|
{
|
|
TString _url;
|
|
|
|
public:
|
|
bool ok(const char * url = nullptr);
|
|
void set_url(const char * url) { if (ok(url)) _url = url; }
|
|
bool get(const char * outfile, const char * path = nullptr);
|
|
|
|
TURL(const char * url = nullptr) { set_url(url); }
|
|
};
|
|
#endif
|