Beispiel #1
0
 public override void Connect()
 {
     impl.Connect();
 }
Beispiel #2
0
        /// <summary>
        /// Analogous to the MLInstall function in mprep-generated C programs.
        /// </summary>
        /// <param name="ml"></param>
        /// <returns>Whether it succeeded or not.</returns>
        ///
        public static bool install(IMathLink ml)
        {
            // Adding nXX functions here requires also adding the symbols to the NETLink`NET.m file.
            try {
                ml.Connect();
                ml.Put("Begin[\"" + KernelLinkImpl.PACKAGE_INTERNAL_CONTEXT + "\"]");
                definePattern(ml, "nCall[typeName_String, obj_Symbol, callType_Integer, isByVal_, memberName_String, argCount_Integer, typesAndArgs___]", "{typeName, obj, callType, isByVal, memberName, argCount, typesAndArgs}", CALL);
                definePattern(ml, "nLoadType1[type_String, assemblyName_]", "{type, assemblyName}", LOADTYPE1);
                definePattern(ml, "nLoadType2[type_String, assemblyObj_]", "{type, assemblyObj}", LOADTYPE2);
                definePattern(ml, "nLoadExistingType[typeObject_?NETObjectQ]", "{typeObject}", LOADEXISTINGTYPE);
                definePattern(ml, "nLoadAssembly[assemblyNameOrPath_String, suppressErrors_]", "{assemblyNameOrPath, suppressErrors}", LOADASSEMBLY);
                definePattern(ml, "nLoadAssemblyFromDir[assemblyName_String, dir_String]", "{assemblyName, dir}", LOADASSEMBLYFROMDIR);
                definePattern(ml, "nGetAssemblyObject[asmName_String]", "{asmName}", GETASSEMBLYOBJ);
                definePattern(ml, "nGetTypeObject[aqTypeName_String]", "{aqTypeName}", GETTYPEOBJ);
                definePattern(ml, "nReleaseObject[instances:{__Symbol}]", "{instances}", RELEASEOBJECT);
                definePattern(ml, "nMakeObject[typeName_String, argType_Integer, val_]", "{typeName, argType, val}", MAKEOBJECT);
                definePattern(ml, "nVal[obj_?NETObjectQ]", "{obj}", VAL);
                definePattern(ml, "nReflectType[typeName_String]", "{typeName}", REFLECTTYPE);
                definePattern(ml, "nReflectAsm[asmName_String]", "{asmName}", REFLECTASM);
                definePattern(ml, "nSetComplex[typeName_String]", "{typeName}", SETCOMPLEX);
                definePattern(ml, "nSameQ[obj1_?NETObjectQ, obj2_?NETObjectQ]", "{obj1, obj2}", SAMEQ);
                definePattern(ml, "nInstanceOf[obj_?NETObjectQ, aqTypeName_String]", "{obj, aqTypeName}", INSTANCEOF);
                definePattern(ml, "nCast[obj_?NETObjectQ, aqTypeName_String]", "{obj, aqTypeName}", CAST);
                definePattern(ml, "nPeekTypes[]", "{}", PEEKTYPES);
                definePattern(ml, "nPeekObjects[]", "{}", PEEKOBJECTS);
                definePattern(ml, "nPeekAssemblies[]", "{}", PEEKASSEMBLIES);

                definePattern(ml, "nCreateDelegate[typeName_String, mFunc_String, sendTheseArgs_Integer, callsUnshare:(True | False), wrapInNETBlock:(True | False)]", "{typeName, mFunc, sendTheseArgs, callsUnshare, wrapInNETBlock}", CREATEDELEGATE);
                definePattern(ml, "nDefineDelegate[name_String, retTypeName_String, paramTypeNames_List]", "{name, retTypeName, paramTypeNames}", DEFINEDELEGATE);
                definePattern(ml, "nDlgTypeName[eventObject_?NETObjectQ, aqTypeName_String, evtName_String]", "{eventObject, aqTypeName, evtName}", DLGTYPENAME);
                definePattern(ml, "nAddHandler[eventObject_?NETObjectQ, aqTypeName_String, evtName_String, delegate_?NETObjectQ]", "{eventObject, aqTypeName, evtName, delegate}", ADDHANDLER);
                definePattern(ml, "nRemoveHandler[eventObject_?NETObjectQ, aqTypeName_String, evtName_String, delegate_?NETObjectQ]", "{eventObject, aqTypeName, evtName, delegate}", REMOVEHANDLER);

                definePattern(ml, "nCreateDLL1[funcName_String, dllName_String, callConv_String, retTypeName_String, argTypeNames_, areOutParams_, strFormat_String]", "{funcName, dllName, callConv, retTypeName, argTypeNames, areOutParams, strFormat}", CREATEDLL1);
                definePattern(ml, "nCreateDLL2[decl_String, refAsms_, lang_String]", "{decl, refAsms, lang}", CREATEDLL2);

                definePattern(ml, "nModal[modal:(True | False), formToActivate_?NETObjectQ]", "{modal, formToActivate}", MODAL);
                definePattern(ml, "nShow[formToActivate_?NETObjectQ]", "{formToActivate}", SHOW);
                definePattern(ml, "nShareKernel[sharing:(True | False)]", "{sharing}", SHAREKERNEL);
                definePattern(ml, "nAllowUIComputations[allow:(True | False)]", "{allow}", ALLOWUICOMPS);
                definePattern(ml, "nUILink[name_String, prot_String]", "{name, prot}", UILINK);

                definePattern(ml, "nIsCOMProp[obj_?NETObjectQ, memberName_String]", "{obj, memberName}", ISCOMPROP);
                definePattern(ml, "nCreateCOM[clsIDOrProgID_String]", "{clsIDOrProgID}", CREATECOM);
                definePattern(ml, "nGetActiveCOM[clsIDOrProgID_String]", "{clsIDOrProgID}", GETACTIVECOM);
                definePattern(ml, "nReleaseCOM[obj_?NETObjectQ]", "{obj}", RELEASECOM);
                definePattern(ml, "nLoadTypeLibrary[tlbPath_String, safeArrayAsArray_, assemblyFile_String]", "{tlbPath, safeArrayAsArray, assemblyFile}", LOADTYPELIBRARY);

                definePattern(ml, "nGetException[]", "{}", GETEXCEPTION);

                definePattern(ml, "nConnectToFEServer[linkName_String]", "{linkName}", CONNECTTOFE);
                definePattern(ml, "nDisconnectToFEServer[]", "{}", DISCONNECTTOFE);

                // For speed testing:
                definePattern(ml, "noop[]", "{}", NOOP);
                definePattern(ml, "noop2[argc_Integer, args___]", "{argc, args}", NOOP2);

                // Here we define the argTypeToInteger function by sending
                // MapThread[(argTypeToInteger[#1] = #2)&, {ToExpression /@ argTypePatterns, {... ARGTYPE_ constants ...}}]
                ml.PutFunction("MapThread", 2);
                ml.PutFunction("Function", 1);
                ml.PutFunction("Set", 2);
                ml.PutFunction("argTypeToInteger", 1);
                ml.PutFunction("Slot", 1);
                ml.Put(1);
                ml.PutFunction("Slot", 1);
                ml.Put(2);
                ml.PutFunction("List", 2);
                ml.PutFunction("Map", 2);
                ml.PutSymbol("ToExpression");
                ml.Put(argTypePatterns);
                ml.PutFunction("List", 13);
                ml.Put(ARGTYPE_INTEGER);
                ml.Put(ARGTYPE_REAL);
                ml.Put(ARGTYPE_STRING);
                ml.Put(ARGTYPE_BOOLEAN);
                ml.Put(ARGTYPE_NULL);
                ml.Put(ARGTYPE_MISSING);
                ml.Put(ARGTYPE_OBJECTREF);
                ml.Put(ARGTYPE_VECTOR);
                ml.Put(ARGTYPE_MATRIX);
                ml.Put(ARGTYPE_TENSOR3);
                ml.Put(ARGTYPE_LIST);
                ml.Put(ARGTYPE_COMPLEX);
                ml.Put(ARGTYPE_OTHER);

                ml.Put("End[]");
                ml.PutSymbol("End");
                ml.Flush();

                return(true);
            } catch (MathLinkException) {
                return(false);
            }
        }