Commit 2dee5360 authored by Alexandre Lision's avatar Alexandre Lision

android: Move jni to daemon

Move all JNI file sources to the daemon. Ring Android client will use
this files to generate the final libring.so including the
ring_wrapper.cpp

Change-Id: I4e800bb1d33b5905c715054d1718c0bdb3fc1d55
Reviewed-by: Guillaume Roguez's avatarGuillaume Roguez <guillaume.roguez@savoirfairelinux.com>
parent cb1ba72f
ringservice_loader.c
ring_wrapper.cpp
ring_wrapper.h
#!/usr/bin/python
# -*- coding: latin-1 -*-
#
# Copyright (C) 2004-2017 Savoir-faire Linux Inc.
#
# Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
# Alexandre Lision <alexandre.lision@savoirfairelinux.com>
# Adrien Béraud <adrien.beraud@savoirfairelinux.com>
#
# 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 3 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
import getopt, sys
import re
from string import Template
def type_to_signature(itype):
if len(itype) > 2:
if itype[-2:] == '[]':
return "[%s" % type_to_signature(itype[:-2])
if itype == "int":
return "I"
if itype == "long":
return "J"
if itype == "void":
return "V"
if itype == "boolean":
return "Z"
if itype == "byte":
return "B"
if itype == "char":
return "C"
if itype == "short":
return "S"
if itype == "float":
return "F"
if itype == "double":
return "D"
if itype == "String":
return "Ljava/lang/String;"
if itype == "Object":
return "Ljava/lang/Object;"
return "Lcx/ring/daemon/%s;" % itype
def parse_java_file(input_stream, package, module):
outputs = []
package_prefix = "Java_%s_%sJNI" % (package.replace(".", "_"), module)
for line in input_stream:
definition = re.match(r'.*public final static native ([^\( ]*) ([^\)]*)\(([^)]*)\).*',line)
if definition is not None:
retour = definition.group(1)
name = definition.group(2)
args = definition.group(3)
args_sigs = []
args_frags = args.split(',')
for args_frag in args_frags:
argf = re.match(r'(\b)?([^ ]+) .*', args_frag.strip())
if argf is not None:
args_sigs.append(type_to_signature(argf.group(2)))
sig = "(%s)%s" % (''.join(args_sigs), type_to_signature(retour))
outputs.append("{\"%s\", \"%s\", (void*)& %s_%s}" % (name, sig, package_prefix, name.replace('_', '_1')))
return outputs
def render_to_template(defs, template_string):
template = Template(template_string)
return template.substitute(defs= ",\r\n".join(defs) )
if __name__ == "__main__":
try:
opts, args = getopt.getopt(sys.argv[1:], "i:o:t:m:p:", ["input=", "output=", "template=", "module=", "package="])
except getopt.GetoptError as err:
# print help information and exit:
print(str(err)) # will print something like "option -a not recognized"
sys.exit(2)
input_stream = None
output_file = None
template_string = None
package = ""
module = ""
for o, a in opts:
if o in ("-i", "--input"):
input_stream = open(a)
if o in ("-o", "--output"):
output_file = open(a, "w")
if o in ("-t", "--template"):
template_string = open(a).read()
if o in ("-m", "--module"):
module = a
if o in ("-p", "--package"):
package = a
defs = parse_java_file(input_stream, package, module)
output_file.write(render_to_template(defs, template_string))
output_file.close()
input_stream.close()
/*
* Copyright (C) 2004-2017 Savoir-faire Linux Inc.
*
* Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
* Alexandre Lision <alexandre.lision@savoirfairelinux.com>
* Adrien Béraud <adrien.beraud@savoirfairelinux.com>
*
* 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 3 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
%header %{
#include "dring/dring.h"
#include "dring/callmanager_interface.h"
class Callback {
public:
virtual ~Callback() {}
virtual void callStateChanged(const std::string& call_id, const std::string& state, int detail_code){}
virtual void transferFailed(void){}
virtual void transferSucceeded(void){}
virtual void recordPlaybackStopped(const std::string& path){}
virtual void voiceMailNotify(const std::string& call_id, int nd_msg){}
virtual void incomingMessage(const std::string& id, const std::string& from, const std::map<std::string, std::string>& messages){}
virtual void incomingCall(const std::string& account_id, const std::string& call_id, const std::string& from){}
virtual void recordPlaybackFilepath(const std::string& id, const std::string& filename){}
virtual void conferenceCreated(const std::string& conf_id){}
virtual void conferenceChanged(const std::string& conf_id, const std::string& state){}
virtual void conferenceRemoved(const std::string& conf_id){}
virtual void newCallCreated(const std::string& call_id, const std::string&, const std::string&){}
virtual void updatePlaybackScale(const std::string& filepath, int position, int scale){}
virtual void conferenceRemove(const std::string& conf_id){}
virtual void newCall(const std::string& account_id, const std::string& call_id, const std::string& to){}
virtual void sipCallStateChange(const std::string& call_id, const std::string& state, int code){}
virtual void recordingStateChanged(const std::string& call_id, int code){}
virtual void recordStateChange(const std::string& call_id, int state){}
virtual void onRtcpReportReceived(const std::string& call_id, const std::map<std::string, int>& stats){}
virtual void peerHold(const std::string& call_id, bool holding){}
};
%}
%feature("director") Callback;
namespace DRing {
/* Call related methods */
std::string placeCall(const std::string& accountID, const std::string& to, const std::map<std::string, std::string>& VolatileCallDetails);
bool refuse(const std::string& callID);
bool accept(const std::string& callID);
bool hangUp(const std::string& callID);
bool hold(const std::string& callID);
bool unhold(const std::string& callID);
bool muteLocalMedia(const std::string& callid, const std::string& mediaType, bool mute);
bool transfer(const std::string& callID, const std::string& to);
bool attendedTransfer(const std::string& transferID, const std::string& targetID);
std::map<std::string, std::string> getCallDetails(const std::string& callID);
std::vector<std::string> getCallList();
/* Conference related methods */
void removeConference(const std::string& conference_id);
bool joinParticipant(const std::string& sel_callID, const std::string& drag_callID);
void createConfFromParticipantList(const std::vector<std::string>& participants);
bool isConferenceParticipant(const std::string& call_id);
bool addParticipant(const std::string& callID, const std::string& confID);
bool addMainParticipant(const std::string& confID);
bool detachParticipant(const std::string& callID);
bool joinConference(const std::string& sel_confID, const std::string& drag_confID);
bool hangUpConference(const std::string& confID);
bool holdConference(const std::string& confID);
bool unholdConference(const std::string& confID);
std::vector<std::string> getConferenceList();
std::vector<std::string> getParticipantList(const std::string& confID);
std::vector<std::string> getDisplayNames(const std::string& confID);
std::string getConferenceId(const std::string& callID);
std::map<std::string, std::string> getConferenceDetails(const std::string& callID);
/* File Playback methods */
bool startRecordedFilePlayback(const std::string& filepath);
void stopRecordedFilePlayback();
/* General audio methods */
bool toggleRecording(const std::string& callID);
/* DEPRECATED */
void setRecording(const std::string& callID);
void recordPlaybackSeek(double value);
bool getIsRecording(const std::string& callID);
std::string getCurrentAudioCodecName(const std::string& callID);
void playDTMF(const std::string& key);
void startTone(int32_t start, int32_t type);
bool switchInput(const std::string& callID, const std::string& resource);
/* Instant messaging */
void sendTextMessage(const std::string& callID, const std::map<std::string, std::string>& messages, const std::string& from, const bool& isMixed);
}
class Callback {
public:
virtual ~Callback() {}
virtual void callStateChanged(const std::string& call_id, const std::string& state, int detail_code){}
virtual void transferFailed(void){}
virtual void transferSucceeded(void){}
virtual void recordPlaybackStopped(const std::string& path){}
virtual void voiceMailNotify(const std::string& call_id, int nd_msg){}
virtual void incomingMessage(const std::string& id, const std::string& from, const std::map<std::string, std::string>& messages){}
virtual void incomingCall(const std::string& account_id, const std::string& call_id, const std::string& from){}
virtual void recordPlaybackFilepath(const std::string& id, const std::string& filename){}
virtual void conferenceCreated(const std::string& conf_id){}
virtual void conferenceChanged(const std::string& conf_id, const std::string& state){}
virtual void conferenceRemoved(const std::string& conf_id){}
virtual void newCallCreated(const std::string& call_id, const std::string&, const std::string&){}
virtual void updatePlaybackScale(const std::string& filepath, int position, int scale){}
virtual void conferenceRemove(const std::string& conf_id){}
virtual void newCall(const std::string& account_id, const std::string& call_id, const std::string& to){}
virtual void sipCallStateChange(const std::string& call_id, const std::string& state, int code){}
virtual void recordingStateChanged(const std::string& call_id, int code){}
virtual void recordStateChange(const std::string& call_id, int state){}
virtual void onRtcpReportReceived(const std::string& call_id, const std::map<std::string, int>& stats){}
virtual void peerHold(const std::string& call_id, bool holding){}
};
This diff is collapsed.
This diff is collapsed.
#!/bin/bash -
#
# Copyright (C) 2004-2017 Savoir-Faire Linux Inc.
#
# Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
# Alexandre Lision <alexandre.lision@savoirfairelinux.com>
#
# 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 3 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
JNIDIR=`pwd`
PACKAGE=cx.ring.daemon
if [ -z "$PACKAGEDIR" ]; then
echo "Define PACKAGEDIR: output dir of generated java files"
exit 1
fi
echo "Checking for SWIG version 3.0.8 or later"
SWIGVER=`swig -version | grep -i "SWIG version" | awk '{print $3}'`
SWIGVER1=`echo $SWIGVER | awk '{split($0, array, ".")} END{print array[1]}'`
SWIGVER2=`echo $SWIGVER | awk '{split($0, array, ".")} END{print array[2]}'`
SWIGVER3=`echo $SWIGVER | awk '{split($0, array, ".")} END{print array[3]}'`
if [[ $SWIGVER1 -ge 3 ]]; then
if [[ $SWIGVER1 -eq 3 ]]; then
if [[ $SWIGVER2 -eq 0 ]]; then
if [[ $SWIGVER3 -lt 8 ]]; then
echo "error: SWIG version $SWIGVER1.$SWIGVER2.$SWIGVER3 is less than 3.0.8"
exit 4
fi
fi
fi
else
echo "error: SWIG version $SWIGVER1.$SWIGVER2.$SWIGVER3 is less than 3.x"
exit 3
fi
mkdir -p $PACKAGEDIR
echo "Generating ring_wrapper.cpp..."
swig -v -c++ -java \
-package $PACKAGE \
-outdir $PACKAGEDIR \
-o $JNIDIR/ring_wrapper.cpp $JNIDIR/jni_interface.i
echo "Generating ringservice_loader.c..."
python $JNIDIR/JavaJNI2CJNI_Load.py \
-i $PACKAGEDIR/RingserviceJNI.java \
-o $JNIDIR/ringservice_loader.c \
-t $JNIDIR/ringservice.c.template \
-m Ringservice \
-p $PACKAGE
echo "Appending ring_wrapper.cpp..."
cat $JNIDIR/ringservice_loader.c >> $JNIDIR/ring_wrapper.cpp
echo "SWIG bindings successfully generated !"
exit 0
/*
* Copyright (C) 2004-2017 Savoir-faire Linux Inc.
*
* Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
*
* 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 3 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* %nodefaultctor ManagerImpl;
%nodefaultdtor ManagerImpl; */
%header %{
#include "dring/dring.h"
%}
namespace DRing {
/**
* Finalizes libsflphone, freeing any resource allocated by the library.
*/
void fini(void);
/**
* Poll for events
*/
void pollEvents(void);
}
/*
* Copyright (C) 2017 Savoir-faire Linux Inc.
*
* Author: Aline Bonnet <aline.bonnet@savoirfairelinux.com>
*
* 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 3 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
%header %{
#include "dring/dring.h"
#include "dring/presencemanager_interface.h"
class PresenceCallback {
public:
virtual ~PresenceCallback(){}
virtual void newServerSubscriptionRequest(const std::string& /*remote*/){}
virtual void serverError(const std::string& /*account_id*/, const std::string& /*error*/, const std::string& /*msg*/){}
virtual void newBuddyNotification(const std::string& /*account_id*/, const std::string& /*buddy_uri*/, int /*status*/, const std::string& /*line_status*/){}
virtual void subscriptionStateChanged(const std::string& /*account_id*/, const std::string& /*buddy_uri*/, int /*state*/){}
};
%}
%feature("director") PresenceCallback;
namespace DRing {
/* Presence subscription/Notification. */
void publish(const std::string& accountID, bool status, const std::string& note);
void answerServerRequest(const std::string& uri, bool flag);
void subscribeBuddy(const std::string& accountID, const std::string& uri, bool flag);
std::vector<std::map<std::string, std::string>> getSubscriptions(const std::string& accountID);
void setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris);
}
class PresenceCallback {
public:
virtual ~PresenceCallback(){}
virtual void newServerSubscriptionRequest(const std::string& /*remote*/){}
virtual void serverError(const std::string& /*account_id*/, const std::string& /*error*/, const std::string& /*msg*/){}
virtual void newBuddyNotification(const std::string& /*account_id*/, const std::string& /*buddy_uri*/, int /*status*/, const std::string& /*line_status*/){}
virtual void subscriptionStateChanged(const std::string& /*account_id*/, const std::string& /*buddy_uri*/, int /*state*/){}
};
\ No newline at end of file
/*
* Copyright (C) 2004-2017 Savoir-faire Linux Inc.
*
* Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
*
* 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 3 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "logger.h"
extern "C" {
#include "libavcodec/jni.h"
}
JavaVM *gJavaVM;
const char *kringservicePath = "cx/ring/daemon/RingserviceJNI";
void deinitClassHelper(JNIEnv *env, jobject obj) {
RING_INFO("deinitClassHelper");
/* delete cached object instances */
env->DeleteGlobalRef(obj);
RING_INFO("deinitClassHelper: object %p deleted", obj);
}
JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEnv *env;
jclass clazz;
jint r;
RING_INFO("JNI_OnLoad");
if (av_jni_set_java_vm(vm, reserved)) {
RING_ERR("JNI_OnLoad: av_jni_set_java_vm failed");
}
//Assume it is c++
r = vm->GetEnv ((void **) &env, JNI_VERSION_1_6);
if (r != JNI_OK) {
RING_ERR("JNI_OnLoad: failed to get the environment using GetEnv()");
return -1;
}
RING_INFO("JNI_Onload: GetEnv %p", env);
clazz = env->FindClass (kringservicePath);
if (!clazz) {
RING_ERR("JNI_Onload: whoops, %s class not found!", kringservicePath);
}
gJavaVM = vm;
RING_INFO("JNI_Onload: JavaVM %p", gJavaVM);
/* put instances of class object we need into cache */
//initClassHelper(env, kManagerPath, &gManagerObject);
JNINativeMethod methods[] = {
$defs
};
r = env->RegisterNatives (clazz, methods, (int) (sizeof(methods) / sizeof(methods[0])));
return JNI_VERSION_1_6;
}
void JNI_OnUnLoad(JavaVM* vm, void* reserved) {
JNIEnv* env;
jclass clazz;
RING_INFO("JNI_OnUnLoad");
/* get env */
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
RING_ERR("JNI_OnUnLoad: failed to get the environment using GetEnv()");
return;
}
RING_INFO("JNI_OnUnLoad: GetEnv %p", env);
/* Get jclass with env->FindClass */
clazz = env->FindClass(kringservicePath);
if (!clazz) {
RING_ERR("JNI_OnUnLoad: whoops, %s class not found!", kringservicePath);
}
/* remove instances of class object we need into cache */
//deinitClassHelper(env, gManagerObject);
env->UnregisterNatives(clazz);
RING_INFO("JNI_OnUnLoad: Native functions unregistered");
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment