pbap client: add skeleton
This new backend represents a phonebook accessible using the Bluetooth PBAP profile.
This commit is contained in:
parent
5ea4afddaa
commit
a961533556
119
src/backends/pbap/PbapSyncSource.cpp
Normal file
119
src/backends/pbap/PbapSyncSource.cpp
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2009 Patrick Ohly <patrick.ohly@gmx.de>
|
||||
* Copyright (C) 2009 Intel Corporation
|
||||
* Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) version 3.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef ENABLE_PBAP
|
||||
|
||||
#include "PbapSyncSource.h"
|
||||
|
||||
// SyncEvolution includes a copy of Boost header files.
|
||||
// They are safe to use without creating additional
|
||||
// build dependencies. boost::filesystem requires a
|
||||
// library and therefore is avoided here. Some
|
||||
// utility functions from SyncEvolution are used
|
||||
// instead, plus standard C/Posix functions.
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <syncevo/util.h>
|
||||
|
||||
#include "src/gdbusxx/gdbus-cxx-bridge.h"
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
#include <syncevo/SyncContext.h>
|
||||
#include <syncevo/declarations.h>
|
||||
SE_BEGIN_CXX
|
||||
|
||||
PbapSyncSource::PbapSyncSource(const SyncSourceParams ¶ms) :
|
||||
TrackingSyncSource(params)
|
||||
{
|
||||
}
|
||||
|
||||
std::string PbapSyncSource::getMimeType() const
|
||||
{
|
||||
return "text/x-vcard";
|
||||
}
|
||||
|
||||
std::string PbapSyncSource::getMimeVersion() const
|
||||
{
|
||||
return "2.1";
|
||||
}
|
||||
|
||||
void PbapSyncSource::open()
|
||||
{
|
||||
const string &database = getDatabaseID();
|
||||
const string prefix("obex-bt://");
|
||||
|
||||
if (!boost::starts_with(database, prefix)) {
|
||||
throwError("database should specifiy device address (obex-bt://<bt-addr>)");
|
||||
}
|
||||
|
||||
std::string address = database.substr(prefix.size());
|
||||
}
|
||||
|
||||
bool PbapSyncSource::isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void PbapSyncSource::close()
|
||||
{
|
||||
}
|
||||
|
||||
PbapSyncSource::Databases PbapSyncSource::getDatabases()
|
||||
{
|
||||
Databases result;
|
||||
|
||||
result.push_back(Database("select database via bluetooth address",
|
||||
"[obex-bt://]<bt-addr>"));
|
||||
return result;
|
||||
}
|
||||
|
||||
void PbapSyncSource::listAllItems(RevisionMap_t &revisions)
|
||||
{
|
||||
}
|
||||
|
||||
void PbapSyncSource::readItem(const string &uid, std::string &item, bool raw)
|
||||
{
|
||||
}
|
||||
|
||||
TrackingSyncSource::InsertItemResult PbapSyncSource::insertItem(const string &uid, const std::string &item, bool raw)
|
||||
{
|
||||
throw std::runtime_error("Operation not supported");
|
||||
}
|
||||
|
||||
void PbapSyncSource::removeItem(const string &uid)
|
||||
{
|
||||
throw std::runtime_error("Operation not supported");
|
||||
}
|
||||
|
||||
SE_END_CXX
|
||||
|
||||
#endif /* ENABLE_PBAP */
|
||||
|
||||
#ifdef ENABLE_MODULES
|
||||
# include "PbapSyncSourceRegister.cpp"
|
||||
#endif
|
62
src/backends/pbap/PbapSyncSource.h
Normal file
62
src/backends/pbap/PbapSyncSource.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2009 Patrick Ohly <patrick.ohly@gmx.de>
|
||||
* Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) version 3.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef INCL_PBAPSYNCSOURCE
|
||||
#define INCL_PBAPSYNCSOURCE
|
||||
|
||||
#include <syncevo/TrackingSyncSource.h>
|
||||
|
||||
#ifdef ENABLE_PBAP
|
||||
|
||||
#include <memory>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
SE_BEGIN_CXX
|
||||
|
||||
class PbapSyncSource : public TrackingSyncSource, private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
PbapSyncSource(const SyncSourceParams ¶ms);
|
||||
|
||||
|
||||
protected:
|
||||
/* implementation of SyncSource interface */
|
||||
virtual void open();
|
||||
virtual bool isEmpty();
|
||||
virtual void close();
|
||||
virtual Databases getDatabases();
|
||||
virtual std::string getMimeType() const;
|
||||
virtual std::string getMimeVersion() const;
|
||||
|
||||
/* implementation of TrackingSyncSource interface */
|
||||
virtual void listAllItems(RevisionMap_t &revisions);
|
||||
//virtual InsertItemResult insertItem(const string &luid, const std::string &item, bool raw);
|
||||
virtual InsertItemResult insertItem(const string &luid, const std::string &item, bool raw);
|
||||
void readItem(const std::string &luid, std::string &item, bool raw);
|
||||
virtual void removeItem(const string &uid);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
SE_END_CXX
|
||||
|
||||
#endif // ENABLE_PBAP
|
||||
#endif // INCL_PBAPSYNCSOURCE
|
143
src/backends/pbap/PbapSyncSourceRegister.cpp
Normal file
143
src/backends/pbap/PbapSyncSourceRegister.cpp
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
|
||||
* Copyright (C) 2009 Intel Corporation
|
||||
* Copyright (C) 2012 BMW Car IT GmbH. All rights reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) version 3.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "PbapSyncSource.h"
|
||||
#include "test.h"
|
||||
|
||||
#include <syncevo/declarations.h>
|
||||
SE_BEGIN_CXX
|
||||
|
||||
static SyncSource *createSource(const SyncSourceParams ¶ms)
|
||||
{
|
||||
SE_LOG_DEBUG(NULL, NULL, "---> PBAP::createSource()");
|
||||
|
||||
SourceType sourceType = SyncSource::getSourceType(params.m_nodes);
|
||||
// The string returned by getSourceType() is always the one
|
||||
// registered as main Aliases() below.
|
||||
bool isMe = sourceType.m_backend == "PBAP Address Book";
|
||||
|
||||
#ifndef ENABLE_PBAP
|
||||
// tell SyncEvolution if the user wanted to use a disabled sync source,
|
||||
// otherwise let it continue searching
|
||||
return isMe ? RegisterSyncSource::InactiveSource : NULL;
|
||||
#else
|
||||
// Also recognize one of the standard types?
|
||||
// Not in the PbapSyncSource!
|
||||
bool maybeMe = false /* sourceType.m_backend == "addressbook" */;
|
||||
|
||||
if (isMe || maybeMe) {
|
||||
return new PbapSyncSource(params);
|
||||
}
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static RegisterSyncSource registerMe("One-way sync using PBAP",
|
||||
#ifdef ENABLE_PBAP
|
||||
true,
|
||||
#else
|
||||
false,
|
||||
#endif
|
||||
createSource,
|
||||
"One-way sync using PBAP = pbap\n"
|
||||
" Requests phonebook entries using PBAP profile, and thus\n"
|
||||
" supporting read-only operations.\n"
|
||||
" The BT address is selected via database=obex-bt://<bt-addr>.\n",
|
||||
Values() +
|
||||
(Aliases("PBAP Address Book") + "pbap"));
|
||||
|
||||
#ifdef ENABLE_PBAP
|
||||
|
||||
// The anonymous namespace ensures that we don't get
|
||||
// name clashes: although the classes and objects are
|
||||
// only defined in this file, the methods generated
|
||||
// for local classes will clash with other methods
|
||||
// of other classes with the same name if no namespace
|
||||
// is used.
|
||||
//
|
||||
// The code above is not yet inside the anonymous
|
||||
// name space because it would show up inside
|
||||
// the CPPUnit unit test names. Use a unique class
|
||||
// name there.
|
||||
namespace {
|
||||
#if 0
|
||||
}
|
||||
#endif
|
||||
|
||||
static class VCard30Test : public RegisterSyncSourceTest {
|
||||
public:
|
||||
VCard30Test() : RegisterSyncSourceTest("file_contact", "eds_contact") {}
|
||||
|
||||
virtual void updateConfig(ClientTestConfig &config) const
|
||||
{
|
||||
config.m_type = "file:text/vcard:3.0";
|
||||
}
|
||||
} VCard30Test;
|
||||
|
||||
static class ICal20Test : public RegisterSyncSourceTest {
|
||||
public:
|
||||
ICal20Test() : RegisterSyncSourceTest("file_event", "eds_event") {}
|
||||
|
||||
virtual void updateConfig(ClientTestConfig &config) const
|
||||
{
|
||||
config.m_type = "file:text/calendar:2.0";
|
||||
|
||||
// A sync source which supports linked items (= recurring
|
||||
// event with detached exception) is expected to handle
|
||||
// inserting the parent or child twice by turning the
|
||||
// second operation into an update. The file backend is
|
||||
// to dumb for that and therefore fails these tests:
|
||||
//
|
||||
// Client::Source::file_event::testLinkedItemsInsertParentTwice
|
||||
// Client::Source::file_event::testLinkedItemsInsertChildTwice
|
||||
//
|
||||
// Disable linked item testing to avoid this.
|
||||
config.m_sourceKnowsItemSemantic = false;
|
||||
}
|
||||
} ICal20Test;
|
||||
|
||||
static class ITodo20Test : public RegisterSyncSourceTest {
|
||||
public:
|
||||
ITodo20Test() : RegisterSyncSourceTest("file_task", "eds_task") {}
|
||||
|
||||
virtual void updateConfig(ClientTestConfig &config) const
|
||||
{
|
||||
config.m_type = "file:text/calendar:2.0";
|
||||
}
|
||||
} ITodo20Test;
|
||||
|
||||
static class SuperTest : public RegisterSyncSourceTest {
|
||||
public:
|
||||
SuperTest() : RegisterSyncSourceTest("file_calendar+todo", "calendar+todo") {}
|
||||
|
||||
virtual void updateConfig(ClientTestConfig &config) const
|
||||
{
|
||||
config.m_type = "virtual:text/x-vcalendar";
|
||||
config.m_subConfigs = "file_event,file_task";
|
||||
}
|
||||
|
||||
} superTest;
|
||||
|
||||
}
|
||||
|
||||
#endif // ENABLE_PBAP
|
||||
|
||||
SE_END_CXX
|
36
src/backends/pbap/configure-sub.in
Normal file
36
src/backends/pbap/configure-sub.in
Normal file
|
@ -0,0 +1,36 @@
|
|||
dnl -*- mode: Autoconf; -*-
|
||||
dnl Invoke autogen.sh to produce a configure script.
|
||||
|
||||
dnl Checks for required libraris can go here; none required for simple files.
|
||||
dnl
|
||||
dnl This is from the sqlite backend:
|
||||
dnl PKG_CHECK_MODULES(SQLITE, sqlite3, SQLITEFOUND=yes, [SQLITEFOUND=no])
|
||||
dnl AC_SUBST(SQLITE_CFLAGS)
|
||||
dnl AC_SUBST(SQLITE_LIBS)
|
||||
|
||||
PBAP_CFLAGS=
|
||||
PBAP_LIBS=
|
||||
AC_SUBST(PBAP_CFLAGS)
|
||||
AC_SUBST(BAP_LIBS)
|
||||
|
||||
dnl If additional compile flags are necessary to include the header
|
||||
dnl files of the backend, then add them here.
|
||||
BACKEND_CPPFLAGS="$BACKEND_CPPFLAGS $PBAP_CFLAGS"
|
||||
|
||||
dnl name of backend library (there could be more than one per directory),
|
||||
dnl name of the directory,
|
||||
dnl help string,
|
||||
dnl --enable/disable chosen explicitly
|
||||
dnl default, may depend on availability of prerequisites in more complex backends
|
||||
SE_ARG_ENABLE_BACKEND(pbap,
|
||||
pbap,
|
||||
[AS_HELP_STRING([--disable-pbap],
|
||||
[disable pbap-based backend which provides one-way synchronization (default on)])],
|
||||
[enable_pbap="$enableval"],
|
||||
[enable_pbap="yes"]
|
||||
)
|
||||
|
||||
if test "$enable_pbap" = "yes"; then
|
||||
dnl It's good to check the prerequisites here, in case --enable-pbap was used.
|
||||
AC_DEFINE(ENABLE_PBAP, 1, [pbap available])
|
||||
fi
|
29
src/backends/pbap/pbap.am
Normal file
29
src/backends/pbap/pbap.am
Normal file
|
@ -0,0 +1,29 @@
|
|||
dist_noinst_DATA += src/backends/pbap/configure-sub.in
|
||||
|
||||
src_backends_pbap_lib = src/backends/pbap/syncpbap.la
|
||||
MOSTLYCLEANFILES += $(src_backends_pbap_lib)
|
||||
if ENABLE_MODULES
|
||||
src_backends_pbap_backenddir = $(BACKENDS_DIRECTORY)
|
||||
src_backends_pbap_backend_LTLIBRARIES = $(src_backends_pbap_lib)
|
||||
else
|
||||
noinst_LTLIBRARIES += $(src_backends_pbap_lib)
|
||||
endif
|
||||
|
||||
src_backends_pbap_src = \
|
||||
src/backends/pbap/PbapSyncSource.h \
|
||||
src/backends/pbap/PbapSyncSource.cpp
|
||||
|
||||
src_backends_pbap_syncpbap_la_SOURCES = $(src_backends_pbap_src)
|
||||
src_backends_pbap_syncpbap_la_LIBADD = $(PBAP_LIBS) $(SYNCEVOLUTION_LIBS)
|
||||
src_backends_pbap_syncpbap_la_LDFLAGS = -module -avoid-version
|
||||
src_backends_pbap_syncpbap_la_CXXFLAGS = $(SYNCEVOLUTION_CXXFLAGS) $(SYNCEVO_WFLAGS)
|
||||
src_backends_pbap_syncpbap_la_CPPFLAGS = $(SYNCEVOLUTION_CFLAGS) -I$(top_srcdir)/test $(BACKEND_CPPFLAGS)
|
||||
src_backends_pbap_syncpbap_la_DEPENDENCIES = $(SYNCEVOLUTION_LIBS)
|
||||
|
||||
# If you need special test cases for your sync source, then
|
||||
# install them here. Here's how the sqlite backend does that:
|
||||
#
|
||||
#../../testcases/sqlite_vcard21.vcf: $(FUNAMBOL_SUBDIR)/test/test/testcases/vcard21.vcf
|
||||
# mkdir -p ${@D}
|
||||
# perl -e '$$_ = join("", <>); s/^(ADR|TEL|EMAIL|PHOTO).*?(?=^\S)//msg; s/;X-EVOLUTION-UI-SLOT=\d+//g; print;' $< >$@
|
||||
#all: ../../testcases/sqlite_vcard21.vcf
|
Loading…
Reference in a new issue