Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2013, Regents of the University of California |
| 4 | * Yingdi Yu |
| 5 | * |
| 6 | * BSD license, See the LICENSE file for more information |
| 7 | * |
| 8 | * Author: Yingdi Yu <yingdi@cs.ucla.edu> |
| 9 | */ |
| 10 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 11 | #ifndef CHRONOS_CONTACT_STORAGE_H |
| 12 | #define CHRONOS_CONTACT_STORAGE_H |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 13 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 14 | #include "contact-item.h" |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 15 | #include <sqlite3.h> |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 16 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 17 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 18 | namespace chronos{ |
| 19 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 20 | class ContactStorage |
| 21 | { |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 22 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 23 | public: |
Yingdi Yu | c9ffa9f | 2014-01-13 11:19:47 -0800 | [diff] [blame] | 24 | struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} }; |
| 25 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 26 | ContactStorage(); |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 27 | |
Yingdi Yu | aa8d769 | 2013-10-18 17:05:02 -0700 | [diff] [blame] | 28 | ~ContactStorage() |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 29 | { sqlite3_close(m_db); } |
| 30 | |
| 31 | ndn::shared_ptr<Profile> |
| 32 | getSelfProfile(const ndn::Name& identity) const; |
| 33 | |
| 34 | // ndn::Block |
| 35 | // getSelfEndorseCertificate(const ndn::Name& identity); |
| 36 | |
| 37 | void |
| 38 | addSelfEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity); |
| 39 | |
| 40 | // ndn::Block |
| 41 | // getEndorseCertificate(const ndn::Name& identity); |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 42 | |
| 43 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 44 | addEndorseCertificate(const EndorseCertificate& endorseCertificate, const ndn::Name& identity); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 45 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 46 | void |
| 47 | updateCollectEndorse(const EndorseCertificate& endorseCertificate); |
| 48 | |
| 49 | void |
| 50 | getCollectEndorseList(const ndn::Name& name, std::vector<ndn::Buffer>& endorseList); |
| 51 | |
| 52 | void |
| 53 | getEndorseList(const ndn::Name& identity, std::vector<std::string>& endorseList); |
| 54 | |
| 55 | |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 56 | |
| 57 | void |
Yingdi Yu | 908f841 | 2013-11-09 00:03:26 -0800 | [diff] [blame] | 58 | removeContact(const ndn::Name& identity); |
| 59 | |
| 60 | void |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 61 | addContact(const ContactItem& contactItem); |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 62 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 63 | ndn::shared_ptr<ContactItem> |
| 64 | getContact(const ndn::Name& name); |
| 65 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 66 | void |
| 67 | updateIsIntroducer(const ndn::Name& identity, bool isIntroducer); |
| 68 | |
Yingdi Yu | 79c25a2 | 2013-10-21 13:38:38 -0700 | [diff] [blame] | 69 | void |
| 70 | updateAlias(const ndn::Name& identity, std::string alias); |
| 71 | |
Yingdi Yu | 6420611 | 2013-12-24 11:16:32 +0800 | [diff] [blame] | 72 | void |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 73 | getAllContacts(std::vector<ndn::shared_ptr<ContactItem> >& contacts) const; |
Yingdi Yu | d40226b | 2013-10-23 14:05:12 -0700 | [diff] [blame] | 74 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 75 | |
Yingdi Yu | 8dacdf2 | 2013-11-05 23:06:43 -0800 | [diff] [blame] | 76 | |
| 77 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 78 | private: |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 79 | void |
| 80 | initializeTable(const std::string& tableName, const std::string& sqlCreateStmt); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 81 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 82 | bool |
Yingdi Yu | 813d4e9 | 2013-11-03 16:22:05 -0800 | [diff] [blame] | 83 | doesContactExist(const ndn::Name& name); |
Yingdi Yu | 0a6b6c5 | 2013-10-15 17:54:00 -0700 | [diff] [blame] | 84 | |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 85 | private: |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 86 | sqlite3 *m_db; |
| 87 | }; |
| 88 | |
Yingdi Yu | a1a688f | 2014-02-06 18:09:22 -0800 | [diff] [blame^] | 89 | }//chronos |
Yingdi Yu | ede8eaf | 2013-10-14 14:07:03 -0700 | [diff] [blame] | 90 | #endif |