From f413690a51d341752cb6149d139f5fee2fe81792 Mon Sep 17 00:00:00 2001 From: cdfrey Date: Fri, 8 Dec 2006 21:35:23 +0000 Subject: [PATCH] - added examples/ directory, with first addcontact.cc example --- Makefile.am | 2 +- buildgen.sh | 2 +- configure.ac | 5 ++- examples/Makefile.am | 10 +++++ examples/addcontact.cc | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 examples/Makefile.am create mode 100644 examples/addcontact.cc diff --git a/Makefile.am b/Makefile.am index 81d0690b..0e8e463a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ EXTRA_DIST = COPYING ChangeLog README -SUBDIRS = . src tools +SUBDIRS = . src tools examples all-local: rm -f barry diff --git a/buildgen.sh b/buildgen.sh index 3332ad67..1c3e9e20 100755 --- a/buildgen.sh +++ b/buildgen.sh @@ -8,7 +8,7 @@ if [ "$1" = "clean" ] ; then rm -rf autom4te.cache rm -f Makefile.in aclocal.m4 config.guess config.h.in config.sub \ configure depcomp install-sh ltmain.sh missing \ - src/Makefile.in tools/Makefile.in + src/Makefile.in tools/Makefile.in examples/Makefile.in else autoreconf -if #autoreconf -ifv diff --git a/configure.ac b/configure.ac index e8b2faf5..a5b73958 100644 --- a/configure.ac +++ b/configure.ac @@ -23,7 +23,7 @@ AC_ARG_WITH(libusb, [LIBUSB_LIB_PATH="/usr/lib" LIBUSB_INC_PATH="/usr/include"]) AC_ARG_WITH(boost, - [ --with-boost= root path of boost installation], + [ --with-boost= root path of boost installation (default=no boost)], [BOOST_LIB_PATH="$with_boost/lib" BOOST_INC_PATH="$with_boost/include" BOOST_ENABLED="true"], @@ -64,6 +64,7 @@ AC_CHECK_FUNCS([bzero gettimeofday memset select strcasecmp strchr strerror strt AC_CONFIG_FILES([Makefile src/Makefile - tools/Makefile]) + tools/Makefile + examples/Makefile]) AC_OUTPUT diff --git a/examples/Makefile.am b/examples/Makefile.am new file mode 100644 index 00000000..542e0a27 --- /dev/null +++ b/examples/Makefile.am @@ -0,0 +1,10 @@ + +#DEFAULT_INCLUDES = +INCLUDES = -I@LIBUSB_INC_PATH@ +AM_CXXFLAGS = -ansi -Wall -g + +noinst_PROGRAMS = addcontact + +addcontact_SOURCES = addcontact.cc +addcontact_LDADD = ../src/libbarry.la + diff --git a/examples/addcontact.cc b/examples/addcontact.cc new file mode 100644 index 00000000..eb5c4f4e --- /dev/null +++ b/examples/addcontact.cc @@ -0,0 +1,101 @@ +/// +/// \file addcontact.cc +/// Example code using the Barry library to add a contact +/// to a Blackberry device. +/// + +/* + Copyright (C) 2006, Net Direct Inc. (http://www.netdirect.ca/) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License in the COPYING file at the + root directory of this project for more details. +*/ + +#include +#include + +using namespace std; +using namespace Barry; + + +void ReadLine(const char *prompt, std::string &data) +{ + cout << prompt << ": "; + getline(cin, data); +} + +void ReadInput(Barry::Contact &contact) +{ + ReadLine("First Name", contact.FirstName); + ReadLine("Last Name", contact.LastName); + ReadLine("Title", contact.Title); + ReadLine("Email Address", contact.Email); + ReadLine("Main Phone Number", contact.Phone); + ReadLine("Home Phone Number", contact.HomePhone); + ReadLine("Work Phone Number", contact.WorkPhone); + ReadLine("Fax Number", contact.Fax); + ReadLine("Cell Number", contact.MobilePhone); + ReadLine("Pager Number", contact.Pager); + ReadLine("Company", contact.Company); + ReadLine("Address Line 1", contact.Address1); + ReadLine("Address Line 2", contact.Address2); + ReadLine("Address Line 3", contact.Address3); + ReadLine("City", contact.City); + ReadLine("Province / State", contact.Province); + ReadLine("Country", contact.Country); + ReadLine("Postal / Zip Code", contact.PostalCode); + ReadLine("Notes", contact.Notes); +} + +void Upload(const Barry::ProbeResult &device, const Barry::Contact &contact) +{ + // connect to address book + Controller con(device); + con.OpenMode(Controller::Desktop); + unsigned int id = con.GetDBID("Address Book"); + + // find out what records are already there, and make new record ID + RecordStateTable table; + con.GetRecordStateTable(id, table); + uint32_t recordId = table.MakeNewRecordId(); + + // add it + con.AddRecordByType(recordId, contact); + cout << "Added successfully." << endl; +} + +int main(int argc, char *argv[]) +{ + try { + + Barry::Init(); + + Barry::Probe probe; + if( probe.GetCount() == 0 ) { + cout << "No Blackberry found!" << endl; + return 1; + } + + + Barry::Contact contact; + ReadInput(contact); + Upload(probe.Get(0), contact); + + } + catch( std::exception &e ) { + std::cerr << "Exception caught: " << e.what() << endl; + return 1; + } + + return 0; +} + -- 2.11.4.GIT