build fix
[LibreOffice.git] / connectivity / source / drivers / evoab2 / EApi.cxx
blob81db0b0d83dfb1c47134a110b03c82beecba103c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <rtl/ustring.hxx>
20 #include <osl/module.hxx>
21 #define DECLARE_FN_POINTERS 1
22 #include "EApi.h"
23 static const char *eBookLibNames[] = {
24 "libebook-1.2.so.19", // evolution-data-server 3.24+
25 "libebook-1.2.so.16",
26 "libebook-1.2.so.15",
27 "libebook-1.2.so.14", // bumped again (evolution-3.6)
28 "libebook-1.2.so.13", // bumped again (evolution-3.4)
29 "libebook-1.2.so.12", // bumped again
30 "libebook-1.2.so.10", // bumped again
31 "libebook-1.2.so.9", // evolution-2.8
32 "libebook-1.2.so.5", // evolution-2.4 and 2.6+
33 "libebook-1.2.so.3", // evolution-2.2
34 "libebook.so.8" // evolution-2.0
37 typedef void (*SymbolFunc) (void);
39 #define SYM_MAP(a) { #a, reinterpret_cast<SymbolFunc *>(&a) }
40 struct ApiMap
42 const char *sym_name;
43 SymbolFunc *ref_value;
46 static const ApiMap aCommonApiMap[] =
48 SYM_MAP( eds_check_version ),
49 SYM_MAP( e_contact_field_name ),
50 SYM_MAP( e_contact_get ),
51 SYM_MAP( e_contact_get_type ),
52 SYM_MAP( e_contact_field_id ),
53 SYM_MAP( e_book_new ),
54 SYM_MAP( e_book_open ),
55 SYM_MAP( e_book_get_source ),
56 SYM_MAP( e_book_get_contacts ),
57 SYM_MAP( e_book_query_field_test ),
58 SYM_MAP( e_book_query_and ),
59 SYM_MAP( e_book_query_or ),
60 SYM_MAP( e_book_query_not ),
61 SYM_MAP( e_book_query_ref ),
62 SYM_MAP( e_book_query_unref ),
63 SYM_MAP( e_book_query_from_string ),
64 SYM_MAP( e_book_query_to_string ),
65 SYM_MAP( e_book_query_field_exists )
68 //< 3.6 api
69 static const ApiMap aOldApiMap[] =
71 SYM_MAP( e_book_get_addressbooks ),
72 SYM_MAP( e_book_get_uri ),
73 SYM_MAP( e_book_authenticate_user ),
74 SYM_MAP( e_source_group_peek_base_uri),
75 SYM_MAP( e_source_peek_name ),
76 SYM_MAP( e_source_get_property ),
77 SYM_MAP( e_source_list_peek_groups ),
78 SYM_MAP( e_source_group_peek_sources )
81 //>= 3.6 api
82 static const ApiMap aNewApiMap[] =
84 SYM_MAP( e_source_registry_list_sources ),
85 SYM_MAP( e_source_registry_new_sync ),
86 SYM_MAP( e_source_has_extension ),
87 SYM_MAP( e_source_get_extension ),
88 SYM_MAP( e_source_backend_get_backend_name ),
89 SYM_MAP( e_source_get_display_name ),
90 SYM_MAP( e_source_get_uid ),
91 SYM_MAP( e_source_registry_ref_source),
92 SYM_MAP( e_client_open_sync ),
93 SYM_MAP( e_client_get_source ),
94 SYM_MAP( e_book_client_get_contacts_sync ),
95 SYM_MAP( e_client_util_free_object_slist )
98 //== indirect read access (3.6 only)
99 static const ApiMap aClientApiMap36[] =
101 SYM_MAP( e_book_client_new )
104 //>= direct read access API (>= 3.8)
105 static const ApiMap aClientApiMap38[] =
107 SYM_MAP( e_book_client_connect_direct_sync )
110 #undef SYM_MAP
112 template<size_t N> static bool
113 tryLink( osl::Module &rModule, const char *pName, const ApiMap (&pMap)[N])
115 for (size_t i = 0; i < N; ++i)
117 SymbolFunc aMethod = reinterpret_cast<SymbolFunc>(
118 rModule.getFunctionSymbol(OUString::createFromAscii(pMap[i].sym_name)));
119 if( !aMethod )
121 fprintf( stderr, "Warning: missing symbol '%s' in '%s'\n",
122 pMap[ i ].sym_name, pName );
123 return false;
125 *pMap[ i ].ref_value = aMethod;
127 return true;
130 bool EApiInit()
132 for( guint j = 0; j < G_N_ELEMENTS( eBookLibNames ); j++ )
134 osl::Module aModule(OUString::createFromAscii(eBookLibNames[j]), SAL_LOADMODULE_DEFAULT);
136 if (!aModule.is())
137 continue;
139 if (tryLink( aModule, eBookLibNames[ j ], aCommonApiMap))
141 if (eds_check_version( 3, 6, 0 ) != nullptr)
143 if (tryLink( aModule, eBookLibNames[ j ], aOldApiMap))
145 aModule.release();
146 return true;
149 else if (tryLink( aModule, eBookLibNames[ j ], aNewApiMap))
151 if (eds_check_version( 3, 7, 6 ) != nullptr)
153 if (tryLink( aModule, eBookLibNames[ j ], aClientApiMap36))
155 aModule.release();
156 return true;
159 else
161 if (tryLink( aModule, eBookLibNames[ j ], aClientApiMap38))
163 aModule.release();
164 return true;
170 fprintf( stderr, "Can find no compliant libebook client libraries\n" );
171 return false;
174 ESourceRegistry *get_e_source_registry()
176 static ESourceRegistry *theInstance;
177 if (!theInstance)
178 theInstance = e_source_registry_new_sync(nullptr, nullptr);
179 return theInstance;
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */