TuioTime.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. TUIO C++ Library - part of the reacTIVision project
  3. http://reactivision.sourceforge.net/
  4. Copyright (c) 2005-2009 Martin Kaltenbrunner <[email protected]>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #include "TuioTime.h"
  18. using namespace TUIO;
  19. long TuioTime::start_seconds = 0;
  20. long TuioTime::start_micro_seconds = 0;
  21. void TuioTime::initSession() {
  22. TuioTime startTime = TuioTime::getSystemTime();
  23. start_seconds = startTime.getSeconds();
  24. start_micro_seconds = startTime.getMicroseconds();
  25. }
  26. TuioTime TuioTime::getSessionTime() {
  27. return (getSystemTime() - getStartTime());
  28. }
  29. TuioTime TuioTime::getStartTime() {
  30. return TuioTime(start_seconds,start_micro_seconds);
  31. }
  32. TuioTime TuioTime::getSystemTime() {
  33. #ifdef WIN32
  34. TuioTime systemTime(GetTickCount());
  35. #else
  36. struct timeval tv;
  37. struct timezone tz;
  38. gettimeofday(&tv,&tz);
  39. TuioTime systemTime(tv.tv_sec,tv.tv_usec);
  40. #endif
  41. return systemTime;
  42. }