-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
290 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Autofac; | ||
|
||
namespace Mpv.JsonIpc | ||
{ | ||
public class DependencyModule : Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
builder.RegisterType<NamedPipeFactory>().As<INamedPipeFactory>(); | ||
builder.RegisterType<Manager>().As<IManager>(); | ||
builder.RegisterType<Ipc>().As<IIpc>(); | ||
builder.RegisterType<Api>().As<IApi>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Mpv.JsonIpc | ||
{ | ||
public interface IApi | ||
{ | ||
Task ShowText(string text, TimeSpan duration); | ||
Task<float> GetVolume(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Mpv.JsonIpc | ||
{ | ||
public interface IIpc | ||
{ | ||
Task<Response<T>> ExecuteCommand<T>(Request request); | ||
Task<Response<T>> GetProperty<T>(Property property, params string[] args); | ||
Task<Response<T>> SetProperty<T>(Property property, params object[] args); | ||
Task<Response<T>> SetPropertyString<T>(Property property, params string[] args); | ||
Task<Response<T>> CycleProperty<T>(Property property); | ||
Request CreateCommand(IEnumerable<object> command); | ||
Request CreateCommand(IEnumerable<object> command, object arg); | ||
Request CreateCommand(IEnumerable<object> command, IEnumerable<object> args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Mpv.JsonIpc | ||
{ | ||
public interface IManager | ||
{ | ||
Task<Response<T>> Execute<T>(Request message); | ||
void Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.IO.Pipes; | ||
|
||
namespace Mpv.JsonIpc | ||
{ | ||
public interface INamedPipeFactory | ||
{ | ||
NamedPipeClientStream CreateNamedPipe(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Mpv.JsonIpc | ||
{ | ||
public class Ipc : IIpc | ||
{ | ||
private readonly IManager _manager; | ||
|
||
public Ipc(IManager manager) | ||
{ | ||
_manager = manager; | ||
} | ||
|
||
public async Task<Response<T>> ExecuteCommand<T>(Request request) | ||
{ | ||
return await _manager.Execute<T>(request); | ||
} | ||
|
||
public async Task<Response<T>> GetProperty<T>(Property property, params string[] args) | ||
{ | ||
var request = CreateCommand(new[] {"get_property", property.GetStringValue()}, args); | ||
return await _manager.Execute<T>(request); | ||
} | ||
|
||
public async Task<Response<T>> SetProperty<T>(Property property, params object[] args) | ||
{ | ||
var request = CreateCommand(new[] {"set_property", property.GetStringValue()}, args); | ||
return await _manager.Execute<T>(request); | ||
} | ||
|
||
public async Task<Response<T>> SetPropertyString<T>(Property property, params string[] args) | ||
{ | ||
var request = CreateCommand(new[] {"set_property_string", property.GetStringValue()}, args); | ||
return await _manager.Execute<T>(request); | ||
} | ||
|
||
public async Task<Response<T>> CycleProperty<T>(Property property) | ||
{ | ||
var request = CreateCommand(new[] {"cycle", property.GetStringValue()}); | ||
return await _manager.Execute<T>(request); | ||
} | ||
|
||
public Request CreateCommand(IEnumerable<object> command) | ||
{ | ||
return CreateCommand(command, Array.Empty<object>()); | ||
} | ||
|
||
public Request CreateCommand(IEnumerable<object> command, object arg) | ||
{ | ||
return CreateCommand(command, new[] {arg}); | ||
} | ||
|
||
public Request CreateCommand(IEnumerable<object> command, IEnumerable<object> args) | ||
{ | ||
return new Request | ||
{ | ||
Command = command.Concat(args).ToArray(), | ||
RequestId = GenerateNewRequestId(), | ||
}; | ||
} | ||
|
||
|
||
private static int GenerateNewRequestId() | ||
{ | ||
return 10; | ||
// return _random.Next(0, 10000); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Autofac; | ||
|
||
namespace Mpv.WebApi | ||
{ | ||
public class DependencyModule : Module | ||
{ | ||
protected override void Load(ContainerBuilder builder) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.