private short ReadPortForWritePort(ref IntPtr readPort, IntPtr writePort) { #if DEBUG DebugUtils.Ping(DebugFlags.ChannelPorts, string.Format("readPort: {0}, writePort: {1}", readPort.ToString(), writePort.ToString())); #endif return(PSError.memFullErr); }
private short AllocateBufferProc(int size, ref IntPtr bufferID) { #if DEBUG DebugUtils.Ping(DebugFlags.BufferSuite, string.Format("Size: {0}", size)); #endif if (size < 0) { return(PSError.paramErr); } short err = PSError.noErr; try { bufferID = Memory.Allocate(size, false); bufferIDs.Add(bufferID); } catch (OutOfMemoryException) { // Free the buffer memory if the framework throws an OutOfMemoryException when adding to the bufferIDs list. if (bufferID != IntPtr.Zero) { Memory.Free(bufferID); bufferID = IntPtr.Zero; } err = PSError.memFullErr; } return(err); }
private short GetPinnedFloatProc(IntPtr descriptor, ref double min, ref double max, ref double floatNumber) { ReadDescriptorState state = readDescriptors[descriptor]; #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: 0x{0:X4}", state.currentKey)); #endif short descErr = PSError.noErr; AETEValue item = state.items[state.currentKey]; double amount = (double)item.Value; if (amount < min) { amount = min; descErr = PSError.coercedParamErr; state.lastReadError = descErr; } else if (amount > max) { amount = max; descErr = PSError.coercedParamErr; state.lastReadError = descErr; } floatNumber = amount; return(descErr); }
internal IntPtr LockHandle(IntPtr h, byte moveHigh) { #if DEBUG DebugUtils.Ping(DebugFlags.HandleSuite, string.Format("Handle: 0x{0}, moveHigh: {1}", h.ToHexString(), moveHigh)); #endif HandleEntry item; if (handles.TryGetValue(h, out item)) { return(item.Pointer); } else { if (SafeNativeMethods.GlobalSize(h).ToInt64() > 0L) { IntPtr hPtr = Marshal.ReadIntPtr(h); if (IsValidReadPtr(hPtr) && SafeNativeMethods.GlobalSize(hPtr).ToInt64() > 0L) { return(SafeNativeMethods.GlobalLock(hPtr)); } return(SafeNativeMethods.GlobalLock(h)); } if (IsValidReadPtr(h) && IsValidWritePtr(h)) // Pointer to a pointer? { return(h); } return(IntPtr.Zero); } }
private unsafe void DisposeRegularHandle(IntPtr h) { #if DEBUG DebugUtils.Ping(DebugFlags.HandleSuite, string.Format("Handle: 0x{0}", h.ToHexString())); #endif DisposeHandleImpl(h); }
internal int GetHandleSize(IntPtr h) { #if DEBUG DebugUtils.Ping(DebugFlags.HandleSuite, string.Format("Handle: 0x{0}", h.ToHexString())); #endif HandleEntry item; if (handles.TryGetValue(h, out item)) { return(item.Size); } else { if (SafeNativeMethods.GlobalSize(h).ToInt64() > 0L) { IntPtr hPtr = Marshal.ReadIntPtr(h); if (IsValidReadPtr(hPtr)) { return(SafeNativeMethods.GlobalSize(hPtr).ToInt32()); } else { return(SafeNativeMethods.GlobalSize(h).ToInt32()); } } return(0); } }
private bool GetKeyProc(IntPtr descriptor, ref uint key, ref uint type, ref int flags) { #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Empty); #endif if (descriptor != IntPtr.Zero) { ReadDescriptorState state = readDescriptors[descriptor]; if (state.keyIndex >= state.keyCount) { return(false); } state.currentKey = key = state.keys[state.keyIndex]; state.keyIndex++; // When a plug-in expects specific keys to be returned this method is documented // to set each key it finds to the null descriptor type before returning it to the plug-in. // The plug-in can use this information to determine if any required keys are missing. if (state.expectedKeys != IntPtr.Zero) { int offset; if (state.expectedKeyOffsets.TryGetValue(key, out offset)) { Marshal.WriteInt32(state.expectedKeys, offset, unchecked ((int)DescriptorTypes.Null)); } } AETEValue item = state.items[key]; try { // If the value is a sub-descriptor it must be retrieved with GetObjectProc. if (item.Value is Dictionary <uint, AETEValue> ) { type = DescriptorTypes.Object; } else { type = item.Type; } } catch (NullReferenceException) { } try { flags = item.Flags; } catch (NullReferenceException) { } return(true); } return(false); }
private unsafe IntPtr OpenReadDescriptorProc(IntPtr descriptorHandle, IntPtr keyArray) { #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("descriptor: 0x{0}", descriptorHandle.ToHexString())); #endif if (descriptorHandle != IntPtr.Zero) { Dictionary <uint, AETEValue> dictionary = descriptorHandles[descriptorHandle]; readDescriptorsIndex++; IntPtr handle = new IntPtr(readDescriptorsIndex); try { readDescriptors.Add(handle, new ReadDescriptorState(dictionary, keyArray)); } catch (OutOfMemoryException) { return(IntPtr.Zero); } return(handle); } return(IntPtr.Zero); }
private short CloseWriteDescriptorProc(IntPtr descriptor, ref IntPtr descriptorHandle) { #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Empty); #endif descriptorHandle = HandleSuite.Instance.NewHandle(0); if (descriptorHandle == IntPtr.Zero) { return(PSError.memFullErr); } try { // Add the items to the descriptor handle dictionary. // If the descriptor is a sub key the plug-in will attach it to a parent descriptor by calling PutObjectProc. descriptorHandles.Add(descriptorHandle, writeDescriptors[descriptor]); writeDescriptors.Remove(descriptor); if (writeDescriptorsIndex == descriptor.ToInt32()) { writeDescriptorsIndex--; } } catch (OutOfMemoryException) { return(PSError.memFullErr); } return(PSError.noErr); }
private short PutAliasProc(IntPtr descriptor, uint key, IntPtr aliasHandle) { #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: {0:X4}", key)); #endif try { IntPtr hPtr = HandleSuite.Instance.LockHandle(aliasHandle, 0); try { int size = HandleSuite.Instance.GetHandleSize(aliasHandle); byte[] data = new byte[size]; Marshal.Copy(hPtr, data, 0, size); writeDescriptors[descriptor].AddOrUpdate(key, new AETEValue(DescriptorTypes.Alias, GetAETEParamFlags(key), size, data)); } finally { HandleSuite.Instance.UnlockHandle(aliasHandle); } } catch (OutOfMemoryException) { return(PSError.memFullErr); } return(PSError.noErr); }
private short AddResource(uint ofType, IntPtr data) { #if DEBUG DebugUtils.Ping(DebugFlags.ResourceSuite, DebugUtils.PropToString(ofType)); #endif int size = HandleSuite.Instance.GetHandleSize(data); try { byte[] bytes = new byte[size]; if (size > 0) { Marshal.Copy(HandleSuite.Instance.LockHandle(data, 0), bytes, 0, size); HandleSuite.Instance.UnlockHandle(data); } int index = CountResource(ofType) + 1; pseudoResources.Add(new PSResource(ofType, index, bytes)); } catch (OutOfMemoryException) { return(PSError.memFullErr); } return(PSError.noErr); }
private IntPtr GetResource(uint ofType, short index) { #if DEBUG DebugUtils.Ping(DebugFlags.ResourceSuite, string.Format("{0}, {1}", DebugUtils.PropToString(ofType), index)); #endif PSResource res = pseudoResources.Find(delegate(PSResource r) { return(r.Equals(ofType, index)); }); if (res != null) { byte[] data = res.GetDataReadOnly(); IntPtr h = HandleSuite.Instance.NewHandle(data.Length); if (h != IntPtr.Zero) { Marshal.Copy(data, 0, HandleSuite.Instance.LockHandle(h, 0), data.Length); HandleSuite.Instance.UnlockHandle(h); } return(h); } return(IntPtr.Zero); }
private short PutObjectProc(IntPtr descriptor, uint key, uint type, IntPtr descriptorHandle) { #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: {0}, type: {1}", DebugUtils.PropToString(key), DebugUtils.PropToString(type))); #endif try { // If the handle is a sub key add it to the parent descriptor. Dictionary <uint, AETEValue> subKeys; if (descriptorHandles.TryGetValue(descriptorHandle, out subKeys)) { writeDescriptors[descriptor].AddOrUpdate(key, new AETEValue(type, GetAETEParamFlags(key), 0, subKeys)); descriptorHandles.Remove(descriptorHandle); } else { return(PSError.paramErr); } } catch (OutOfMemoryException) { return(PSError.memFullErr); } return(PSError.noErr); }
private short PutScopedObjectProc(IntPtr descriptor, uint key, uint type, IntPtr handle) { #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Empty); #endif IntPtr hPtr = HandleSuite.Instance.LockHandle(handle, 0); try { try { int size = HandleSuite.Instance.GetHandleSize(handle); byte[] data = new byte[size]; Marshal.Copy(hPtr, data, 0, size); writeDescriptors[descriptor].AddOrUpdate(key, new AETEValue(type, GetAETEParamFlags(key), size, data)); } finally { HandleSuite.Instance.UnlockHandle(handle); } } catch (OutOfMemoryException) { return(PSError.memFullErr); } return(PSError.noErr); }
private int SPBasicAcquireSuite(IntPtr name, int version, ref IntPtr suite) { string suiteName = Marshal.PtrToStringAnsi(name); if (suiteName == null) { return(PSError.kSPBadParameterError); } #if DEBUG DebugUtils.Ping(DebugFlags.SPBasicSuite, string.Format("name: {0}, version: {1}", suiteName, version)); #endif int error = PSError.kSPNoError; ActivePICASuites.PICASuiteKey suiteKey = new ActivePICASuites.PICASuiteKey(suiteName, version); if (activePICASuites.IsLoaded(suiteKey)) { suite = activePICASuites.AddRef(suiteKey); } else { error = AllocatePICASuite(suiteKey, ref suite); } return(error); }
private short WriteBasePixels(IntPtr port, ref VRect writeRect, PixelMemoryDesc srcDesc) { #if DEBUG DebugUtils.Ping(DebugFlags.ChannelPorts, string.Format("port: {0}, rect: {1}", port.ToString(), writeRect.ToString())); #endif return(PSError.memFullErr); }
private unsafe bool SPBasicIsEqual(IntPtr token1, IntPtr token2) { #if DEBUG DebugUtils.Ping(DebugFlags.SPBasicSuite, string.Format("token1: {0}, token2: {1}", Marshal.PtrToStringAnsi(token1), Marshal.PtrToStringAnsi(token2))); #endif if (token1 == IntPtr.Zero) { if (token2 == IntPtr.Zero) { return(true); } return(false); } else if (token2 == IntPtr.Zero) { return(false); } // Compare two null-terminated ASCII strings for equality. byte *src = (byte *)token1.ToPointer(); byte *dst = (byte *)token2.ToPointer(); while (*dst != 0) { if ((*src - *dst) != 0) { return(false); } src++; dst++; } return(true); }
private int SPBasicUndefined() { #if DEBUG DebugUtils.Ping(DebugFlags.SPBasicSuite, string.Empty); #endif return(PSError.kSPNoError); }
private short PutCountProc(IntPtr descriptor, uint key, uint count) { #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: {0:X4}", key)); #endif return(PSError.noErr); }
private short Interpolate1DProc(ref PSImagePlane source, ref PSImagePlane destination, ref Rect16 area, IntPtr coords, short method) { #if DEBUG DebugUtils.Ping(DebugFlags.ImageServices, string.Format("srcBounds: {0}, dstBounds: {1}, area: {2}, method: {3}", new object[] { source.bounds.ToString(), destination.bounds.ToString(), area.ToString(), ((InterpolationModes)method).ToString() })); #endif return(PSError.memFullErr); }
private int SPBasicFreeBlock(IntPtr block) { #if DEBUG DebugUtils.Ping(DebugFlags.SPBasicSuite, string.Format("block: 0x{0}", block.ToHexString())); #endif Memory.Free(block); return(PSError.kSPNoError); }
private IntPtr BufferLockProc(IntPtr bufferID, byte moveHigh) { #if DEBUG DebugUtils.Ping(DebugFlags.BufferSuite, string.Format("Buffer: 0x{0}", bufferID.ToHexString())); #endif return(bufferID); }
private void BufferFreeProc(IntPtr bufferID) { #if DEBUG DebugUtils.Ping(DebugFlags.BufferSuite, string.Format("Buffer: 0x{0}, Size: {1}", bufferID.ToHexString(), Memory.Size(bufferID))); #endif Memory.Free(bufferID); bufferIDs.Remove(bufferID); }
private unsafe short SetHandleSize(IntPtr h, int newSize) { #if DEBUG DebugUtils.Ping(DebugFlags.HandleSuite, string.Format("Handle: 0x{0}", h.ToHexString())); #endif if (newSize < 0) { return(PSError.paramErr); } if (AllocatedBySuite(h)) { try { PSHandle *handle = (PSHandle *)h.ToPointer(); IntPtr ptr = Memory.ReAlloc(handle->pointer, newSize); handle->pointer = ptr; handles.AddOrUpdate(h, new HandleEntry(h, ptr, newSize)); } catch (OutOfMemoryException) { return(PSError.memFullErr); } } else { if (SafeNativeMethods.GlobalSize(h).ToInt64() > 0L) { IntPtr hPtr = Marshal.ReadIntPtr(h); if (IsValidReadPtr(hPtr) && SafeNativeMethods.GlobalSize(hPtr).ToInt64() > 0L) { IntPtr hMem = SafeNativeMethods.GlobalReAlloc(hPtr, new UIntPtr((uint)newSize), NativeConstants.GPTR); if (hMem == IntPtr.Zero) { return(PSError.memFullErr); } Marshal.WriteIntPtr(h, hMem); } else { if (SafeNativeMethods.GlobalReAlloc(h, new UIntPtr((uint)newSize), NativeConstants.GPTR) == IntPtr.Zero) { return(PSError.memFullErr); } } } else { return(PSError.nilHandleErr); } } return(PSError.noErr); }
private unsafe short WriteBasePixels(IntPtr port, VRect *writeRect, PixelMemoryDesc srcDesc) { #if DEBUG DebugUtils.Ping(DebugFlags.ChannelPorts, string.Format("port: {0}, rect: {1}", port.ToString(), DebugUtils.PointerToString(writeRect))); #endif if (writeRect == null) { return(PSError.paramErr); } return(PSError.memFullErr); }
private short GetCountProc(IntPtr descriptor, ref uint count) { ReadDescriptorState state = readDescriptors[descriptor]; #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: 0x{0:X4}", state.currentKey)); #endif count = (uint)state.items.Count; return(PSError.noErr); }
private unsafe short ReadPortForWritePort(IntPtr *readPort, IntPtr writePort) { #if DEBUG DebugUtils.Ping(DebugFlags.ChannelPorts, string.Format("readPort: {0}, writePort: {1}", DebugUtils.PointerToHexString(readPort), writePort.ToString())); #endif if (readPort == null) { return(PSError.paramErr); } return(PSError.memFullErr); }
private short GetClassProc(IntPtr descriptor, ref uint type) { ReadDescriptorState state = readDescriptors[descriptor]; #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: 0x{0:X4}", state.currentKey)); #endif AETEValue item = state.items[state.currentKey]; type = (uint)item.Value; return(PSError.noErr); }
private short GetSimpleReferenceProc(IntPtr descriptor, ref PIDescriptorSimpleReference data) { ReadDescriptorState state = readDescriptors[descriptor]; #if DEBUG DebugUtils.Ping(DebugFlags.DescriptorParameters, string.Format("key: 0x{0:X4}", state.currentKey)); #endif AETEValue item = state.items[state.currentKey]; data = (PIDescriptorSimpleReference)item.Value; return(PSError.noErr); }
private int SPBasicReleaseSuite(IntPtr name, int version) { string suiteName = Marshal.PtrToStringAnsi(name); #if DEBUG DebugUtils.Ping(DebugFlags.SPBasicSuite, string.Format("name: {0}, version: {1}", suiteName, version.ToString())); #endif ActivePICASuites.PICASuiteKey suiteKey = new ActivePICASuites.PICASuiteKey(suiteName, version); activePICASuites.Release(suiteKey); return(PSError.kSPNoError); }