ICP  1
icputils.h
Go to the documentation of this file.
1 #ifndef ICPUTILS_H
2 #define ICPUTILS_H
3 
4 #include "IsisBase.h"
5 #include "isisvme_types.h"
6 #include "DAEstatus.h"
7 
8 std::string convertLatin1ToUTF8(const std::string& latin_string);
9 std::string convertWindows1252ToUTF8(const std::string& win_string);
10 
11 extern SECURITY_ATTRIBUTES* defaultNoInheritHandles();
12 
13 class Win32Exception : public std::runtime_error
14 {
15 public:
16  explicit Win32Exception(const std::string& message) : std::runtime_error(win32_message(message, GetLastError())) { }
17  explicit Win32Exception(const std::string& message, DWORD code) : std::runtime_error(win32_message(message, code)) { }
18 private:
19  static std::string win32_message(const std::string& message, DWORD code)
20  {
21  std::string s(message);
22  s.append(": ");
23  LPTSTR errMsg;
24  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
25  | FORMAT_MESSAGE_FROM_SYSTEM
26  | FORMAT_MESSAGE_IGNORE_INSERTS,
27  NULL,
28  code,
29  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
30  (LPTSTR) &errMsg,
31  0,
32  NULL);
33  s.append(errMsg);
34  LocalFree((LPVOID)errMsg);
35  return s;
36  }
37 };
38 
39 class Win32StructuredException : public std::runtime_error
40 {
41 public:
42  explicit Win32StructuredException(const std::string& message) : std::runtime_error(message) { }
43  explicit Win32StructuredException(unsigned int code, EXCEPTION_POINTERS *pExp) : std::runtime_error(win32_message(code, pExp)) { }
44 private:
45  static std::string win32_message(unsigned int code, EXCEPTION_POINTERS * pExp)
46  {
47  char buffer[256];
48  _snprintf(buffer, sizeof(buffer), "Win32StructuredException code 0x%x pExpCode 0x%x pExpAddress %p", code, pExp->ExceptionRecord->ExceptionCode, pExp->ExceptionRecord->ExceptionAddress);
49  buffer[sizeof(buffer)-1] = '\0';
50  return std::string(buffer);
51  }
52 };
53 
54 class CRTLException : public std::runtime_error
55 {
56 public:
57  explicit CRTLException(const std::string& message) : std::runtime_error(crtl_message(message, errno)) { }
58  explicit CRTLException(const std::string& message, int code) : std::runtime_error(crtl_message(message, code)) { }
59 private:
60  static std::string crtl_message(const std::string& message, int code)
61  {
62  std::string s(message);
63  s.append(": ");
64  s.append(strerror(code));
65  }
66 };
67 
68 class WinsockException : public std::runtime_error
69 {
70 public:
71  explicit WinsockException(const std::string& message) : std::runtime_error(win32_message(message, WSAGetLastError())) { }
72  explicit WinsockException(const std::string& message, DWORD code) : std::runtime_error(win32_message(message, code)) { }
73 private:
74  static std::string win32_message(const std::string& message, DWORD code)
75  {
76  std::string s(message);
77  s.append(": ");
78  LPTSTR errMsg;
79  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
80  | FORMAT_MESSAGE_FROM_SYSTEM
81  | FORMAT_MESSAGE_IGNORE_INSERTS,
82  NULL,
83  code,
84  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
85  (LPTSTR) &errMsg,
86  0,
87  NULL);
88  s.append(errMsg);
89  LocalFree((LPVOID)errMsg);
90  return s;
91  }
92 };
93 
94 void getConfigStringList(std::vector<std::string>& string_list, const std::string& config_item);
95 void getConfigIntList(std::vector<int>& int_list, const std::string& config_item);
96 
97 static void RetryWIN32APIBOOL(boost::function<BOOL()> func, int nretry)
98 {
99  BOOL ret = TRUE;
100  for( ; ( (ret = func()) == FALSE ) && (nretry >= 0); --nretry)
101  {
102  Sleep(100);
103  }
104  if (ret == FALSE)
105  {
106  throw Win32Exception("RetryWIN32APIBOOL");
107  }
108 }
109 
111 {
112 private:
114 
115 public:
116  ThreadPriorityRaiser(int prio = THREAD_PRIORITY_ABOVE_NORMAL)
117  {
118  m_old_prio = GetThreadPriority(GetCurrentThread());
119  if (m_old_prio == THREAD_PRIORITY_ERROR_RETURN)
120  {
121  throw std::runtime_error("GetThreadPriority");
122  }
123  if (SetThreadPriority(GetCurrentThread(), prio) == 0)
124  {
125  throw Win32Exception("SetThreadPriority");
126  }
127  }
128 
130  {
131  if (SetThreadPriority(GetCurrentThread(), m_old_prio) == 0)
132  {
133  throw Win32Exception("SetThreadPriority");
134  }
135  }
136 
138  {
139  revertPriority();
140  }
141 };
142 
143 class ICPClock : public ISIS::Base
144 {
145 private:
146  LARGE_INTEGER m_proc_freq, m_perf_counter;
147  FILETIME m_filetime;
148  double m_perf_to_ft;
149 
150 public:
152  {
153  setLoggerName("ICPClock");
155  }
156 
158  {
159  if (QueryPerformanceCounter(&m_perf_counter) == 0)
160  {
161  throw Win32Exception("QueryPerformanceCounter");
162  }
163  GetSystemTimeAsFileTime(&m_filetime);
164  if (QueryPerformanceFrequency(&m_proc_freq) == 0) // counts per second
165  {
166  throw Win32Exception("QueryPerformanceFrequency");
167  }
168  m_perf_to_ft = (double)m_proc_freq.QuadPart / 10000000.0; // convert to 100ns for FILETIME
169  }
170 
171  void setParameters(LONGLONG perf_counter, LONGLONG proc_freq, FILETIME filetime)
172  {
173  // proc_freq == 0 if we are startiong from scratch e.g.
174  if ( (proc_freq != 0) && (proc_freq != m_proc_freq.QuadPart) )
175  {
176  LOGSTR_ERROR("ICPClock proc frequency mismatch: " << proc_freq << " != " << m_proc_freq.QuadPart);
177  m_proc_freq.QuadPart = proc_freq;
178  }
179  m_filetime = filetime;
180  m_perf_counter.QuadPart = perf_counter;
181  m_perf_to_ft = (double)m_proc_freq.QuadPart / 10000000.0; // convert to 100ns for FILETIME
182  }
183 
184  void getParameters(LONGLONG& perf_counter, LONGLONG& proc_freq, FILETIME& filetime)
185  {
186  filetime = m_filetime;
187  proc_freq = m_proc_freq.QuadPart;
188  perf_counter = m_perf_counter.QuadPart;
189  }
190 
191  void getCurrentTimeAsFiletime(FILETIME& ft)
192  {
193  LARGE_INTEGER perf_counter, perf_elapsed;
194  ULONGLONG filetime_elapsed;
195  ULARGE_INTEGER ft_ul;
196  // need to look at setting thread affinity mask
197  if (QueryPerformanceCounter(&perf_counter) == 0)
198  {
199  throw Win32Exception("QueryPerformanceCounter");
200  }
201  perf_elapsed.QuadPart = perf_counter.QuadPart - m_perf_counter.QuadPart;
202  filetime_elapsed = static_cast<ULONGLONG>(0.5 + (double)perf_elapsed.QuadPart / m_perf_to_ft);
203  ft_ul.LowPart = m_filetime.dwLowDateTime;
204  ft_ul.HighPart = m_filetime.dwHighDateTime;
205  ft_ul.QuadPart += filetime_elapsed;
206  ft.dwLowDateTime = ft_ul.LowPart;
207  ft.dwHighDateTime = ft_ul.HighPart;
208  }
209 
210  void getCurrentTimeFromEpoch(time_t& tt)
211  {
212  FILETIME ft;
214  tt = Poco::Timestamp::fromFileTimeNP(ft.dwLowDateTime, ft.dwHighDateTime).epochTime();
215  }
216 };
217 
218 extern Poco::SingletonHolder<ICPClock> g_icp_clock;
219 
221 template <typename T>
223 {
224  T value;
225  Poco::Timestamp time;
226 
227  Poco::Timestamp::TimeDiff timeDiff(const ValueWithTimestamp& v)
228  {
229  return time - v.time;
230  }
232  {
233  return value - v.value;
234  }
235 };
236 
237 class ICPTimer
238 {
239 private:
240  std::string m_title;
242  struct timeb m_tb;
243  SYSTEMTIME m_st;
244  Poco::Timestamp m_ts;
245  struct timings_t
246  {
247  FILETIME create;
248  FILETIME exit;
249  FILETIME kernel;
250  FILETIME user;
251  };
252  timings_t m_thread_times;
253  timings_t m_process_times;
254 
255 public:
256  ICPTimer();
257  ICPTimer(const char* title, DAEstatus& status);
258  ~ICPTimer();
259  void start(const char* title = NULL);
260  double info(const char* title, std::ostream& os, bool add_nl = true);
261  double info(const char* title, DAEstatus& status);
262  double info(const std::string& title, DAEstatus& status) { return info(title.c_str(), status); }
263 };
264 
265 inline std::string padWithZeros(int number, int len)
266 {
267  std::vector<char> buffer(len+1);
268  char* bdata = buffer.data();
269  if ( _snprintf(bdata, len+1, "%0*d", len, number) < 0 )
270  {
271  memset(bdata, '#', len);
272  }
273  bdata[len] = '\0';
274  return bdata;
275 }
276 
277 std::string fileNameFromMappedView(void* pMem);
278 void printComputerMemoryStats(DAEstatus& status);
280 void setICPChannelReporter(DAEreport_func_t* report_func, void* report_arg);
281 int loadAppConfig(const std::string& app_name);
282 int removeWithRetry(const char* filename);
283 
284 int createEmptyFileAndClose(const std::string& file_name, size_t file_size);
285 HANDLE createEmptyFile(const std::string& file_name, size_t file_size);
286 int compareBuffers(const std::string& title, const isisU32_t* buffer1, const isisU32_t* buffer2, int nbuffer, DAEstatus& status);
287 
288 template <typename T>
289 void findConsecutive(const std::vector<T>& vec, T invalid_val, std::vector<int>& indexes, std::vector<int>& sizes);
290 
291 int sendSMS(const std::string& phone, const std::string& message, DAEstatus& status);
292 int sendEmail(const std::string& sender, const std::string& recipient, const std::string& subject, const std::string& content, DAEstatus& status);
293 
294 void pollUntilTasksComplete(const Poco::TaskManager& tm, int poll_time_in_ms);
295 
296 int findFiles(const char* directory, const char* pattern, std::vector<std::string>& list, bool full_path = true);
297 
298 void AddEventSource( PCTSTR pszName, PCTSTR pszMessageFile, DWORD dwCategoryCount);
299 
300 std::string unescapeXML(const char* xml_str);
301 std::string escapeXML(const char* xml_str);
302 
303 typedef unsigned char md5checksum_t[16];
304 int md5sumFile(const char* filename, unsigned char* md5sum, DAEstatus& status);
305 int md5sumString(const void* buffer, int len, unsigned char* md5sum, DAEstatus& status);
306 bool compareChecksums(const unsigned char* md5sum1, const unsigned char* md5sum2);
307 int updateChecksum(unsigned char* md5sum1, const unsigned char* md5sum2);
308 int parseSpectraRange(const std::string& spec_range, int& spec_from, int& spec_to);
309 std::string checksumAsString(md5checksum_t checksum);
310 
311 typedef void (*overlap_complete_func_t)(void* arg);
312 
313 void appendToFileAsync(const char* filename, const char* message);
314 void appendToFileAsync(HANDLE h, const char* message, bool close_after_write = false);
315 HANDLE createAppendFile(const char* filename);
316 
317 typedef struct {
318  ULONG i[2];
319  ULONG buf[4];
320  unsigned char in[64];
321  unsigned char digest[16];
322 } MD5_CTX;
323 
324 typedef void (__stdcall *MD5Init_t)(MD5_CTX *);
325 
326 typedef void (__stdcall *MD5Update_t)(MD5_CTX *, const unsigned char *, unsigned int);
327 
328 typedef void (__stdcall *MD5Final_t)(MD5_CTX *);
329 
331 {
332 private:
333  CRITICAL_SECTION* m_critical;
334  volatile LONG m_lockcount;
336 
337 public:
338  ICPCritical(CRITICAL_SECTION* pCsect, bool locked = true) : m_critical(pCsect), m_lockcount(0)
339  {
340  if (pCsect == NULL)
341  {
342  throw std::runtime_error("ICPcritical: NULL");
343  }
344  if (locked)
345  {
346  lock();
347  }
348  }
349  void lock()
350  {
351  EnterCriticalSection(m_critical);
352  InterlockedIncrement(&m_lockcount);
353  }
354  void unlock()
355  {
356  if (m_lockcount > 0)
357  {
358  InterlockedDecrement(&m_lockcount);
359  LeaveCriticalSection(m_critical);
360  }
361  }
363  {
364  if (m_critical != NULL)
365  {
366  while(m_lockcount > 0)
367  {
368  unlock();
369  }
370  m_critical = NULL;
371  }
372  }
373 };
374 
375 
376 extern Poco::Mutex* atomic_mutex;
377 
378 // 0 on success, -1 on error
379 template<typename T>
380 int atomic_write(const std::string& filename, const std::string& old_suffix, const std::string& new_suffix, T* data, int n)
381 {
382  Poco::Mutex::ScopedLock _lock(*atomic_mutex);
383  std::string old_file = filename + old_suffix;
384  std::string new_file = filename + new_suffix;
385  FILE* f = _fsopen(new_file.c_str(), "wbcN", _SH_DENYWR); // "c" forces commit to disk on fflush()
386  if (f == NULL)
387  {
388  Sleep(100);
389  f = _fsopen(new_file.c_str(), "wbcN", _SH_DENYWR);
390  }
391  if (f != NULL)
392  {
393  if (std::fwrite(data, sizeof(T), n, f) != n)
394  {
395  std::fclose(f);
396  std::remove(new_file.c_str());
397  throw std::runtime_error("cannot write data");
398  }
399  if (std::fflush(f) != 0)
400  {
401  std::fclose(f);
402  std::remove(new_file.c_str());
403  throw std::runtime_error("cannot flush data");
404  }
405  if (std::fclose(f) != 0)
406  {
407  std::remove(new_file.c_str());
408  throw std::runtime_error("cannot close data");
409  }
410  if (access(old_file.c_str(), 0) == 0)
411  {
412  RetryWIN32APIBOOL(boost::bind(DeleteFile, old_file.c_str()), 10);
413  }
414  if (access(filename.c_str(), 0) == 0)
415  {
416  RetryWIN32APIBOOL(boost::bind(MoveFile, filename.c_str(), old_file.c_str()), 10);
417  }
418  RetryWIN32APIBOOL(boost::bind(MoveFile, new_file.c_str(), filename.c_str()), 10);
419  return 0;
420  }
421  else
422  {
423  throw std::runtime_error("atomic:write: cannot open file");
424  return -1;
425  }
426 }
427 
428 // 0 on success, -1 on error
429 extern int flushed_write(const std::string& file, const void* data, int nbytes);
430 
431 // 0 on success, -1 on error
432 template<typename T>
433 int atomic_read(const std::string& filename, const std::string& old_suffix, T* data, size_t n)
434 {
435  Poco::Mutex::ScopedLock _lock(*atomic_mutex);
436  std::string old_file = filename + old_suffix;
437  FILE* f = _fsopen(filename.c_str(), "rbN", _SH_DENYNO);
438  if (f == NULL)
439  {
440  f = _fsopen(old_file.c_str(), "rbN", _SH_DENYNO);
441  }
442  if (f != NULL)
443  {
444  size_t nread = fread(data, sizeof(T), n, f);
445  fclose(f);
446  if (nread == n)
447  {
448  return 0;
449  }
450  else
451  {
452  return -1;
453  }
454  }
455  else
456  {
457  return -1;
458  }
459 }
460 
461 off_t file_size_bytes(const std::string& filename);
462 int64_t fileSizeBytes(const std::string& filename);
463 
464 
465 
467 template <typename T>
468 inline size_t array_length(const T& /*data*/)
469 {
470  return boost::extent<T>::value;
471 }
472 
473 LONGLONG diffFileTimes(const FILETIME& start, const FILETIME& finish);
474 double diffFileTimesInMilliSec(const FILETIME& start, const FILETIME& finish);
475 
476 template<typename T1, typename T2>
478 {
479  static const T2& second(const std::pair<T1, T2>& p)
480  {
481  return p.second;
482  }
483  typedef const T2& (*second_t)(const std::pair<T1, T2>& p);
484 };
485 
487 //
488 //template <typename Key, typename T>
489 //boost::transform_iterator< typename pair_second<Key,T>::second_t, typename std::map<Key,T>::const_iterator >& value_iterator(typename std::map<Key,T>::const_iterator& iter)
490 //{
491 // return boost::make_transform_iterator(iter, pair_second<Key,T>::second);
492 //}
493 
495 template <typename T>
497 {
498  private:
499  T sum;
500  public:
501  sum_values() : sum(0) { }
502  void operator()(const T& val) { sum += val; }
503  operator T() { return sum; }
504 };
505 
506 template <typename T, typename U>
507 U sum_map_values(const std::map<T,U>& m)
508 {
509  class sum_map_values_impl
510  {
511  private:
512  U sum;
513  public:
514  sum_map_values_impl() : sum(0) { }
515  void operator()(const typename std::map<T,U>::value_type& p) { sum += p.second; }
516  operator U() { return sum; }
517  };
518  return std::for_each(m.begin(), m.end(), sum_map_values_impl());
519 }
520 
521 
522 template<typename T>
523 class GenericTask : public Poco::Task, ISIS::Base
524 {
525  Poco::SharedPtr<Poco::Event> m_finish_event;
526  typedef boost::function<T()> func_t;
528 
529 public:
530  GenericTask(const std::string& name, Poco::SharedPtr<Poco::Event> finish_event, const func_t& func) : Poco::Task(name), Base("GenericTask"), m_finish_event(finish_event), m_func(func) { }
531 
532  void runTask()
533  {
534  LOGSTR_DEBUG("Starting task " << name() << " thread id " << Poco::Thread::currentTid());
535  m_func();
536  m_finish_event->set();
537 // setProgress(0.5);
538 // if (isCancelled())
539 // {
540 // return;
541 // }
542 // if (sleep(100)) // sleep returns true if we are cancelled
543 // {
544 // return;
545 // }
546  LOGSTR_DEBUG("Terminating task " << name() << " thread id " << Poco::Thread::currentTid());
547  }
548 
549  void cancel()
550  {
551  Poco::Task::cancel();
552  }
553 };
554 
555 
557 {
558 public:
559  void onProgress(Poco::TaskProgressNotification* pNf)
560  {
561  pNf->release();
562  }
563 
564  void onFinished(Poco::TaskFinishedNotification* pNf)
565  {
566  pNf->task()->name();
567  pNf->release();
568  }
569 };
570 
571 template <class T>
572 class GenericWorkNotification : public Poco::Notification
573 {
574 private:
575  T* m_data;
576 public:
578  T* data()
579  {
580  return m_data;
581  }
582 };
583 
584 template <class T>
585 class GenericWorker : public Poco::Runnable, ISIS::Base
586 {
587 private:
588  GenericWorker() : Base("GenericWorker") { }
589  Poco::NotificationQueue& m_queue;
590 public:
591  GenericWorker(Poco::NotificationQueue& queue) : Base("GenericWorker"), m_queue(queue) { }
592  virtual void run()
593  {
594  LOGSTR_DEBUG("Creating GenericWorker thread id " << Poco::Thread::currentTid());
595  Poco::AutoPtr<Poco::Notification> pNf(m_queue.waitDequeueNotification());
596  while(pNf)
597  {
598  GenericWorkNotification<T>* pWorkNf = dynamic_cast<GenericWorkNotification<T>*>(pNf.get());
599  if (pWorkNf)
600  {
601  doWork(pWorkNf->data());
602  }
603  pNf = m_queue.waitDequeueNotification();
604  }
605  LOGSTR_DEBUG("Terminating GenericWorker thread id " << Poco::Thread::currentTid());
606  }
607 
608  virtual void doWork(T* data) = 0;
609 };
610 
611 #if 0
612  WriteFileProgressHandler ph;
613  m_taskmgr.addObserver(Poco::Observer<WriteFileProgressHandler, Poco::TaskProgressNotification>(ph, &WriteFileProgressHandler::onProgress));
614  m_taskmgr.addObserver(Poco::Observer<WriteFileProgressHandler, Poco::TaskFinishedNotification>(ph, &WriteFileProgressHandler::onFinished));
615  m_taskmgr.start(new WriteFileTask("write 1"));
616  m_taskmgr.joinAll();
617  Poco::NotificationQueue nq;
618  Worker w1(nq);
619  Poco::ThreadPool::defaultPool().start(w1);
620  nq.enqueueNotification(new WorkNotification());
621  while(!nq.empty())
622  {
623  Poco::Thread::sleep(100);
624  }
625  nq.wakeUpAll(); // tell them they are done - only works of queue is empty
626  Poco::ThreadPool::defaultPool().joinAll();
627  return 0;
628 #endif
629 
630 
631 // Poco::ActiveMethod<int, uint32_t, DetectorCard> flushEvents;
632 // int flushEventsImpl(const uint32_t last_address_read);
633 
634 template <typename R>
636 {
637 public:
638  typedef boost::function<R()> func_t;
640  {
641  }
642 
643  Poco::ActiveMethod<R, func_t, ActiveObject> run;
644 
645 private:
646  R runImpl(const func_t& arg)
647  {
648  return arg();
649  }
650 };
651 
653 {
654 private:
655  Poco::Semaphore* m_sem;
656  void operator=(const Poco::Semaphore&) { throw std::runtime_error("ScopedSemaphore"); }
657  ScopedSemaphore(const Poco::Semaphore&) : m_sem(NULL) { throw std::runtime_error("ScopedSemaphore"); }
658 
659 public:
660  ScopedSemaphore(Poco::Semaphore& sem) : m_sem(&sem) { m_sem->wait(); }
661  ~ScopedSemaphore() { m_sem->set(); }
662 };
663 
664 
665 template <typename T>
667 {
668 private:
669  Poco::Mutex m_mutex;
670  typedef typename std::list<T*> list_t;
672 public:
673  T* get()
674  {
675  Poco::Mutex::ScopedLock _lock(m_mutex);
676  if (m_vals.empty())
677  {
678  return new T;
679  }
680  else
681  {
682  T* ret = m_vals.back();
683  m_vals.pop_back();
684  return ret;
685  }
686  }
687  void put(T* val)
688  {
689  Poco::Mutex::ScopedLock _lock(m_mutex);
690  m_vals.push_back(val);
691  }
692  void clear()
693  {
694  Poco::Mutex::ScopedLock _lock(m_mutex);
695  for(list_t::iterator it = m_vals.begin(); it != m_vals.end(); ++it)
696  {
697  delete *it;
698  }
699  m_vals.clear();
700  }
702  {
703  clear();
704  }
705 };
706 
707 
708 #if 0
709 
710 template<typename T>
711 class poco_mempool_allocator
712 {
713 public:
714  typedef std::size_t size_type;
715  typedef std::ptrdiff_t difference_type;
716  typedef T* pointer;
717  typedef const T* const_pointer;
718  typedef T& reference;
719  typedef const T& const_reference;
720  typedef T value_type;
721  template <class U> struct rebind {
722  typedef poco_mempool_allocator<U> other;
723  };
724  poco_mempool_allocator() throw() { }
725  poco_mempool_allocator(const poco_mempool_allocator&) throw() { }
726  template<class U> poco_mempool_allocator(const poco_mempool_allocator<U>&) throw() { }
727  ~poco_mempool_allocator() throw() { }
728  pointer address(reference x) const { return &x; }
729  const_pointer address(const_reference x) const { return &x; }
730  pointer allocate(size_type n, void* hint = 0)
731  {
732  return static_cast<T*>(n*sizeof(T));
733  }
734  void deallocate(pointer p, size_type n) { }
735  size_type max_size() const throw() { return bytes / sizeof(T); }
736  void construct(pointer p, const T& val)
737  {
738  new(static_cast<void*>(p)) T(val);
739  }
740  void destroy(pointer p)
741  {
742  p->~T();
743  }
744 };
745 
746 template<typename T>
747 bool operator==(const poco_mempool_allocator<T>&, const poco_mempool_allocator<T>&)
748 {
749  return true;
750 }
751 
752 template<typename T>
753 bool operator!=(const poco_mempool_allocator<T>&, const poco_mempool_allocator<T>&)
754 {
755  return false;
756 }
757 
758 template<>
759 class poco_mempool_allocator<void>
760 {
761 public:
762  typedef void* pointer;
763  typedef const void* const_pointer;
764  typedef void value_type;
765  template <class U> struct rebind {
766  typedef poco_mempool_allocator<U> other;
767  }
768 };
769 #endif /* if 0 */
770 
771 #endif /* ICPUTILS_H */
int md5sumFile(const char *filename, unsigned char *md5sum, DAEstatus &status)
Definition: icputils.cpp:253
sum_values()
Definition: icputils.h:501
Poco::Timestamp m_ts
Definition: icptimer.h:10
void getCurrentTimeFromEpoch(time_t &tt)
Definition: icputils.h:210
void operator=(const Poco::Semaphore &)
Definition: icputils.h:656
WinsockException(const std::string &message, DWORD code)
Definition: icputils.h:72
LONGLONG diffFileTimes(const FILETIME &start, const FILETIME &finish)
finish - start, returned in 100ns units
Definition: icputils.cpp:630
void pollUntilTasksComplete(const Poco::TaskManager &tm, int poll_time_in_ms)
Definition: icputils.cpp:1100
std::string checksumAsString(md5checksum_t checksum)
Definition: icputils.cpp:354
std::list< T * > list_t
Definition: icputils.h:670
void cancel()
Definition: icputils.h:549
Poco::Timestamp::TimeDiff timeDiff(const ValueWithTimestamp &v)
Definition: icputils.h:227
int compareBuffers(const std::string &title, const isisU32_t *buffer1, const isisU32_t *buffer2, int nbuffer, DAEstatus &status)
Definition: icputils.cpp:748
SYSTEMTIME m_st
Definition: icptimer.h:9
int atomic_read(const std::string &filename, const std::string &old_suffix, T *data, size_t n)
Definition: icputils.h:433
void syncToSystemTime()
Definition: icputils.h:157
bool compareChecksums(const unsigned char *md5sum1, const unsigned char *md5sum2)
Definition: icputils.cpp:313
static std::string win32_message(const std::string &message, DWORD code)
Definition: icputils.h:19
void setICPChannelReporter(DAEreport_func_t *report_func, void *report_arg)
Definition: icputils.cpp:839
static std::string crtl_message(const std::string &message, int code)
Definition: icputils.h:60
int DAEreport_func_t(const DAEstatus_message &mess, void *arg)
Definition: DAEstatus.h:119
ScopedSemaphore(const Poco::Semaphore &)
Definition: icputils.h:657
std::string fileNameFromMappedView(void *pMem)
Definition: icputils.cpp:1033
DAEstatus * m_status
Definition: icputils.h:241
unsigned long isisU32_t
Definition: isisvme_types.h:8
void(* overlap_complete_func_t)(void *arg)
Definition: icputils.h:311
R runImpl(const func_t &arg)
Definition: icputils.h:646
Win32Exception(const std::string &message, DWORD code)
Definition: icputils.h:17
Win32StructuredException(unsigned int code, EXCEPTION_POINTERS *pExp)
Definition: icputils.h:43
~ICPCritical()
Definition: icputils.h:362
T valueDiff(const ValueWithTimestamp &v)
Definition: icputils.h:231
~SimpleStore()
Definition: icputils.h:701
volatile LONG m_lockcount
Definition: icputils.h:334
void clear()
Definition: icputils.h:692
off_t file_size_bytes(const std::string &filename)
return size of a file in bytes
Definition: icputils.cpp:648
boost::function< R()> func_t
Definition: icputils.h:638
static void RetryWIN32APIBOOL(boost::function< BOOL()> func, int nretry)
Definition: icputils.h:97
int updateChecksum(unsigned char *md5sum1, const unsigned char *md5sum2)
Definition: icputils.cpp:331
SECURITY_ATTRIBUTES * defaultNoInheritHandles()
Definition: icputils.cpp:1121
#define LOGSTR_DEBUG(__arg)
Definition: IsisBase.h:71
void runTask()
Definition: icputils.h:532
Poco::Mutex m_mutex
Definition: icputils.h:669
Poco::Mutex * atomic_mutex
Definition: icputils.cpp:778
double diffFileTimesInMilliSec(const FILETIME &start, const FILETIME &finish)
finish - start in milliseconds
Definition: icputils.cpp:624
void(__stdcall * MD5Final_t)(MD5_CTX *)
Definition: icputils.h:328
Poco::ActiveMethod< R, func_t, ActiveObject > run
Definition: icputils.h:643
size_t array_length(const T &)
calculate number of elements in a fixed array e.g. int something[10] ot int s[] = { &quot;a&quot;...
Definition: icputils.h:468
HANDLE createEmptyFile(const std::string &file_name, size_t file_size)
Definition: icputils.cpp:963
double m_perf_to_ft
Definition: icputils.h:148
std::string convertWindows1252ToUTF8(const std::string &win_string)
Definition: icputils.cpp:18
Poco::NotificationQueue & m_queue
Definition: icputils.h:589
void appendToFileAsync(HANDLE h, const char *message, bool close_after_write)
Definition: icputils.cpp:441
std::string padWithZeros(int number, int len)
Definition: icputils.h:265
CRTLException(const std::string &message, int code)
Definition: icputils.h:58
std::string escapeXML(const char *xml_str)
Definition: icputils.cpp:118
timings_t m_thread_times
Definition: icptimer.h:18
static std::string win32_message(const std::string &message, DWORD code)
Definition: icputils.h:74
func_t m_func
Definition: icputils.h:527
void(__stdcall * MD5Init_t)(MD5_CTX *)
Definition: icputils.h:324
ThreadPriorityRaiser(int prio=THREAD_PRIORITY_ABOVE_NORMAL)
Definition: icputils.h:116
ICPCritical(CRITICAL_SECTION *pCsect, bool locked=true)
Definition: icputils.h:338
LARGE_INTEGER m_proc_freq
Definition: icputils.h:146
int findFiles(const char *directory, const char *pattern, std::vector< std::string > &list, bool full_path)
Definition: icputils.cpp:477
GenericWorkNotification(T *data)
Definition: icputils.h:577
FILETIME m_filetime
Definition: icputils.h:147
Win32StructuredException(const std::string &message)
Definition: icputils.h:42
HANDLE createAppendFile(const char *filename)
Definition: icputils.cpp:424
void put(T *val)
Definition: icputils.h:687
std::string m_title
Definition: icptimer.h:7
#define LOGSTR_ERROR(__arg)
Definition: IsisBase.h:99
int loadAppConfig(const std::string &app_name)
load a config file from ../../.. i.e. from c:/labview modules/dae if we are in c:/labview modules/dae...
Definition: icputils.cpp:866
unsigned char md5checksum_t[16]
Definition: icputils.h:303
ICPTimer()
Definition: icputils.cpp:29
int sendEmail(const std::string &sender, const std::string &recipient, const std::string &subject, const std::string &content, DAEstatus &status)
Definition: icputils.cpp:582
double info(const char *title, std::ostream &os, bool add_nl=true)
Definition: icptimer.h:83
void start(const char *title=NULL)
Definition: icptimer.h:64
static std::string win32_message(unsigned int code, EXCEPTION_POINTERS *pExp)
Definition: icputils.h:45
Poco::SingletonHolder< ICPClock > g_icp_clock
Definition: icputils.cpp:5
FILETIME kernel
Definition: icptimer.h:15
void AddEventSource(PCTSTR pszName, PCTSTR pszMessageFile, DWORD dwCategoryCount)
Definition: icputils.cpp:206
int removeWithRetry(const char *filename)
return 0 on success, else error
Definition: icputils.cpp:1090
boost::function< T()> func_t
Definition: icputils.h:526
virtual void doWork(T *data)=0
void getConfigIntList(std::vector< int > &int_list, const std::string &config_item)
read a ; separated list of items from a properties file and return the items as a vector&lt;int&gt; ...
Definition: icputils.cpp:854
void(__stdcall * MD5Update_t)(MD5_CTX *, const unsigned char *, unsigned int)
Definition: icputils.h:326
Poco::SharedPtr< Poco::Event > m_finish_event
Definition: icputils.h:525
struct MD5Context MD5_CTX
Definition: md5.h:44
void setParameters(LONGLONG perf_counter, LONGLONG proc_freq, FILETIME filetime)
Definition: icputils.h:171
void operator()(const T &val)
Definition: icputils.h:502
void unlock()
Definition: icputils.h:354
nice idea, but problems with return type...
Definition: icputils.h:496
static const T2 & second(const std::pair< T1, T2 > &p)
Definition: icputils.h:479
list_t m_vals
Definition: icputils.h:671
int md5sumString(const void *buffer, int len, unsigned char *md5sum, DAEstatus &status)
Definition: icputils.cpp:277
ICPClock()
Definition: icputils.h:151
FILETIME create
Definition: icptimer.h:13
int createEmptyFileAndClose(const std::string &file_name, size_t file_size)
Definition: icputils.cpp:1061
Base(const std::string &logger_name="UNKNOWN")
Definition: IsisBase.h:13
GenericWorker(Poco::NotificationQueue &queue)
Definition: icputils.h:591
timings_t m_process_times
Definition: icptimer.h:19
Poco::Timestamp time
Definition: icputils.h:225
void getConfigStringList(std::vector< std::string > &string_list, const std::string &config_item)
read a ; separated list of items from a properties file and return the items as a vector&lt;string&gt; ...
Definition: icputils.cpp:845
void lock()
Definition: icputils.h:349
U sum_map_values(const std::map< T, U > &m)
Definition: icputils.h:507
double info(const std::string &title, DAEstatus &status)
Definition: icputils.h:262
void getParameters(LONGLONG &perf_counter, LONGLONG &proc_freq, FILETIME &filetime)
Definition: icputils.h:184
void setLoggerName(const std::string &logger_name)
Definition: IsisBase.h:17
WinsockException(const std::string &message)
Definition: icputils.h:71
void onProgress(Poco::TaskProgressNotification *pNf)
Definition: icputils.h:559
this must have NO VIRTUAL FUNCTIONS as it is embedded inside the CRPT
Definition: icputils.h:222
std::string unescapeXML(const char *xml_str)
Definition: icputils.cpp:72
void getCurrentTimeAsFiletime(FILETIME &ft)
Definition: icputils.h:191
void registerExtraLoggerChannels()
Definition: icputils.cpp:830
ScopedSemaphore(Poco::Semaphore &sem)
Definition: icputils.h:660
void onFinished(Poco::TaskFinishedNotification *pNf)
Definition: icputils.h:564
CRITICAL_SECTION * m_critical
Definition: icputils.h:333
int parseSpectraRange(const std::string &spec_range, int &spec_from, int &spec_to)
Definition: icputils.cpp:338
virtual void run()
Definition: icputils.h:592
int sendSMS(const std::string &phone, const std::string &message, DAEstatus &status)
Definition: icputils.cpp:569
Win32Exception(const std::string &message)
Definition: icputils.h:16
void findConsecutive(const std::vector< T > &vec, T invalid_val, std::vector< int > &indexes, std::vector< int > &sizes)
return an array of indices containing the start points of consecutive sequences of numbers ...
Definition: icputils.cpp:664
int atomic_write(const std::string &filename, const std::string &old_suffix, const std::string &new_suffix, T *data, int n)
Definition: icputils.h:380
CRTLException(const std::string &message)
Definition: icputils.h:57
LARGE_INTEGER m_perf_counter
Definition: icputils.h:146
static int flushed_write(const std::vector< std::string > &files, const std::vector< const void * > &data, const std::vector< int > &nbytes)
Definition: icputils.cpp:910
GenericTask(const std::string &name, Poco::SharedPtr< Poco::Event > finish_event, const func_t &func)
Definition: icputils.h:530
void printComputerMemoryStats(DAEstatus &status)
Definition: icputils.cpp:1072
~ICPTimer()
Definition: icptimer.h:60
std::string convertLatin1ToUTF8(const std::string &latin_string)
convert ISO Latin-1 (8859-1) to UTF-8
Definition: icputils.cpp:8
Poco::Semaphore * m_sem
Definition: icputils.h:655
struct timeb m_tb
Definition: icptimer.h:8
int64_t fileSizeBytes(const std::string &filename)
Definition: icputils.cpp:1049