⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsm_phonebook.cc

📁 对各种手机进行编程的工具包源码gsmlib 1.9版本。
💻 CC
📖 第 1 页 / 共 2 页
字号:
}Phonebook::Phonebook(string phonebookName, Ref<GsmAt> at, MeTa &myMeTa,                     bool preload) throw(GsmException) :  _phonebookName(phonebookName), _at(at), _myMeTa(myMeTa), _useCache(true){  // select phonebook  _myMeTa.setPhonebook(_phonebookName);  // query size and maximum capacity of phonebook  _size = -1;                   // -1 means not known yet  _maxSize = -1;  Parser q(_at->chat("+CPBS?", "+CPBS:"));  string dummy = q.parseString();  if (q.parseComma(true))       // this means that  {                             // used and total result is supported by ME    _size = q.parseInt();    q.parseComma();    _maxSize = q.parseInt();  }    // get basic phonebook info from ME  Parser p(_at->chat("+CPBR=?", "+CPBR:"));  // get index of actually available entries in the phonebook  vector<bool> availablePositions = p.parseIntList();  p.parseComma();  _maxNumberLength = p.parseInt();  p.parseComma();  _maxTextLength = p.parseInt();    // find out capacity of phonebook in ME  // Note: The phonebook in the ME may be sparse, eg. the range of  // allowed index numbers may be something like (3-4, 20-100, 120).  // The standard allows this, even though it is unlikely to be   // implemented like that by anyone.  // In memory we store only phonebook entries that may actually be  // used, ie. the phonebook in memory is not sparse.  // Each entry has a member _index that corresponds to the index in the ME.  if (_maxSize == -1)  {    _maxSize = 0;    for (vector<bool>::iterator i = availablePositions.begin();         i != availablePositions.end(); ++i)      if (*i) ++_maxSize;  }  // for use with preload below  int *meToPhonebookIndexMap =    (int*)alloca(sizeof(int) * (availablePositions.size() + 1));  // initialize phone book entries  if (_maxSize == 0)    _phonebook = NULL;  else    _phonebook = new PhonebookEntry[_maxSize];  int nextAvailableIndex = 0;  int i;  for (i = 0; i < _maxSize; i++)  {    while (! availablePositions[nextAvailableIndex])      nextAvailableIndex++;    _phonebook[i]._index = nextAvailableIndex;    _phonebook[i]._cached = false;    _phonebook[i]._myPhonebook = this;    meToPhonebookIndexMap[nextAvailableIndex++] = i;  }  // find out first index number of phonebook  int firstIndex = -1;  for (i = 0; i < _maxSize; i++)    if (availablePositions[i])    {      firstIndex = i;      break;    }  // preload phonebook  // Note: this contains a workaround for the bug that  // some MEs can not return the entire phonebook with one AT command  // To detect this condition, _size must be known  // also, this code only handles non-sparse phonebooks  if (preload && _size != -1 &&       (int)availablePositions.size() == _maxSize + firstIndex)  {    int entriesRead = 0;    int startIndex = firstIndex;    while (entriesRead < _size)    {      reportProgress(0, _maxSize); // chatv also calls reportProgress()      vector<string> responses =        _at->chatv("+CPBR=" + intToStr(startIndex) +                   "," + intToStr(_maxSize + firstIndex - 1),                   "+CPBR:", true);      // this means that we have read nothing even though not all      // entries have been retrieved (entriesRead < _size)      // this could be due to a malfunction of the ME...      // anyway, missing entries can be read later by readEntry()      if (responses.size() == 0)      {#ifndef NDEBUG        if (debugLevel() >= 1)          cerr << "*** error when preloading phonebook: "            "not all entries returned" << endl;#endif        break;      }      for (vector<string>::iterator i = responses.begin();           i != responses.end(); ++i)      {        string telephone, text;        int meIndex = parsePhonebookEntry(*i, telephone, text);        _phonebook[meToPhonebookIndexMap[meIndex]]._cached = true;        _phonebook[meToPhonebookIndexMap[meIndex]]._telephone = telephone;        _phonebook[meToPhonebookIndexMap[meIndex]]._text = text;        assert(_phonebook[meToPhonebookIndexMap[meIndex]]._index == meIndex);        ++entriesRead;        startIndex = meIndex + 1;#ifndef NDEBUG        if (debugLevel() >= 1)          cerr << "*** Preloading PB entry " << meIndex               << " number " << telephone                << " text " << text << endl;#endif      }    }  }}Phonebook::iterator Phonebook::begin(){  return &_phonebook[0];}Phonebook::const_iterator Phonebook::begin() const{  return &_phonebook[0];}Phonebook::iterator Phonebook::end(){  return &_phonebook[_maxSize];}Phonebook::const_iterator Phonebook::end() const{  return &_phonebook[_maxSize];}Phonebook::reference Phonebook::operator[](int n){  return _phonebook[n];}Phonebook::const_reference Phonebook::operator[](int n) const{  return _phonebook[n];}Phonebook::reference Phonebook::front(){  return _phonebook[0];}Phonebook::const_reference Phonebook::front() const{  return _phonebook[0];}Phonebook::reference Phonebook::back(){  return _phonebook[_maxSize - 1];}Phonebook::const_reference Phonebook::back() const{  return _phonebook[_maxSize - 1];}int Phonebook::size() const throw(GsmException){  if (_size != -1)    return _size;  else  {    int result = 0;    for (int i = 0; i < _maxSize; i++)      if (! _phonebook[i].empty())        result++;    Phonebook *thisPhonebook = const_cast<Phonebook*>(this);    thisPhonebook->_size = result;    return result;  }}Phonebook::iterator Phonebook::insert(iterator position,                                      const PhonebookEntry& x)  throw(GsmException){  if (x.useIndex() && x.index() != -1)    return insert(x.telephone(), x.text(), x.index());  else    return insertFirstEmpty(x.telephone(), x.text());}void Phonebook::insert (iterator pos, int n, const PhonebookEntry& x)  throw(GsmException){  for (int i = 0; i < n; i++)    if (x.useIndex() && x.index() != -1)      insert(x.telephone(), x.text(), x.index());    else      insertFirstEmpty(x.telephone(), x.text());}void Phonebook::insert (iterator pos, long n, const PhonebookEntry& x)  throw(GsmException){  for (long i = 0; i < n; i++)    if (x.useIndex() && x.index() != -1)      insert(x.telephone(), x.text(), x.index());    else      insertFirstEmpty(x.telephone(), x.text());}Phonebook::iterator Phonebook::erase(iterator position)  throw(GsmException){  if (! position->empty())  {    position->set("", "");    adjustSize(-1);  }  return position + 1;}Phonebook::iterator Phonebook::erase(iterator first, iterator last)  throw(GsmException){  iterator i;  for (i = first; i != last; ++i)    erase(i);  return i;}void Phonebook::clear() throw(GsmException){  for (iterator i = begin(); i != end(); ++i)    erase(i);}Phonebook::iterator Phonebook::find(string text) throw(GsmException){  int index;  string telephone;  int i;  for (i = 0; i < _maxSize; i++)    if (_phonebook[i].text() == text)      return begin() + i;  findEntry(text, index, telephone);    for (i = 0; i < _maxSize; i++)    if (_phonebook[i].index() == index)      if (_phonebook[i].cached())      {        // if entry was already (= cached) and is now different        // the SIM card or it's contents were changed        if (_phonebook[i]._telephone != telephone ||            _phonebook[i]._text != text)          throw GsmException(_("SIM card changed while accessing phonebook"),                             OtherError);      }      else      {        _phonebook[i]._cached = true;        _phonebook[i]._telephone = telephone;        _phonebook[i]._text = text;        return begin() + i;      }  return end();}Phonebook::~Phonebook(){  delete []_phonebook;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -