LibreOffice Module connectivity (master) 1
EApi.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#include <rtl/ustring.hxx>
20#include <osl/module.hxx>
21#define DECLARE_FN_POINTERS 1
22#include "EApi.h"
23static const char *eBookLibNames[] = {
24 "libebook-1.2.so.21", // evolution-data-server 3.45.2+
25 "libebook-1.2.so.20", // evolution-data-server 3.33.2+
26 "libebook-1.2.so.19", // evolution-data-server 3.24+
27 "libebook-1.2.so.16"
28};
29
30typedef void (*SymbolFunc) ();
31
32namespace {
33
34struct ApiMap
35{
36 const char *sym_name;
37 SymbolFunc *ref_value;
38};
39
40}
41
42const ApiMap aCommonApiMap[] =
43{
44 { "eds_check_version", reinterpret_cast<SymbolFunc *>(&eds_check_version) },
45 { "e_contact_field_name", reinterpret_cast<SymbolFunc *>(&e_contact_field_name) },
46 { "e_contact_get", reinterpret_cast<SymbolFunc *>(&e_contact_get) },
47 { "e_contact_get_type", reinterpret_cast<SymbolFunc *>(&e_contact_get_type) },
48 { "e_contact_field_id", reinterpret_cast<SymbolFunc *>(&e_contact_field_id) },
49 { "e_book_new", reinterpret_cast<SymbolFunc *>(&e_book_new) },
50 { "e_book_open", reinterpret_cast<SymbolFunc *>(&e_book_open) },
51 { "e_book_get_source", reinterpret_cast<SymbolFunc *>(&e_book_get_source) },
52 { "e_book_get_contacts", reinterpret_cast<SymbolFunc *>(&e_book_get_contacts) },
53 { "e_book_query_field_test", reinterpret_cast<SymbolFunc *>(&e_book_query_field_test) },
54 { "e_book_query_and", reinterpret_cast<SymbolFunc *>(&e_book_query_and) },
55 { "e_book_query_or", reinterpret_cast<SymbolFunc *>(&e_book_query_or) },
56 { "e_book_query_not", reinterpret_cast<SymbolFunc *>(&e_book_query_not) },
57 { "e_book_query_ref", reinterpret_cast<SymbolFunc *>(&e_book_query_ref) },
58 { "e_book_query_unref", reinterpret_cast<SymbolFunc *>(&e_book_query_unref) },
59 { "e_book_query_from_string", reinterpret_cast<SymbolFunc *>(&e_book_query_from_string) },
60 { "e_book_query_to_string", reinterpret_cast<SymbolFunc *>(&e_book_query_to_string) },
61 { "e_book_query_field_exists", reinterpret_cast<SymbolFunc *>(&e_book_query_field_exists) }
62};
63
64const ApiMap aNewApiMap[] =
65{
66 { "e_source_registry_list_sources", reinterpret_cast<SymbolFunc *>(&e_source_registry_list_sources) },
67 { "e_source_registry_new_sync", reinterpret_cast<SymbolFunc *>(&e_source_registry_new_sync) },
68 { "e_source_has_extension", reinterpret_cast<SymbolFunc *>(&e_source_has_extension) },
69 { "e_source_get_extension", reinterpret_cast<SymbolFunc *>(&e_source_get_extension) },
70 { "e_source_backend_get_backend_name", reinterpret_cast<SymbolFunc *>(&e_source_backend_get_backend_name) },
71 { "e_source_get_display_name", reinterpret_cast<SymbolFunc *>(&e_source_get_display_name) },
72 { "e_source_get_uid", reinterpret_cast<SymbolFunc *>(&e_source_get_uid) },
73 { "e_source_registry_ref_source", reinterpret_cast<SymbolFunc *>(&e_source_registry_ref_source) },
74 { "e_client_open_sync", reinterpret_cast<SymbolFunc *>(&e_client_open_sync) },
75 { "e_client_get_source", reinterpret_cast<SymbolFunc *>(&e_client_get_source) },
76 { "e_book_client_get_contacts_sync", reinterpret_cast<SymbolFunc *>(&e_book_client_get_contacts_sync) },
77 { "e_client_util_free_object_slist", reinterpret_cast<SymbolFunc *>(&e_client_util_free_object_slist) }
78};
79
80//>= direct read access API (>= 3.8)
81const ApiMap aClientApiMap38[] =
82{
83 { "e_book_client_connect_direct_sync", reinterpret_cast<SymbolFunc *>(&e_book_client_connect_direct_sync) }
84};
85
86template<size_t N> static bool
87tryLink( osl::Module &rModule, const char *pName, const ApiMap (&pMap)[N])
88{
89 for (size_t i = 0; i < N; ++i)
90 {
91 SymbolFunc aMethod = reinterpret_cast<SymbolFunc>(
92 rModule.getFunctionSymbol(OUString::createFromAscii(pMap[i].sym_name)));
93 if( !aMethod )
94 {
95 fprintf( stderr, "Warning: missing symbol '%s' in '%s'\n",
96 pMap[ i ].sym_name, pName );
97 return false;
98 }
99 *pMap[ i ].ref_value = aMethod;
100 }
101 return true;
102}
103
105{
106 for( guint j = 0; j < G_N_ELEMENTS( eBookLibNames ); j++ )
107 {
108 osl::Module aModule(OUString::createFromAscii(eBookLibNames[j]), SAL_LOADMODULE_DEFAULT);
109
110 if (!aModule.is())
111 continue;
112
113 if (tryLink( aModule, eBookLibNames[ j ], aCommonApiMap))
114 {
115 if (tryLink( aModule, eBookLibNames[ j ], aNewApiMap))
116 {
117 if (tryLink( aModule, eBookLibNames[ j ], aClientApiMap38))
118 {
119 aModule.release();
120 return true;
121 }
122 }
123 }
124 }
125 fprintf( stderr, "Can find no compliant libebook client libraries\n" );
126 return false;
127}
128
130{
131 static ESourceRegistry *theInstance = e_source_registry_new_sync(nullptr, nullptr);
132 return theInstance;
133}
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ESourceRegistry * get_e_source_registry()
Definition: EApi.cxx:129
bool EApiInit()
Definition: EApi.cxx:104
static const char * eBookLibNames[]
Definition: EApi.cxx:23
const ApiMap aClientApiMap38[]
Definition: EApi.cxx:81
static bool tryLink(osl::Module &rModule, const char *pName, const ApiMap(&pMap)[N])
Definition: EApi.cxx:87
void(* SymbolFunc)()
Definition: EApi.cxx:30
const ApiMap aNewApiMap[]
Definition: EApi.cxx:64
const ApiMap aCommonApiMap[]
Definition: EApi.cxx:42
EAPI_EXTERN void(* e_client_util_free_object_slist)(GSList *objects)
Definition: EApi.h:153
EAPI_EXTERN const char *(* e_contact_field_name)(EContactField field_id)
Definition: EApi.h:49
EAPI_EXTERN EBookQuery *(* e_book_query_not)(EBookQuery *q, gboolean unref)
Definition: EApi.h:114
EAPI_EXTERN ESource *(* e_client_get_source)(EClient *client)
Definition: EApi.h:151
EAPI_EXTERN gpointer(* e_source_get_extension)(ESource *source, const gchar *extension_name)
Definition: EApi.h:142
EAPI_EXTERN EContactField(* e_contact_field_id)(const char *field_name)
Definition: EApi.h:60
EAPI_EXTERN gboolean(* e_book_open)(EBook *book, gboolean only_if_exists, GError **error)
Definition: EApi.h:86
EAPI_EXTERN const gchar *(* e_source_backend_get_backend_name)(ESourceBackend *extension)
Definition: EApi.h:143
EAPI_EXTERN EBookClient *(* e_book_client_connect_direct_sync)(ESourceRegistry *registry, ESource *source, guint32 wait_for_connected_seconds, GCancellable *cancellable, GError **error)
Definition: EApi.h:149
EAPI_EXTERN const gchar *(* e_source_get_display_name)(ESource *source)
Definition: EApi.h:144
void ESourceRegistry
Definition: EApi.h:134
EAPI_EXTERN EBookQuery *(* e_book_query_field_test)(EContactField field, EBookQueryTest test, const char *value)
Definition: EApi.h:109
EAPI_EXTERN ESourceRegistry *(* e_source_registry_new_sync)(GCancellable *cancellable, GError **error)
Definition: EApi.h:139
EAPI_EXTERN EBook *(* e_book_new)(ESource *source, GError **error)
Definition: EApi.h:83
EAPI_EXTERN gpointer(* e_contact_get)(EContact *contact, EContactField field_id)
Definition: EApi.h:50
EAPI_EXTERN ESource *(* e_source_registry_ref_source)(ESourceRegistry *registry, const gchar *uid)
Definition: EApi.h:147
EAPI_EXTERN ESource *(* e_book_get_source)(EBook *book)
Definition: EApi.h:91
EAPI_EXTERN EBookQuery *(* e_book_query_ref)(EBookQuery *q)
Definition: EApi.h:115
EAPI_EXTERN gboolean(* e_source_has_extension)(ESource *source, const gchar *extension_name)
Definition: EApi.h:141
EAPI_EXTERN void(* e_book_query_unref)(EBookQuery *q)
Definition: EApi.h:116
EAPI_EXTERN EBookQuery *(* e_book_query_from_string)(const char *query_string)
Definition: EApi.h:118
EAPI_EXTERN EBookQuery *(* e_book_query_and)(int nqs, EBookQuery **qs, gboolean unref)
Definition: EApi.h:112
EAPI_EXTERN char *(* e_book_query_to_string)(EBookQuery *q)
Definition: EApi.h:117
EAPI_EXTERN gboolean(* e_book_client_get_contacts_sync)(EBookClient *client, const gchar *sexp, GSList **contacts, GCancellable *cancellable, GError **error)
Definition: EApi.h:152
EAPI_EXTERN const gchar *(* eds_check_version)(guint required_major, guint required_minor, guint required_micro)
Definition: EApi.h:145
EAPI_EXTERN GType(* e_contact_get_type)(void)
Definition: EApi.h:59
EAPI_EXTERN const gchar *(* e_source_get_uid)(ESource *source)
Definition: EApi.h:146
EAPI_EXTERN GList *(* e_source_registry_list_sources)(ESourceRegistry *registry, const gchar *extension_name)
Definition: EApi.h:140
EAPI_EXTERN gboolean(* e_book_get_contacts)(EBook *book, EBookQuery *query, GList **contacts, GError **error)
Definition: EApi.h:96
EAPI_EXTERN gboolean(* e_client_open_sync)(EClient *client, gboolean only_if_exists, GCancellable *cancellable, GError **error)
Definition: EApi.h:150
EAPI_EXTERN EBookQuery *(* e_book_query_field_exists)(EContactField field)
Definition: EApi.h:108
EAPI_EXTERN EBookQuery *(* e_book_query_or)(int nqs, EBookQuery **qs, gboolean unref)
Definition: EApi.h:113
const char * pName
int i
#define N