Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
OperationManager.cpp
Go to the documentation of this file.
1 
11 #include "stdafx.h"
12 #include "OperationManager.h"
13 
14 #define FUNC_TYPE "update_list"
15 #define FUNC_NAME "update_log_list"
16 
17 using namespace kome::operation;
18 
19 
20 #include <crtdbg.h>
21 #ifdef _DEBUG
22  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
23  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
24 #endif // _DEBUG
25 
26 
27 // constructor
29  m_saveCount = -1;
30 }
31 
32 // destructor
34  // delete all operation
35  int i = m_operations.size()-1;
36  while( i > -1 ){
37  delete m_operations[i].operation;
38 
39  i--;
40  }
41  m_operations.clear();
42 }
43 
44 // Add Operation
46  if( operation == NULL ){
47  return;
48  }
49 
50  for( unsigned int i=0; i < m_operations.size(); i++ ){
51  if( m_operations[i].operation == operation ){
52  return;
53  }
54  }
55  // operation info
56  OperationInfo optInf;
57  optInf.operation = operation;
58  optInf.iState = TYPE_NONE;
59 
60  m_operations.push_back( optInf );
61 }
62 
63 // Remove Operation
65  int i = m_operations.size()-1;
66  while( i > -1 ){
67  Operation* opt = m_operations[i].operation;
68  if( opt == operation ){
69  m_operations.erase( m_operations.begin() + i );
70  // リストの更新処理
71  SendStatusToList();
72  return;
73  }
74  i--;
75  }
76 }
77 
78 // get number of operations
80  return m_operations.size();
81 }
82 
83 // get operation
84 Operation* OperationManager::getOperation( const unsigned int i ){
85  if( i >= m_operations.size() ){
86  return NULL;
87  }
88  return m_operations[i].operation;
89 }
90 
91 // get number of finished operations
93  int inum = 0;
94  for( unsigned int i=0; i < m_operations.size(); i++ ){
95  if( m_operations[i].iState == TYPE_FINISH ){ // finish
96  inum++;
97  }
98  }
99  return inum;
100 }
101 
102 // get finished operation
104  std::vector<Operation*> opt;
105  for( unsigned i=0; i < m_operations.size(); i++ ){
106  if( m_operations[i].iState == TYPE_FINISH ){ // finish
107  opt.push_back( m_operations[i].operation );
108  }
109  }
110 
111  if( index > (int)opt.size() || index <= -1 ){
112  return NULL;
113  }
114  return opt[index];
115 }
116 
117 // get number of canseled operations
119  int inum = 0;
120  for( unsigned int i=0; i < m_operations.size(); i++ ){
121  if( m_operations[i].iState == TYPE_CANCEL ){ // cansel
122  inum++;
123  }
124  }
125  return inum;
126 }
127 
128 // get canseled operation
130  std::vector<Operation*> opt;
131  for( unsigned int i=0; i < m_operations.size(); i++ ){
132  if( m_operations[i].iState == TYPE_CANCEL ){ // cansel
133  opt.push_back( m_operations[i].operation );
134  }
135  }
136 
137  if( index > (int)opt.size() || index <= -1 ){
138  return NULL;
139  }
140  return opt[index];
141 }
142 
143 // get Update Data File Path
145  // Manager
147 
148  // Operation Folder
149  std::string folderName = "Operation";
150  std::string operatFolder = getpath( msppMgr.getTmpDir(), folderName.c_str() );
151 
152  if( !fileexists( operatFolder.c_str() ) ){
153  makedirectory( operatFolder.c_str() );
154  }
155 
156  m_updateFilePath = operation->getUpdateFilePath();
157  if( !fileexists( m_updateFilePath.c_str() ) ){
158  // file name ( not path )
159  std::string strName = operation->getOperationName();
160  strName = "UpdatePath" + strName ;
161 
162  std::string datFile = msppMgr.getTmpFileName( strName.c_str(), ".dat", folderName.c_str() );
163  m_updateFilePath = getpath( operatFolder.c_str(), datFile.c_str() );
164  }
165 
166  return m_updateFilePath.c_str();
167 }
168 
169 // get Previouse Data File Path
171  // Manager
173 
174  // Operation Folder
175  std::string folderName = "Operation";
176  std::string operatFolder = getpath( msppMgr.getTmpDir(), folderName.c_str() );
177 
178  if( !fileexists( operatFolder.c_str() ) ){
179  makedirectory( operatFolder.c_str() );
180  }
181 
182  m_prevFilePath = operation->getPrevFilePath();
183  // 一致するファイルがない場合は新規作成
184  if( !fileexists( m_prevFilePath.c_str()) ){
185  // file name ( not path )
186  std::string strName = operation->getOperationName();
187  strName = "PrevPath" + strName ;
188 
189  std::string datFile = msppMgr.getTmpFileName( strName.c_str(), ".dat", folderName.c_str() );
190  m_prevFilePath = getpath( operatFolder.c_str(), datFile.c_str() );
191  }
192 
193  return m_prevFilePath.c_str();
194 }
195 
196 // move to finished
198  for( unsigned int i=0; i < m_operations.size(); i++ ){
199  if( m_operations[i].operation == operation ){
200  m_operations[i].iState = TYPE_FINISH;
201 
202  SendStatusToList();
203 
204  return;
205  }
206  }
207 
208  // operation info
209  OperationInfo optInf;
210  optInf.iState = TYPE_FINISH;
211  optInf.operation = operation;
212 
213  m_operations.push_back( optInf );
214 
215  // リストの更新処理
216  SendStatusToList();
217 }
218 
219 // move to canseled
221  for( unsigned int i=0; i < m_operations.size(); i++ ){
222  if( m_operations[i].operation == operation ){
223  m_operations[i].iState = TYPE_CANCEL;
224 
225  SendStatusToList();
226 
227  return;
228  }
229  }
230 
231  // operation inofo
232  OperationInfo optInf;
233  optInf.iState = TYPE_CANCEL;
234  optInf.operation = operation;
235 
236  m_operations.push_back( optInf );
237 
238  // リストの更新処理
239  SendStatusToList();
240 }
241 
242 // clearCanseledOperation
244  int i = m_operations.size()-1;
245 
246  // @date 2013.09.17 <Mod> ->
247  while( i > -1 ){
248  if( m_operations[i].iState == TYPE_CANCEL ){
249  delete m_operations[i].operation;
250  m_operations[i].operation = NULL;
251  }
252  i--;
253  }
254  // @date 2013.09.17 <Mod> <-
255 }
256 
257 // Send a state to list
258 void OperationManager::SendStatusToList(){
259 
260  //リストの更新処理
261  kome::plugin::PluginFunctionItem* item;
262 
263  kome::plugin::PluginManager& plgMgr = kome::plugin::PluginManager::getInstance();
264  unsigned int iFuncItem = plgMgr.getNumberOfFunctionItems( FUNC_TYPE );
265  item = plgMgr.getFunctionItem( FUNC_TYPE, FUNC_NAME );
266  if( item != NULL ){
267  item->getCall()->invoke( NULL );
268  }
269 }
270 
271 // set status
272 void OperationManager::setState( const unsigned int index, int state ){
273  if( index >= m_operations.size() ){
274  return;
275  }
276 
277  m_operations[index].iState = state;
278 }
279 
280 // get status
281 int OperationManager::getState( const unsigned int index ){
282  if( index >= m_operations.size() ){
283  return -1;
284  }
285  return m_operations[index].iState;
286 }
287 
288 // get refer to OperationManager object
290  // create the only object
291  static OperationManager plgMgr;
292 
293  return plgMgr;
294 }
void addOperation(Operation *operation)
add managed operation
static MsppManager & getInstance()
gets MsppManager object (This is the only object.)
int getNumberOfCanceledOperations()
gets the number of canceled operations
void moveToFinished(Operation *operation)
moves the operation to the finished queue.
implements of GridEmailTextCtrl class
Mass++ manager class.
Definition: MsppManager.h:28
static OperationManager & getInstance()
get operation manager object (This is the only object.)
std::string getPrevFilePath()
gets previouse data file path
Definition: Operation.cpp:175
const char * getPreviousDataFilePath(Operation *operation)
gets the file path to save the previous status
bool fileexists(const char *path)
judge whether file exists
int getState(const unsigned int index)
gets the operation status
const char * getTmpDir()
gets temporary file directory name
#define NULL
Definition: CoreMacros.h:18
std::string getUpdateFilePath()
gets udate data file path
Definition: Operation.cpp:185
void removeOperation(Operation *operation)
remove managed operation
bool makedirectory(const char *path)
creates directory
Operation * getCanceledOperation(int i)
gets the canceled operation
const char * getOperationName()
gets operation name
Definition: Operation.cpp:53
Operation * getFinishedOperation(int i)
gets the finished operation.
void clearCanceledOperation()
clears canceled operations
Operation * getOperation(const unsigned int index)
gets the managed operation
unsigned int getNumberOfOperations()
gets the number of managed operation
virtual ~OperationManager()
destructor
void movetoCanseled(Operation *operation)
move the operation to the canceled queue.
const char * getUpdateDataFilePath(Operation *operation)
the file path to save the update status
std::string getTmpFileName(const char *prefix, const char *suffix, const char *dir=NULL)
gets temporary file name
Operation information class.
Definition: Operation.h:22
operation management class
std::vector< OperationInfo > m_operations
void setState(const unsigned int index, int state)
sets the operation stateus
int getNumberOfFinishedOperations()
gets the number of finished operations
std::string getpath(const char *dir, const char *file)
get file path