1 /*
2 LinphoneFriendImpl.java
3 Copyright (C) 2010  Belledonne Communications, Grenoble, France
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 */
19 package org.linphone.core;
20 
21 import java.io.Serializable;
22 
23 class LinphoneFriendListImpl implements LinphoneFriendList, Serializable {
24 
25 	protected final long nativePtr;
finalize(long nativePtr)26 	private native void finalize(long nativePtr);
newLinphoneFriendList(long corePtr)27 	private native long newLinphoneFriendList(long corePtr);
setRLSAddress(long nativePtr, long addrPtr)28 	private native void setRLSAddress(long nativePtr, long addrPtr);
setRLSUri(long nativePtr, String uri)29 	private native void setRLSUri(long nativePtr, String uri);
getRLSUri(long nativePtr)30 	private native String getRLSUri(long nativePtr);
addFriend(long nativePtr, long friendPtr)31 	private native void addFriend(long nativePtr, long friendPtr);
addLocalFriend(long nativePtr, long friendPtr)32 	private native void addLocalFriend(long nativePtr, long friendPtr);
getFriendList(long nativePtr)33 	private native LinphoneFriend[] getFriendList(long nativePtr);
updateSubscriptions(long nativePtr)34 	private native void updateSubscriptions(long nativePtr);
enableSubscriptions(long nativePtr, boolean enable)35 	private native void enableSubscriptions(long nativePtr, boolean enable);
getCore(long ptr)36 	private native Object getCore(long ptr);
findFriendByUri(long nativePtr, String uri)37 	private native LinphoneFriend findFriendByUri(long nativePtr, String uri);
setListener(long ptr, LinphoneFriendListListener listener)38 	private native void setListener(long ptr, LinphoneFriendListListener listener);
39 
LinphoneFriendListImpl(LinphoneCoreImpl core)40 	protected LinphoneFriendListImpl(LinphoneCoreImpl core)  {
41 		nativePtr = newLinphoneFriendList(core.nativePtr);
42 	}
43 
44 	@Override
setRLSAddress(LinphoneAddress addr)45 	public void setRLSAddress(LinphoneAddress addr){
46 		synchronized(getSyncObject()){
47 			setRLSAddress(nativePtr, ((LinphoneAddressImpl)addr).nativePtr);
48 		}
49 	}
50 
51 	@Override
setRLSUri(String uri)52 	public void  setRLSUri(String uri) {
53 		synchronized(getSyncObject()){
54 			setRLSUri(nativePtr, uri);
55 		}
56 	}
57 
58 	@Override
getRLSUri()59 	public String getRLSUri() {
60 		synchronized(getSyncObject()){
61 			return getRLSUri(nativePtr);
62 		}
63 	}
64 
65 	@Override
addFriend(LinphoneFriend friend)66 	public void addFriend(LinphoneFriend friend) {
67 		synchronized(getSyncObject()){
68 			addFriend(nativePtr, friend.getNativePtr());
69 		}
70 	}
71 
72 	@Override
addLocalFriend(LinphoneFriend friend)73 	public void addLocalFriend(LinphoneFriend friend) {
74 		synchronized(getSyncObject()){
75 			addLocalFriend(nativePtr, friend.getNativePtr());
76 		}
77 	}
78 
79 	@Override
getFriendList()80 	public LinphoneFriend[] getFriendList() {
81 		synchronized(getSyncObject()){
82 			return getFriendList(nativePtr);
83 		}
84 	}
85 
86 	@Override
updateSubscriptions()87 	public void updateSubscriptions() {
88 		synchronized(getSyncObject()){
89 			updateSubscriptions(nativePtr);
90 		}
91 	}
92 
93 	@Override
enableSubscriptions(boolean enable)94 	public void enableSubscriptions(boolean enable) {
95 		synchronized(getSyncObject()) {
96 			enableSubscriptions(nativePtr, enable);
97 		}
98 	}
99 
100 	@Override
findFriendByUri(String uri)101 	public LinphoneFriend findFriendByUri(String uri) {
102 		synchronized(getSyncObject()){
103 			return findFriendByUri(nativePtr,uri);
104 		}
105 	}
106 
setUri(long nativePtr, String uri)107 	private native void setUri(long nativePtr, String uri);
108 	@Override
setUri(String uri)109 	public void setUri(String uri) {
110 		synchronized(getSyncObject()) {
111 			setUri(nativePtr, uri);
112 		}
113 	}
114 
synchronizeFriendsFromServer(long nativePtr)115 	private native void synchronizeFriendsFromServer(long nativePtr);
116 	@Override
synchronizeFriendsFromServer()117 	public void synchronizeFriendsFromServer() {
118 		synchronized(getSyncObject()) {
119 			synchronizeFriendsFromServer(nativePtr);
120 		}
121 	}
122 
importFriendsFromVCardFile(long nativePtr, String file)123 	private native int importFriendsFromVCardFile(long nativePtr, String file);
124 	@Override
importFriendsFromVCardFile(String file)125 	public int importFriendsFromVCardFile(String file) {
126 		return importFriendsFromVCardFile(nativePtr, file);
127 	}
128 
importFriendsFromVCardBuffer(long nativePtr, String buffer)129 	private native int importFriendsFromVCardBuffer(long nativePtr, String buffer);
130 	@Override
importFriendsFromVCardBuffer(String buffer)131 	public int importFriendsFromVCardBuffer(String buffer) {
132 		return importFriendsFromVCardBuffer(nativePtr, buffer);
133 	}
134 
exportFriendsToVCardFile(long nativePtr, String file)135 	private native void exportFriendsToVCardFile(long nativePtr, String file);
136 	@Override
exportFriendsToVCardFile(String file)137 	public void exportFriendsToVCardFile(String file) {
138 		exportFriendsToVCardFile(nativePtr, file);
139 	}
140 
141 	@Override
setListener(LinphoneFriendListListener listener)142 	public void setListener(LinphoneFriendListListener listener) {
143 		setListener(nativePtr, listener);
144 	}
145 
146 
147 	/*reserved for JNI */
LinphoneFriendListImpl(long aNativePtr)148 	protected LinphoneFriendListImpl(long aNativePtr)  {
149 		nativePtr = aNativePtr;
150 	}
151 	@Override
finalize()152 	protected void finalize() throws Throwable {
153 		if (nativePtr != 0) {
154 			finalize(nativePtr);
155 		}
156 		super.finalize();
157 	}
158 
159 	@Override
getNativePtr()160 	public long getNativePtr() {
161 		return nativePtr;
162 	}
getSyncObject()163 	private Object getSyncObject(){
164 		 return this;
165 	}
166 }
167 
168