contactprovider.c 4.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 *  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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

17
#include "contact_providers_priv.h"
18
#include "contactprovider.h"
19
#include <linphonecore.h>
20

21 22 23
/* ############################ *
 * LinphoneContactSearchRequest *
 * ############################ */
24

25 26 27 28
void linphone_contact_search_init(LinphoneContactSearch* obj,
								const char* predicate,
								ContactSearchCallback cb,
								void* cb_data)
29
{
30 31 32 33 34 35 36 37 38
	static unsigned int request_id_counter = 1;
	obj->id = request_id_counter++; // unique id
	obj->predicate = ms_strdup(predicate?predicate:"");
	obj->cb   = cb;
	obj->data = cb_data;
}

static void linphone_contact_search_destroy( LinphoneContactSearch* req) {
	if( req->predicate ) ms_free(req->predicate);
39 40
}

41
ContactSearchID linphone_contact_search_get_id(LinphoneContactSearch* obj)
42
{
43 44
	return obj->id;
}
45

46 47 48
const char*linphone_contact_search_get_predicate(LinphoneContactSearch* obj)
{
	return obj->predicate;
49 50
}

51 52
void linphone_contact_search_invoke_cb(LinphoneContactSearch* req, MSList* friends)
{
53
	if( req->cb ) req->cb(req, friends, req->data);
54 55 56 57 58 59 60 61
}

int linphone_contact_search_compare(const void* a, const void* b) {
	LinphoneContactSearch *ra=((LinphoneContactSearch*)a);
	LinphoneContactSearch *rb=((LinphoneContactSearch*)b);
	return !(ra->id == rb->id); // return 0 if id is equal, 1 otherwise
}

62
LinphoneContactSearch*linphone_contact_search_ref(void* obj)
63 64 65 66 67 68 69 70 71 72 73 74 75 76
{
	return LINPHONE_CONTACT_SEARCH(belle_sip_object_ref(obj));
}

void linphone_ldap_contact_search_unref(void* obj)
{
	belle_sip_object_unref(obj);
}

LinphoneContactSearch* linphone_contact_search_cast(void* obj)
{
	return LINPHONE_CONTACT_SEARCH(obj);
}

77 78 79 80 81 82 83 84 85
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneContactSearch);

BELLE_SIP_INSTANCIATE_VPTR(LinphoneContactSearch,belle_sip_object_t,
	(belle_sip_object_destroy_t)linphone_contact_search_destroy,
	NULL, // clone
	NULL, // marshal
	FALSE
);

86 87 88 89 90


/* ####################### *
 * LinphoneContactProvider *
 * ####################### */
91 92 93 94 95 96 97 98 99 100


void linphone_contact_provider_init(LinphoneContactProvider* obj, LinphoneCore* lc){
	obj->lc = lc;
}

static void contact_provider_destroy(LinphoneContactProvider* obj){
	(void)obj;
}

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
LinphoneContactSearch* linphone_contact_provider_begin_search(LinphoneContactProvider* obj, const char* predicate, ContactSearchCallback cb, void* data)
{
	return BELLE_SIP_OBJECT_VPTR(obj,LinphoneContactProvider)->begin_search( LINPHONE_CONTACT_PROVIDER(obj), predicate, cb, data);
}

unsigned int linphone_contact_provider_cancel_search(LinphoneContactProvider* obj, LinphoneContactSearch* request)
{
	return BELLE_SIP_OBJECT_VPTR(obj,LinphoneContactProvider)->cancel_search( LINPHONE_CONTACT_PROVIDER(obj), request);
}

LinphoneContactProvider* linphone_contact_provider_ref(void* obj)
{
	return LINPHONE_CONTACT_PROVIDER(belle_sip_object_ref(obj));
}

void linphone_contact_provider_unref(void* obj)
{
	belle_sip_object_unref(obj);
}

LinphoneContactProvider*linphone_contact_provider_cast(void* obj)
{
	return LINPHONE_CONTACT_PROVIDER(obj);
}
125 126

BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneContactProvider);
127
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(LinphoneContactProvider)
128 129 130 131 132 133 134 135 136 137
	{
		BELLE_SIP_VPTR_INIT(LinphoneContactProvider,belle_sip_object_t,TRUE),
		(belle_sip_object_destroy_t) contact_provider_destroy,
		NULL,/*no clone*/
		NULL,/*no marshal*/
	},
	"",
	// Pure virtual
	NULL, /* begin_search -> pure virtual */
	NULL  /* cancel_search -> pure virtual */
138
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END