use of com.sun.jna.ptr.IntByReference in project jnanomsg by niwinz.
the class AbstractSocket method setSocketOpt.
public void setSocketOpt(SocketOption type, Object value) {
int rc = 0;
int typeVal = type.value();
final int socket_level = OptionLevel.NN_SOL_SOCKET.value();
final int sub_level = SocketType.NN_SUB.value();
switch(type) {
case NN_LINGER:
case NN_SNDBUF:
case NN_RCVBUF:
case NN_RCVMAXSIZE:
case NN_SNDTIMEO:
case NN_RCVTIMEO:
case NN_RECONNECT_IVL:
case NN_RECONNECT_IVL_MAX:
case NN_SNDPRIO:
case NN_RCVPRIO:
case NN_IPV4ONLY:
final IntByReference valueRef = new IntByReference((Integer) value);
final Pointer valuePtr = valueRef.getPointer();
rc = nn_setsockopt(this.fd, socket_level, typeVal, valuePtr, 4);
break;
case NN_SUB_UNSUBSCRIBE:
case NN_SUB_SUBSCRIBE:
{
byte[] topic;
if (value instanceof byte[]) {
topic = (byte[]) value;
} else if (value instanceof String) {
try {
topic = ((String) value).getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("Wrong type.");
}
final Memory mem = new Memory(topic.length);
mem.write(0, topic, 0, topic.length);
rc = nn_setsockopt(this.fd, sub_level, type.value(), mem, topic.length);
}
break;
case NN_SOCKET_NAME:
{
byte[] name;
if (value instanceof byte[]) {
name = (byte[]) value;
} else if (value instanceof String) {
try {
name = ((String) value).getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException("Wrong type.");
}
final Memory mem = new Memory(name.length);
mem.write(0, name, 0, name.length);
rc = nn_setsockopt(this.fd, socket_level, type.value(), mem, name.length);
}
break;
default:
throw new RuntimeException("Wrong property or value type.");
}
if (rc < 0) {
Nanomsg.handleError(rc);
}
}
use of com.sun.jna.ptr.IntByReference in project processing by processing.
the class WindowsRegistry method getSubKeys.
/**
* Get all sub keys of a key.
*
* @param rootKey root key
* @param parent key name
* @return array with all sub key names
*/
public static String[] getSubKeys(REGISTRY_ROOT_KEY rootKey, String parent) {
//Advapi32 advapi32;
//int handle = 0, dwIndex;
//char[] lpName;
//IntByReference lpcName;
//WinBase.FILETIME lpftLastWriteTime;
TreeSet<String> subKeys = new TreeSet<String>();
Advapi32 advapi32 = Advapi32.INSTANCE;
HKEY handle = openKey(rootKey, parent, WinNT.KEY_READ);
char[] lpName = new char[256];
IntByReference lpcName = new IntByReference(256);
WinBase.FILETIME lpftLastWriteTime = new WinBase.FILETIME();
//if(handle != 0) {
if (handle != null) {
int dwIndex = 0;
while (advapi32.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null, null, null, lpftLastWriteTime) == WinError.ERROR_SUCCESS) {
subKeys.add(new String(lpName, 0, lpcName.getValue()));
lpcName.setValue(256);
dwIndex++;
}
advapi32.RegCloseKey(handle);
}
return subKeys.toArray(new String[] {});
}
use of com.sun.jna.ptr.IntByReference in project processing by processing.
the class WindowsRegistry method createKey.
/**
* Create a new key.
*
* @param rootKey root key
* @param parent name of parent key
* @param name key name
* @return true on success
*/
public static boolean createKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
//Advapi32 advapi32;
//IntByReference hkResult, dwDisposition;
//int handle = 0;
Advapi32 advapi32 = Advapi32.INSTANCE;
//IntByReference hkResult = new IntByReference();
HKEYByReference hkResult = new HKEYByReference();
IntByReference dwDisposition = new IntByReference();
HKEY handle = openKey(rootKey, parent, WinNT.KEY_READ);
boolean ret = false;
//if(handle != 0) {
if (handle != null) {
if (advapi32.RegCreateKeyEx(handle, name, 0, null, WinNT.REG_OPTION_NON_VOLATILE, WinNT.KEY_READ, null, hkResult, dwDisposition) == WinError.ERROR_SUCCESS) {
ret = true;
advapi32.RegCloseKey(hkResult.getValue());
} else {
ret = false;
}
advapi32.RegCloseKey(handle);
}
return ret;
}
use of com.sun.jna.ptr.IntByReference in project processing by processing.
the class WindowsRegistry method valueExists.
/**
* Check for existence of a value.
*
* @param rootKey root key
* @param subKeyName key name
* @param name value name
* @return true if exists
*/
public static boolean valueExists(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
//Advapi32 advapi32;
//IntByReference pType, lpcbData;
//int handle = 0;
Advapi32 advapi32 = Advapi32.INSTANCE;
IntByReference pType = new IntByReference();
IntByReference lpcbData = new IntByReference();
HKEY handle = openKey(rootKey, subKeyName, WinNT.KEY_READ);
byte[] lpData = new byte[1];
boolean ret = false;
//if(handle != 0) {
if (handle != null) {
//if (advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) != WinError.ERROR_FILE_NOT_FOUND) {
if (advapi32.RegQueryValueEx(handle, name, 0, pType, lpData, lpcbData) != WinError.ERROR_FILE_NOT_FOUND) {
ret = true;
} else {
ret = false;
}
advapi32.RegCloseKey(handle);
}
return ret;
}
use of com.sun.jna.ptr.IntByReference in project processing by processing.
the class WindowsRegistry method getIntValue.
/**
* Read an int value.
*
* @return int or 0
* @param rootKey root key
* @param subKeyName key name
* @param name value name
*/
public static int getIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
Advapi32 advapi32 = Advapi32.INSTANCE;
IntByReference pType = new IntByReference();
IntByReference lpcbData = new IntByReference();
HKEY handle = openKey(rootKey, subKeyName, WinNT.KEY_READ);
int ret = 0;
byte[] lpData = new byte[1];
//if(handle != 0) {
if (handle != null) {
//if (advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WinError.ERROR_MORE_DATA) {
if (advapi32.RegQueryValueEx(handle, name, 0, pType, lpData, lpcbData) == WinError.ERROR_MORE_DATA) {
lpData = new byte[lpcbData.getValue()];
//if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WinError.ERROR_SUCCESS) {
if (advapi32.RegQueryValueEx(handle, name, 0, pType, lpData, lpcbData) == WinError.ERROR_SUCCESS) {
ret = convertBufferToInt(lpData);
}
}
advapi32.RegCloseKey(handle);
}
return ret;
}
Aggregations