1 /*===========================================================================
2 *
3 *                            PUBLIC DOMAIN NOTICE
4 *               National Center for Biotechnology Information
5 *
6 *  This software/database is a "United States Government Work" under the
7 *  terms of the United States Copyright Act.  It was written as part of
8 *  the author's official duties as a United States Government employee and
9 *  thus cannot be copyrighted.  This software/database is freely available
10 *  to the public for use. The National Library of Medicine and the U.S.
11 *  Government have not placed any restriction on its use or reproduction.
12 *
13 *  Although all reasonable efforts have been taken to ensure the accuracy
14 *  and reliability of the software and data, the NLM and the U.S.
15 *  Government do not and cannot warrant the performance or results that
16 *  may be obtained by using this software or data. The NLM and the U.S.
17 *  Government disclaim all warranties, express or implied, including
18 *  warranties of performance, merchantability or fitness for any particular
19 *  purpose.
20 *
21 *  Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26 
27 #include "ptimemgr.hpp"
28 #include <kfc/time.hpp>
29 #include <kfc/callstk.hpp>
30 #include <kfc/rsrc.hpp>
31 #include <kfc/caps.hpp>
32 #include <kfc/syserr.hpp>
33 
34 #if UNIX
35 #include <sys/time.h>
36 #include <errno.h>
37 #else
38 #error "unsupported target platform"
39 #endif
40 
41 namespace vdb3
42 {
43 
44 
45     /*------------------------------------------------------------------
46      * ptimemgr_t
47      *  primordial time manager
48      */
49 
make_primordial()50     TimeMgr PrimordTimeMgr :: make_primordial ()
51     {
52         FUNC_ENTRY ();
53         PrimordTimeMgr * obj = new PrimordTimeMgr;
54         return obj -> make_tmmgr_ref ( obj, CAP_READ );
55     }
56 
cur_time() const57     timestamp_t PrimordTimeMgr :: cur_time () const
58     {
59         FUNC_ENTRY ();
60 
61 #if UNIX
62         struct timeval tv;
63         int status =  gettimeofday ( & tv, 0 );
64         if ( status != 0 )
65             THROW_OSERR ( gettimeofday, errno );
66 
67         seconds_t sec = tv . tv_sec;
68         uS_t uS = tv . tv_usec;
69         uS += sec;
70 
71         return make_timestamp ( uS );
72 #else
73 #error no implementation for cur_time on this platform
74 #endif
75     }
76 
PrimordTimeMgr()77     PrimordTimeMgr :: PrimordTimeMgr ()
78     {
79     }
80 
81 }
82