void GPUdb::addKnownTypeFromTable(const std::string& tableName, const avro::DecoderPtr& decoder) { ShowTableRequest request(tableName, std::map<std::string, std::string>()); ShowTableResponse response; submitRequest("/show/table", request, response); if (response.typeIds.empty()) { throw GPUdbException("Table " + tableName + " does not exist."); } std::string& typeId = response.typeIds[0]; for (std::vector<std::string>::const_iterator it = response.typeIds.begin(); it != response.typeIds.end(); ++it) { if (*it != typeId) { throw GPUdbException("Table " + tableName + " is not homogeneous."); } } if (!decoder) { boost::mutex::scoped_lock lock(knownTypesMutex); knownTypes.erase(typeId); } else { boost::mutex::scoped_lock lock(knownTypesMutex); knownTypes[typeId] = decoder; } }
avro::DecoderPtr GPUdb::getDecoder(const std::string& typeId) const { { boost::mutex::scoped_lock lock(knownTypesMutex); if (knownTypes.find(typeId) != knownTypes.end()) { return knownTypes[typeId]; } } ShowTypesRequest request(typeId, "", std::map<std::string, std::string>()); ShowTypesResponse response; submitRequest("/show/types", request, response); if (response.typeSchemas.size() == 0) { throw GPUdbException("Unable to obtain type information for type " + typeId + "."); } Type type(response.labels[0], response.typeSchemas[0], response.properties[0]); avro::DecoderPtr decoder = avro::createDecoder<GenericRecord>(type); boost::mutex::scoped_lock lock(knownTypesMutex); if (knownTypes.find(typeId) != knownTypes.end()) { return knownTypes[typeId]; } knownTypes[typeId] = decoder; return decoder; }
void acceptInput() { char line[256]; char input[256]; char request[256]; char response[256]; // infinite loop while(1) { // display prompt fputs(">> ", stderr); // accept input fgets(line, sizeof line, stdin); sscanf(line, "%s", input); // if input is "exit" if(strcmp(input, "exit") == 0) exit(0); // quit program else { fprintf(stdout, "String Entered %s, Characters read : %d\n", input, strlen(line) - 1); parseInput(input, request); submitRequest(request); acceptResponse(response); parseResponse(response); } } }
/* * Proxy for all I/O with a device * @author Dan Streetman */ JNIEXPORT void JNICALL Java_com_ibm_jusb_os_linux_JavaxUsb_nativeDeviceProxy ( JNIEnv *env, jclass JavaxUsb, jobject linuxDeviceProxy ) { int fd = 0; struct usbdevfs_urb *urb; int loop_count = 0; jclass LinuxDeviceProxy; jobject linuxRequest; jstring jkey; jmethodID startCompleted, isRequestWaiting, getReadyRequest, getCancelRequest; jmethodID getKey; LinuxDeviceProxy = (*env)->GetObjectClass( env, linuxDeviceProxy ); startCompleted = (*env)->GetMethodID( env, LinuxDeviceProxy, "startCompleted", "(I)V" ); isRequestWaiting = (*env)->GetMethodID( env, LinuxDeviceProxy, "isRequestWaiting", "()Z" ); getReadyRequest = (*env)->GetMethodID( env, LinuxDeviceProxy, "getReadyRequest", "()Lcom/ibm/jusb/os/linux/LinuxRequest;" ); getCancelRequest = (*env)->GetMethodID( env, LinuxDeviceProxy, "getCancelRequest", "()Lcom/ibm/jusb/os/linux/LinuxRequest;" ); getKey = (*env)->GetMethodID( env, LinuxDeviceProxy, "getKey", "()Ljava/lang/String;" ); jkey = (*env)->CallObjectMethod( env, linuxDeviceProxy, getKey ); (*env)->DeleteLocalRef( env, LinuxDeviceProxy ); errno = 0; fd = open_device( env, jkey, O_RDWR ); (*env)->DeleteLocalRef( env, jkey ); if (0 > fd) { dbg( MSG_ERROR, "nativeDeviceProxy : Could not open node for device!\n" ); (*env)->CallVoidMethod( env, linuxDeviceProxy, startCompleted, errno ); return; } (*env)->CallVoidMethod( env, linuxDeviceProxy, startCompleted, 0 ); /* run forever...? */ while (1) { /* FIXME - stop using polling! */ if ( loop_count > 20 ) { usleep( 0 ); loop_count = 0; } loop_count ++; if (JNI_TRUE == (*env)->CallBooleanMethod( env, linuxDeviceProxy, isRequestWaiting )) { if ((linuxRequest = (*env)->CallObjectMethod( env, linuxDeviceProxy, getReadyRequest ))) { dbg( MSG_DEBUG1, "nativeDeviceProxy : Got Request\n" ); submitRequest( env, fd, linuxRequest ); (*env)->DeleteLocalRef( env, linuxRequest ); dbg( MSG_DEBUG1, "nativeDeviceProxy : Completed Request\n" ); } if ((linuxRequest = (*env)->CallObjectMethod( env, linuxDeviceProxy, getCancelRequest ))) { dbg( MSG_DEBUG1, "nativeDeviceProxy : Got Abort Request\n" ); cancelRequest( env, fd, linuxRequest ); (*env)->DeleteLocalRef( env, linuxRequest ); dbg( MSG_DEBUG1, "nativeDeviceProxy : Completed Abort Request\n" ); } } if (!(ioctl( fd, USBDEVFS_REAPURBNDELAY, &urb ))) { dbg( MSG_DEBUG1, "nativeDeviceProxy : Got completed URB\n" ); linuxRequest = urb->usercontext; completeRequest( env, linuxRequest ); (*env)->DeleteGlobalRef( env, linuxRequest ); dbg( MSG_DEBUG1, "nativeDeviceProxy : Finished completed URB\n" ); } } dbg( MSG_ERROR, "nativeDeviceProxy : Proxy exiting! ERROR!\n" ); close( fd ); }
status_t BnCameraDeviceUser::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { switch(code) { case DISCONNECT: { ALOGV("DISCONNECT"); CHECK_INTERFACE(ICameraDeviceUser, data, reply); disconnect(); reply->writeNoException(); return NO_ERROR; } break; case SUBMIT_REQUEST: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); // arg0 = request sp<CaptureRequest> request; if (data.readInt32() != 0) { request = new CaptureRequest(); request->readFromParcel(const_cast<Parcel*>(&data)); } // arg1 = streaming (bool) bool repeating = data.readInt32(); // return code: requestId (int32) reply->writeNoException(); int64_t lastFrameNumber = -1; reply->writeInt32(submitRequest(request, repeating, &lastFrameNumber)); reply->writeInt32(1); reply->writeInt64(lastFrameNumber); return NO_ERROR; } break; case SUBMIT_REQUEST_LIST: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); List<sp<CaptureRequest> > requestList; int requestListSize = data.readInt32(); for (int i = 0; i < requestListSize; i++) { if (data.readInt32() != 0) { sp<CaptureRequest> request = new CaptureRequest(); if (request->readFromParcel(const_cast<Parcel*>(&data)) != OK) { return BAD_VALUE; } requestList.push_back(request); } else { sp<CaptureRequest> request = 0; requestList.push_back(request); ALOGE("A request is missing. Sending in null request."); } } bool repeating = data.readInt32(); reply->writeNoException(); int64_t lastFrameNumber = -1; reply->writeInt32(submitRequestList(requestList, repeating, &lastFrameNumber)); reply->writeInt32(1); reply->writeInt64(lastFrameNumber); return NO_ERROR; } break; case CANCEL_REQUEST: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int requestId = data.readInt32(); reply->writeNoException(); int64_t lastFrameNumber = -1; reply->writeInt32(cancelRequest(requestId, &lastFrameNumber)); reply->writeInt32(1); reply->writeInt64(lastFrameNumber); return NO_ERROR; } break; case DELETE_STREAM: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int streamId = data.readInt32(); reply->writeNoException(); reply->writeInt32(deleteStream(streamId)); return NO_ERROR; } break; case CREATE_STREAM: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int width, height, format; width = data.readInt32(); ALOGV("%s: CREATE_STREAM: width = %d", __FUNCTION__, width); height = data.readInt32(); ALOGV("%s: CREATE_STREAM: height = %d", __FUNCTION__, height); format = data.readInt32(); ALOGV("%s: CREATE_STREAM: format = %d", __FUNCTION__, format); sp<IGraphicBufferProducer> bp; if (data.readInt32() != 0) { String16 name = readMaybeEmptyString16(data); bp = interface_cast<IGraphicBufferProducer>( data.readStrongBinder()); ALOGV("%s: CREATE_STREAM: bp = %p, name = %s", __FUNCTION__, bp.get(), String8(name).string()); } else { ALOGV("%s: CREATE_STREAM: bp = unset, name = unset", __FUNCTION__); } status_t ret; ret = createStream(width, height, format, bp); reply->writeNoException(); ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__); reply->writeInt32(ret); ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret); return NO_ERROR; } break; case CREATE_DEFAULT_REQUEST: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int templateId = data.readInt32(); CameraMetadata request; status_t ret; ret = createDefaultRequest(templateId, &request); reply->writeNoException(); reply->writeInt32(ret); // out-variables are after exception and return value reply->writeInt32(1); // to mark presence of metadata object request.writeToParcel(const_cast<Parcel*>(reply)); return NO_ERROR; } break; case GET_CAMERA_INFO: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); CameraMetadata info; status_t ret; ret = getCameraInfo(&info); reply->writeNoException(); reply->writeInt32(ret); // out-variables are after exception and return value reply->writeInt32(1); // to mark presence of metadata object info.writeToParcel(reply); return NO_ERROR; } break; case WAIT_UNTIL_IDLE: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); reply->writeNoException(); reply->writeInt32(waitUntilIdle()); return NO_ERROR; } break; case FLUSH: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); reply->writeNoException(); int64_t lastFrameNumber = -1; reply->writeInt32(flush(&lastFrameNumber)); reply->writeInt32(1); reply->writeInt64(lastFrameNumber); return NO_ERROR; } case BEGIN_CONFIGURE: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); reply->writeNoException(); reply->writeInt32(beginConfigure()); return NO_ERROR; } break; case END_CONFIGURE: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); reply->writeNoException(); reply->writeInt32(endConfigure()); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } }
status_t BnCameraDeviceUser::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { switch(code) { case DISCONNECT: { ALOGV("DISCONNECT"); CHECK_INTERFACE(ICameraDeviceUser, data, reply); disconnect(); reply->writeNoException(); return NO_ERROR; } break; case SUBMIT_REQUEST: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); // arg0 = request sp<CaptureRequest> request; if (data.readInt32() != 0) { request = new CaptureRequest(); request->readFromParcel(const_cast<Parcel*>(&data)); } // arg1 = streaming (bool) bool repeating = data.readInt32(); // return code: requestId (int32) reply->writeNoException(); int64_t lastFrameNumber = -1; reply->writeInt32(submitRequest(request, repeating, &lastFrameNumber)); reply->writeInt32(1); reply->writeInt64(lastFrameNumber); return NO_ERROR; } break; case SUBMIT_REQUEST_LIST: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); List<sp<CaptureRequest> > requestList; int requestListSize = data.readInt32(); for (int i = 0; i < requestListSize; i++) { if (data.readInt32() != 0) { sp<CaptureRequest> request = new CaptureRequest(); if (request->readFromParcel(const_cast<Parcel*>(&data)) != OK) { return BAD_VALUE; } requestList.push_back(request); } else { sp<CaptureRequest> request = 0; requestList.push_back(request); ALOGE("A request is missing. Sending in null request."); } } bool repeating = data.readInt32(); reply->writeNoException(); int64_t lastFrameNumber = -1; reply->writeInt32(submitRequestList(requestList, repeating, &lastFrameNumber)); reply->writeInt32(1); reply->writeInt64(lastFrameNumber); return NO_ERROR; } break; case CANCEL_REQUEST: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int requestId = data.readInt32(); reply->writeNoException(); int64_t lastFrameNumber = -1; reply->writeInt32(cancelRequest(requestId, &lastFrameNumber)); reply->writeInt32(1); reply->writeInt64(lastFrameNumber); return NO_ERROR; } break; case DELETE_STREAM: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int streamId = data.readInt32(); reply->writeNoException(); reply->writeInt32(deleteStream(streamId)); return NO_ERROR; } break; case CREATE_STREAM: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); status_t ret = BAD_VALUE; if (data.readInt32() != 0) { OutputConfiguration outputConfiguration(data); ret = createStream(outputConfiguration); } else { ALOGE("%s: cannot take an empty OutputConfiguration", __FUNCTION__); } reply->writeNoException(); ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__); reply->writeInt32(ret); ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret); return NO_ERROR; } break; case CREATE_INPUT_STREAM: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int width, height, format; width = data.readInt32(); height = data.readInt32(); format = data.readInt32(); status_t ret = createInputStream(width, height, format); reply->writeNoException(); reply->writeInt32(ret); return NO_ERROR; } break; case GET_INPUT_SURFACE: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); sp<IGraphicBufferProducer> bp; status_t ret = getInputBufferProducer(&bp); sp<IBinder> b(IInterface::asBinder(ret == OK ? bp : NULL)); reply->writeNoException(); reply->writeInt32(ret); reply->writeInt32(1); reply->writeString16(String16("camera input")); // name of surface reply->writeStrongBinder(b); return NO_ERROR; } break; case CREATE_DEFAULT_REQUEST: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int templateId = data.readInt32(); CameraMetadata request; status_t ret; ret = createDefaultRequest(templateId, &request); reply->writeNoException(); reply->writeInt32(ret); // out-variables are after exception and return value reply->writeInt32(1); // to mark presence of metadata object request.writeToParcel(const_cast<Parcel*>(reply)); return NO_ERROR; } break; case GET_CAMERA_INFO: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); CameraMetadata info; status_t ret; ret = getCameraInfo(&info); reply->writeNoException(); reply->writeInt32(ret); // out-variables are after exception and return value reply->writeInt32(1); // to mark presence of metadata object info.writeToParcel(reply); return NO_ERROR; } break; case WAIT_UNTIL_IDLE: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); reply->writeNoException(); reply->writeInt32(waitUntilIdle()); return NO_ERROR; } break; case FLUSH: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); reply->writeNoException(); int64_t lastFrameNumber = -1; reply->writeInt32(flush(&lastFrameNumber)); reply->writeInt32(1); reply->writeInt64(lastFrameNumber); return NO_ERROR; } case BEGIN_CONFIGURE: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); reply->writeNoException(); reply->writeInt32(beginConfigure()); return NO_ERROR; } break; case END_CONFIGURE: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); bool isConstrainedHighSpeed = data.readInt32(); reply->writeNoException(); reply->writeInt32(endConfigure(isConstrainedHighSpeed)); return NO_ERROR; } break; case PREPARE: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int streamId = data.readInt32(); reply->writeNoException(); reply->writeInt32(prepare(streamId)); return NO_ERROR; } break; case TEAR_DOWN: { CHECK_INTERFACE(ICameraDeviceUser, data, reply); int streamId = data.readInt32(); reply->writeNoException(); reply->writeInt32(tearDown(streamId)); return NO_ERROR; } break; default: return BBinder::onTransact(code, data, reply, flags); } }
inline oscpp::AsyncIORequest * read(void * const buffer, const size_t size) { return submitRequest(new oscpp::GenericAsyncIORequest(oscpp::AsyncIORequest::REQUEST_TYPE_READ, buffer, size)); }
inline oscpp::AsyncIORequest * close() { return submitRequest(new oscpp::GenericAsyncIORequest(oscpp::AsyncIORequest::REQUEST_TYPE_CLOSE, NULL, 0)); }
inline oscpp::AsyncIORequest * open (const std::string & fileName) { return submitRequest(new oscpp::GenericAsyncIORequest(oscpp::AsyncIORequest::REQUEST_TYPE_OPEN, const_cast<char * >(fileName.c_str()), fileName.size())); }
inline void finish() { submitRequest(NULL); }