From e8175c7b23047fefd52f85afe05e2864b2a9bba8 Mon Sep 17 00:00:00 2001 From: geronimo Date: Sat, 4 Aug 2012 11:10:44 +0200 Subject: created new icons to enable visual feedback on mediatype selection, changed json-parser and enabled virtual mediatype usage --- cmpcj/.classpath | 3 +- cmpcj/lib/gson-2.2.2.jar | Bin 0 -> 189285 bytes cmpcj/lib/jackson-all-1.9.2.jar | Bin 1107436 -> 0 bytes cmpcj/res/images/folder_black.png | Bin 117733 -> 0 bytes cmpcj/res/images/folder_black_dvd.png | Bin 116838 -> 0 bytes cmpcj/res/images/folder_black_i_dvd.png | Bin 128700 -> 0 bytes cmpcj/res/images/folder_black_i_movies.png | Bin 133715 -> 0 bytes cmpcj/res/images/folder_black_i_vdr.png | Bin 140435 -> 0 bytes cmpcj/res/images/folder_black_i_vdr_old.png | Bin 181800 -> 0 bytes cmpcj/res/images/folder_black_library.png | Bin 121207 -> 0 bytes cmpcj/res/images/folder_black_movies.png | Bin 125320 -> 0 bytes cmpcj/res/images/folder_black_music.png | Bin 121853 -> 0 bytes cmpcj/res/images/folder_black_photos.png | Bin 129249 -> 0 bytes cmpcj/res/images/folder_black_playlist.png | Bin 121207 -> 0 bytes cmpcj/res/images/folder_black_vdr.png | Bin 128692 -> 0 bytes cmpcj/res/images/folder_black_vdr_old.png | Bin 172383 -> 0 bytes cmpcj/res/images/sr_default.png | Bin 0 -> 114212 bytes cmpcj/res/images/sr_dvd.png | Bin 0 -> 119043 bytes cmpcj/res/images/sr_dvd_i.png | Bin 0 -> 134812 bytes cmpcj/res/images/sr_lvdr.png | Bin 0 -> 174142 bytes cmpcj/res/images/sr_lvdr_i.png | Bin 0 -> 185903 bytes cmpcj/res/images/sr_movies.png | Bin 0 -> 122199 bytes cmpcj/res/images/sr_movies_i.png | Bin 0 -> 138608 bytes cmpcj/res/images/sr_music.png | Bin 0 -> 117609 bytes cmpcj/res/images/sr_photos.png | Bin 0 -> 124129 bytes cmpcj/res/images/sr_playlist.png | Bin 0 -> 116457 bytes cmpcj/res/images/sr_vdr.png | Bin 0 -> 130356 bytes cmpcj/res/images/sr_vdr_i.png | Bin 0 -> 145850 bytes cmpcj/res/images/sradefault.png | Bin 0 -> 131251 bytes cmpcj/res/images/sradvd.png | Bin 0 -> 136534 bytes cmpcj/res/images/sradvd_i.png | Bin 0 -> 152638 bytes cmpcj/res/images/sralvdr.png | Bin 0 -> 190151 bytes cmpcj/res/images/sralvdr_i.png | Bin 0 -> 201594 bytes cmpcj/res/images/sramovies.png | Bin 0 -> 138966 bytes cmpcj/res/images/sramovies_i.png | Bin 0 -> 156017 bytes cmpcj/res/images/sramusic.png | Bin 0 -> 134757 bytes cmpcj/res/images/sraphotos.png | Bin 0 -> 140488 bytes cmpcj/res/images/sraplaylist.png | Bin 0 -> 132791 bytes cmpcj/res/images/sravdr.png | Bin 0 -> 146699 bytes cmpcj/res/images/sravdr_i.png | Bin 0 -> 162536 bytes .../src/de/schwarzrot/cmpc/app/SRMediaPlayer.java | 37 +++-- cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java | 34 ++-- .../de/schwarzrot/cmpc/util/MediaListLoader.java | 36 ++--- .../de/schwarzrot/cmpc/util/MediaTypeSelect.java | 39 +++-- .../de/schwarzrot/cmpc/util/MedialistParser.java | 173 +++++++++++++++++++++ cmps/main.cc | 23 ++- cmps/nbproject/Makefile-Debug.mk | 30 ++-- cmps/nbproject/Makefile-Release.mk | 12 ++ cmps/nbproject/configurations.xml | 12 ++ cmps/tests/StringBuilderTest.cc | 17 ++ libs/IO/src/CommandReader.cc | 12 +- libs/mediaScan/src/Audio.cc | 2 + libs/mediaScan/src/DVDImage.cc | 2 + libs/mediaScan/src/LegacyVdrRecording.cc | 2 + libs/mediaScan/src/Movie.cc | 2 + libs/mediaScan/src/Picture.cc | 2 + libs/mediaScan/src/VdrRecording.cc | 2 + libs/networking/src/HTTPServer.cc | 2 - libs/util/include/StringBuilder.h | 7 +- libs/util/src/JSonWriter.cc | 5 +- libs/util/src/StringBuilder.cc | 50 +++++- 61 files changed, 416 insertions(+), 88 deletions(-) create mode 100644 cmpcj/lib/gson-2.2.2.jar delete mode 100644 cmpcj/lib/jackson-all-1.9.2.jar delete mode 100644 cmpcj/res/images/folder_black.png delete mode 100644 cmpcj/res/images/folder_black_dvd.png delete mode 100644 cmpcj/res/images/folder_black_i_dvd.png delete mode 100644 cmpcj/res/images/folder_black_i_movies.png delete mode 100644 cmpcj/res/images/folder_black_i_vdr.png delete mode 100644 cmpcj/res/images/folder_black_i_vdr_old.png delete mode 100644 cmpcj/res/images/folder_black_library.png delete mode 100644 cmpcj/res/images/folder_black_movies.png delete mode 100644 cmpcj/res/images/folder_black_music.png delete mode 100644 cmpcj/res/images/folder_black_photos.png delete mode 100644 cmpcj/res/images/folder_black_playlist.png delete mode 100644 cmpcj/res/images/folder_black_vdr.png delete mode 100644 cmpcj/res/images/folder_black_vdr_old.png create mode 100644 cmpcj/res/images/sr_default.png create mode 100644 cmpcj/res/images/sr_dvd.png create mode 100644 cmpcj/res/images/sr_dvd_i.png create mode 100644 cmpcj/res/images/sr_lvdr.png create mode 100644 cmpcj/res/images/sr_lvdr_i.png create mode 100644 cmpcj/res/images/sr_movies.png create mode 100644 cmpcj/res/images/sr_movies_i.png create mode 100644 cmpcj/res/images/sr_music.png create mode 100644 cmpcj/res/images/sr_photos.png create mode 100644 cmpcj/res/images/sr_playlist.png create mode 100644 cmpcj/res/images/sr_vdr.png create mode 100644 cmpcj/res/images/sr_vdr_i.png create mode 100644 cmpcj/res/images/sradefault.png create mode 100644 cmpcj/res/images/sradvd.png create mode 100644 cmpcj/res/images/sradvd_i.png create mode 100644 cmpcj/res/images/sralvdr.png create mode 100644 cmpcj/res/images/sralvdr_i.png create mode 100644 cmpcj/res/images/sramovies.png create mode 100644 cmpcj/res/images/sramovies_i.png create mode 100644 cmpcj/res/images/sramusic.png create mode 100644 cmpcj/res/images/sraphotos.png create mode 100644 cmpcj/res/images/sraplaylist.png create mode 100644 cmpcj/res/images/sravdr.png create mode 100644 cmpcj/res/images/sravdr_i.png create mode 100644 cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java diff --git a/cmpcj/.classpath b/cmpcj/.classpath index ae6697e..b28f98d 100644 --- a/cmpcj/.classpath +++ b/cmpcj/.classpath @@ -4,6 +4,7 @@ - + + diff --git a/cmpcj/lib/gson-2.2.2.jar b/cmpcj/lib/gson-2.2.2.jar new file mode 100644 index 0000000..f2108e0 Binary files /dev/null and b/cmpcj/lib/gson-2.2.2.jar differ diff --git a/cmpcj/lib/jackson-all-1.9.2.jar b/cmpcj/lib/jackson-all-1.9.2.jar deleted file mode 100644 index f1d8c3d..0000000 Binary files a/cmpcj/lib/jackson-all-1.9.2.jar and /dev/null differ diff --git a/cmpcj/res/images/folder_black.png b/cmpcj/res/images/folder_black.png deleted file mode 100644 index 01b5b20..0000000 Binary files a/cmpcj/res/images/folder_black.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_dvd.png b/cmpcj/res/images/folder_black_dvd.png deleted file mode 100644 index 26c72c2..0000000 Binary files a/cmpcj/res/images/folder_black_dvd.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_i_dvd.png b/cmpcj/res/images/folder_black_i_dvd.png deleted file mode 100644 index 2b4294c..0000000 Binary files a/cmpcj/res/images/folder_black_i_dvd.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_i_movies.png b/cmpcj/res/images/folder_black_i_movies.png deleted file mode 100644 index e5ed555..0000000 Binary files a/cmpcj/res/images/folder_black_i_movies.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_i_vdr.png b/cmpcj/res/images/folder_black_i_vdr.png deleted file mode 100644 index 129b733..0000000 Binary files a/cmpcj/res/images/folder_black_i_vdr.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_i_vdr_old.png b/cmpcj/res/images/folder_black_i_vdr_old.png deleted file mode 100644 index 4cb2584..0000000 Binary files a/cmpcj/res/images/folder_black_i_vdr_old.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_library.png b/cmpcj/res/images/folder_black_library.png deleted file mode 100644 index 6e1cc81..0000000 Binary files a/cmpcj/res/images/folder_black_library.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_movies.png b/cmpcj/res/images/folder_black_movies.png deleted file mode 100644 index 34c46f3..0000000 Binary files a/cmpcj/res/images/folder_black_movies.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_music.png b/cmpcj/res/images/folder_black_music.png deleted file mode 100644 index e534703..0000000 Binary files a/cmpcj/res/images/folder_black_music.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_photos.png b/cmpcj/res/images/folder_black_photos.png deleted file mode 100644 index 59f80a4..0000000 Binary files a/cmpcj/res/images/folder_black_photos.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_playlist.png b/cmpcj/res/images/folder_black_playlist.png deleted file mode 100644 index 6e1cc81..0000000 Binary files a/cmpcj/res/images/folder_black_playlist.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_vdr.png b/cmpcj/res/images/folder_black_vdr.png deleted file mode 100644 index 17fcbb9..0000000 Binary files a/cmpcj/res/images/folder_black_vdr.png and /dev/null differ diff --git a/cmpcj/res/images/folder_black_vdr_old.png b/cmpcj/res/images/folder_black_vdr_old.png deleted file mode 100644 index b56f5f7..0000000 Binary files a/cmpcj/res/images/folder_black_vdr_old.png and /dev/null differ diff --git a/cmpcj/res/images/sr_default.png b/cmpcj/res/images/sr_default.png new file mode 100644 index 0000000..8628dfe Binary files /dev/null and b/cmpcj/res/images/sr_default.png differ diff --git a/cmpcj/res/images/sr_dvd.png b/cmpcj/res/images/sr_dvd.png new file mode 100644 index 0000000..899b0e3 Binary files /dev/null and b/cmpcj/res/images/sr_dvd.png differ diff --git a/cmpcj/res/images/sr_dvd_i.png b/cmpcj/res/images/sr_dvd_i.png new file mode 100644 index 0000000..18a7571 Binary files /dev/null and b/cmpcj/res/images/sr_dvd_i.png differ diff --git a/cmpcj/res/images/sr_lvdr.png b/cmpcj/res/images/sr_lvdr.png new file mode 100644 index 0000000..1b90956 Binary files /dev/null and b/cmpcj/res/images/sr_lvdr.png differ diff --git a/cmpcj/res/images/sr_lvdr_i.png b/cmpcj/res/images/sr_lvdr_i.png new file mode 100644 index 0000000..31a475e Binary files /dev/null and b/cmpcj/res/images/sr_lvdr_i.png differ diff --git a/cmpcj/res/images/sr_movies.png b/cmpcj/res/images/sr_movies.png new file mode 100644 index 0000000..794a5fa Binary files /dev/null and b/cmpcj/res/images/sr_movies.png differ diff --git a/cmpcj/res/images/sr_movies_i.png b/cmpcj/res/images/sr_movies_i.png new file mode 100644 index 0000000..efe3e3a Binary files /dev/null and b/cmpcj/res/images/sr_movies_i.png differ diff --git a/cmpcj/res/images/sr_music.png b/cmpcj/res/images/sr_music.png new file mode 100644 index 0000000..cacaa0c Binary files /dev/null and b/cmpcj/res/images/sr_music.png differ diff --git a/cmpcj/res/images/sr_photos.png b/cmpcj/res/images/sr_photos.png new file mode 100644 index 0000000..8493512 Binary files /dev/null and b/cmpcj/res/images/sr_photos.png differ diff --git a/cmpcj/res/images/sr_playlist.png b/cmpcj/res/images/sr_playlist.png new file mode 100644 index 0000000..41ca388 Binary files /dev/null and b/cmpcj/res/images/sr_playlist.png differ diff --git a/cmpcj/res/images/sr_vdr.png b/cmpcj/res/images/sr_vdr.png new file mode 100644 index 0000000..d750edf Binary files /dev/null and b/cmpcj/res/images/sr_vdr.png differ diff --git a/cmpcj/res/images/sr_vdr_i.png b/cmpcj/res/images/sr_vdr_i.png new file mode 100644 index 0000000..a02a741 Binary files /dev/null and b/cmpcj/res/images/sr_vdr_i.png differ diff --git a/cmpcj/res/images/sradefault.png b/cmpcj/res/images/sradefault.png new file mode 100644 index 0000000..fa5ae3d Binary files /dev/null and b/cmpcj/res/images/sradefault.png differ diff --git a/cmpcj/res/images/sradvd.png b/cmpcj/res/images/sradvd.png new file mode 100644 index 0000000..fd66ad5 Binary files /dev/null and b/cmpcj/res/images/sradvd.png differ diff --git a/cmpcj/res/images/sradvd_i.png b/cmpcj/res/images/sradvd_i.png new file mode 100644 index 0000000..b7fc014 Binary files /dev/null and b/cmpcj/res/images/sradvd_i.png differ diff --git a/cmpcj/res/images/sralvdr.png b/cmpcj/res/images/sralvdr.png new file mode 100644 index 0000000..5677308 Binary files /dev/null and b/cmpcj/res/images/sralvdr.png differ diff --git a/cmpcj/res/images/sralvdr_i.png b/cmpcj/res/images/sralvdr_i.png new file mode 100644 index 0000000..c6f1725 Binary files /dev/null and b/cmpcj/res/images/sralvdr_i.png differ diff --git a/cmpcj/res/images/sramovies.png b/cmpcj/res/images/sramovies.png new file mode 100644 index 0000000..b74967a Binary files /dev/null and b/cmpcj/res/images/sramovies.png differ diff --git a/cmpcj/res/images/sramovies_i.png b/cmpcj/res/images/sramovies_i.png new file mode 100644 index 0000000..85c08e7 Binary files /dev/null and b/cmpcj/res/images/sramovies_i.png differ diff --git a/cmpcj/res/images/sramusic.png b/cmpcj/res/images/sramusic.png new file mode 100644 index 0000000..9a0ceb9 Binary files /dev/null and b/cmpcj/res/images/sramusic.png differ diff --git a/cmpcj/res/images/sraphotos.png b/cmpcj/res/images/sraphotos.png new file mode 100644 index 0000000..47192f0 Binary files /dev/null and b/cmpcj/res/images/sraphotos.png differ diff --git a/cmpcj/res/images/sraplaylist.png b/cmpcj/res/images/sraplaylist.png new file mode 100644 index 0000000..f1dc30b Binary files /dev/null and b/cmpcj/res/images/sraplaylist.png differ diff --git a/cmpcj/res/images/sravdr.png b/cmpcj/res/images/sravdr.png new file mode 100644 index 0000000..2f75626 Binary files /dev/null and b/cmpcj/res/images/sravdr.png differ diff --git a/cmpcj/res/images/sravdr_i.png b/cmpcj/res/images/sravdr_i.png new file mode 100644 index 0000000..24c0e18 Binary files /dev/null and b/cmpcj/res/images/sravdr_i.png differ diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java index 73f6204..0448549 100644 --- a/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java +++ b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== * - * File: SRMediaPlayer.java - * Created: - * Author: Geronimo - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media + * File: SRMediaPlayer.java Created: Author: Geronimo Project: cmpc - a java frontend + * (client) part of compound media player uses external players to play the + * media * * CMP - compound media player * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. + * is a client/server mediaplayer intended to play any media from any + * workstation without the need to export or mount shares. cmps is an easy to + * use backend with a (ready to use) HTML-interface. Additionally the backend + * supports authentication via HTTP-digest authorization. cmpc is a client with + * vdr-like osd-menues. * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under + * Creative Commons by-sa For details see + * http://creativecommons.org/licenses/by-sa/3.0/ * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * The cmp project's homepage is at + * http://projects.vdr-developer.org/projects/cmp * * -------------------------------------------------------------- */ @@ -159,6 +159,7 @@ public class SRMediaPlayer implements IMediaPlayer { public static void main(final String[] args) { + appInfo(); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -169,6 +170,14 @@ public class SRMediaPlayer implements IMediaPlayer { }); } + + protected static void appInfo() { + System.err.println("cmpcj - the java frontend of CMP (compound media player)"); + System.err.println(" serves to browse a medialist from remote systems and to start a player"); + System.err.println(" for selected media."); + System.err.println(" (c) 2012 - Reinhard Mantey - some rights reserved."); + System.err.println(" CMP is published as open source under Creative Commons by-sa"); + } private boolean debug = false; private JFrame mainFrame; private Config config; diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java index c336329..57f320f 100644 --- a/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java +++ b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== * - * File: MediaType.java - * Created: - * Author: Geronimo - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media + * File: MediaType.java Created: Author: Geronimo Project: cmpc - a java frontend + * (client) part of compound media player uses external players to play the + * media * * CMP - compound media player * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. + * is a client/server mediaplayer intended to play any media from any + * workstation without the need to export or mount shares. cmps is an easy to + * use backend with a (ready to use) HTML-interface. Additionally the backend + * supports authentication via HTTP-digest authorization. cmpc is a client with + * vdr-like osd-menues. * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under + * Creative Commons by-sa For details see + * http://creativecommons.org/licenses/by-sa/3.0/ * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * The cmp project's homepage is at + * http://projects.vdr-developer.org/projects/cmp * * -------------------------------------------------------------- */ @@ -32,7 +32,7 @@ public class MediaType { } - public int getStart() { + public long getStart() { return start; } @@ -42,10 +42,10 @@ public class MediaType { } - public void setStart(int start) { + public void setStart(long start) { this.start = start; } private String name; - private int start; + private long start; } diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java index b37834c..983fdd3 100644 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java +++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== * - * File: MediaListLoader.java - * Created: - * Author: Geronimo - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media + * File: MediaListLoader.java Created: Author: Geronimo Project: cmpc - a java frontend + * (client) part of compound media player uses external players to play the + * media * * CMP - compound media player * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. + * is a client/server mediaplayer intended to play any media from any + * workstation without the need to export or mount shares. cmps is an easy to + * use backend with a (ready to use) HTML-interface. Additionally the backend + * supports authentication via HTTP-digest authorization. cmpc is a client with + * vdr-like osd-menues. * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under + * Creative Commons by-sa For details see + * http://creativecommons.org/licenses/by-sa/3.0/ * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * The cmp project's homepage is at + * http://projects.vdr-developer.org/projects/cmp * * -------------------------------------------------------------- */ @@ -30,7 +30,6 @@ import java.net.ConnectException; import java.net.URL; import java.net.URLConnection; import java.util.Date; -import org.codehaus.jackson.map.ObjectMapper; import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import de.schwarzrot.cmpc.domain.Media; @@ -64,7 +63,7 @@ public class MediaListLoader implements Runnable { start = new Date(); request = new URL("http", hostName, port, "/?format=json"); URLConnection conn = request.openConnection(); - final PlayList firstPlaylist = jsonOM.readValue(conn.getInputStream(), PlayList.class); + final PlayList firstPlaylist = jsonParser.parseListChunk(conn.getInputStream()); mediaPool.getReadWriteLock().writeLock().lock(); for (Media m : firstPlaylist.getResults()) { @@ -85,7 +84,7 @@ public class MediaListLoader implements Runnable { uri = String.format("/?start=%d&limit=%d&format=json", n, 100); request = new URL("http", hostName, port, uri); conn = request.openConnection(); - next = jsonOM.readValue(conn.getInputStream(), PlayList.class); + next = jsonParser.parseListChunk(conn.getInputStream()); mediaPool.getReadWriteLock().writeLock().lock(); for (Media m : next.getResults()) { mediaPool.add(m); @@ -96,6 +95,7 @@ public class MediaListLoader implements Runnable { } } catch (Throwable t) { System.out.println("Oups, media list contains now #" + mediaPool.size() + " entries."); + System.err.println("Error on chunk #" + n); t.printStackTrace(); } finally { try { @@ -119,6 +119,6 @@ public class MediaListLoader implements Runnable { private String hostName; private int port; - private ObjectMapper jsonOM = new ObjectMapper(); + private MedialistParser jsonParser = new MedialistParser(); private EventList mediaPool = new BasicEventList(); } diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java index 24cd506..bde865a 100644 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java +++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java @@ -60,14 +60,17 @@ public class MediaTypeSelect extends AbstractMatcherEditor implements Lis @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + ImageIcon icon = null; + if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); + icon = selImages[((Media.SupportedMediaType) value).ordinal()]; } else { setBackground(list.getBackground()); setForeground(list.getForeground()); + icon = stdImages[((Media.SupportedMediaType) value).ordinal()]; } - ImageIcon icon = images[((Media.SupportedMediaType) value).ordinal()]; setSize(110, 110); setHorizontalAlignment(JLabel.CENTER); @@ -86,21 +89,35 @@ public class MediaTypeSelect extends AbstractMatcherEditor implements Lis ClassLoader cl = getClass().getClassLoader(); URL url; - images = new ImageIcon[iconFiles.length]; + stdImages = new ImageIcon[iconFiles.length]; for (int i = 0; i < iconFiles.length; ++i) { try { url = cl.getResource(iconFiles[i]); img = ImageIO.read(url); - images[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH)); + stdImages[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH)); } catch (Throwable t) { System.err.println("failed to read image from " + iconFiles[i]); t.printStackTrace(); } } + + selImages = new ImageIcon[activeIconFiles.length]; + for (int i = 0; i < activeIconFiles.length; ++i) { + try { + url = cl.getResource(activeIconFiles[i]); + + img = ImageIO.read(url); + selImages[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH)); + } catch (Throwable t) { + System.err.println("failed to read image from " + activeIconFiles[i]); + t.printStackTrace(); + } + } } - ImageIcon[] images; + ImageIcon[] stdImages; + ImageIcon[] selImages; } @@ -139,11 +156,15 @@ public class MediaTypeSelect extends AbstractMatcherEditor implements Lis private EventList selectedTypes; private JList mediaTypeJList; private static final String[] iconFiles; + private static final String[] activeIconFiles; static { - iconFiles = new String[] { "images/folder_black.png", "images/folder_black_music.png", - "images/folder_black_movies.png", "images/folder_black_i_movies.png", "images/folder_black_dvd.png", - "images/folder_black_i_dvd.png", "images/folder_black_vdr_old.png", - "images/folder_black_i_vdr_old.png", "images/folder_black_vdr.png", "images/folder_black_i_vdr.png", - "images/folder_black_photos.png", "images/folder_black.png" }; + iconFiles = new String[] { "images/sr_default.png", "images/sr_music.png", "images/sr_movies.png", + "images/sr_movies_i.png", "images/sr_dvd.png", "images/sr_dvd_i.png", "images/sr_lvdr.png", + "images/sr_lvdr_i.png", "images/sr_vdr.png", "images/sr_vdr_i.png", "images/sr_photos.png", + "images/sr_default.png" }; + activeIconFiles = new String[] { "images/sradefault.png", "images/sramusic.png", "images/sramovies.png", + "images/sramovies_i.png", "images/sradvd.png", "images/sradvd_i.png", "images/sralvdr.png", + "images/sralvdr_i.png", "images/sravdr.png", "images/sravdr_i.png", "images/sraphotos.png", + "images/sradefault.png" }; } } diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java b/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java new file mode 100644 index 0000000..8f69af0 --- /dev/null +++ b/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java @@ -0,0 +1,173 @@ +package de.schwarzrot.cmpc.util; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import com.google.gson.stream.JsonReader; +import de.schwarzrot.cmpc.domain.Media; +import de.schwarzrot.cmpc.domain.MediaType; +import de.schwarzrot.cmpc.domain.PlayList; + + +public class MedialistParser { + public PlayList parseListChunk(InputStream is) { + JsonReader reader = null; + PlayList rv = null; + + try { + reader = new JsonReader(new InputStreamReader(is, "UTF-8")); + + rv = readPlayList(reader); + } catch (Throwable t) { + t.printStackTrace(); + } finally { + try { + reader.close(); + } catch (Throwable t) { + } + } + return rv; + } + + + @Test + public void testJSonParsing() { + FileInputStream fis = null; + + try { + fis = new FileInputStream(new File("test.json")); + parseListChunk(fis); + fis.close(); + fis = null; + } catch (Throwable t) { + t.printStackTrace(); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (Throwable t) { + } + } + } + } + + + protected Media readMedia(JsonReader reader) { + Media rv = new Media(); + + try { + reader.beginObject(); + while (reader.hasNext()) { + String name = reader.nextName(); + + if ("name".equals(name)) { + rv.setName(reader.nextString()); + } else if ("type".equals(name)) { + rv.setType(reader.nextInt()); + } else if ("format".equals(name)) { + rv.setFormat(reader.nextString()); + } else if ("width".equals(name)) { + rv.setWidth(reader.nextInt()); + } else if ("height".equals(name)) { + rv.setHeight(reader.nextInt()); + } else if ("path".equals(name)) { + rv.setPath(reader.nextString()); + } else { + reader.skipValue(); + } + } + reader.endObject(); + } catch (Throwable t) { + t.printStackTrace(); + } + return rv; + } + + + protected List readMediaArray(JsonReader reader) { + List rv = new ArrayList(); + + try { + reader.beginArray(); + while (reader.hasNext()) { + rv.add(readMedia(reader)); + } + reader.endArray(); + } catch (Throwable t) { + t.printStackTrace(); + } + return rv; + } + + + protected MediaType readMediaType(JsonReader reader) { + MediaType rv = new MediaType(); + + try { + reader.beginObject(); + while (reader.hasNext()) { + String name = reader.nextName(); + + if ("name".equals(name)) { + rv.setName(reader.nextString()); + } else if ("start".equals(name)) { + rv.setStart(reader.nextLong()); + } else { + reader.skipValue(); + } + } + reader.endObject(); + } catch (Throwable t) { + t.printStackTrace(); + } + return rv; + } + + + protected PlayList readPlayList(JsonReader reader) { + PlayList rv = new PlayList(); + + try { + reader.beginObject(); + while (reader.hasNext()) { + String name = reader.nextName(); + + if ("total".equals(name)) { + rv.setTotal(reader.nextLong()); + } else if ("types".equals(name)) { + rv.setTypes(readTypeArray(reader)); + } else if ("results".equals(name)) { + rv.setResults(readMediaArray(reader)); + } else { + reader.skipValue(); + } + } + reader.endObject(); + } catch (Throwable t) { + t.printStackTrace(); + rv = null; + } + return rv; + } + + + protected List readTypeArray(JsonReader reader) { + List rv = new ArrayList(); + + try { + reader.beginArray(); + while (reader.hasNext()) { + rv.add(readMediaType(reader)); + } + reader.endArray(); + } catch (Throwable t) { + t.printStackTrace(); + } + return rv; + } +} diff --git a/cmps/main.cc b/cmps/main.cc index a5d2b04..e1be73c 100644 --- a/cmps/main.cc +++ b/cmps/main.cc @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -56,10 +57,23 @@ static int refreshScanner(void *opaque, cHTTPRequest &Request) return -1; } +static void appID(void) +{ + fprintf(stderr, "\ncmps - the backend of CMP (compound media player)\n"); +} + +static void appInfo(void) +{ + appID(); + fprintf(stderr, " is a streaming- and HTTP-server\n"); + fprintf(stderr, " (c) 2012 - Reinhard Mantey - some rights reserved.\n"); + fprintf(stderr, " CMP is published as open source under Creative Commons by-sa\n\n"); +} + static void usage(void) { - fprintf(stderr, "cmps - the backend of CMP (compound media player)\n"); - fprintf(stderr, " is streaming- and HTTP-server and accepts these commandline options:\n"); + appID(); + fprintf(stderr, " is streaming- and HTTP-server and accepts these commandline options:\n"); fprintf(stderr, "-h, --help the help, you are reading\n"); fprintf(stderr, "-d, --appDir the directory, where the server may write config files\n"); fprintf(stderr, " (default is /var/lib/cmp)\n"); @@ -107,7 +121,8 @@ static void setup(int argc, char *argv[], cServerConfig &config) int main(int argc, char** argv) { - cServerConfig config("/var/lib/cmp"); + appInfo(); + cMediaServerConfig config("/var/lib/cmp"); setup(argc, argv, config); cFSMediaScanner *scanner = new cFSMediaScanner(); @@ -142,11 +157,13 @@ int main(int argc, char** argv) * register/enable internal commands */ cCommandHandler::RegisterCallback("refresh", refreshScanner, scanner); + fprintf(stderr, "start searching for media at %s\n", config.DocumentRoot()); scanner->Refresh(); /* * now start the server */ + fprintf(stderr, "ok, ready for client connections.\n"); if (!server->Start()) { fprintf(stderr, "failed to start application (3)"); exit(-3); diff --git a/cmps/nbproject/Makefile-Debug.mk b/cmps/nbproject/Makefile-Debug.mk index af8aa89..d825972 100644 --- a/cmps/nbproject/Makefile-Debug.mk +++ b/cmps/nbproject/Makefile-Debug.mk @@ -42,6 +42,7 @@ TESTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tests # Test Files TESTFILES= \ + ${TESTDIR}/TestFiles/f8 \ ${TESTDIR}/TestFiles/codecTest \ ${TESTDIR}/TestFiles/connectionHandlerTest \ ${TESTDIR}/TestFiles/fileSystemTest \ @@ -89,7 +90,7 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps: ${OBJECTFILES} ${OBJECTDIR}/main.o: nbproject/Makefile-${CND_CONF}.mk main.cc ${MKDIR} -p ${OBJECTDIR} ${RM} $@.d - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -MMD -MP -MF $@.d -o ${OBJECTDIR}/main.o main.cc + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${OBJECTDIR}/main.o main.cc # Subprojects .build-subprojects: @@ -107,6 +108,10 @@ ${OBJECTDIR}/main.o: nbproject/Makefile-${CND_CONF}.mk main.cc # Build Test Targets .build-tests-conf: .build-conf ${TESTFILES} +${TESTDIR}/TestFiles/f8: ${TESTDIR}/tests/BaseScanTest.o ${OBJECTFILES:%.o=%_nomain.o} + ${MKDIR} -p ${TESTDIR}/TestFiles + ${LINK.cc} -o ${TESTDIR}/TestFiles/f8 $^ ${LDLIBSOPTIONS} + ${TESTDIR}/TestFiles/codecTest: ${TESTDIR}/tests/CodecTest.o ${OBJECTFILES:%.o=%_nomain.o} ${MKDIR} -p ${TESTDIR}/TestFiles ${LINK.cc} -o ${TESTDIR}/TestFiles/codecTest $^ ${LDLIBSOPTIONS} @@ -136,46 +141,52 @@ ${TESTDIR}/TestFiles/stringBuilderTest: ${TESTDIR}/tests/StringBuilderTest.o ${O ${LINK.cc} -o ${TESTDIR}/TestFiles/stringBuilderTest $^ ${LDLIBSOPTIONS} +${TESTDIR}/tests/BaseScanTest.o: tests/BaseScanTest.cc + ${MKDIR} -p ${TESTDIR}/tests + ${RM} $@.d + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/BaseScanTest.o tests/BaseScanTest.cc + + ${TESTDIR}/tests/CodecTest.o: tests/CodecTest.cc ${MKDIR} -p ${TESTDIR}/tests ${RM} $@.d - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/CodecTest.o tests/CodecTest.cc + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/CodecTest.o tests/CodecTest.cc ${TESTDIR}/tests/ConnectionHandlerTest.o: tests/ConnectionHandlerTest.cc ${MKDIR} -p ${TESTDIR}/tests ${RM} $@.d - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/ConnectionHandlerTest.o tests/ConnectionHandlerTest.cc + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/ConnectionHandlerTest.o tests/ConnectionHandlerTest.cc ${TESTDIR}/tests/FileSystemTest.o: tests/FileSystemTest.cc ${MKDIR} -p ${TESTDIR}/tests ${RM} $@.d - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/FileSystemTest.o tests/FileSystemTest.cc + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/FileSystemTest.o tests/FileSystemTest.cc ${TESTDIR}/tests/FScanTest.o: tests/FScanTest.cc ${MKDIR} -p ${TESTDIR}/tests ${RM} $@.d - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/FScanTest.o tests/FScanTest.cc + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/FScanTest.o tests/FScanTest.cc ${TESTDIR}/tests/JSonTest.o: tests/JSonTest.cc ${MKDIR} -p ${TESTDIR}/tests ${RM} $@.d - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/JSonTest.o tests/JSonTest.cc + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/JSonTest.o tests/JSonTest.cc ${TESTDIR}/tests/MetaScanTest.o: tests/MetaScanTest.cc ${MKDIR} -p ${TESTDIR}/tests ${RM} $@.d - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/MetaScanTest.o tests/MetaScanTest.cc + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/MetaScanTest.o tests/MetaScanTest.cc ${TESTDIR}/tests/StringBuilderTest.o: tests/StringBuilderTest.cc ${MKDIR} -p ${TESTDIR}/tests ${RM} $@.d - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/StringBuilderTest.o tests/StringBuilderTest.cc + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -I. -MMD -MP -MF $@.d -o ${TESTDIR}/tests/StringBuilderTest.o tests/StringBuilderTest.cc ${OBJECTDIR}/main_nomain.o: ${OBJECTDIR}/main.o main.cc @@ -186,7 +197,7 @@ ${OBJECTDIR}/main_nomain.o: ${OBJECTDIR}/main.o main.cc (echo "$$NMOUTPUT" | ${GREP} 'T _main$$'); \ then \ ${RM} $@.d;\ - $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/main_nomain.o main.cc;\ + $(COMPILE.cc) -g -Wall -D_GNU_SOURCE=1 -D_REENTRANT -Iinclude -Iserverlib/include -I../libs/mediaScan/include -I../libs/networking/include -I../libs/IO/include -I../libs/util/include -I../libs/vdr/include -I. -Dmain=__nomain -MMD -MP -MF $@.d -o ${OBJECTDIR}/main_nomain.o main.cc;\ else \ ${CP} ${OBJECTDIR}/main.o ${OBJECTDIR}/main_nomain.o;\ fi @@ -195,6 +206,7 @@ ${OBJECTDIR}/main_nomain.o: ${OBJECTDIR}/main.o main.cc .test-conf: @if [ "${TEST}" = "" ]; \ then \ + ${TESTDIR}/TestFiles/f8 || true; \ ${TESTDIR}/TestFiles/codecTest || true; \ ${TESTDIR}/TestFiles/connectionHandlerTest || true; \ ${TESTDIR}/TestFiles/fileSystemTest || true; \ diff --git a/cmps/nbproject/Makefile-Release.mk b/cmps/nbproject/Makefile-Release.mk index 4232298..550c27f 100644 --- a/cmps/nbproject/Makefile-Release.mk +++ b/cmps/nbproject/Makefile-Release.mk @@ -48,6 +48,7 @@ TESTFILES= \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps \ + ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps # C Compiler Flags @@ -84,6 +85,10 @@ ${OBJECTDIR}/main.o: nbproject/Makefile-${CND_CONF}.mk main.cc # Build Test Targets .build-tests-conf: .build-conf ${TESTFILES} +${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps: ${TESTDIR}/tests/BaseScanTest.o ${OBJECTFILES:%.o=%_nomain.o} + ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} + ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps $^ ${LDLIBSOPTIONS} + ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps: ${TESTDIR}/tests/CodecTest.o ${OBJECTFILES:%.o=%_nomain.o} ${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM} ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps $^ ${LDLIBSOPTIONS} @@ -113,6 +118,12 @@ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps: ${TESTDIR}/tests/StringBuilderT ${LINK.cc} -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps $^ ${LDLIBSOPTIONS} +${TESTDIR}/tests/BaseScanTest.o: tests/BaseScanTest.cc + ${MKDIR} -p ${TESTDIR}/tests + ${RM} $@.d + $(COMPILE.cc) -O2 -MMD -MP -MF $@.d -o ${TESTDIR}/tests/BaseScanTest.o tests/BaseScanTest.cc + + ${TESTDIR}/tests/CodecTest.o: tests/CodecTest.cc ${MKDIR} -p ${TESTDIR}/tests ${RM} $@.d @@ -179,6 +190,7 @@ ${OBJECTDIR}/main_nomain.o: ${OBJECTDIR}/main.o main.cc ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps || true; \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps || true; \ ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps || true; \ + ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/cmps || true; \ else \ ./${TEST} || true; \ fi diff --git a/cmps/nbproject/configurations.xml b/cmps/nbproject/configurations.xml index de3675f..d2880dd 100644 --- a/cmps/nbproject/configurations.xml +++ b/cmps/nbproject/configurations.xml @@ -18,6 +18,12 @@ displayName="Test Files" projectFiles="false" kind="TEST_LOGICAL_FOLDER"> + + tests/BaseScanTest.cc + default + + + . + + include @@ -84,6 +95,7 @@ ../libs/IO/include ../libs/util/include ../libs/vdr/include + . -std=gnu++0x -fomit-frame-pointer -fPIC -pthread -Wall -Wno-parentheses -Wno-switch -Wdisabled-optimization -Wpointer-arith -Wredundant-decls -Wwrite-strings -Wtype-limits -Wundef -fno-math-errno -fno-signed-zeros -fno-tree-vectorize -Werror=implicit-function-declaration diff --git a/cmps/tests/StringBuilderTest.cc b/cmps/tests/StringBuilderTest.cc index 9814411..8d2b150 100644 --- a/cmps/tests/StringBuilderTest.cc +++ b/cmps/tests/StringBuilderTest.cc @@ -75,6 +75,22 @@ void basicTests() free(result); } +void replaceTest() +{ + const char char2Replace[] = { '"', '\0' }; + const char *replacements[] = { "\\\"", NULL }; + const char *sample = "mal sehen, was \"hier\" so abgeht?!"; + cStringBuilder sb(17); + + sb.Append(sample, char2Replace, replacements); + char *result = sb.toString(); + + std::cout << "result with replace: " << result << std::endl; +// std::cout << "result with replace (size " << sb.Size() << "): " << result << std::endl; + std::cout << "size-check: " << strlen(sample) << " <> " << strlen(result) << std::endl; + free(result); +} + void lineReaderTest() { cLineReader lr(new cFileReader(new cFile("srclient.conf"))); @@ -92,6 +108,7 @@ int main() lineReaderTest(); basicTests(); rangeTests(); + replaceTest(); return 0; } diff --git a/libs/IO/src/CommandReader.cc b/libs/IO/src/CommandReader.cc index 0bc6109..accd79f 100644 --- a/libs/IO/src/CommandReader.cc +++ b/libs/IO/src/CommandReader.cc @@ -51,17 +51,10 @@ void cCommandReader::Close(void) int status = 0; if (!fdMax) fdMax = getdtablesize(); - if (fd > 0 && fd < fdMax) { - close(fd); - isyslog("closed fd #%d", fd); - } + if (fd > 0 && fd < fdMax) close(fd); fd = -1; - if (pid != waitpid(pid, &status, 0)) { + if (pid != waitpid(pid, &status, 0)) esyslog("ERROR: failed to wait for child #%d - error #%d", pid, errno); - } - else { - isyslog("child exit status: %d", WEXITSTATUS(status)); - } pid = -1; } @@ -110,7 +103,6 @@ bool cCommandReader::Open(void) esyslog("ERROR: failed to close write end from parent side!"); exit(-1); } - isyslog("child process #%d started ... fd %d", pid, child2Parent[FDRead]); fd = child2Parent[FDRead]; return true; } diff --git a/libs/mediaScan/src/Audio.cc b/libs/mediaScan/src/Audio.cc index 9420db6..62e9379 100644 --- a/libs/mediaScan/src/Audio.cc +++ b/libs/mediaScan/src/Audio.cc @@ -24,6 +24,7 @@ */ #include #include +#include #include #include #include @@ -74,6 +75,7 @@ void cAudio::AddMeta(cMediainfoReader::InfoEntry* Entry) void cAudio::EnableDeepScan(bool DoScan) { deepScanEnabled = DoScan; + isyslog("cAudio::enableDeepScan(%s)", deepScanEnabled ? "true" : "false"); } const char *cAudio::ContentType(const char* Extension) diff --git a/libs/mediaScan/src/DVDImage.cc b/libs/mediaScan/src/DVDImage.cc index 0ddcdac..1a78581 100644 --- a/libs/mediaScan/src/DVDImage.cc +++ b/libs/mediaScan/src/DVDImage.cc @@ -23,6 +23,7 @@ * -------------------------------------------------------------- */ #include +#include #include #include #include @@ -55,6 +56,7 @@ size_t cDVDImage::Size(void) const void cDVDImage::EnableDeepScan(bool DoScan) { deepScanEnabled = DoScan; + isyslog("cDVDImage::enableDeepScan(%s)", deepScanEnabled ? "true" : "false"); } bool cDVDImage::NeedsFurtherScan(void) const diff --git a/libs/mediaScan/src/LegacyVdrRecording.cc b/libs/mediaScan/src/LegacyVdrRecording.cc index 2b4d7af..b12d693 100644 --- a/libs/mediaScan/src/LegacyVdrRecording.cc +++ b/libs/mediaScan/src/LegacyVdrRecording.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ cLegacyVdrRecording::~cLegacyVdrRecording() void cLegacyVdrRecording::EnableDeepScan(bool DoScan) { deepScanEnabled = DoScan; + isyslog("cLegacyVdrRecording::enableDeepScan(%s)", deepScanEnabled ? "true" : "false"); } bool cLegacyVdrRecording::NeedsFurtherScan(void) const diff --git a/libs/mediaScan/src/Movie.cc b/libs/mediaScan/src/Movie.cc index 19fc629..7194f54 100644 --- a/libs/mediaScan/src/Movie.cc +++ b/libs/mediaScan/src/Movie.cc @@ -23,6 +23,7 @@ * -------------------------------------------------------------- */ #include +#include #include #include #include @@ -82,6 +83,7 @@ void cMovie::AddMeta(cMediainfoReader::InfoEntry *Entry) void cMovie::EnableDeepScan(bool DoScan) { deepScanEnabled = DoScan; + isyslog("cMovie::enableDeepScan(%s)", deepScanEnabled ? "true" : "false"); } bool cMovie::NeedsFurtherScan(void) const diff --git a/libs/mediaScan/src/Picture.cc b/libs/mediaScan/src/Picture.cc index 0401401..a480e45 100644 --- a/libs/mediaScan/src/Picture.cc +++ b/libs/mediaScan/src/Picture.cc @@ -23,6 +23,7 @@ * -------------------------------------------------------------- */ #include +#include #include #include @@ -72,6 +73,7 @@ const char *cPicture::ContentType(const char* Extension) void cPicture::EnableDeepScan(bool DoScan) { deepScanEnabled = DoScan; + isyslog("cPicture::enableDeepScan(%s)", deepScanEnabled ? "true" : "false"); } bool cPicture::NeedsFurtherScan(void) const diff --git a/libs/mediaScan/src/VdrRecording.cc b/libs/mediaScan/src/VdrRecording.cc index bf1eaab..afb930a 100644 --- a/libs/mediaScan/src/VdrRecording.cc +++ b/libs/mediaScan/src/VdrRecording.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,7 @@ cVdrRecording::~cVdrRecording() void cVdrRecording::EnableDeepScan(bool DoScan) { deepScanEnabled = DoScan; + isyslog("cVdrRecording::enableDeepScan(%s)", deepScanEnabled ? "true" : "false"); } bool cVdrRecording::NeedsFurtherScan(void) const diff --git a/libs/networking/src/HTTPServer.cc b/libs/networking/src/HTTPServer.cc index ba62283..a857ff1 100644 --- a/libs/networking/src/HTTPServer.cc +++ b/libs/networking/src/HTTPServer.cc @@ -65,8 +65,6 @@ void cHTTPServer::Action() cleaner->Start(); } #endif - fprintf(stderr, "startup server now\n"); - ServerSocket().Open(); while (Running()) { cConnectionPoint *cp = ServerSocket().Accept(); diff --git a/libs/util/include/StringBuilder.h b/libs/util/include/StringBuilder.h index db98934..977c4e7 100644 --- a/libs/util/include/StringBuilder.h +++ b/libs/util/include/StringBuilder.h @@ -34,7 +34,7 @@ public: cStringBuilder(int chunkSize = 127); virtual ~cStringBuilder(); - cStringBuilder &Append(const char *Text); + cStringBuilder &Append(const char *Text, const char char2Replace[] = NULL, const char *replacements[] = NULL); cStringBuilder &Append(char c); cStringBuilder &Append(bool v, const char *TrueValue = "X", const char *FalseValue="-"); cStringBuilder &Append(double v); @@ -48,9 +48,12 @@ public: size_t Copy(char *Buf, size_t BufSize); char *toString(void); +protected: + void Write(const char *Text); + void WriteAndReplace(const char *Text, const char char2Replace[], const char *replacements[]); + private: void init(void); - void Write(const char *p); int chunkSize; size_t readOffset; ///< read offest is the offset over all chunks (thus goes from 0 to size) ///< Copy can be called subsequently, if Buf is smaller than StringBuilders size diff --git a/libs/util/src/JSonWriter.cc b/libs/util/src/JSonWriter.cc index ec9b1dc..8fcb140 100644 --- a/libs/util/src/JSonWriter.cc +++ b/libs/util/src/JSonWriter.cc @@ -28,6 +28,9 @@ #include #define DEBUG 1 +static const char char2Replace[] = { '"', '\0' }; +static const char *replacements[] = { "\\\"", NULL }; + cJSonWriter::cJSonWriter(cStringBuilder &StringBuilder) : lastState(JS_Unknown) , sb(StringBuilder) @@ -130,7 +133,7 @@ cJSonWriter &cJSonWriter::Value(const char *Text) { } else { PopState(); - sb.Append("\"").Append(Text).Append("\""); + sb.Append("\"").Append(Text, char2Replace, replacements).Append("\""); } return *this; } diff --git a/libs/util/src/StringBuilder.cc b/libs/util/src/StringBuilder.cc index 28b048e..7da1aac 100644 --- a/libs/util/src/StringBuilder.cc +++ b/libs/util/src/StringBuilder.cc @@ -91,6 +91,51 @@ void cStringBuilder::Write(const char *Text) } } +void cStringBuilder::WriteAndReplace(const char *Text, const char char2Replace[], const char *replacements[]) +{ + if (!Text) { + esyslog("ERROR: text to add is a NULL-pointer!"); + return; + } + int done; + char *curChunk = (char *) pool[pool.size() - 1]; + char *chunkLast = curChunk + chunkSize; + char *pd; + const char *ps, *srcLast = Text + strlen(Text), *pChk; + + for (ps = Text, pd = curChunk + writeOffset; ps < srcLast; ++ps) { + done = 0; + for (pChk = char2Replace; pChk && *pChk; ++pChk) { + if (*ps == *pChk) { + const char *rps = replacements[pChk - char2Replace]; + done = 1; + + while (rps && *rps) { + if (writeOffset == chunkSize) { + curChunk = (char *) malloc(chunkSize); + pool.push_back(curChunk); + writeOffset = 0; + pd = curChunk; + chunkLast = curChunk + chunkSize; + } + *pd++ = *rps++; + ++writeOffset; + } + } + } + if (done) continue; + if (writeOffset == chunkSize) { + curChunk = (char *) malloc(chunkSize); + pool.push_back(curChunk); + writeOffset = 0; + pd = curChunk; + chunkLast = curChunk + chunkSize; + } + *pd++ = *ps; + ++writeOffset; + } +} + size_t cStringBuilder::Size() { return (pool.size() - 1) * chunkSize + writeOffset; @@ -125,10 +170,11 @@ size_t cStringBuilder::Copy(char* Buf, size_t BufSize) return bytesWritten; } -cStringBuilder &cStringBuilder::Append(const char* Text) +cStringBuilder &cStringBuilder::Append(const char* Text, const char char2Replace[], const char *replacements[]) { if (!Text) Write("(null)"); - Write(Text); + if (char2Replace && replacements) WriteAndReplace(Text, char2Replace, replacements); + else Write(Text); return *this; } -- cgit v1.2.3