Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
aff070bc
Commit
aff070bc
authored
Nov 02, 2014
by
Thomas Guillem
Committed by
Max Kellermann
Aug 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
android: add LogListener
A Java object to send logs on the android side.
parent
5af2632d
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
102 additions
and
4 deletions
+102
-4
Makefile.am
Makefile.am
+2
-1
Bridge.java
android/src/Bridge.java
+7
-1
Main.java
android/src/Main.java
+1
-1
LogBackend.cxx
src/LogBackend.cxx
+5
-0
Main.cxx
src/Main.cxx
+6
-1
Main.hxx
src/Main.hxx
+3
-0
LogListener.cxx
src/android/LogListener.cxx
+46
-0
LogListener.hxx
src/android/LogListener.hxx
+32
-0
No files found.
Makefile.am
View file @
aff070bc
...
...
@@ -276,7 +276,8 @@ libjava_a_SOURCES = \
noinst_LIBRARIES
+=
libandroid.a
libandroid_a_SOURCES
=
\
src/android/Context.cxx src/android/Context.hxx
\
src/android/Environment.cxx src/android/Environment.hxx
src/android/Environment.cxx src/android/Environment.hxx
\
src/android/LogListener.cxx src/android/LogListener.hxx
libandroid_a_CPPFLAGS
=
$(AM_CPPFLAGS)
-Iandroid
/build/include
noinst_LIBRARIES
+=
libmain.a
...
...
android/src/Bridge.java
View file @
aff070bc
...
...
@@ -25,6 +25,12 @@ import android.content.Context;
* Bridge to native code.
*/
public
class
Bridge
{
public
static
native
void
run
(
Context
context
);
/* used by jni */
public
interface
LogListener
{
public
void
onLog
(
int
priority
,
String
msg
);
}
public
static
native
void
run
(
Context
context
,
LogListener
logListener
);
public
static
native
void
shutdown
();
}
android/src/Main.java
View file @
aff070bc
...
...
@@ -69,7 +69,7 @@ public class Main extends Activity implements Runnable {
}
@Override
public
void
run
()
{
Bridge
.
run
(
this
);
Bridge
.
run
(
this
,
null
);
quitHandler
.
sendMessage
(
quitHandler
.
obtainMessage
());
}
}
src/LogBackend.cxx
View file @
aff070bc
...
...
@@ -34,6 +34,8 @@
#ifdef ANDROID
#include <android/log.h>
#include "android/LogListener.hxx"
#include "Main.hxx"
static
int
ToAndroidLogLevel
(
LogLevel
log_level
)
...
...
@@ -177,6 +179,9 @@ Log(const Domain &domain, LogLevel level, const char *msg)
#ifdef ANDROID
__android_log_print
(
ToAndroidLogLevel
(
level
),
"MPD"
,
"%s: %s"
,
domain
.
GetName
(),
msg
);
if
(
logListener
!=
nullptr
)
logListener
->
OnLog
(
Java
::
GetEnv
(),
ToAndroidLogLevel
(
level
),
"%s: %s"
,
domain
.
GetName
(),
msg
);
#else
if
(
level
<
log_threshold
)
...
...
src/Main.cxx
View file @
aff070bc
...
...
@@ -92,6 +92,7 @@
#include "java/File.hxx"
#include "android/Environment.hxx"
#include "android/Context.hxx"
#include "android/LogListener.hxx"
#include "fs/StandardDirectory.hxx"
#include "fs/FileSystem.hxx"
#include "org_musicpd_Bridge.h"
...
...
@@ -128,6 +129,7 @@ static constexpr unsigned DEFAULT_BUFFER_BEFORE_PLAY = 10;
#ifdef ANDROID
Context
*
context
;
LogListener
*
logListener
;
#endif
Instance
*
instance
;
...
...
@@ -676,16 +678,19 @@ try {
gcc_visibility_default
JNIEXPORT
void
JNICALL
Java_org_musicpd_Bridge_run
(
JNIEnv
*
env
,
jclass
,
jobject
_context
)
Java_org_musicpd_Bridge_run
(
JNIEnv
*
env
,
jclass
,
jobject
_context
,
jobject
_logListener
)
{
Java
::
Init
(
env
);
Java
::
File
::
Initialise
(
env
);
Environment
::
Initialise
(
env
);
context
=
new
Context
(
env
,
_context
);
if
(
_logListener
!=
nullptr
)
logListener
=
new
LogListener
(
env
,
_logListener
);
mpd_main
(
0
,
nullptr
);
delete
logListener
;
delete
context
;
Environment
::
Deinitialise
(
env
);
}
...
...
src/Main.hxx
View file @
aff070bc
...
...
@@ -25,7 +25,10 @@ class Context;
struct
Instance
;
#ifdef ANDROID
#include "android/LogListener.hxx"
extern
Context
*
context
;
extern
LogListener
*
logListener
;
#endif
extern
Instance
*
instance
;
...
...
src/android/LogListener.cxx
0 → 100644
View file @
aff070bc
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "LogListener.hxx"
#include "java/Class.hxx"
#include "java/String.hxx"
#include "util/AllocatedString.hxx"
#include "util/FormatString.hxx"
void
LogListener
::
OnLog
(
JNIEnv
*
env
,
int
priority
,
const
char
*
fmt
,
...)
const
{
assert
(
env
!=
nullptr
);
Java
::
Class
cls
(
env
,
env
->
GetObjectClass
(
Get
()));
jmethodID
method
=
env
->
GetMethodID
(
cls
,
"onLog"
,
"(ILjava/lang/String;)V"
);
assert
(
method
);
va_list
args
;
va_start
(
args
,
fmt
);
const
auto
log
=
FormatStringV
(
fmt
,
args
);
va_end
(
args
);
env
->
CallVoidMethod
(
Get
(),
method
,
priority
,
Java
::
String
(
env
,
log
.
c_str
()).
Get
());
}
src/android/LogListener.hxx
0 → 100644
View file @
aff070bc
/*
* Copyright 2003-2018 The Music Player Daemon Project
* http://www.musicpd.org
*
* 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 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ANDROID_LOG_LISTENER_HXX
#define MPD_ANDROID_LOG_LISTENER_HXX
#include "java/Object.hxx"
class
LogListener
:
public
Java
::
Object
{
public
:
LogListener
(
JNIEnv
*
env
,
jobject
obj
)
:
Java
::
Object
(
env
,
obj
)
{}
void
OnLog
(
JNIEnv
*
env
,
int
priority
,
const
char
*
fmt
,
...)
const
;
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment