Reads the current time and date from the system clock on the server that runs a remote _EDMdatabase{_}.
Related function: edmiUnpackDate.
Header:
#include "sdai.h"
Prototype:
EdmiError edmiRemoteGetDate(SdaiServerContext serverContextId,
EdmiPackedDate *packedDate,
EdmiDate *date,
EdmiStringDate *stringDate,
SdaiInteger stringFormat,
SdaiInvocationId *edmiInvocationId);
Arguments:
serverContextId |
Context identification, from edmiDefineServerContext |
packedDate |
A variable that will receive the current time and date in an EdmiPackedDate format. Dates from January 1, 1990 to December 31, 2053 may be represented in this format. |
date |
A variable that will receive a pointer to an EdmiDate structure containing the current time and date. See sdai.h for the declaration of EdmiDate. |
stringDate |
A variable that will receive a pointer to a buffer that contains the current time and date in string format. |
stringFormat |
Currently not used. |
edmiInvocationId |
Currently not used. |
Returns:
A completion code of datatype EdmiError is the returned function value. The completion code has the following values:
Completion code = 0 : Operation successfully performed.
Completion code != 0: Error in operation. Completion code is an _EDMinterface_ error code. Use edmiGetErrorText to get the error text corresponding to the error code.
Example:
#define S_MAXDIFF 30
/* Check if the clocks on two servers are
unsyncronized beyond a threshold value */
EdmiError rstat;
SdaiServerContext tellusContext, saturnContext;
EdmiPackedDate tellusPackedDate, saturnPackedDate, dateDiff;
EdmiDate tellusDate, saturnDate;
EdmiStringDate tellusStringDate, saturnStringDate;
SdaiUnsignedInt tellusSeconds, saturnSeconds;
/* Create a Tellus server context */
rstat = edmiDefineServerContext("TellusContext",
"superuser", NULL, "xfx56kl9",
"TCP", "9090", "Tellus",
NULL, NULL, NULL, NULL, NULL, &tellusContext);
/* Create a Saturn server context */
rstat = edmiDefineServerContext("SaturnContext",
"superuser", NULL, "xgg45k22",
"TCP", "9095", "Saturn",
NULL, NULL, NULL, NULL, NULL, &saturnContext);
/* Read the clock on server Tellus */
rstat = edmiRemoteGetDate(tellusContext, &tellusPackedDate,
&tellusDate, &tellusStringDate, 0, NULL);
/* Read the clock on server Saturn */
rstat = edmiRemoteGetDate(saturnContext, &saturnPackedDate,
&saturnDate, &saturnStringDate, 0, NULL);
printf("\nMaster time is (Tellus):");
printf("\n Year ..............: %d", tellusDate.year);
printf("\n Month .............: %d", tellusDate.month);
printf("\n Day .............. : %d", tellusDate.day);
printf("\n Hour ..............: %d", tellusDate.hour);
printf("\n Minute ............: %d", tellusDate.minute);
printf("\n Second ............: %d", tellusDate.second);
printf("\n WeekDay ...........: %d", tellusDate.weekday);
printf("\n Day of Year .......: %d", tellusDate.dayOfYear);
printf("\n daylightSavingTime : %d", tellusDate.daylightSavingTime);
if (tellusDate.dayOfYear != saturnDate.dayOfYear) {
_sleep(S_MAXDIFF*1000);
}
tellusSeconds = 3600 * tellusDate.hour;
tellusSeconds += 60 * tellusDate.minute;
tellusSeconds += tellusDate.second;
saturnSeconds = 3600 * saturnDate.hour;
saturnSeconds += 60 * saturnDate.minute;
saturnSeconds += saturnDate.second;
dateDiff = saturnSeconds - tellusSeconds;
if (abs(dateDiff) > S_MAXDIFF) {
printf("\n\nWARNING!!! Unsyncronized server clocks.");
printf("\nSaturn is %d seconds %s Tellus", abs(dateDiff),
(dateDiff > 0) ? "ahead of" : "behind");
} else {
printf("\nServer clocks are syncronized.");
printf("\n – Saturn drift is %d seconds", dateDiff);
}
. . .