blob: 40cf101274cde336d6ff47caee668d3f959da1a1 [file] [log] [blame]
Adrien Béraud04d822c2015-04-02 17:44:36 -04001/*
2 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3 * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * Additional permission under GNU GPL version 3 section 7:
19 *
20 * If you modify this program, or any covered work, by linking or
21 * combining it with the OpenSSL project's OpenSSL library (or a
22 * modified version of that library), containing parts covered by the
23 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
24 * grants you additional permission to convey the resulting work.
25 * Corresponding Source for a non-source form of such a combination
26 * shall include the source code for the parts of OpenSSL used as well
27 * as that of the covered work.
28 */
29
30/* File : jni_interface.i */
31%module (directors="1") Ringservice
32
33#define SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON
34%include "typemaps.i"
35%include "std_string.i" /* std::string typemaps */
36%include "enums.swg"
37%include "arrays_java.i";
38%include "carrays.i";
39%include "std_map.i";
40%include "std_vector.i";
41%include "stdint.i";
Adrien Béraud7f97ca92015-06-07 15:36:06 -040042%header %{
43
44#include <android/log.h>
45
46%}
Adrien Béraud04d822c2015-04-02 17:44:36 -040047
48/* void* shall be handled as byte arrays */
49%typemap(jni) void * "void *"
50%typemap(jtype) void * "byte[]"
51%typemap(jstype) void * "byte[]"
52%typemap(javain) void * "$javainput"
53%typemap(in) void * %{
54 $1 = $input;
55%}
56%typemap(javadirectorin) void * "$jniinput"
57%typemap(out) void * %{
58 $result = $1;
59%}
60%typemap(javaout) void * {
61 return $jnicall;
62}
63
64namespace std {
Adrien Béraud7f97ca92015-06-07 15:36:06 -040065
Adrien Béraudb30e6dd2015-06-10 12:22:15 -040066%typemap(javacode) map<string, string> %{
67 public static $javaclassname toSwig(java.util.Map<String,String> in) {
68 $javaclassname n = new $javaclassname();
69 for (java.util.Map.Entry<String, String> entry : in.entrySet()) {
70 n.set(entry.getKey(), entry.getValue());
Adrien Béraud7f97ca92015-06-07 15:36:06 -040071 }
Adrien Béraudb30e6dd2015-06-10 12:22:15 -040072 return n;
73 }
Adrien Béraudda712a42015-11-22 23:45:26 -050074 public java.util.HashMap<String,String> toNative() {
75 java.util.HashMap<String,String> out = new java.util.HashMap<>((int)size());
Adrien Béraudb30e6dd2015-06-10 12:22:15 -040076 StringVect keys = keys();
77 for (String s : keys)
78 out.put(s, get(s));
79 return out;
80 }
81%}
82%extend map<string, string> {
83 std::vector<std::string> keys() const {
84 std::vector<std::string> k;
85 k.reserve($self->size());
86 for (const auto& i : *$self)
87 k.push_back(i.first);
88 return k;
Adrien Béraud7f97ca92015-06-07 15:36:06 -040089 }
Adrien Béraudb30e6dd2015-06-10 12:22:15 -040090}
91%template(StringMap) map<string, string>;
Adrien Béraud7f97ca92015-06-07 15:36:06 -040092
Adrien Béraudb30e6dd2015-06-10 12:22:15 -040093%typemap(javabase) vector<string> "java.util.AbstractList<String>"
94%typemap(javainterface) vector<string> "java.util.RandomAccess"
95%extend vector<string> {
96 value_type set(int i, const value_type& in) throw (std::out_of_range) {
97 const std::string old = $self->at(i);
98 $self->at(i) = in;
99 return old;
100 }
101 bool add(const value_type& in) {
102 $self->push_back(in);
103 return true;
104 }
105 int32_t size() const {
106 return $self->size();
107 }
108}
109%template(StringVect) vector<string>;
110
111%typemap(javacode) vector< map<string,string> > %{
112 public java.util.ArrayList<java.util.Map<String, String>> toNative() {
113 java.util.ArrayList<java.util.Map<String, String>> out = new java.util.ArrayList<>();
114 for (int i = 0; i < size(); ++i)
115 out.add(get(i).toNative());
116 return out;
117 }
118%}
119%template(VectMap) vector< map<string,string> >;
120%template(IntegerMap) map<string,int>;
121%template(IntVect) vector<int32_t>;
122%template(UintVect) vector<uint32_t>;
123%template(Blob) vector<uint8_t>;
Adrien Béraud04d822c2015-04-02 17:44:36 -0400124}
125
126/* not parsed by SWIG but needed by generated C files */
127%header %{
128
129#include <functional>
130
131%}
132
133/* parsed by SWIG to generate all the glue */
134/* %include "../managerimpl.h" */
135/* %include <client/callmanager.h> */
136
137%include "managerimpl.i"
138%include "callmanager.i"
139%include "configurationmanager.i"
140
Adrien Béraud7f97ca92015-06-07 15:36:06 -0400141#include "dring/callmanager_interface.h"
142
Adrien Béraud04d822c2015-04-02 17:44:36 -0400143%inline %{
144/* some functions that need to be declared in *_wrap.cpp
145 * that are not declared elsewhere in the c++ code
146 */
Adrien Béraud04d822c2015-04-02 17:44:36 -0400147
Adrien Béraud7f97ca92015-06-07 15:36:06 -0400148void init(ConfigurationCallback* confM, Callback* callM) {
Adrien Béraud04d822c2015-04-02 17:44:36 -0400149 using namespace std::placeholders;
Adrien Béraud04d822c2015-04-02 17:44:36 -0400150
Adrien Béraud7f97ca92015-06-07 15:36:06 -0400151 using std::bind;
152 using DRing::exportable_callback;
153 using DRing::CallSignal;
154 using DRing::ConfigurationSignal;
155
156 using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>;
Adrien Béraud04d822c2015-04-02 17:44:36 -0400157
158 // Call event handlers
Adrien Béraud7f97ca92015-06-07 15:36:06 -0400159 const std::map<std::string, SharedCallback> callEvHandlers = {
160 exportable_callback<CallSignal::StateChange>(bind(&Callback::callStateChanged, callM, _1, _2, _3)),
161 exportable_callback<CallSignal::TransferFailed>(bind(&Callback::transferFailed, callM)),
162 exportable_callback<CallSignal::TransferSucceeded>(bind(&Callback::transferSucceeded, callM)),
163 exportable_callback<CallSignal::RecordPlaybackStopped>(bind(&Callback::recordPlaybackStopped, callM, _1)),
164 exportable_callback<CallSignal::VoiceMailNotify>(bind(&Callback::voiceMailNotify, callM, _1, _2)),
165 exportable_callback<CallSignal::IncomingMessage>(bind(&Callback::incomingMessage, callM, _1, _2, _3)),
166 exportable_callback<CallSignal::IncomingCall>(bind(&Callback::incomingCall, callM, _1, _2, _3)),
167 exportable_callback<CallSignal::RecordPlaybackFilepath>(bind(&Callback::recordPlaybackFilepath, callM, _1, _2)),
168 exportable_callback<CallSignal::ConferenceCreated>(bind(&Callback::conferenceCreated, callM, _1)),
169 exportable_callback<CallSignal::ConferenceChanged>(bind(&Callback::conferenceChanged, callM, _1, _2)),
170 exportable_callback<CallSignal::UpdatePlaybackScale>(bind(&Callback::updatePlaybackScale, callM, _1, _2, _3)),
171 exportable_callback<CallSignal::ConferenceRemoved>(bind(&Callback::conferenceRemoved, callM, _1)),
172 exportable_callback<CallSignal::NewCallCreated>(bind(&Callback::newCallCreated, callM, _1, _2, _3)),
173 exportable_callback<CallSignal::RecordingStateChanged>(bind(&Callback::recordingStateChanged, callM, _1, _2)),
174 exportable_callback<CallSignal::SecureSdesOn>(bind(&Callback::secureSdesOn, callM, _1)),
175 exportable_callback<CallSignal::SecureSdesOff>(bind(&Callback::secureSdesOff, callM, _1)),
176 exportable_callback<CallSignal::SecureZrtpOn>(bind(&Callback::secureZrtpOn, callM, _1, _2)),
177 exportable_callback<CallSignal::SecureZrtpOff>(bind(&Callback::secureZrtpOff, callM, _1)),
178 exportable_callback<CallSignal::ShowSAS>(bind(&Callback::showSAS, callM, _1, _2, _3)),
179 exportable_callback<CallSignal::ZrtpNotSuppOther>(bind(&Callback::zrtpNotSuppOther, callM, _1)),
180 exportable_callback<CallSignal::ZrtpNegotiationFailed>(bind(&Callback::zrtpNegotiationFailed, callM, _1, _2, _3)),
181 exportable_callback<CallSignal::RtcpReportReceived>(bind(&Callback::onRtcpReportReceived, callM, _1, _2)),
182 exportable_callback<CallSignal::PeerHold>(bind(&Callback::peerHold, callM, _1, _2))
Adrien Béraud04d822c2015-04-02 17:44:36 -0400183 };
184
185 // Configuration event handlers
Adrien Béraud7f97ca92015-06-07 15:36:06 -0400186 const std::map<std::string, SharedCallback> configEvHandlers = {
187 exportable_callback<ConfigurationSignal::VolumeChanged>(bind(&ConfigurationCallback::volumeChanged, confM, _1, _2)),
188 exportable_callback<ConfigurationSignal::AccountsChanged>(bind(&ConfigurationCallback::accountsChanged, confM)),
189 exportable_callback<ConfigurationSignal::StunStatusFailed>(bind(&ConfigurationCallback::stunStatusFailure, confM, _1)),
190 exportable_callback<ConfigurationSignal::RegistrationStateChanged>(bind(&ConfigurationCallback::registrationStateChanged, confM, _1, _2, _3, _4)),
191 exportable_callback<ConfigurationSignal::VolatileDetailsChanged>(bind(&ConfigurationCallback::volatileAccountDetailsChanged, confM, _1, _2)),
192 exportable_callback<ConfigurationSignal::Error>(bind(&ConfigurationCallback::errorAlert, confM, _1)),
193 exportable_callback<ConfigurationSignal::IncomingAccountMessage>(bind(&ConfigurationCallback::incomingAccountMessage, confM, _1, _2, _3 )),
Adrien Béraud9f4d86d2015-07-15 10:52:16 -0400194 exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&ConfigurationCallback::incomingTrustRequest, confM, _1, _2, _3, _4 )),
Adrien Béraud7f97ca92015-06-07 15:36:06 -0400195 exportable_callback<ConfigurationSignal::CertificatePinned>(bind(&ConfigurationCallback::certificatePinned, confM, _1 )),
196 exportable_callback<ConfigurationSignal::CertificatePathPinned>(bind(&ConfigurationCallback::certificatePathPinned, confM, _1, _2 )),
197 exportable_callback<ConfigurationSignal::CertificateExpired>(bind(&ConfigurationCallback::certificateExpired, confM, _1 )),
198 exportable_callback<ConfigurationSignal::CertificateStateChanged>(bind(&ConfigurationCallback::certificateStateChanged, confM, _1, _2, _3 )),
Adrien Béraudb30e6dd2015-06-10 12:22:15 -0400199 exportable_callback<ConfigurationSignal::GetHardwareAudioFormat>(bind(&ConfigurationCallback::getHardwareAudioFormat, confM, _1 )),
Adrien Béraud62a280b2015-06-15 23:32:19 -0400200 exportable_callback<ConfigurationSignal::GetAppDataPath>(bind(&ConfigurationCallback::getAppDataPath, confM, _1, _2 ))
Adrien Béraud04d822c2015-04-02 17:44:36 -0400201 };
202
Adrien Béraud7f97ca92015-06-07 15:36:06 -0400203/*
204 // Presence event handlers
205 const std::map<std::string, SharedCallback> presEvHandlers = {
206 exportable_callback<PresenceSignal::NewServerSubscriptionRequest>(bind(&DBusPresenceManager::newServerSubscriptionRequest, presM, _1)),
207 exportable_callback<PresenceSignal::ServerError>(bind(&DBusPresenceManager::serverError, presM, _1, _2, _3)),
208 exportable_callback<PresenceSignal::NewBuddyNotification>(bind(&DBusPresenceManager::newBuddyNotification, presM, _1, _2, _3, _4)),
209 exportable_callback<PresenceSignal::SubscriptionStateChanged>(bind(&DBusPresenceManager::subscriptionStateChanged, presM, _1, _2, _3)),
210 };
211
212#ifdef RING_VIDEO
213 // Video event handlers
214 const std::map<std::string, SharedCallback> videoEvHandlers = {
215 exportable_callback<VideoSignal::DeviceEvent>(bind(&DBusVideoManager::deviceEvent, videoM)),
216 exportable_callback<VideoSignal::DecodingStarted>(bind(&DBusVideoManager::startedDecoding, videoM, _1, _2, _3, _4, _5)),
217 exportable_callback<VideoSignal::DecodingStopped>(bind(&DBusVideoManager::stoppedDecoding, videoM, _1, _2, _3)),
218 };
219#endif
220*/
221
222 if (!DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_DEBUG)))
223 return -1;
224
225 registerCallHandlers(callEvHandlers);
226 registerConfHandlers(configEvHandlers);
227/* registerPresHandlers(presEvHandlers);
228#ifdef RING_VIDEO
229 registerVideoHandlers(videoEvHandlers);
230#endif
231*/
232 DRing::start();
Adrien Béraud04d822c2015-04-02 17:44:36 -0400233}
234
Adrien Béraud7f97ca92015-06-07 15:36:06 -0400235
Adrien Béraud04d822c2015-04-02 17:44:36 -0400236%}
237#ifndef SWIG
238/* some bad declarations */
239#endif