com.sun.jna.NativeLong Java Examples
The following examples show how to use
com.sun.jna.NativeLong.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertySetLogicDefaultMockTest.java From canon-sdk-java with MIT License | 6 votes |
@Disabled("Fail on Travis but work on local") @Test void setPropertyDataForInt32() { final ArrayList<PropertyInfo> infos = Lists.newArrayList(new PropertyInfo(EdsDataType.kEdsDataType_Int32, 4), new PropertyInfo(EdsDataType.kEdsDataType_UInt32, 4)); for (PropertyInfo propertyInfo : infos) { when(propertyLogic.getPropertyTypeAndSize(cameraRef, propertyID)).thenReturn(propertyInfo); mockEdsdkLibrary(); when(canonLibrary.edsdkLibrary().EdsSetPropertyData(eq(cameraRef), any(NativeLong.class), any(NativeLong.class), any(NativeLong.class), any(Pointer.class))).thenReturn(new NativeLong(0)); propertySetLogic.setPropertyData(cameraRef, propertyID, nativeEnum); propertySetLogic.setPropertyData(cameraRef, propertyID, nativeEnum.value().longValue()); propertySetLogic.setPropertyData(cameraRef, propertyID, inParam, nativeEnum); propertySetLogic.setPropertyData(cameraRef, propertyID, inParam, nativeEnum.value().longValue()); propertySetLogic.setPropertyDataAdvanced(cameraRef, propertyID, 5L); propertySetLogic.setPropertyDataAdvanced(cameraRef, propertyID, inParam, 6L); } }
Example #2
Source File: PropertySetLogicDefaultMockTest.java From canon-sdk-java with MIT License | 6 votes |
@Test void setPropertyDataForInt64() { final ArrayList<PropertyInfo> infos = Lists.newArrayList(new PropertyInfo(EdsDataType.kEdsDataType_Int64, 8), new PropertyInfo(EdsDataType.kEdsDataType_UInt64, 8)); for (PropertyInfo propertyInfo : infos) { when(propertyLogic.getPropertyTypeAndSize(cameraRef, propertyID)).thenReturn(propertyInfo); mockEdsdkLibrary(); when(canonLibrary.edsdkLibrary().EdsSetPropertyData(eq(cameraRef), any(NativeLong.class), any(NativeLong.class), any(NativeLong.class), any(Pointer.class))).thenReturn(new NativeLong(0)); propertySetLogic.setPropertyData(cameraRef, propertyID, nativeEnum); propertySetLogic.setPropertyData(cameraRef, propertyID, nativeEnum.value().longValue()); propertySetLogic.setPropertyData(cameraRef, propertyID, inParam, nativeEnum); propertySetLogic.setPropertyData(cameraRef, propertyID, inParam, nativeEnum.value().longValue()); propertySetLogic.setPropertyDataAdvanced(cameraRef, propertyID, 5L); propertySetLogic.setPropertyDataAdvanced(cameraRef, propertyID, inParam, 6L); } }
Example #3
Source File: PropertyDescLogicDefaultMockTest.java From canon-sdk-java with MIT License | 6 votes |
@Test void getPropertyDescColorTemperature() { final NativeLong[] desc = new NativeLong[128]; desc[0] = new NativeLong(100); desc[1] = new NativeLong(1000); desc[2] = new NativeLong(2000); desc[3] = new NativeLong(3000); desc[4] = new NativeLong(6500); final EdsPropertyDesc propertyDesc = new EdsPropertyDesc( new NativeLong(0), new NativeLong(0), new NativeLong(5), desc ); propertyDescLogicDefaultExtended.setPropertyDescStructure(propertyDesc); final List<Integer> propertyDescColorTemperature = propertyDescLogicDefaultExtended.getPropertyDescColorTemperature(fakeCamera); Assertions.assertEquals(5, propertyDescColorTemperature.size()); Assertions.assertEquals(100, propertyDescColorTemperature.get(0)); Assertions.assertEquals(6500, propertyDescColorTemperature.get(4)); }
Example #4
Source File: PropertyDescLogicDefaultMockTest.java From canon-sdk-java with MIT License | 6 votes |
@Test void getPropertyDescValues() { final NativeLong[] desc = new NativeLong[128]; final EdsPropertyDesc propertyDesc = new EdsPropertyDesc( new NativeLong(0), new NativeLong(0), new NativeLong(0), desc ); propertyDescLogicDefaultExtended.setPropertyDescStructure(propertyDesc); final List<Integer> propertyDescValues = propertyDescLogicDefaultExtended.getPropertyDescValues(fakeCamera, EdsPropertyID.kEdsPropID_ISOSpeed); Assertions.assertEquals(0, propertyDescValues.size()); }
Example #5
Source File: CameraStateEventLogicDefaultMockTest.java From canon-sdk-java with MIT License | 6 votes |
@Test void buildHandlerUseWeakReference() throws InterruptedException { final EdsdkLibrary.EdsStateEventHandler handler; try { final Method buildHandler = MockFactory.initialCanonFactory.getCameraStateEventLogic().getClass().getDeclaredMethod("buildHandler", EdsdkLibrary.EdsCameraRef.class); buildHandler.setAccessible(true); handler = (EdsdkLibrary.EdsStateEventHandler) buildHandler.invoke(MockFactory.initialCanonFactory.getCameraStateEventLogic(), fakeCamera); } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { Assertions.fail("Failed reflection", e); throw new IllegalStateException("can not reach"); } final NativeLong apply = handler.apply(new NativeLong(EdsStateEvent.kEdsStateEvent_Shutdown.value()), new NativeLong(0L), new Pointer(0)); fakeCamera = null; for (int i = 0; i < 50; i++) { System.gc(); Thread.sleep(50); System.gc(); } // Let's hope gc actually happened... Assertions.assertThrows(IllegalStateException.class, () -> handler.apply(new NativeLong(EdsStateEvent.kEdsStateEvent_Shutdown.value()), new NativeLong(0L), new Pointer(0))); }
Example #6
Source File: mman.java From domino-jna with Apache License 2.0 | 6 votes |
/** * Map the given region of the given file descriptor into memory. * Returns a Pointer to the newly mapped memory throws an * IOException on error.<br> * <br> * The contents of a file mapping (as opposed to an anonymous mapping; * see MAP_ANONYMOUS below), are initialized using length bytes starting * at offset offset in the file (or other object) referred to by the * file descriptor fd. offset must be a multiple of the page size as * returned by sysconf(_SC_PAGE_SIZE). * * @param len number of bytes to map * @param prot describes the desired memory protection of the mapping: {@link #PROT_NONE}, {@link #PROT_READ}, {@link #PROT_WRITE}, {@link #PROT_EXEC} * @param flags flags * @param fd file descriptor * @param off offset to start mapping, must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE) * @return pointer */ public static Pointer mmap(long len, int prot, int flags, int fd, long off) { // we don't really have a need to change the recommended pointer. Pointer addr = new Pointer(0); Pointer result = CLibrary.mmap(addr, new NativeLong(len), prot, flags, fd, new NativeLong(off)); if(Pointer.nativeValue(result) == -1) { throw new RuntimeException("mmap failed: " + errno.strerror()); } return result; }
Example #7
Source File: PropertyDescLogicDefaultMockTest.java From canon-sdk-java with MIT License | 6 votes |
@Test void getPropertyDescEvfColorTemperature() { final NativeLong[] desc = new NativeLong[128]; desc[0] = new NativeLong(100); desc[1] = new NativeLong(1000); desc[2] = new NativeLong(2000); desc[3] = new NativeLong(3000); final EdsPropertyDesc propertyDesc = new EdsPropertyDesc( new NativeLong(0), new NativeLong(0), new NativeLong(4), desc ); propertyDescLogicDefaultExtended.setPropertyDescStructure(propertyDesc); final List<Integer> propertyDescColorTemperature = propertyDescLogicDefaultExtended.getPropertyDescEvfColorTemperature(fakeCamera); Assertions.assertEquals(4, propertyDescColorTemperature.size()); Assertions.assertEquals(100, propertyDescColorTemperature.get(0)); Assertions.assertEquals(3000, propertyDescColorTemperature.get(3)); }
Example #8
Source File: StructureTest.java From canon-sdk-java with MIT License | 5 votes |
@Test void test5() { final EdsFrameDesc eds1 = new EdsFrameDesc(); final List<String> fieldOrder = eds1.getFieldOrder(); Assertions.assertNotNull(fieldOrder); Assertions.assertFalse(fieldOrder.isEmpty()); final EdsFrameDesc eds2 = new EdsFrameDesc(new Pointer(0)); final EdsFrameDesc eds3 = new EdsFrameDesc(new NativeLong(0), new NativeLong(0), new NativeLong(0), new EdsRect(), new NativeLong(0)); new EdsFrameDesc.ByReference(); new EdsFrameDesc.ByValue(); }
Example #9
Source File: PropertyGetLogicDefaultMockTest.java From canon-sdk-java with MIT License | 5 votes |
@Test void getPropertyDataForPictureStyleDesc() { final EdsPictureStyleDesc expectedResult = new EdsPictureStyleDesc(mockMemory); final EdsPropertyID propertyID = EdsPropertyID.kEdsPropID_ISOSpeed; final long inParam = 0L; final int inPropertySize = 4; propertyInfo = new PropertyInfo(EdsDataType.kEdsDataType_PictureStyleDesc, inPropertySize); // mocks when(CanonFactory.propertyLogic().getPropertyTypeAndSize(fakeBaseRef, propertyID, inParam)).thenReturn(propertyInfo); returnNoErrorForEdsGetPropertyData(propertyID, inParam, inPropertySize); // mock actual result // when(mockMemory.getDouble(0)).thenReturn(expectedResult); final EdsPictureStyleDesc result = propertyGetLogicDefaultExtended.getPropertyData(fakeBaseRef, propertyID); // Assertions.assertEquals(expectedResult, result); Assertions.assertEquals(expectedResult.colorTone, result.colorTone); Assertions.assertEquals(expectedResult.contrast, result.contrast); Assertions.assertEquals(expectedResult.filterEffect, result.filterEffect); Assertions.assertEquals(expectedResult.sharpness, result.sharpness); Assertions.assertEquals(expectedResult.sharpFineness, result.sharpFineness); verify(CanonFactory.propertyLogic()).getPropertyTypeAndSize(fakeBaseRef, propertyID, inParam); verify(CanonFactory.edsdkLibrary()).EdsGetPropertyData(eq(fakeBaseRef), eq(new NativeLong(propertyID.value())), eq(new NativeLong(inParam)), eq(new NativeLong(inPropertySize)), eq(mockMemory)); }
Example #10
Source File: TransientStorePool.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
public void destroy() { for (ByteBuffer byteBuffer : availableBuffers) { final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.munlock(pointer, new NativeLong(fileSize)); } }
Example #11
Source File: ReplFileStatsStruct.java From domino-jna with Apache License 2.0 | 5 votes |
public static ReplFileStatsStruct newInstance(final NativeLong TotalFiles, final NativeLong FilesCompleted, final NativeLong NotesAdded, final NativeLong NotesDeleted, final NativeLong NotesUpdated, final NativeLong Successful, final NativeLong Failed, final NativeLong NumberErrors) { return AccessController.doPrivileged(new PrivilegedAction<ReplFileStatsStruct>() { @Override public ReplFileStatsStruct run() { return new ReplFileStatsStruct(TotalFiles, FilesCompleted, NotesAdded, NotesDeleted, NotesUpdated, Successful, Failed, NumberErrors); } }); }
Example #12
Source File: Win32ProcessTools.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
private static boolean setGuard(HANDLE hOtherProcess, MEMORY_BASIC_INFORMATION mbi) { if (hasGuard(mbi)) { return true; } int oldProt = mbi.protect.intValue(); int newProt = oldProt | WinNT.PAGE_GUARD; IntByReference oldProtRef = new IntByReference(); boolean ok = Kernel32.INSTANCE.VirtualProtectEx(hOtherProcess, new WinDef.LPVOID(pointerToAddress(mbi.baseAddress)), mbi.regionSize, newProt, oldProtRef); if (ok) { mbi.protect = new NativeLong(newProt); return true; } return false; }
Example #13
Source File: EdsSaveImageSetting.java From canon-sdk-java with MIT License | 5 votes |
/** * @param JPEGQuality C type : EdsUInt32<br> * @param iccProfileStream C type : EdsStreamRef<br> * @param reserved C type : EdsUInt32 */ public EdsSaveImageSetting(NativeLong JPEGQuality, EdsStreamRef iccProfileStream, NativeLong reserved) { super(); this.JPEGQuality = JPEGQuality; this.iccProfileStream = iccProfileStream; this.reserved = reserved; }
Example #14
Source File: CameraLogicDefaultMockTest.java From canon-sdk-java with MIT License | 5 votes |
@Test void getCameraConnectedCount() { when(edsdkLibrary().EdsGetCameraList(any(EdsdkLibrary.EdsCameraListRef.ByReference.class))).thenReturn(new NativeLong(0)); when(edsdkLibrary().EdsGetChildCount(any(), any(NativeLongByReference.class))).thenReturn(new NativeLong(0)); final int cameraConnectedCount = spyCameraLogic.getCameraConnectedCount(); Assertions.assertEquals(0, cameraConnectedCount); }
Example #15
Source File: PlatformUtils.java From Quelea with GNU General Public License v3.0 | 5 votes |
private static boolean setFullScreenWindow(long wid, boolean fullScreen) { //Ignore this method for now. Doesn't work with snaps. if(true) return false; // Use the JNA platform X11 binding X11 x = X11.INSTANCE; X11.Display display = null; try { // Open the display display = x.XOpenDisplay(null); // Send the message int result = sendClientMessage( display, wid, "_NET_WM_STATE", new NativeLong[]{ new NativeLong(fullScreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE), x.XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", false), x.XInternAtom(display, "_NET_WM_STATE_ABOVE", false), new NativeLong(0L), new NativeLong(0L) } ); return (result != 0); } finally { if (display != null) { // Close the display x.XCloseDisplay(display); } } }
Example #16
Source File: EdsdkLibraryMock.java From canon-sdk-java with MIT License | 5 votes |
@Override public NativeLong EdsRelease(final EdsBaseRef inRef) { assertWasInitialized(); final Integer total = countRetain.compute(inRef, (edsBaseRef, integer) -> { if (integer == null) return -1; else return integer - 1; }); return new NativeLong(total); }
Example #17
Source File: TransientStorePool.java From DDMQ with Apache License 2.0 | 5 votes |
/** * It's a heavy init method. */ public void init() { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); availableBuffers.offer(byteBuffer); } }
Example #18
Source File: CameraLogicDefaultMockTest.java From canon-sdk-java with MIT License | 5 votes |
@Test void closeSessionThrowsOnError() { when(edsdkLibrary().EdsCloseSession(fakeCamera)).thenReturn(new NativeLong(EdsdkError.EDS_ERR_DEVICE_INVALID.value())); when(edsdkLibrary().EdsRelease(fakeCamera)).thenReturn(new NativeLong(0L)); final CloseSessionOption option = new CloseSessionOptionBuilder() .setCameraRef(fakeCamera) .build(); Assertions.assertThrows(EdsdkDeviceInvalidErrorException.class, () -> spyCameraLogic.closeSession(option)); verify(edsdkLibrary(), times(0)).EdsRelease(same(fakeCamera)); }
Example #19
Source File: TransientStorePool.java From rocketmq with Apache License 2.0 | 5 votes |
/** * It's a heavy init method. */ public void init() { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); availableBuffers.offer(byteBuffer); } }
Example #20
Source File: EdsdkLibraryMock.java From canon-sdk-java with MIT License | 5 votes |
@Override public NativeLong EdsRetain(final EdsBaseRef inRef) { assertWasInitialized(); final Integer total = countRetain.compute(inRef, (edsBaseRef, integer) -> { if (integer == null) return 1; else return integer + 1; }); return new NativeLong(total); }
Example #21
Source File: TransientStorePool.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
/** * It's a heavy init method. */ public void init() { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); availableBuffers.offer(byteBuffer); } }
Example #22
Source File: CameraObjectEventLogicDefault.java From canon-sdk-java with MIT License | 5 votes |
@Override public void registerCameraObjectEvent(final EdsCameraRef cameraRef) { Objects.requireNonNull(cameraRef); final EdsObjectEventHandler objectEventHandler = buildHandler(cameraRef); handlerLock.writeLock().lock(); try { handlerMap.put(cameraRef, objectEventHandler); final EdsdkError edsdkError = toEdsdkError(CanonFactory.edsdkLibrary().EdsSetObjectEventHandler(cameraRef, new NativeLong(EdsObjectEvent.kEdsObjectEvent_All.value()), objectEventHandler, Pointer.NULL)); if (edsdkError != EdsdkError.EDS_ERR_OK) { throw edsdkError.getException(); } } finally { handlerLock.writeLock().unlock(); } }
Example #23
Source File: CameraObjectEventLogicDefault.java From canon-sdk-java with MIT License | 5 votes |
private EdsObjectEventHandler buildHandler(final EdsCameraRef cameraRef) { final WeakReference<EdsCameraRef> cameraRefWeakReference = new WeakReference<>(cameraRef); return (inEvent, inRef, inContext) -> { final EdsCameraRef edsCameraRef = cameraRefWeakReference.get(); if (edsCameraRef == null) { // this should not happen but who knows... log.error("Received an event from a camera ref that is not referenced in the code anymore"); throw new IllegalStateException("Received an event from a camera ref that is not referenced in the code anymore"); // we throw or we just return doing nothing } this.handle(new CanonObjectEventImpl(edsCameraRef, EdsObjectEvent.ofValue(inEvent.intValue()), inRef)); return new NativeLong(0); }; }
Example #24
Source File: TransientStorePool.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 5 votes |
/** * It's a heavy init method. */ public void init() { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); availableBuffers.offer(byteBuffer); } }
Example #25
Source File: CameraObjectEventLogicDefaultMockTest.java From canon-sdk-java with MIT License | 5 votes |
@Test void registerCameraObjectEvent() { when(edsdkLibrary().EdsSetObjectEventHandler(eq(fakeCamera), any(), any(), (Pointer) isNull())).thenReturn(new NativeLong(0)); spyCameraObjectEventLogic.registerCameraObjectEvent(fakeCamera); verify(edsdkLibrary(), times(1)).EdsSetObjectEventHandler(eq(fakeCamera), any(), any(), (Pointer) isNull()); }
Example #26
Source File: CameraLogicDefaultMockTest.java From canon-sdk-java with MIT License | 5 votes |
@Test void sendCommandEdsDcRemoteShootingMode() { when(edsdkLibrary().EdsSendCommand(eq(fakeCamera), any(), any())).thenReturn(new NativeLong(0)); spyCameraLogic.sendCommand(fakeCamera, EdsDcRemoteShootingMode.kDcRemoteShootingModeStart); verify(edsdkLibrary()).EdsSendCommand(eq(fakeCamera), eq(new NativeLong(EdsCameraCommand.kEdsCameraCommand_SetRemoteShootingMode.value())), eq(new NativeLong(EdsDcRemoteShootingMode.kDcRemoteShootingModeStart.value()))); }
Example #27
Source File: UartNativeOsx.java From arcusplatform with Apache License 2.0 | 5 votes |
public Termios() { this.c_iflag = new NativeLong(); this.c_oflag = new NativeLong(); this.c_cflag = new NativeLong(); this.c_lflag = new NativeLong(); this.c_ispeed = new NativeLong(); this.c_ospeed = new NativeLong(); this.c_cc = new byte[NCCS]; }
Example #28
Source File: CameraLogicDefaultMockTest.java From canon-sdk-java with MIT License | 5 votes |
@Test void closeSession() { when(edsdkLibrary().EdsCloseSession(fakeCamera)).thenReturn(new NativeLong(0)); when(edsdkLibrary().EdsRelease(fakeCamera)).thenReturn(new NativeLong(0L)); final CloseSessionOption option = new CloseSessionOptionBuilder() .setCameraRef(fakeCamera) .build(); spyCameraLogic.closeSession(option); verify(edsdkLibrary()).EdsRelease(same(fakeCamera)); }
Example #29
Source File: MappedFile.java From rocketmq_trans_message with Apache License 2.0 | 5 votes |
public void munlock() { final long beginTime = System.currentTimeMillis(); final long address = ((DirectBuffer) (this.mappedByteBuffer)).address(); Pointer pointer = new Pointer(address); int ret = LibC.INSTANCE.munlock(pointer, new NativeLong(this.fileSize)); log.info("munlock {} {} {} ret = {} time consuming = {}", address, this.fileName, this.fileSize, ret, System.currentTimeMillis() - beginTime); }
Example #30
Source File: Event2CameraTest.java From canon-sdk-java with MIT License | 5 votes |
@BeforeEach void setUp() { TestShortcutUtil.registerCameraAddedHandler(inContext -> { log.warn("Camera added called {}", inContext); cameraEventCalledCount.incrementAndGet(); return new NativeLong(0); }); TestShortcutUtil.registerPropertyEventHandler(cameraRef, (inEvent, inPropertyID, inParam, inContext) -> { log.warn("Camera property called {}, {}, {}", EdsPropertyEvent.ofValue(inEvent.intValue()), EdsPropertyID.ofValue(inPropertyID.intValue()), inContext); propertyEventCalledCount.incrementAndGet(); return new NativeLong(0); }); TestShortcutUtil.registerObjectEventHandler(cameraRef, (inEvent, inRef, inContext) -> { log.warn("Camera object called {}, {}, {}", inEvent, inRef, inContext); objectEventCalledCount.incrementAndGet(); return new NativeLong(0); }); TestShortcutUtil.registerStateEventHandler(cameraRef, (inEvent, inEventData, inContext) -> { log.warn("Camera state called {}, {}, {}", inEvent, inEventData, inContext); stateEventCalledCount.incrementAndGet(); return new NativeLong(0); }); resetCounts(); }