Example #1
0
jint Java_tbb_core_ioManager_Events_createVirtualDevice(
		JNIEnv* env, jobject thiz, jstring touchDevice, jint protocol, jint absX, jint absY) {
	//return 0;
	const char *nativeString = (*env)->GetStringUTFChars(env, touchDevice, 0);

	return startDevice(nativeString, protocol, absX, absY);
}
Example #2
0
/*
 * Class:     com_ibm_media_protocol_device_DevicePushSourceStream
 * Method:    read
 * Signature: ([BII)I
 */
JNIEXPORT jint JNICALL Java_com_ibm_media_protocol_device_DevicePushSourceStream_read
(JNIEnv* env, jobject obj, jbyteArray arr, jint offset, jint length) {
	
	MMRESULT result;

	jclass cls;
	jmethodID mid;
	jsize len = (*env)->GetArrayLength(env, arr);
	jbyte* body = (*env)->GetByteArrayElements(env, arr, JNI_FALSE);

	/* fill the buffer struct */
	waveHeader.lpData = &body[offset];
	waveHeader.dwBufferLength = length;
	waveHeader.dwBytesRecorded = 0; 
	waveHeader.dwUser = NULL;
	waveHeader.dwFlags = NULL;
	waveHeader.dwLoops = NULL;
	waveHeader.lpNext = NULL;
	waveHeader.reserved = NULL;

	isBufferFilled = FALSE;

	/* preper the buffer */
	result = waveInPrepareHeader(hwi, &waveHeader, sizeof(WAVEHDR)); 
	/* DEBUG */
	if (result != MMSYSERR_NOERROR)
		printf("ERROR while adding buffer to device !\n %d\n", result);
	/* end DEBUG */

	result = waveInAddBuffer(hwi, &waveHeader, sizeof(WAVEHDR));
	/* DEBUG */
	if (result != MMSYSERR_NOERROR)
		printf("ERROR while adding buffer to device !\n %d\n", result);
	/* end DEBUG */
	
	if (!isStarted) 
		startDevice();

	/* wait until buffer was filled */
	while (!isBufferFilled)
		Sleep(10);

	(*env)->ReleaseByteArrayElements(env, arr, body, 0);
    
	/* notify DevicePushSourceStream it can generate another transferData call */
	if (isStarted) {
		cls = (*env)->GetObjectClass(env, obj);
		mid = (*env)->GetMethodID(env, cls, "notify", "()V");
		if (mid == 0) {
			printf("Error indentifying native method\n");
			return;
		}
		(*env)->CallVoidMethod(env, obj, mid);
	}
	
	return waveHeader.dwBytesRecorded;
}
Example #3
0
bool
device::start()
{
  if(startDevice()){
    _running = true;
    
    _readthread = new boost::thread(boost::bind(&device::readLoop, this));
  }
  
  return _running;
}
void resetDevice(string device){
	ProtoMessage msg;
	msg.set_signal(ProtoMessage::RESET);
	msg.set_dest_device(device);
	msg.set_time(-1);
	sendProtobufMessage(name2acceptor[device],msg);
	device2Thread[device].join();
	device2Thread.erase(device);
	close(name2acceptor[device]);
	cout <<"Reseting " <<device <<endl;
	startDevice(device);
}
Example #5
0
void processInitializingState(inputData* inputData, outputData* outputData) { 
  // Keys or accelerometer may trigger a wake-up from standby. For this to work, the  
 keyboard
/accelerometer interface must stop to bring the hardware in the correct 
 state. For this to be allowed, the keyboard interface must first be started.
 
  startDevice(keyboard); 
  stopDevice(keyboard); 
  startDevice(accelerometer); 
  stopDevice(accelerometer); 
   
  if (inputData->hostState == connected) { 
    enterConnectedStateFromInitializingState(); 
  } else { 
    enterConnectingState(outputData); 
  } if 
bool startAll(){
	runing = true;
	for (auto& pair: Name2port)
	{
		if(pair.first == self) {
			// continue;
			// 1. Connect to Pod
			struct addrinfo hints;
			memset(&hints, 0, sizeof(struct addrinfo));
		    hints.ai_family = AF_INET;    /* Allow IPv4 or IPv6 */
		    hints.ai_socktype = SOCK_STREAM; 

		    
			struct addrinfo *result,*rp;
			getaddrinfo(name2hostname["pod"].c_str(),
						pair.second.c_str(),
						&hints,
						&result);
		 	for (rp = result; rp != NULL; rp = rp->ai_next) {
		        name2socket["pod"] = socket(rp->ai_family, rp->ai_socktype,
		                     rp->ai_protocol);
		        if (name2socket["pod"] == -1)continue;
		        struct timeval t;    
				t.tv_sec = 1;
				t.tv_usec = 0;
		        setsockopt(
					name2socket["pod"],     // Socket descriptor
					SOL_SOCKET, // To manipulate options at the sockets API level
					SO_RCVTIMEO,// Specify the receiving or sending timeouts 
					(const void *)(&t), // option values
					sizeof(t) 
				);
		       	if (connect(name2socket["pod"], rp->ai_addr, rp->ai_addrlen) != -1) {
		       		cout << "Connected to pod"<<endl;
		            break;                  /* Success */
		       	}
		       	close(name2socket["pod"]);
		    }
		    if (rp == NULL) {
		        cerr <<"Failed to connect to Pod\n";
		        exit(1);
		    }
		    freeaddrinfo(result);
		    ProtoMessage msg;
			msg.set_signal(ProtoMessage::START);
			msg.set_dest_device(self);
			sendProtobufMessage(name2socket["pod"],msg);
		} else {
			struct addrinfo hints;
			memset(&hints, 0, sizeof(struct addrinfo));
		    hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
		    hints.ai_socktype = SOCK_STREAM; 	 
		    hints.ai_flags = AI_PASSIVE; 

		    struct addrinfo *result,*rp;
		 	getaddrinfo(NULL,pair.second.c_str(),&hints,&result);
		    for (rp = result; rp != NULL; rp = rp->ai_next) {
		        name2socket[pair.first] = socket(rp->ai_family, rp->ai_socktype,
		                rp->ai_protocol);
		        if (name2socket[pair.first] == -1) continue;

		        int enable = 1;
		        setsockopt(
					name2socket[pair.first],
					SOL_SOCKET,
					SO_REUSEADDR,
					(const void *)(&enable),
					sizeof(int)
				);
		        struct timeval t;    
				t.tv_sec = 1;
				t.tv_usec = 0;
				setsockopt(
					name2socket[pair.first],     // Socket descriptor
					SOL_SOCKET, // To manipulate options at the sockets API level
					SO_RCVTIMEO,// Specify the receiving or sending timeouts 
					(const void *)(&t), // option values
					sizeof(t) 
				);
		       	if (bind(name2socket[pair.first], rp->ai_addr, rp->ai_addrlen) == 0)
		            break;                  /* Success */
		       	close(name2socket[pair.first]);
		    }
			listen(name2socket[pair.first], 10);
			if (rp == NULL) {
		        cerr <<"Failed to connect to "<<pair.first<<endl;
		        exit(1);
		    }
			freeaddrinfo(result);
			startDevice(pair.first);
			
		}
	}
	
}
Example #7
0
void toolbar::Start()
{
    DisabledToolbar(1);
    emit startDevice(pComboMode->currentIndex(),pTime->time(),pComboNIT->currentIndex(),pSpinBox2->currentIndex());
    emit setFlagSaveData();
}