2 //=============================================================================
6 * Class implentation for SMI Timeticks class.
8 * @author Peter E MellquistMichael R MacFaden mrm@cisco.com - rework & ACE port
10 //=============================================================================
12 /*===================================================================
14 Hewlett-Packard Company
16 ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
17 Permission to use, copy, modify, distribute and/or sell this software
18 and/or its documentation is hereby granted without fee. User agrees
19 to display the above copyright notice and this license notice in all
20 copies of the software and any documentation of the software. User
21 agrees to assume all liability for the use of the software; Hewlett-Packard
22 makes no representations about the suitability of this software for any
23 purpose. It is provided "AS-IS without warranty of any kind,either express
24 or implied. User hereby grants a royalty-free license to any and all
25 derivatives based upon this software code base.
26 =====================================================================*/
28 #include "asnmp/timetick.h" // include header file for timetick class
29 #include "ace/OS_NS_stdio.h"
31 // constructor with a value
32 TimeTicks::TimeTicks( const unsigned long i
):SnmpUInt32(i
)
34 smival
.syntax
= sNMP_SYNTAX_TIMETICKS
;
38 TimeTicks::TimeTicks( const TimeTicks
&t
)
41 smival
.value
.uNumber
= t
.smival
.value
.uNumber
;
42 smival
.syntax
= sNMP_SYNTAX_TIMETICKS
;
46 TimeTicks::~TimeTicks()
51 SmiUINT32
TimeTicks::get_syntax()
53 return sNMP_SYNTAX_TIMETICKS
;
56 // create a new instance of this Value
57 SnmpSyntax
*TimeTicks::clone() const
59 return (SnmpSyntax
*) new TimeTicks(*this);
62 // overloaded assignement from ulong
63 TimeTicks
& TimeTicks::operator=( const unsigned long int i
)
65 smival
.value
.uNumber
=i
; return *this;
68 // overloaded assignment from TimeTicks
69 TimeTicks
& TimeTicks::operator=( const TimeTicks
&uli
)
71 this->smival
.value
.uNumber
= uli
.smival
.value
.uNumber
; return *this;
74 // general assignment from any Value
75 SnmpSyntax
& TimeTicks::operator=( SnmpSyntax
&in_val
)
77 if ( this == &in_val
) // handle assignement from itself
80 valid_flag
= 0; // will get set true if really valid
82 switch (in_val
.get_syntax()) {
83 case sNMP_SYNTAX_UINT32
:
84 // case sNMP_SYNTAX_GAUGE32: .. indistinquishable from UINT32
85 case sNMP_SYNTAX_CNTR32
:
86 case sNMP_SYNTAX_TIMETICKS
:
87 case sNMP_SYNTAX_INT32
: // implied cast int -> uint
88 this->smival
.value
.uNumber
=
89 ((TimeTicks
&)in_val
).smival
.value
.uNumber
;
97 // otherwise, behave like an unsigned long
98 TimeTicks::operator unsigned long()
100 return smival
.value
.uNumber
;
104 // ASCII format return
105 const char * TimeTicks::to_string()
106 /* Should do something nicer like days:hours:minutes... */
108 unsigned long tt
, hseconds
, seconds
, minutes
, hours
, days
;
109 tt
= this->smival
.value
.uNumber
;
129 ACE_OS::sprintf( output_buffer
,"%ld:%02ld:%02ld.%02ld", hours
,
130 minutes
,seconds
,hseconds
);
132 ACE_OS::sprintf( output_buffer
,"1 day %ld:%02ld:%02ld.%02ld", hours
,
133 minutes
,seconds
,hseconds
);
135 ACE_OS::sprintf( output_buffer
,"%ld days, %ld:%02ld:%02ld.%02ld",
136 days
,hours
, minutes
,seconds
, hseconds
);
138 return output_buffer
;