Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Flatten the class hierarchy

Refactoring everything into classes earned me a fatal "illegal redeclaration of
symbol 'XMMS2::Client'". Seems it didn't like names like "XMMS2::Client::Result"
for some reason, but that's fixed now.
  • Loading branch information...
commit 474fd9ca82729df533f3527cf5f35ce301502c2c 1 parent eeeeaef
@flussence authored
View
4 lib/XMMS2/Client.pm6
@@ -1,6 +1,6 @@
use v6;
use NativeCall;
-use XMMS2::Client::Connection;
+use XMMS2::Connection;
#####
# The user-interfaceable part
@@ -16,6 +16,6 @@ class XMMS2::Client {
}
submethod BUILD(Str $client_name, Str $path) {
- $!connection = XMMS2::Client::Connection.new($client_name, $path);
+ $!connection = XMMS2::Connection.new($client_name, $path);
}
};
View
54 lib/XMMS2/Client/Connection.pm6
@@ -1,54 +0,0 @@
-use v6;
-use NativeCall;
-use XMMS2::Client::Result;
-
-# Pointer to an xmms2d connection
-# Would be nice if I could put the "is OpaquePointer" on the class below and have it DWIM...
-class xmmsc_connection_t is OpaquePointer { };
-
-# Wrapper around a connection pointer
-class XMMS2::Client::Connection {
- has xmmsc_connection_t $.connection;
-
- method new(Str $client_name, Str $path = %*ENV<XMMS_PATH>) {
- self.bless(*, :$client_name, :$path);
- }
-
- # TODO: there's async API, but this doesn't do that yet.
- method play(:$synchronous!) returns Bool {
- my $result =
- my Bool $success = XMMS2::Client::Result.new(:result => xmmsc_playback_start($!connection)).ok;
-
- warn 'Playback start failed!' if not $success;
-
- return $success;
- }
-
- submethod BUILD(Str $client_name, Str $path) {
- # FIXME: this can return NULL in an out-of-memory condition. No matter how implausible that
- # might sound, it should still be checked...
- $!connection = xmmsc_init($client_name);
-
- xmmsc_connect($!connection, $path || pir::null__P())
- or die "Connecting via '$path' failed with error: {xmmsc_get_last_error($!connection)}";
- }
-
- submethod DESTROY {
- xmmsc_unref($!connection);
- }
-};
-
-sub xmmsc_playback_start(xmmsc_connection_t --> xmmsc_result_t)
- is native('libxmmsclient') { ... }
-
-sub xmmsc_init(Str $clientname --> xmmsc_connection_t)
- is native('libxmmsclient') { ... }
-
-sub xmmsc_connect(xmmsc_connection_t, Str $path --> Int)
- is native('libxmmsclient') { ... }
-
-sub xmmsc_unref(xmmsc_connection_t)
- is native('libxmmsclient') { ... }
-
-sub xmmsc_get_last_error(xmmsc_connection_t --> Str)
- is native('libxmmsclient') { ... }
View
37 lib/XMMS2/Client/Result.pm6
@@ -1,37 +0,0 @@
-use v6;
-use NativeCall;
-use XMMS2::Value;
-
-# Result struct from a command
-class xmmsc_result_t is OpaquePointer { };
-
-# Wrapper around a result object
-class XMMS2::Client::Result {
- has xmmsc_result_t $.result;
-
- # Check whether this result is an error status
- method ok(:$verbose!) returns Bool {
- xmmsc_result_wait($!result);
- my $status = XMMS2::Value.new: xmmsc_result_get_value($!result);
- my $failed = ?$status.error;
-
- if $verbose and $failed {
- warn $status.error;
- }
-
- return not $failed;
- }
-
- submethod DESTROY {
- xmmsc_result_unref($!result);
- }
-};
-
-sub xmmsc_result_wait(xmmsc_result_t)
- is native('libxmmsclient') { ... }
-
-sub xmmsc_result_get_value(xmmsc_result_t --> xmmsv_t)
- is native('libxmmsclient') { ... }
-
-sub xmmsc_result_unref(xmmsc_result_t)
- is native('libxmmsclient') { ... }
View
53 lib/XMMS2/Connection.pm6
@@ -0,0 +1,53 @@
+use v6;
+use NativeCall;
+use XMMS2::Result;
+
+# Pointer to an xmms2d connection
+class xmmsc_connection_t is OpaquePointer { };
+
+# Native functions
+sub xmmsc_playback_start(xmmsc_connection_t --> xmmsc_result_t)
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_init(Str $clientname --> xmmsc_connection_t)
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_connect(xmmsc_connection_t, Str $path --> Int)
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_unref(xmmsc_connection_t)
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_get_last_error(xmmsc_connection_t --> Str)
+ is native('libxmmsclient') { ... }
+
+# Wrapper around a connection pointer
+class XMMS2::Connection;
+has xmmsc_connection_t $.connection;
+
+method new(Str $client_name, Str $path = %*ENV<XMMS_PATH>) {
+ self.bless(*, :$client_name, :$path);
+}
+
+# TODO: there's async API, but this doesn't do that yet.
+method play(:$synchronous!) returns Bool {
+ my $result =
+ my Bool $success = XMMS2::Result.new(:result => xmmsc_playback_start($!connection)).ok;
+
+ warn 'Playback start failed!' if not $success;
+
+ return $success;
+}
+
+submethod BUILD(Str $client_name, Str $path) {
+ # FIXME: this can return NULL in an out-of-memory condition. No matter how implausible that
+ # might sound, it should still be checked...
+ $!connection = xmmsc_init($client_name);
+
+ xmmsc_connect($!connection, $path || pir::null__P())
+ or die "Connecting via '$path' failed with error: {xmmsc_get_last_error($!connection)}";
+}
+
+submethod DESTROY {
+ xmmsc_unref($!connection);
+}
View
37 lib/XMMS2/Result.pm6
@@ -0,0 +1,37 @@
+use v6;
+use NativeCall;
+use XMMS2::Value;
+
+# Result struct from a command
+class xmmsc_result_t is OpaquePointer { };
+
+# Native functions
+sub xmmsc_result_wait(xmmsc_result_t)
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_result_get_value(xmmsc_result_t --> xmmsv_t)
+ is native('libxmmsclient') { ... }
+
+sub xmmsc_result_unref(xmmsc_result_t)
+ is native('libxmmsclient') { ... }
+
+# Wrapper around a result object
+class XMMS2::Result;
+has xmmsc_result_t $.result;
+
+# Check whether this result is an error status
+method ok(:$verbose!) returns Bool {
+ xmmsc_result_wait($!result);
+ my $status = XMMS2::Value.new: xmmsc_result_get_value($!result);
+ my $failed = ?$status.error;
+
+ if $verbose and $failed {
+ warn $status.error;
+ }
+
+ return not $failed;
+}
+
+submethod DESTROY {
+ xmmsc_result_unref($!result);
+}
View
24 lib/XMMS2/Value.pm6
@@ -4,20 +4,20 @@ use NativeCall;
# XMMS2 variant value
class xmmsv_t is OpaquePointer { };
-# Wrapper around an XMMS2 value struct
-class XMMS2::Value {
- has $!value;
-
- method error returns Str {
- return Str unless xmmsv_is_error($!value);
-
- xmmsv_get_error($!value, my $error-str);
- return $error-str;
- }
-}
-
+# Native functions
sub xmmsv_is_error(xmmsv_t --> Int)
is native('libxmmsclient') { ... }
sub xmmsv_get_error(xmmsv_t, Str $error is rw --> Int)
is native('libxmmsclient') { ... }
+
+# Wrapper around an XMMS2 value struct
+class XMMS2::Value;
+has $!value;
+
+method error returns Str {
+ return Str unless xmmsv_is_error($!value);
+
+ xmmsv_get_error($!value, my $error-str);
+ return $error-str;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.