/** * Portions Copyright (c) Microsoft Corporation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR * PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. * * See the Apache Version 2.0 License for specific language governing * permissions and limitations under the License. */ #ifndef __EDGE_H #define __EDGE_H #include "../common/edge_common.h" #include #using #using using namespace v8; using namespace System::Collections::Generic; using namespace System::Reflection; using namespace System::Threading::Tasks; using namespace System::Threading; using namespace System::Web::Script::Serialization; Handle stringCLR2V8(System::String^ text); System::String^ stringV82CLR(Handle text); System::String^ exceptionV82stringCLR(Handle exception); Handle throwV8Exception(Handle exception); typedef struct clrActionContext { gcroot action; static void ActionCallback(void* data); } ClrActionContext; ref class ClrFuncInvokeContext { private: Persistent* callback; uv_edge_async_t* uv_edge_async; void DisposeCallback(); public: property System::Object^ Payload; property Task^ Task; property bool Sync; ClrFuncInvokeContext(Handle callbackOrSync); void CompleteOnCLRThread(System::Threading::Tasks::Task^ task); void CompleteOnV8ThreadAsynchronous(); Handle CompleteOnV8Thread(); void InitializeAsyncOperation(); }; ref class NodejsFunc { public: property Persistent* Func; NodejsFunc(Handle function); ~NodejsFunc(); !NodejsFunc(); Task^ FunctionWrapper(System::Object^ payload); }; ref class PersistentDisposeContext { private: System::IntPtr ptr; public: PersistentDisposeContext(Persistent* handle); void CallDisposeOnV8Thread(); }; ref class NodejsFuncInvokeContext; typedef struct nodejsFuncInvokeContextWrap { gcroot context; } NodejsFuncInvokeContextWrap; ref class NodejsFuncInvokeContext { private: NodejsFunc^ functionContext; System::Object^ payload; System::Exception^ exception; System::Object^ result; NodejsFuncInvokeContextWrap* wrap; void Complete(); public: property TaskCompletionSource^ TaskCompletionSource; NodejsFuncInvokeContext( NodejsFunc^ functionContext, System::Object^ payload); ~NodejsFuncInvokeContext(); !NodejsFuncInvokeContext(); void CompleteWithError(System::Exception^ exception); void CompleteWithResult(Handle result); void CallFuncOnV8Thread(); }; ref class ClrFuncReflectionWrap { private: System::Object^ instance; MethodInfo^ invokeMethod; ClrFuncReflectionWrap(); public: static ClrFuncReflectionWrap^ Create(Assembly^ assembly, System::String^ typeName, System::String^ methodName); Task^ Call(System::Object^ payload); }; ref class ClrFunc { private: System::Func^>^ func; ClrFunc(); static Handle MarshalCLRObjectToV8(System::Object^ netdata); public: static NAN_METHOD(Initialize); static Handle Initialize(System::Func^>^ func); Handle Call(Handle payload, Handle callback); static Handle MarshalCLRToV8(System::Object^ netdata); static Handle MarshalCLRExceptionToV8(System::Exception^ exception); static System::Object^ MarshalV8ToCLR(Handle jsdata); }; typedef struct clrFuncWrap { gcroot clrFunc; } ClrFuncWrap; #endif