BundleTimestamp.cc

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 
00018 #include <time.h>
00019 #include <oasys/debug/Log.h>
00020 
00021 #include "BundleTimestamp.h"
00022 
00023 namespace dtn {
00024 
00028 u_int32_t BundleTimestamp::TIMEVAL_CONVERSION = 946684800;
00029 
00030 u_int32_t
00031 BundleTimestamp::get_current_time()
00032 {
00033     struct timeval now;
00034     ::gettimeofday(&now, 0);
00035     
00036     ASSERT((u_int)now.tv_sec > TIMEVAL_CONVERSION);
00037     return now.tv_sec - TIMEVAL_CONVERSION;
00038 }
00039 
00040 bool
00041 BundleTimestamp::check_local_clock()
00042 {
00043     struct timeval now;
00044     ::gettimeofday(&now, 0);
00045 
00046     if ((u_int)now.tv_sec < TIMEVAL_CONVERSION) {
00047         logf("/dtn/bundle/timestamp", oasys::LOG_ERR,
00048              "invalid local clock setting: "
00049              "current time '%s' is before Jan 1, 2000",
00050              ctime((const time_t*)&now.tv_sec));
00051 
00052         log_err_p("/dtn/bundle/timestamp",
00053                           "invalid local clock setting: "
00054                           "current time '%s' is before Jan 1, 2000",
00055                           ctime((const time_t*)&now.tv_sec));
00056         return false;
00057     }
00058 
00059     return true;
00060 }
00061 } // namespace dtn

Generated on Sat Sep 8 08:43:26 2007 for DTN Reference Implementation by  doxygen 1.5.3