Garmin Fleet Management Controller  2.19.0
AobrdDriverItem.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * AobrdDriverItem.cpp
5 *
6 * Copyright 2012 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include "AobrdDriverItem.h"
13 
14 #define CURRENT_VERSION 1
15 #define RECORD_SEPARATOR 30
16 
17 //----------------------------------------------------------------------
19 //----------------------------------------------------------------------
21  : mParent( NULL ),
22  mLongTermRuleset(0),
23 #if( FMI_SUPPORT_A615 )
24  mLoadTypeRuleset(0),
25 #endif
26  mTimeZone(0)
27 {
28 
29 }
30 
31 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
35 {
36 
37 }
38 
39 //----------------------------------------------------------------------
42 //----------------------------------------------------------------------
44 {
45  CString driverId;
46  TCHAR tcharName[50];
47  MultiByteToWideChar( CP_UTF8, 0, mDriverId.c_str(), -1, tcharName, 50 );
48  driverId.SetString( tcharName );
49 
50  return driverId;
51 }
52 
53 //----------------------------------------------------------------------
57 //----------------------------------------------------------------------
59 {
60  return mDriverId;
61 }
62 
63 //----------------------------------------------------------------------
67 //----------------------------------------------------------------------
69 {
70  CString driverPassword;
71  TCHAR tcharName[50];
72  MultiByteToWideChar( CP_UTF8, 0, mDriverPassword.c_str(), -1, tcharName, 50 );
73  driverPassword.SetString( tcharName );
74 
75  return driverPassword;
76 }
77 
78 //----------------------------------------------------------------------
82 //----------------------------------------------------------------------
84 {
85  CString value;
86  TCHAR tcharValue[50];
87  MultiByteToWideChar( CP_UTF8, 0, mFirstName.c_str(), -1, tcharValue, 50 );
88  value.SetString( tcharValue );
89 
90  return value;
91 }
92 
93 //----------------------------------------------------------------------
97 //----------------------------------------------------------------------
99 {
100  CString value;
101  TCHAR tcharValue[50];
102  MultiByteToWideChar( CP_UTF8, 0, mLastName.c_str(), -1, tcharValue, 50 );
103  value.SetString( tcharValue );
104 
105  return value;
106 }
107 
108 //----------------------------------------------------------------------
112 //----------------------------------------------------------------------
114 {
115  CString value;
116  TCHAR tcharValue[50];
117  MultiByteToWideChar( CP_UTF8, 0, mCarrierName.c_str(), -1, tcharValue, 50 );
118  value.SetString( tcharValue );
119 
120  return value;
121 }
122 
123 //----------------------------------------------------------------------
127 //----------------------------------------------------------------------
129 {
130  CString value;
131  TCHAR tcharValue[50];
132  MultiByteToWideChar( CP_UTF8, 0, mCarrierID.c_str(), -1, tcharValue, 50 );
133  value.SetString( tcharValue );
134 
135  return value;
136 }
137 
138 //----------------------------------------------------------------------
142 //----------------------------------------------------------------------
144 {
145  return mLongTermRuleset;
146 }
147 
148 //----------------------------------------------------------------------
152 //----------------------------------------------------------------------
154 {
155  return mTimeZone;
156 }
157 
158 //----------------------------------------------------------------------
162 //----------------------------------------------------------------------
163 const std::vector<AobrdShipment> & AobrdDriverItem::getShipments() const
164 {
165  return mShipments;
166 }
167 
168 //----------------------------------------------------------------------
172 //----------------------------------------------------------------------
174 {
175  mShipments.push_back( shipment );
176 }
177 
178 //----------------------------------------------------------------------
183 //----------------------------------------------------------------------
184 void AobrdDriverItem::replaceShipment( AobrdShipment & shipment, int index )
185 {
186  deleteShipment( index );
187  mShipments.insert( mShipments.begin()+index, shipment );
188 }
189 
190 //----------------------------------------------------------------------
194 //----------------------------------------------------------------------
196 {
197  mShipments.erase( mShipments.begin()+index );
198 }
199 
200 //----------------------------------------------------------------------
205 //----------------------------------------------------------------------
207  (
208  std::istream &aStream
209  )
210 {
211 #if( FMI_SUPPORT_A615 )
212  uint16 version = 0;
213 
214  // see if the record is of the newer format
215  // older formats shouldn't have the next character be anything less than a 32
216  if ( RECORD_SEPARATOR == aStream.peek() )
217  {
218  aStream.get(); //read record separator
219  version = aStream.get();
220  }
221 #endif
222 
223  char temp;
224 
225  mDriverId.clear();
226  while( aStream.peek() != '\0' && !aStream.eof() )
227  {
228  aStream.read( &temp, 1 );
229  mDriverId.append( 1, temp );
230  }
231 
232  aStream.get(); // consume the '\0' inserted between mDriverId and mPassword
233 
234  mDriverPassword.clear();
235  while( aStream.peek() != '\0' && !aStream.eof() )
236  {
237  aStream.read( &temp, 1 );
238  mDriverPassword.append( 1, temp );
239  }
240 
241  aStream.get(); // consume the '\0' inserted after mPassword
242 
243  mFirstName.clear();
244  while( aStream.peek() != '\0' && !aStream.eof() )
245  {
246  aStream.read( &temp, 1 );
247  mFirstName.append( 1, temp );
248  }
249 
250  aStream.get(); // consume the '\0' inserted after first name
251 
252  mLastName.clear();
253  while( aStream.peek() != '\0' && !aStream.eof() )
254  {
255  aStream.read( &temp, 1 );
256  mLastName.append( 1, temp );
257  }
258 
259  aStream.get(); // consume the '\0' inserted after last name
260 
261  mCarrierName.clear();
262  while( aStream.peek() != '\0' && !aStream.eof() )
263  {
264  aStream.read( &temp, 1 );
265  mCarrierName.append( 1, temp );
266  }
267 
268  aStream.get(); // consume the '\0' inserted after carrier name
269 
270  mCarrierID.clear();
271  while( aStream.peek() != '\0' && !aStream.eof() )
272  {
273  aStream.read( &temp, 1 );
274  mCarrierID.append( 1, temp );
275  }
276 
277  aStream.get(); // consume the separator
278 
279  //read long term ruleset
280 
281  aStream >> mLongTermRuleset;
282  aStream.get(); // consume the separator
283 
284 #if( FMI_SUPPORT_A615 )
285  if (version > 0 )
286  {
287  //read load type ruleset
288 
289  aStream >> mLoadTypeRuleset;
290  aStream.get(); // consume the separator
291  }
292  else {
293  mLoadTypeRuleset = 0;
294  }
295 #endif
296 
297  //read time zone
298 
299  aStream >> mTimeZone;
300 
301  aStream.get(); // consume the '\0'
302 
303  //read shipment count and shipments
304  uint32 shipmentCount = aStream.get();
305 
306  for( uint32 i=0; i<shipmentCount; i++ )
307  {
308  AobrdShipment shipment;
309  shipment.readFromStream( aStream );
310  mShipments.push_back( shipment );
311  }
312 
313  if( !aStream.eof() )
314  {
315  mIsValid = TRUE;
316  }
317 
318  aStream.get(); // consume the '\n'
319 }
320 
321 //----------------------------------------------------------------------
324 //----------------------------------------------------------------------
326 {
327  if( mParent )
328  {
329  mParent->save();
330  }
331 }
332 
333 //----------------------------------------------------------------------
337 //----------------------------------------------------------------------
339  (
340  const key_type & aId
341  )
342 {
343  mDriverId = aId;
344 }
345 
346 //----------------------------------------------------------------------
350 //----------------------------------------------------------------------
352  (
354  )
355 {
356  mParent = aParent;
357 }
358 
359 //----------------------------------------------------------------------
363 //----------------------------------------------------------------------
365  (
366  const std::string & aPassword
367  )
368 {
369  mDriverPassword = aPassword;
370 
371  setValid();
372 }
373 
374 //----------------------------------------------------------------------
378 //----------------------------------------------------------------------
380  (
381  const std::string & aFirstName
382  )
383 {
384  mFirstName = aFirstName;
385 
386  setValid();
387 }
388 
389 //----------------------------------------------------------------------
393 //----------------------------------------------------------------------
395  (
396  const std::string & aLastName
397  )
398 {
399  mLastName = aLastName;
400 
401  setValid();
402 }
403 
404 //----------------------------------------------------------------------
408 //----------------------------------------------------------------------
410  (
411  const std::string & aCarrierName
412  )
413 {
414  mCarrierName = aCarrierName;
415 
416  setValid();
417 }
418 
419 //----------------------------------------------------------------------
423 //----------------------------------------------------------------------
425  (
426  const std::string & aCarrierID
427  )
428 {
429  mCarrierID = aCarrierID;
430 
431  setValid();
432 }
433 
434 //----------------------------------------------------------------------
438 //----------------------------------------------------------------------
440  (
441  const uint16 aRuleset
442  )
443 {
444  mLongTermRuleset = aRuleset;
445 
446  setValid();
447 }
448 
449 #if( FMI_SUPPORT_A615 )
450 //----------------------------------------------------------------------
454 //----------------------------------------------------------------------
456 {
457  return mLoadTypeRuleset;
458 }
459 
460 //----------------------------------------------------------------------
464 //----------------------------------------------------------------------
466  (
467  const uint16 aRuleset
468  )
469 {
470  mLoadTypeRuleset = aRuleset;
471 
472  setValid();
473 }
474 #endif
475 
476 //----------------------------------------------------------------------
480 //----------------------------------------------------------------------
482  (
483  const uint16 aTimeZone
484  )
485 {
486  mTimeZone = aTimeZone;
487 
488  setValid();
489 }
490 
491 //----------------------------------------------------------------------
495 //----------------------------------------------------------------------
497  (
498  std::ofstream &aStream
499  ) const
500 {
501 #if( FMI_SUPPORT_A615 )
502  // insert value below first readable ascii character as the record separator to indicate new format
503  aStream.put( RECORD_SEPARATOR );
504  aStream.put( CURRENT_VERSION );
505 #endif
506 
507  aStream << mDriverId << '\0' << mDriverPassword << '\0'
508  << mFirstName << '\0' << mLastName << '\0'
509  << mCarrierName << '\0' << mCarrierID << '\0'
510  << mLongTermRuleset << '\0'
511 #if( FMI_SUPPORT_A615 )
512  << mLoadTypeRuleset << '\0'
513 #endif
514  << mTimeZone << '\0';
515 
516  //write the shipment count and shipments
517  uint8 shipmentCount = (uint8) mShipments.size();
518  aStream.put(shipmentCount);
519 
520  for( uint8 i=0; i<shipmentCount; i++ )
521  {
522  AobrdShipment shipment = mShipments[ i ];
523  shipment.writeToStream( aStream );
524  }
525 
526  //record separator
527  aStream << '\n';
528 }
virtual ~AobrdDriverItem()
Destructor.
CString getPassword() const
Get item&#39;s password.
std::string mFirstName
The driver first name, UTF8 encoded.
void readFromStream(std::istream &aStream)
Read a AobrdDriverItem from an input stream.
void deleteShipment(int index)
Delete a shipment.
void setFirstName(const std::string &aFirstName)
Set the first name of this driver.
Data structure to holds an AOBRD shipment info. Used by the FmiApplicationLayer to provision shipment...
Definition: AobrdShipment.h:23
const key_type & getId() const
Get item&#39;s ID.
void setLoadTypeRuleset(const uint16 aRuleset)
Set the load type ruleset of this driver.
uint16 getTimeZone() const
Get item&#39;s time zone.
void setCarrierID(const std::string &aCarrierID)
Set the carrier ID of this driver.
CString getDriverId() const
Get the driver ID as a CString.
CString getFirstName() const
Get item&#39;s first name.
#define RECORD_SEPARATOR
std::string mDriverPassword
The driver password, UTF8 encoded.
AobrdDriverItem()
Constructor.
uint16 mLongTermRuleset
The driver long term ruleset.
void setParent(FileBackedMap< AobrdDriverItem > *aParent)
Set the parent map of this item.
#define CURRENT_VERSION
uint16 getLoadTypeRuleset() const
Get item&#39;s load type ruleset.
std::string mCarrierName
The driver carrier name, UTF8 encoded.
void setValid(BOOL aValid=TRUE)
Set this item as valid.
void setTimeZone(const uint16 aTimeZone)
Set the time zone of this driver.
#define TRUE
Definition: garmin_types.h:45
void writeToStream(std::ofstream &aStream) const
Write a AobrdShipment to an output stream.
CString getCarrierName() const
Get item&#39;s carrier name.
#define FMI_SUPPORT_A615
If true, app was built with support for A615 protocols.
Definition: fmi.h:69
std::string key_type
uint16 getLongTermRuleset() const
Get item&#39;s long term ruleset.
void setLongTermRuleset(const uint16 aRuleset)
Set the long term ruleset of this driver.
CString getLastName() const
Get item&#39;s last name.
unsigned short int uint16
16-bit unsigned integer
Definition: garmin_types.h:64
BOOL mIsValid
True if this list item is mIsValid.
uint16 mLoadTypeRuleset
The driver load type ruleset.
void addShipment(AobrdShipment &shipment)
Add a shipment.
const std::vector< AobrdShipment > & getShipments() const
Get the list of shipments.
void writeToStream(std::ofstream &aStream) const
Write a AobrdDriverItem to an output stream.
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
std::string mDriverId
The driver ID, UTF8 encoded.
void setCarrierName(const std::string &aCarrierName)
Set the carrier name of this driver.
void setPassword(const std::string &aPassword)
Set the password of this driver.
FileBackedMap< AobrdDriverItem > * mParent
The map that this DriverItem is a part of.
void setLastName(const std::string &aLastName)
Set the last name of this driver.
void setId(const key_type &aId)
Set the ID (key) of this item.
void save()
Save this item.
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
void save()
Save the map to disk.
std::string mCarrierID
The driver first name, UTF8 encoded.
void readFromStream(std::istream &aStream)
Read a AobrdShipment from an input stream.
std::vector< AobrdShipment > mShipments
The shipments.
uint16 mTimeZone
The driver time zone.
void replaceShipment(AobrdShipment &shipment, int index)
Update a shipment.
CString getCarrierID() const
Get item&#39;s carrier ID.
std::string mLastName
The driver last name, UTF8 encoded.