Skip to content

Commit

Permalink
MMDevice: Remove gettimeofday() for Windows
Browse files Browse the repository at this point in the history
It is a bad idea to define functions named like POSIX standard ones,
because other people can have the same idea and they can clash (we
previously had this issue with Python < 3.7 and gettimeofday()).

Fortunately no device adapter is currently using this function on
Windows, so just remove the dead code.

In modern C++, std::chrono offers better time functions for any new code
that may need similar facilities.

A few errors corrected in 3 device adapters that used definitions from
Windows.h, which is no longer included (without WIN32_LEAN_AND_MEAN)
by DeviceUtils.h.
  • Loading branch information
marktsuchida committed Jan 22, 2024
1 parent 62855a4 commit 5a0ba3b
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 71 deletions.
2 changes: 1 addition & 1 deletion DeviceAdapters/IlluminateLEDArray/LEDArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ int LedArray::ReadResponse() {
return DEVICE_ERR;
}

int LedArray::SetShutter(boolean open)
int LedArray::SetShutter(bool open)
{
//TODO maybe update property?
shutterOpen_ = open;
Expand Down
2 changes: 1 addition & 1 deletion DeviceAdapters/IlluminateLEDArray/LEDArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class LedArray: public CSLMBase<LedArray>
int OnBrightness(MM::PropertyBase* pPropt, MM::ActionType eAct);


int SetShutter(boolean open);
int SetShutter(bool open);
bool GetShutter();

private:
Expand Down
4 changes: 2 additions & 2 deletions DeviceAdapters/PointGrey/PointGrey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ int PointGrey::CameraID(PGRGuid id, std::string* camIdString)
*/
int PointGrey::CameraGUIDfromOurID(BusManager* busMgr, PGRGuid* guid, std::string ourId)
{
boolean found = false;
bool found = false;
unsigned int numCameras;
PGRGuid localGuid;
Error error = busMgr->GetNumOfCameras(&numCameras);
Expand Down Expand Up @@ -1984,7 +1984,7 @@ int PointGrey::VideoModeAndFrameRateEnumsFromString(std::string readableString,
}

// find matching Videomode and Framerate by cycling brute force through our arrays
boolean found = false;
bool found = false;
unsigned int counter = 0;
while (!found && counter < g_NumVideoModes) {
if (parts[0] == g_VideoModes[counter]) {
Expand Down
2 changes: 1 addition & 1 deletion DeviceAdapters/SigmaKoki/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ int Camera::OnBinning(MM::PropertyBase* pProp, MM::ActionType eAct)
{
BOOL ans = TRUE;
WORD mode = 0;
byte skippH, skippV, hBin, vBin;
BYTE skippH, skippV, hBin, vBin;

cout << "Product is " << productName_ << endl;

Expand Down
41 changes: 0 additions & 41 deletions MMDevice/DeviceUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,44 +188,3 @@ bool CDeviceUtils::CheckEnvironment(std::string env)
}
return bvalue;
}



#if defined(_WIN32) && !defined(MMDEVICE_NO_GETTIMEOFDAY)

int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag;

if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);

tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;

/*converting file time to unix epoch*/
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tmpres /= 10; /*convert into microseconds*/
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}

if (NULL != tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}

return 0;
}

#endif
25 changes: 0 additions & 25 deletions MMDevice/DeviceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,6 @@
#include "MMDeviceConstants.h"
#include <vector>
#include <string>
#ifdef _WIN32
#include <time.h>
#include <windows.h>
#endif

#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif

// Definition of struct timezone and gettimeofday can be disabled in case
// interfacing with some other system that also tries to define conflicting
// symbols (e.g. Python <= 3.6).
#if defined(_WIN32) && !defined(MMDEVICE_NO_GETTIMEOFDAY)
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};

int gettimeofday(struct timeval *tv__, struct timezone *tz__);

#endif


class CDeviceUtils
{
Expand Down

0 comments on commit 5a0ba3b

Please sign in to comment.