示例#1
0
        /// <summary>Runs as java pass through helper.</summary>
        /// <param name="callingFrame">The calling frame.</param>
        /// <param name="list">The list.</param>
        /// <param name="found">The found.</param>
        /// <param name="retval">The retval.</param>
        /// <param name="methodKey">The method key.</param>
        /// <param name="returnValueGetter">The return value getter.</param>
        /// <param name="exceptions">The exceptions.</param>
        private void RunAsJavaPassThroughHelper(StackFrame callingFrame, object[] list, KeyValuePair <JniMethodDescription, Tuple <IEntity, IEntity, IEntity> >?found,
                                                ExecutionResult retval, JniMethodDescription methodKey, Dictionary <string, Delegate> returnValueGetter, StringBuilder exceptions)
        {
            IntPtr hProcAddress;

            if (found?.Value != null)
            {
                var paramType          = new List <string>();
                var method             = callingFrame.GetMethod();
                var paramList          = method.GetParameters().ToList();
                var dynamicLibrary     = (DynamicLibrary)found.Value.Value.Item2;
                var methodInformation  = (JavaClassMetadata)found.Value.Value.Item1;
                var libraryInformation = (JniMethodInformation)found.Value.Value.Item3;
                paramList.ForEach(_ => paramType.Add(_.ParameterType.Name.ToLower()));
                var returnType = ((MethodInfo)method)?.ReturnParameter?.ToString().ToLower().Trim();

                if ((hProcAddress = Win32Helper.GetProcAddress(jvmHandles["hModuleJniBridge"], JniBridgeMethod.RunMethodInJar)) != IntPtr.Zero)
                {
                    var functor = Marshal.GetDelegateForFunctionPointer(hProcAddress, typeof(Win32Helper.RunMethodInJar)) as
                                  Win32Helper.RunMethodInJar;

                    retval.IsSuccess = functor(methodInformation.ClassName.Replace(".", "/"), methodKey.MethodName,
                                               libraryInformation.JavaMethod.Contains("static"),
                                               libraryInformation.JniDescriptor, list, paramType.ToArray(), list.Length,
                                               Marshal.GetFunctionPointerForDelegate(returnValueGetter[returnType]), exceptions,
                                               returnType) == 0;

                    retval.JniErrorMessage = exceptions.ToString();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Runs as java pass through.
        /// </summary>
        /// <param name="callingFrame">The calling frame.</param>
        /// <param name="service">The service.</param>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        public ExecutionResult RunAsJavaPassThrough(StackFrame callingFrame, Type service, params object[] list)
        {
            var retval = ExecutionResult.Empty;
            var result = ExecutionResult.Empty;
            KeyValuePair <JniMethodDescription, Tuple <IEntity, IEntity, IEntity> >?found = null;
            var exceptions = new StringBuilder(Win32Helper.Max_BufferSizeForMessagesFromJni);

            var returnValueGetter = ReturnDelegateBasedOnType(retval);

            try {
                if (IsJvmLoaded.Value)
                {
                    _perfCounters.IncrementCounter(Enums.PerfCounter.TotalRequests);                     // Increase "TotalRequest" performance counter
                    var methodKey = new JniMethodDescription(callingFrame, service);
                    // Let's retrieve method metadata from dictionary (if exists), otherwise we'll get it from database
                    if (CachedJniMethods.ContainsKey(methodKey.MethodSignature))
                    {
                        found = CachedJniMethods[methodKey.MethodSignature];
                        _perfCounters.IncrementCounter(Enums.PerfCounter.CachedJniMethodCall);                         // Increase "CachedJniMethodCall"	performance counter
                    }
                    else
                    {
                        result = _dataservice.GetMethodInformationForJniCall(service, callingFrame, list);
                        _perfCounters.IncrementCounter(Enums.PerfCounter.DbJniMethodCall);                         // Increase "DbJniMethodCall"	performance counter
                        var metadata = result.Tag as Tuple <IEntity, IEntity, IEntity>;

                        if (result.IsSuccess && metadata != null)
                        {
                            found = new KeyValuePair <JniMethodDescription, Tuple <IEntity, IEntity, IEntity> >(methodKey, metadata);
                            CachedJniMethods.Add(methodKey.MethodSignature, found.Value);
                        }
                    }

                    RunAsJavaPassThroughHelper(callingFrame, list, found, retval, methodKey, returnValueGetter, exceptions);
                }
            } catch (Exception e) {
                retval.LastExceptionIfAny = e;
            }

            return(retval);
        }