mirror of https://github.com/icedream/npsharp.git
Make RPC stream accessible from high-level API since it's incomplete as fuck.
parent
817007c135
commit
b380f926ca
|
@ -20,7 +20,8 @@ namespace NPSharp.NP
|
||||||
private readonly ushort _port;
|
private readonly ushort _port;
|
||||||
private CancellationToken _cancellationToken;
|
private CancellationToken _cancellationToken;
|
||||||
private CancellationTokenSource _cancellationTokenSource;
|
private CancellationTokenSource _cancellationTokenSource;
|
||||||
private RPCClientStream _rpc;
|
|
||||||
|
public RPCClientStream RPC { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the NP client with a specified host and port.
|
/// Initializes the NP client with a specified host and port.
|
||||||
|
@ -58,7 +59,7 @@ namespace NPSharp.NP
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_rpc = RPCClientStream.Open(_host, _port);
|
RPC = RPCClientStream.Open(_host, _port);
|
||||||
}
|
}
|
||||||
catch (Exception err)
|
catch (Exception err)
|
||||||
{
|
{
|
||||||
|
@ -77,7 +78,7 @@ namespace NPSharp.NP
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (_rpc.Read() == null)
|
if (RPC.Read() == null)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +105,7 @@ namespace NPSharp.NP
|
||||||
_cancellationTokenSource.Cancel(true);
|
_cancellationTokenSource.Cancel(true);
|
||||||
// TODO: Find a cleaner way to cancel _processingTask (focus: _rpc.Read)
|
// TODO: Find a cleaner way to cancel _processingTask (focus: _rpc.Read)
|
||||||
//_procTask.Wait(_cancellationToken);
|
//_procTask.Wait(_cancellationToken);
|
||||||
_rpc.Close();
|
RPC.Close();
|
||||||
|
|
||||||
LoginId = 0;
|
LoginId = 0;
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ namespace NPSharp.NP
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<bool>();
|
var tcs = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
_rpc.AttachHandlerForNextMessage(packet =>
|
RPC.AttachHandlerForNextMessage(packet =>
|
||||||
{
|
{
|
||||||
var result = packet as AuthenticateResultMessage;
|
var result = packet as AuthenticateResultMessage;
|
||||||
if (result == null)
|
if (result == null)
|
||||||
|
@ -134,7 +135,7 @@ namespace NPSharp.NP
|
||||||
SessionToken = result.SessionToken;
|
SessionToken = result.SessionToken;
|
||||||
tcs.SetResult(true);
|
tcs.SetResult(true);
|
||||||
});
|
});
|
||||||
_rpc.Send(new AuthenticateWithTokenMessage {Token = token});
|
RPC.Send(new AuthenticateWithTokenMessage {Token = token});
|
||||||
|
|
||||||
return await tcs.Task;
|
return await tcs.Task;
|
||||||
}
|
}
|
||||||
|
@ -150,14 +151,14 @@ namespace NPSharp.NP
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<bool>();
|
var tcs = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
_rpc.AttachHandlerForNextMessage(packet =>
|
RPC.AttachHandlerForNextMessage(packet =>
|
||||||
{
|
{
|
||||||
var result = (StorageWriteUserFileResultMessage) packet;
|
var result = (StorageWriteUserFileResultMessage) packet;
|
||||||
if (result.Result != 0)
|
if (result.Result != 0)
|
||||||
tcs.SetResult(false);
|
tcs.SetResult(false);
|
||||||
tcs.SetResult(true);
|
tcs.SetResult(true);
|
||||||
});
|
});
|
||||||
_rpc.Send(new StorageWriteUserFileMessage {FileData = contents, FileName = filename, NPID = LoginId});
|
RPC.Send(new StorageWriteUserFileMessage {FileData = contents, FileName = filename, NPID = LoginId});
|
||||||
|
|
||||||
return await tcs.Task;
|
return await tcs.Task;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +172,7 @@ namespace NPSharp.NP
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<byte[]>();
|
var tcs = new TaskCompletionSource<byte[]>();
|
||||||
|
|
||||||
_rpc.AttachHandlerForNextMessage(packet =>
|
RPC.AttachHandlerForNextMessage(packet =>
|
||||||
{
|
{
|
||||||
var result = (StorageUserFileMessage) packet;
|
var result = (StorageUserFileMessage) packet;
|
||||||
if (result.Result != 0)
|
if (result.Result != 0)
|
||||||
|
@ -181,7 +182,7 @@ namespace NPSharp.NP
|
||||||
}
|
}
|
||||||
tcs.SetResult(result.FileData);
|
tcs.SetResult(result.FileData);
|
||||||
});
|
});
|
||||||
_rpc.Send(new StorageGetUserFileMessage {FileName = filename, NPID = LoginId});
|
RPC.Send(new StorageGetUserFileMessage {FileName = filename, NPID = LoginId});
|
||||||
|
|
||||||
return await tcs.Task;
|
return await tcs.Task;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +210,7 @@ namespace NPSharp.NP
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<byte[]>();
|
var tcs = new TaskCompletionSource<byte[]>();
|
||||||
|
|
||||||
_rpc.AttachHandlerForNextMessage(packet =>
|
RPC.AttachHandlerForNextMessage(packet =>
|
||||||
{
|
{
|
||||||
var result = (StoragePublisherFileMessage) packet;
|
var result = (StoragePublisherFileMessage) packet;
|
||||||
if (result.Result != 0)
|
if (result.Result != 0)
|
||||||
|
@ -219,7 +220,7 @@ namespace NPSharp.NP
|
||||||
}
|
}
|
||||||
tcs.SetResult(result.FileData);
|
tcs.SetResult(result.FileData);
|
||||||
});
|
});
|
||||||
_rpc.Send(new StorageGetPublisherFileMessage {FileName = filename});
|
RPC.Send(new StorageGetPublisherFileMessage {FileName = filename});
|
||||||
|
|
||||||
return await tcs.Task;
|
return await tcs.Task;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +239,7 @@ namespace NPSharp.NP
|
||||||
|
|
||||||
public void SendRandomString(string data)
|
public void SendRandomString(string data)
|
||||||
{
|
{
|
||||||
_rpc.Send(new StorageSendRandomStringMessage {RandomString = data});
|
RPC.Send(new StorageSendRandomStringMessage {RandomString = data});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using log4net;
|
|
||||||
using NPSharp.RPC.Messages;
|
using NPSharp.RPC.Messages;
|
||||||
|
|
||||||
namespace NPSharp.RPC
|
namespace NPSharp.RPC
|
||||||
|
@ -32,11 +31,6 @@ namespace NPSharp.RPC
|
||||||
protected readonly List<KeyValuePair<uint, Action<TRecv>>> TypeCallbacks =
|
protected readonly List<KeyValuePair<uint, Action<TRecv>>> TypeCallbacks =
|
||||||
new List<KeyValuePair<uint, Action<TRecv>>>();
|
new List<KeyValuePair<uint, Action<TRecv>>>();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Logger instance.
|
|
||||||
/// </summary>
|
|
||||||
private readonly ILog _log;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ID of the next message.
|
/// ID of the next message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -53,7 +47,6 @@ namespace NPSharp.RPC
|
||||||
/// <param name="sock">Client's network stream</param>
|
/// <param name="sock">Client's network stream</param>
|
||||||
protected RPCStream(Socket sock)
|
protected RPCStream(Socket sock)
|
||||||
{
|
{
|
||||||
_log = LogManager.GetLogger("RPC");
|
|
||||||
_sock = sock;
|
_sock = sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue