OpenAB  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PBAP.hpp
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5  */
10 #ifndef PBAP_H_
11 #define PBAP_H_
12 
13 #include <plugin/source/Source.hpp>
14 
16 #include <gio/gio.h>
17 
18 #include <iostream>
19 #include <fstream>
20 
21 #include <queue>
22 
23 #include <cstdio>
24 #include <cerrno>
25 #include <cstring>
26 #include <unistd.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 
30 #include <pthread.h>
31 #include "BluezOBEXTransfer.hpp"
32 
34 {
35  public:
36  FIFOBuffer();
37  ~FIFOBuffer();
38 
39  void tryPush(const std::string& s);
40  bool tryPop(std::string& s);
41  void close();
42 
43  private:
44  static const unsigned int fifoBufferSize = 5000000;
45  unsigned int size;
46  bool active;
47  std::queue<std::string> fifoBuffer;
48  pthread_mutex_t mutex;
49 };
50 
78 {
79  public:
83  PBAPSource(const std::string& mac, const std::string& pb,
84  const std::string& filter, unsigned int batchDownloadTime);
85 
86  virtual ~PBAPSource();
87 
89 
91 
93 
95 
97 
98  int getTotalCount() const;
99 
100  private:
104  PBAPSource(PBAPSource const &other);
105 
109  PBAPSource& operator=(PBAPSource const &other);
110 
111  void cleanup();
112 
113  static void* threadFuncFIFOWrapper(void* ptr);
114  void threadFuncFIFO();
115  static void transferStatusChanged(BluezOBEXTransfer::Status status, void*userData);
116 
117  bool createSession();
118  bool selectPhonebook();
119  bool getPhonebookSize();
120  bool getSupportedFilters();
121  bool pullPhonebook(unsigned int offset, unsigned int count);
122  bool disconnectSession();
123 
124 
125  std::string macAddress;
126  std::string pbLocation;
127  unsigned int batchDownloadDesiredTime;
128 
129 
130  std::vector<std::string> ignoredFields;
131  std::vector<std::string> filters;
132  std::vector<std::string> supportedFilters;
133 
134  std::string tempFIFO;
135  FIFOBuffer fifoBuffer;
136  pthread_t threadFIFO;
137  bool threadCreated;
138 
139  GDBusConnection* connection;
140  GDBusProxy* proxyClient1;
141  GDBusProxy* proxyPhonebookAccess1;
142  GDBusProxy* proxyTransfer1;
143  BluezOBEXTransfer transfer;
144  OpenAB_Source::Source::eGetItemRet transferStatus;
145 
146  std::string sessionPath;
147  unsigned int phonebookSize;
148 };
149 
150 #endif // PBAP_H_
Documentation for class BluezOBEXTransfer.
Definition: BluezOBEXTransfer.hpp:18
PBAPSource(const std::string &mac, const std::string &pb, const std::string &filter, unsigned int batchDownloadTime)
Constructor.
Definition: PBAP.cpp:17
eCancelRet
Definition: Source.hpp:138
eResumeRet
Definition: Source.hpp:123
void close()
Definition: PBAP.cpp:741
enum OpenAB_Source::Source::eResumeRet resume()
Resumes Source, if such operation is supported.
Definition: PBAP.cpp:512
bool tryPop(std::string &s)
Definition: PBAP.cpp:723
void tryPush(const std::string &s)
Definition: PBAP.cpp:706
int getTotalCount() const
Returns total count of items available from Source, if such information is available.
Definition: PBAP.cpp:540
eSuspendRet
Definition: Source.hpp:108
Definition: PBAP.hpp:77
enum OpenAB_Source::Source::eCancelRet cancel()
Cancels Source, if such operation is supported. After canceling Source next call to getVCard() should...
Definition: PBAP.cpp:523
Documentation for Source plugin interface.
Definition: Source.hpp:76
eGetItemRet
Definition: Source.hpp:155
enum OpenAB_Source::Source::eSuspendRet suspend()
Suspends Source, if such operation is supported.
Definition: PBAP.cpp:494
enum OpenAB_Source::Source::eInit init()
Initializes Source.
Definition: PBAP.cpp:98
Status
Definition: BluezOBEXTransfer.hpp:21
virtual ~PBAPSource()
Definition: PBAP.cpp:58
Definition: PBAP.hpp:33
FIFOBuffer()
Definition: PBAP.cpp:694
enum OpenAB_Source::Source::eGetItemRet getItem(OpenAB::SmartPtr< OpenAB::PIMItem > &item)
Gets PIM Item from Source. If Source is suspended getItem() should block until Source will be resumed...
Definition: PBAP.cpp:460
eInit
Definition: Source.hpp:94
~FIFOBuffer()
Definition: PBAP.cpp:701