| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #include "stdafx.h"
- //#include "OTSData.h"
- #include "MsrThreadStatus.h"
- namespace OTSMODEL {
- using namespace OTSDATA;
- // constructor
- CMsrThreadStatus::CMsrThreadStatus()
- {
- // initialization
- Init();
- }
- // copy constructor
- CMsrThreadStatus::CMsrThreadStatus(const CMsrThreadStatus& a_oSource)
- {
- // can't copy itself
- if (&a_oSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(a_oSource);
- }
- // copy constructor
- CMsrThreadStatus::CMsrThreadStatus(CMsrThreadStatus* a_poSource)
- {
- // input check
- ASSERT(a_poSource);
- if (!a_poSource)
- {
- return;
- }
- // can't copy itself
- if (a_poSource == this)
- {
- return;
- }
- // copy data over
- Duplicate(*a_poSource);
- }
- // =operator
- CMsrThreadStatus& CMsrThreadStatus::operator=(const CMsrThreadStatus& a_oSource)
- {
- // cleanup
- Cleanup();
- // copy the class data over
- Duplicate(a_oSource);
- // return class
- return *this;
- }
- // destructor
- CMsrThreadStatus::~CMsrThreadStatus()
- {
- // cleanup
- Cleanup();
- }
- // ==operator
- BOOL CMsrThreadStatus::operator==(const CMsrThreadStatus& a_oSource)
- {
- int nSize = (int)m_listCpldSamples.size();
- if (nSize != (int)a_oSource.m_listCpldSamples.size())
- {
- return FALSE;
- }
- // return FALSE if any of the samples are different
- for (int i = 0; i < nSize; ++i)
- {
- if (!(*(m_listCpldSamples[i].get()) == *(a_oSource.m_listCpldSamples[i].get())))
- {
- return FALSE;
- }
- }
- return m_nStatus == a_oSource.m_nStatus &&
- m_timeStart == a_oSource.m_timeStart &&
- m_timeUsed == a_oSource.m_timeUsed &&
- m_timeStart == a_oSource.m_timeStart;
- }
- // CMsrThreadStatus member functions
- // public
- // serialization
-
- void CMsrThreadStatus::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
- {
- xmls::xInt xnStatus;
- xmls::xOleDateTime xtimeStart;
- xmls::xOleDateTimeSpan xtimeUsed;
- xmls::xOleDateTime xtimeEnd;
- xmls::Collection<COTSSample> xSamples;
- xmls::Slo slo;
- slo.Register("CompletedFields", &xnStatus);
- slo.Register("timeStart", &xtimeStart);
- slo.Register("timeUsed", &xtimeUsed);
- slo.Register("timeEnd", &xtimeEnd);
- if (isStoring)
- {
- xnStatus = (int)m_nStatus;
- xtimeStart = m_timeStart;
- xtimeUsed = m_timeUsed;
- xtimeEnd = m_timeEnd;
- xSamples.Clear();
- for (auto pSample : m_listCpldSamples)
- {
- xSamples.addItem(pSample.get());
- }
- slo.Serialize(true, classDoc, rootNode);
- }
- else
- {
- slo.Serialize(false, classDoc, rootNode);
- m_nStatus = (OTS_MSR_THREAD_STATUS)xnStatus.value();
- m_timeStart = xtimeStart.value ();
- m_timeUsed = xtimeUsed.value ();
- m_timeEnd = xtimeEnd.value ();
- m_listCpldSamples.clear();
- for (unsigned int i=0;i<xSamples.size ();i++)
- {
- m_listCpldSamples.push_back (COTSSamplePtr(xSamples.getItem (i)));
- }
- }
- }
- BOOL CMsrThreadStatus::ComputeTime(OTS_THREAD_TIME_TYPE a_nType)
- {
- if (a_nType == OTS_THREAD_TIME_TYPE::START)
- {
- if (m_timeStart == COleDateTime())
- {
- m_timeStart = COleDateTime::GetCurrentTime();
- m_timeStartCur = m_timeStart;
-
- }
- else
- {
- m_timeStartCur = COleDateTime::GetCurrentTime();
- }
- m_timeEnd = COleDateTime::GetCurrentTime();
- }
- else if (a_nType == OTS_THREAD_TIME_TYPE::STOPPED)
- {
- // set current time as end time
- m_timeEnd = COleDateTime::GetCurrentTime();
- // compute used time
- COleDateTimeSpan timeUsed = COleDateTimeSpan();
- if (m_timeStartCur == m_timeStart)
- {
- // first compute time
- timeUsed = m_timeEnd - m_timeStart;
- }
- else
- {
- // not the first compute time
- timeUsed = m_timeUsed + m_timeEnd - m_timeStartCur;
- }
-
- m_timeUsed = timeUsed;
- }
- else
- {
- return FALSE;
- }
- return TRUE;
- }
-
- // protected
- // cleanup
- void CMsrThreadStatus::Cleanup()
- {
- m_listCpldSamples.clear();
- }
- void CMsrThreadStatus::SetCompletedSamples(COTSSamplesList& a_listCpldSamples)
- {
- m_listCpldSamples.clear();
- for (auto pSample : a_listCpldSamples)
- {
-
- m_listCpldSamples.push_back(pSample);
- }
- }
- // initialization
- void CMsrThreadStatus::Init()
- {
- m_nStatus = DEFAULT_MSR_THREAD_STATUS;
- m_timeStart = COleDateTime();
- m_timeUsed = COleDateTimeSpan();
- m_timeEnd = COleDateTime();
- m_timeStartCur = COleDateTime();
- m_listCpldSamples.clear();
- }
- // duplication
- void CMsrThreadStatus::Duplicate(const CMsrThreadStatus& a_oSource)
- {
- // initialization
- Init();
- // copy data over
- m_nStatus = a_oSource.m_nStatus;
- m_timeStart = a_oSource.m_timeStart;
- m_timeUsed = a_oSource.m_timeUsed;
- m_timeEnd = a_oSource.m_timeEnd;
- for (auto pSample : a_oSource.m_listCpldSamples)
- {
- COTSSamplePtr pSampleNew = COTSSamplePtr(new COTSSample(pSample.get()));
- m_listCpldSamples.push_back(pSampleNew);
- }
- }
- }
|