Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2263 kivins 1
//---------------------------------------------------------------------------
2
 
3
#ifndef UdTransferManagerH
4
#define UdTransferManagerH
5
 
6
#include <vcl.h>
7
#include <map>
8
#include <vector>
9
#include <syncobjs.hpp>
10
 
11
#include "IDeviceFactory.h"
12
 
13
//---------------------------------------------------------------------------
14
 
15
typedef enum
16
{
17
    UdTransferCompleted = 0,
18
    UdTransferFailed = 1,
19
    UdTransferAborted = 2,
20
    UdTransferInProgress = 3,
21
    UdTransferPending = 4
22
 
23
} UdTransferTaskState;
24
 
25
typedef enum
26
{
27
    RampTestDisabled = 0,
28
    RampTestByDemand = 1,
29
    RampTestByRatio  = 2
30
 
31
} RampTestType;
32
 
33
typedef std::vector<int>        BatchSizeList;
34
typedef BatchSizeList::iterator BatchSizeItem;
35
 
36
struct UdTransferStatistics
37
{
38
    int     processedFiles;
39
    int     totalFiles;
40
    int     processedBytes;
41
    int     totalBytes;
42
    bool    completed;
43
    TDateTime startTime;
44
    TDateTime endTime;   
45
    BatchSizeList batches;    
46
};
47
 
48
struct UdFile
49
{
50
    AnsiString  name;
51
    int         size;
52
    TDateTime   time;
53
 
54
    UdFile() {}
55
    UdFile( const UdFile & rhs ) :
56
        name( rhs.name ), size( rhs.size ), time( rhs.time ) {}
57
 
58
    bool operator<( const UdFile & rhs ) const
59
    {
60
        return time < rhs.time;
61
    };
62
};
63
 
64
typedef std::vector<UdFile>     UdFileList;
65
typedef UdFileList::iterator    UdFileItem;
66
 
67
struct UdTransferTask
68
{
69
    int                 id;
70
    int                 batchSize;
71
    unsigned int        duration;
72
    int                 frequency;
73
    bool                recurring;
74
    AnsiString          sourcePath;
75
    AnsiString          destination;
76
    UdFileList          files;
77
    UdTransferTaskState state;
78
    RampTestType        rampType;
79
    double              gradient;
80
    TDateTime           rampTime;
81
 
82
    UdTransferTask() {}
83
    UdTransferTask( const UdTransferTask & rhs ) :
84
        id( rhs.id ), batchSize( rhs.batchSize ), duration( rhs.duration ),
85
        frequency( rhs.frequency ), recurring( rhs.recurring ), sourcePath( rhs.sourcePath ),
86
        destination( rhs.destination ), files( rhs.files ), state( rhs.state ),
87
        rampType( rhs.rampType ), gradient( rhs.gradient ), rampTime( rhs.rampTime ) {}
88
 
89
    bool operator!=( const UdTransferTask & rhs )
90
    {
91
        return (batchSize != rhs.batchSize &&
92
                duration  != rhs.duration &&
93
                frequency != rhs.frequency &&
94
                recurring != rhs.recurring &&
95
                sourcePath != rhs.sourcePath &&
96
                destination != rhs.destination &&
97
                state != rhs.state &&
98
                rampType != rhs.rampType &&
99
                gradient != rhs.gradient &&
100
                rampTime != rhs.rampTime);
101
    }
102
};
103
 
104
typedef std::vector<UdTransferTask>     UdTransferTaskList;
105
typedef UdTransferTaskList::iterator    UdTransferTaskItem;
106
 
107
class UdTransferThread;
108
 
109
typedef std::map<int, UdTransferThread *> UdTransferThreadMap;
110
typedef UdTransferThreadMap::iterator   UdTransferThreadItem;
111
 
112
//---------------------------------------------------------------------------
113
class UdTransferManager
114
{
115
public:
116
    UdTransferManager();
117
    virtual ~UdTransferManager();
118
 
119
    void AddNewTask( const UdTransferTask & task );
120
    void LoadPendingTasks();
121
    void UpdateTask( const UdTransferTask & task,
122
                     const AnsiString & comment = "" );
123
    bool GetTaskDetails( UdTransferTask & task );
124
    bool LaunchTask( const UdTransferTask & task );
125
    bool GetTaskStatistics( const int & taskId,
126
                            UdTransferStatistics & stats );
127
    void UpdateTaskStatistics( const int & taskId,
128
                               const UdTransferStatistics & stats );
129
    bool IsTaskRunning();
130
 
131
    AnsiString GetUsername() { return m_username; }
132
    AnsiString GetHostname() { return m_hostname; } 
133
 
134
private:
135
    AnsiString  m_username;
136
    AnsiString  m_hostname;
137
 
138
    UdTransferThreadMap m_threads;
139
    UdTransferTaskList  m_tasks;
140
 
141
    Syncobjs::TCriticalSection *  m_tasksLock;
142
 
143
    HINSTANCE           m_deviceSimulatorWrapperDll;
144
    getDeviceFactory_t  m_getDeviceFactory;
145
    IDeviceFactory *    m_deviceSimulatorFactory;
146
};
147
 
148
#endif