Accuracy.cpp
Go to the documentation of this file.00001
00010 #include "Accuracy.h"
00011 #include "Buffer.h"
00012 #include "PKIXTSP.h"
00013 #include "components.h"
00014 #include "ToolkitUtils.h"
00015 #include "TSPException.h"
00016 #include "PKIFCommonErrors.h"
00017 #include "ASN1Helper.h"
00018
00020
00021 struct CPKIFAccuracyImpl
00022 {
00023 void SetSecondsPresent(bool b);
00024 void SetMillisPresent(bool b);
00025 void SetMicrosPresent(bool b);
00026
00027 int m_seconds;
00028 int m_millis;
00029 int m_micros;
00030 bool m_secondsPresent;
00031 bool m_millisPresent;
00032 bool m_microsPresent;
00033 };
00034
00042 void CPKIFAccuracyImpl::SetSecondsPresent(
00044 bool b)
00045 {
00046 m_secondsPresent = b;
00047 }
00048
00056 void CPKIFAccuracyImpl::SetMillisPresent(
00058 bool b)
00059 {
00060 m_millisPresent = b;
00061 }
00062
00070 void CPKIFAccuracyImpl::SetMicrosPresent(
00072 bool b)
00073 {
00074 m_microsPresent = b;
00075 }
00076
00078
00086 CPKIFAccuracy::CPKIFAccuracy():m_impl(new CPKIFAccuracyImpl)
00087 {
00088 LOG_STRING_DEBUG("CPKIFAccuracy::CPKIFAccuracy()", TOOLKIT_TSP_ASN, 0, this);
00089
00090 m_impl->m_seconds = 0;
00091 m_impl->m_millis = 0;
00092 m_impl->m_micros = 0;
00093 m_impl->m_secondsPresent = false;
00094 m_impl->m_millisPresent = false;
00095 m_impl->m_microsPresent = false;
00096 }
00104 CPKIFAccuracy::CPKIFAccuracy(
00106
00107 const CPKIFBufferPtr& accuracyBuf)
00108 :m_impl(new CPKIFAccuracyImpl)
00109 {
00110 LOG_STRING_DEBUG("CPKIFAccuracy::CPKIFAccuracy(PKIFTSPAccuracy& accuracy)", TOOLKIT_TSP_ASN, 0, this);
00111
00112 CACASNWRAPPER_CREATE(PKIFTSPAccuracy, AccuWrapper);
00113 PKIFTSPAccuracy* accuracy = AccuWrapper.Decode(accuracyBuf->GetBuffer(), accuracyBuf->GetLength());
00114
00115 m_impl->m_secondsPresent = false;
00116 m_impl->m_millisPresent = false;
00117 m_impl->m_microsPresent = false;
00118
00119
00120 if(accuracy->m.secondsPresent)
00121 {
00122 SetSeconds(accuracy->seconds);
00123 }
00124 if(accuracy->m.millisPresent)
00125 {
00126 SetMillis(accuracy->millis);
00127 }
00128 if(accuracy->m.microsPresent)
00129 {
00130 SetMicros(accuracy->micros);
00131 }
00132 }
00133
00141 CPKIFAccuracy::~CPKIFAccuracy()
00142 {
00143 LOG_STRING_DEBUG("CPKIFAccuracy::~CPKIFAccuracy()", TOOLKIT_TSP_ASN, 0, this);
00144
00145 if (m_impl) {
00146 delete m_impl;
00147 }
00148 }
00156 bool CPKIFAccuracy::GetSecondsPresent()
00157 {
00158 return m_impl->m_secondsPresent;
00159 }
00160
00168 bool CPKIFAccuracy::GetMillisPresent()
00169 {
00170 return m_impl->m_millisPresent;
00171 }
00172
00180 bool CPKIFAccuracy::GetMicrosPresent()
00181 {
00182 return m_impl->m_microsPresent;
00183 }
00184
00193 int CPKIFAccuracy::GetSeconds() const
00194 {
00195 return m_impl->m_seconds;
00196 }
00204 void CPKIFAccuracy::SetSeconds(
00206 int seconds)
00207 {
00208 if(seconds > 999 || seconds < 0)
00209 throw new CPKIFTSPException(TOOLKIT_TSP_ASN, COMMON_INVALID_INPUT, "Invalids number of seconds passed to SetSeconds.");
00210 m_impl->m_seconds = seconds;
00211 m_impl->SetSecondsPresent(0 == m_impl->m_seconds);
00212 }
00222 int CPKIFAccuracy::GetMillis() const
00223 {
00224 return m_impl->m_millis;
00225 }
00234 void CPKIFAccuracy::SetMillis(
00236 int millis)
00237 {
00238 if(millis > 999 || millis < 0)
00239 throw new CPKIFTSPException(TOOLKIT_TSP_ASN, COMMON_INVALID_INPUT, "Invalids number of seconds passed to SetSeconds.");
00240 m_impl->m_millis = millis;
00241 m_impl->SetMillisPresent(0 == m_impl->m_millis);
00242 }
00252 int CPKIFAccuracy::GetMicros() const
00253 {
00254 return m_impl->m_micros;
00255 }
00264 void CPKIFAccuracy::SetMicros(
00266 int micros)
00267 {
00268 if(micros > 999 || micros < 0)
00269 throw new CPKIFTSPException(TOOLKIT_TSP_ASN, COMMON_INVALID_INPUT, "Invalids number of seconds passed to SetSeconds.");
00270 m_impl->m_micros = micros;
00271 m_impl->SetMillisPresent(0 == m_impl->m_micros);
00272 }