1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/ustring.hxx>
28cdf0e10cSrcweir #include <osl/module.h>
29cdf0e10cSrcweir #include <stdio.h>
30cdf0e10cSrcweir #define  DECLARE_FN_POINTERS 1
31cdf0e10cSrcweir #include "EApi.h"
32cdf0e10cSrcweir static const char *eBookLibNames[] = {
33cdf0e10cSrcweir 	"libebook-1.2.so.9", // evolution-2.8
34cdf0e10cSrcweir 	"libebook-1.2.so.5", // evolution-2.4 and 2.6+
35cdf0e10cSrcweir 	"libebook-1.2.so.3", // evolution-2.2
36cdf0e10cSrcweir 	"libebook.so.8"      // evolution-2.0
37cdf0e10cSrcweir };
38cdf0e10cSrcweir 
39cdf0e10cSrcweir typedef void (*SymbolFunc) (void);
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #define SYM_MAP(a) { #a, (SymbolFunc *)&a }
42cdf0e10cSrcweir     static struct {
43cdf0e10cSrcweir 	const char *sym_name;
44cdf0e10cSrcweir 	SymbolFunc *ref_value;
45cdf0e10cSrcweir     } aApiMap[] = {
46cdf0e10cSrcweir 	SYM_MAP( e_contact_field_name ),
47cdf0e10cSrcweir 	SYM_MAP( e_contact_get ),
48cdf0e10cSrcweir 	SYM_MAP( e_contact_get_type ),
49cdf0e10cSrcweir 	SYM_MAP( e_contact_field_id ),
50cdf0e10cSrcweir 	SYM_MAP( e_source_peek_name ),
51cdf0e10cSrcweir 	SYM_MAP( e_source_get_property ),
52cdf0e10cSrcweir 	SYM_MAP( e_source_list_peek_groups ),
53cdf0e10cSrcweir 	SYM_MAP( e_source_group_peek_sources ),
54cdf0e10cSrcweir 	SYM_MAP( e_book_new ),
55cdf0e10cSrcweir 	SYM_MAP( e_book_open ),
56cdf0e10cSrcweir 	SYM_MAP( e_book_get_uri ),
57cdf0e10cSrcweir 	SYM_MAP( e_book_get_source ),
58cdf0e10cSrcweir 	SYM_MAP( e_book_get_addressbooks ),
59cdf0e10cSrcweir 	SYM_MAP( e_book_get_contacts ),
60cdf0e10cSrcweir 	SYM_MAP( e_book_authenticate_user ),
61cdf0e10cSrcweir 	SYM_MAP( e_book_query_field_test ),
62cdf0e10cSrcweir 	SYM_MAP( e_book_query_and ),
63cdf0e10cSrcweir 	SYM_MAP( e_book_query_or ),
64cdf0e10cSrcweir 	SYM_MAP( e_book_query_not ),
65cdf0e10cSrcweir 	SYM_MAP( e_book_query_ref ),
66cdf0e10cSrcweir 	SYM_MAP( e_book_query_unref ),
67cdf0e10cSrcweir 	SYM_MAP( e_book_query_from_string ),
68cdf0e10cSrcweir 	SYM_MAP( e_book_query_to_string ),
69cdf0e10cSrcweir 	SYM_MAP( e_book_query_field_exists ),
70cdf0e10cSrcweir 	SYM_MAP( e_source_group_peek_base_uri)
71cdf0e10cSrcweir     };
72cdf0e10cSrcweir #undef SYM_MAP
73cdf0e10cSrcweir 
74cdf0e10cSrcweir static bool
tryLink(oslModule & aModule,const char * pName)75cdf0e10cSrcweir tryLink( oslModule &aModule, const char *pName )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     for( guint i = 0; i < G_N_ELEMENTS( aApiMap ); i++ )
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir 	SymbolFunc aMethod;
80cdf0e10cSrcweir 	aMethod = (SymbolFunc) osl_getFunctionSymbol
81cdf0e10cSrcweir 		( aModule, rtl::OUString::createFromAscii ( aApiMap[ i ].sym_name ).pData );
82cdf0e10cSrcweir 	if( !aMethod )
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 	    fprintf( stderr, "Warning: missing symbol '%s' in '%s'",
85cdf0e10cSrcweir 		     aApiMap[ i ].sym_name, pName );
86cdf0e10cSrcweir 	    return false;
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 	* aApiMap[ i ].ref_value = aMethod;
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir     return true;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
EApiInit()93cdf0e10cSrcweir bool EApiInit()
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     oslModule aModule;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     for( guint j = 0; j < G_N_ELEMENTS( eBookLibNames ); j++ )
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir 		aModule = osl_loadModule( rtl::OUString::createFromAscii
100cdf0e10cSrcweir 								  ( eBookLibNames[ j ] ).pData,
101cdf0e10cSrcweir 								  SAL_LOADMODULE_DEFAULT );
102cdf0e10cSrcweir 		if( aModule)
103cdf0e10cSrcweir 		{
104cdf0e10cSrcweir 		    if ( tryLink( aModule, eBookLibNames[ j ] ) )
105cdf0e10cSrcweir 				return true;
106cdf0e10cSrcweir 		    osl_unloadModule( aModule );
107cdf0e10cSrcweir 		}
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir     fprintf( stderr, "Can find no compliant libebook client libraries\n" );
110cdf0e10cSrcweir     return false;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir #if 0
114cdf0e10cSrcweir // hjs: SOLARDEF does no longer exist please lookup the required
115cdf0e10cSrcweir // defines in a regular compile line
116cdf0e10cSrcweir /*
117cdf0e10cSrcweir  * Test code - enable &
118cdf0e10cSrcweir  *
119cdf0e10cSrcweir  * Compile with ( after source LinuxIntelEnv.Set.sh )
120cdf0e10cSrcweir    gcc $SOLARDEF -I $SOLARVER/$UPD/$INPATH/inc \
121cdf0e10cSrcweir      -I. `pkg-config --cflags --libs gobject-2.0` \
122cdf0e10cSrcweir      -L $SOLARVER/$UPD/$INPATH/lib -luno_sal -lstdc++ EApi.cxx
123cdf0e10cSrcweir  */
124cdf0e10cSrcweir 
125cdf0e10cSrcweir int main( int argc, char **argv)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir     return EApiInit();
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #endif
131cdf0e10cSrcweir 
132