DeviceAtlas C++ Api documentation
carrierapi.h
1 #ifndef MOBI_MTLD_CI
2 #define MOBI_MTLD_CI
3 #include <mtld/common.h>
4 #include <fstream>
5 #include <cstring>
6 
7 #define API_CI_MAJOR_VERSION 1
8 #define API_CI_MINOR_VERSION 0
9 #define API_CI_REVISION_VERSION 0
10 
11 /*
12  * Copyright (c) DeviceAtlas Limited 2021. All Rights Reserved.
13  */
14 
15 namespace Mobi { namespace Mtld { namespace Da { namespace Carrier {
16 using namespace std;
17 
22 enum IpHeaderID {
23  IP,
24  IPID_MAX = 16
25 };
26 
27 struct HeaderParser;
28 struct BucketParser;
29 
35 struct DA_EXPORT HttpHeaders : public CommonHttpHeaders{
36  std::string evidence[IPID_MAX];
37  size_t ipheaderindex;
38  HttpHeaders(const char *ipAddr);
39  HttpHeaders(const HeaderMap & headers);
40 };
41 
42 typedef map<int32_t, int32_t> PPair;
43 typedef vector<PPair> PVPair;
44 
45 class DA_EXPORT CarrierApi : public CommonDeviceAtlas {
49  int32_t *lt;
50  int32_t *rt;
51  int32_t *vl;
52  PVPair pvalues;
53  const char *copyright;
54  const char *creationdate;
55  const char *version;
56  friend struct HeaderParser;
57  friend struct BucketParser;
58 public:
60  ~CarrierApi();
65  void loadDataFromFile(const char *);
66  int32_t getLt(int32_t idx) const { return lt[idx]; }
67  int32_t getRt(int32_t idx) const { return rt[idx]; }
68  int32_t getVl(int32_t idx) const { return vl[idx]; }
69  const PPair getPv(int32_t idx) const { return pvalues[idx]; }
70  const Value *getValue(size_t) const;
71  const char *getCopyright() const { return copyright; }
72  const char *getCreationDate() const { return creationdate; }
73  const char *getVersion() const { return version; }
74  int getDataRevision() const;
75  time_t getDataGeneration() const;
76 };
77 
78 class DA_EXPORT DeliveryContext : public CommonDeliveryContext {
79 private:
80  const CarrierApi &ci;
81 
82 public:
83  DeliveryContext(const CarrierApi &ci_, const HttpHeaders &);
84  ~DeliveryContext();
85 
86  const Property &getPropertyDescr(const char *propname, PropertyType *addAs);
87  const Property &getPropertyDescr(size_t idx) const;
88  const Value *findProperty(const Property &p) const;
89  const Value *findProperty(size_t) const;
90  void setProperty(const Property &, const Value *);
91  void setProperty(size_t, const Value *);
92 
93  const CarrierApi &getCarrierApi() const { return ci; }
94  const Value *findGlobalProperty(size_t) const;
95  const Value *findLocalProperty(size_t) const;
96  class const_iterator;
97  friend class const_iterator;
99  public:
100  typedef std::pair<const Property *, const Value *> PVPair;
101  private:
102  const DeliveryContext &props;
103  size_t idx;
104  size_t propcount;
105  friend class DeliveryContext;
106  PVPair builtin;
107  public:
108  const_iterator(const DeliveryContext &props_, size_t idx_);
109  const PVPair operator * () const;
110  const PVPair *operator -> ();
111  const_iterator &operator++();
112  bool operator==(const const_iterator &rhs) const;
113  bool operator!=(const const_iterator &rhs) const;
114  };
115 
116  // std-style const iterator for all properties.
117  const_iterator begin() const;
118  const_iterator end() const;
119  const_iterator find(const Property &) const;
120  const_iterator find(const char *) const;
121  size_t size() const;
122  size_t totalsize() const;
123  bool empty();
124  const Value *operator[](const Property &) const;
125  const Value *operator[](const char *propname) const;
126 
127 };
128 }
129 }
130 }
131 }
132 #endif
133 
HttpHeaders represents the evidence used to look up the CarrierApi for properties.
Definition: carrierapi.h:35
Definition: binary.cpp:34
Definition: common.h:230
Definition: binary.cpp:81
Definition: common.h:190
Definition: carrierapi.h:45
Definition: common.h:240
Definition: binary.h:13
Definition: common.h:140
Definition: carrierapi.h:78