From 01ddf4e24db8f9e0ed0a686a74a969bec3838ec7 Mon Sep 17 00:00:00 2001 From: xieguigang Date: Mon, 18 Apr 2016 13:37:05 +0800 Subject: [PATCH] protocols --- .../SharedMemory/HashValue.vb | 15 ++++++++++ .../SharedMemory/Protocols.vb | 28 +++++++++++++++++-- .../SharedMemory/SharedSvr.vb | 27 +++++++++++++++++- .../Taskhost.d/Invoke/InvokeInfo.vb | 4 +++ 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/ComputingServices/ComputingServices/SharedMemory/HashValue.vb b/ComputingServices/ComputingServices/SharedMemory/HashValue.vb index 1da4e69..09fd23d 100644 --- a/ComputingServices/ComputingServices/SharedMemory/HashValue.vb +++ b/ComputingServices/ComputingServices/SharedMemory/HashValue.vb @@ -20,4 +20,19 @@ Namespace SharedMemory Return $"Dim {Identifier} As {Type.ToString} = {JsonContract.GetJson(value, Type.GetType)}" End Function End Class + + Public Structure Argv : Implements sIdEnumerable + + Public Property Identifier As String Implements sIdEnumerable.Identifier + Public Property value As TaskHost.Argv + + Sub New(name As String, x As Object) + Identifier = name + value = New TaskHost.Argv(x) + End Sub + + Public Overrides Function ToString() As String + Return Me.GetJson + End Function + End Structure End Namespace \ No newline at end of file diff --git a/ComputingServices/ComputingServices/SharedMemory/Protocols.vb b/ComputingServices/ComputingServices/SharedMemory/Protocols.vb index 660f8c5..cab3e36 100644 --- a/ComputingServices/ComputingServices/SharedMemory/Protocols.vb +++ b/ComputingServices/ComputingServices/SharedMemory/Protocols.vb @@ -1,4 +1,9 @@ -Imports Microsoft.VisualBasic.Net.Protocols +Imports System.Runtime.CompilerServices +Imports Microsoft.VisualBasic.ComputingServices.TaskHost +Imports Microsoft.VisualBasic.Net +Imports Microsoft.VisualBasic.Net.Protocols +Imports Microsoft.VisualBasic.Net.Protocols.Reflection +Imports Microsoft.VisualBasic.Serialization Namespace SharedMemory @@ -9,12 +14,31 @@ Namespace SharedMemory Write End Enum - Public Function ReadValue(name As String) As RequestStream + Public ReadOnly Property ProtocolEntry As Long = New Protocol(GetType(MemoryProtocols)).EntryPoint + Public Function ReadValue(name As String) As RequestStream + Return New RequestStream(ProtocolEntry, MemoryProtocols.Read, name) End Function Public Function WriteValue(name As String, value As Object) As RequestStream + Dim json As New Argv(name, value) + Dim req As New RequestStream(ProtocolEntry, MemoryProtocols.Write, json.GetJson) + Return req + End Function + + + Public Function ReadValue(remote As IPEndPoint, name As String, type As Type) As Object + Dim req As RequestStream = ReadValue(name) + Dim rep As RequestStream = New AsynInvoke(remote).SendMessage(req) + Dim value As TaskHost.Argv = rep.LoadObject(Of TaskHost.Argv) + Return JsonContract.LoadObject(value.value, type) + End Function + + Public Function WriteValue(remote As IPEndPoint, name As String, value As Object) As Boolean + Dim req As RequestStream = WriteValue(name, value) + Dim rep As RequestStream = New AsynInvoke(remote).SendMessage(req) + Return rep.Protocol = HTTP_RFC.RFC_OK End Function End Module End Namespace \ No newline at end of file diff --git a/ComputingServices/ComputingServices/SharedMemory/SharedSvr.vb b/ComputingServices/ComputingServices/SharedMemory/SharedSvr.vb index 4c5f0cd..ec29edc 100644 --- a/ComputingServices/ComputingServices/SharedMemory/SharedSvr.vb +++ b/ComputingServices/ComputingServices/SharedMemory/SharedSvr.vb @@ -1,18 +1,43 @@ -Imports Microsoft.VisualBasic.Net +Imports Microsoft.VisualBasic.ComponentModel.DataSourceModel +Imports Microsoft.VisualBasic.Net +Imports Microsoft.VisualBasic.Net.Protocols +Imports Microsoft.VisualBasic.Net.Protocols.Reflection Namespace SharedMemory ''' ''' Memory shared services. ''' + ''' + Public Class SharedSvr : Implements IDisposable + Implements IObjectModel_Driver ReadOnly __localSvr As TcpSynchronizationServicesSocket Sub New(local As Integer) __localSvr = New TcpSynchronizationServicesSocket(local) + __localSvr.Responsehandler = AddressOf New ProtocolHandler(Me).HandleRequest End Sub + + Private Function Read(CA As Long, args As RequestStream, remote As IPEndPoint) As RequestStream + + End Function + + + Private Function Write(CA As Long, args As RequestStream, remote As IPEndPoint) As RequestStream + + End Function + + Public Overrides Function ToString() As String + Return __localSvr.ToString + End Function + + Public Function Run() As Integer Implements IObjectModel_Driver.Run + Return __localSvr.Run + End Function + #Region "IDisposable Support" Private disposedValue As Boolean ' To detect redundant calls diff --git a/ComputingServices/ComputingServices/Taskhost.d/Invoke/InvokeInfo.vb b/ComputingServices/ComputingServices/Taskhost.d/Invoke/InvokeInfo.vb index e048aa5..9a5842e 100644 --- a/ComputingServices/ComputingServices/Taskhost.d/Invoke/InvokeInfo.vb +++ b/ComputingServices/ComputingServices/Taskhost.d/Invoke/InvokeInfo.vb @@ -17,6 +17,10 @@ Namespace TaskHost Sub New() End Sub + ''' + ''' Creates the function remote calls one of its parameter value. + ''' + ''' Sub New(o As Object) Dim type As Type = o.GetType