BOOL CppSQLite3Query::getBoolField(int nField, BOOL bNullValue/*=FALSE*/) { int nDefaultValue = bNullValue ? 1 : 0; // return getIntField(nField, nDefaultValue) ? TRUE : FALSE; }
int CppSQLite3Query::getIntField(const char* szField, int nNullValue/*=0*/) { int nField = fieldIndex(szField); return getIntField(nField, nNullValue); }
/* **************************************************************************** * * mongoUpdateContextAvailabilitySubscription - */ HttpStatusCode mongoUpdateContextAvailabilitySubscription ( UpdateContextAvailabilitySubscriptionRequest* requestP, UpdateContextAvailabilitySubscriptionResponse* responseP, Format notifyFormat, const std::string& tenant ) { bool reqSemTaken; LM_T(LmtMongo, ("Update Context Subscription, notifyFormat: '%s'", formatToString(notifyFormat))); reqSemTake(__FUNCTION__, "ngsi9 update subscription request", SemWriteOp, &reqSemTaken); /* Look for document */ BSONObj sub; std::string err; OID id; if (!safeGetSubId(requestP->subscriptionId, &id, &(responseP->errorCode))) { reqSemGive(__FUNCTION__, "ngsi9 update subscription request (mongo assertion exception)", reqSemTaken); if (responseP->errorCode.code == SccContextElementNotFound) { std::string details = std::string("invalid OID format: '") + requestP->subscriptionId.get() + "'"; alarmMgr.badInput(clientIp, details); } else // SccReceiverInternalError { LM_E(("Runtime Error (exception getting OID: %s)", responseP->errorCode.details.c_str())); } return SccOk; } if (!collectionFindOne(getSubscribeContextAvailabilityCollectionName(tenant), BSON("_id" << id), &sub, &err)) { reqSemGive(__FUNCTION__, "ngsi9 update subscription request (mongo db exception)", reqSemTaken); responseP->errorCode.fill(SccReceiverInternalError, err); return SccOk; } if (sub.isEmpty()) { responseP->errorCode.fill(SccContextElementNotFound); reqSemGive(__FUNCTION__, "ngsi9 update subscription request (no subscriptions found)", reqSemTaken); return SccOk; } /* We start with an empty BSONObjBuilder and process requestP for all the fields that can * be updated. I don't like too much this strategy (I would have preferred to start with * a copy of the original document, then modify as neded, but this doesn't seem to be easy * using the API provide by the Mongo C++ driver) * * FIXME: a better implementation strategy could be doing an findAndModify() query to do the * update, so detecting if the document was not found, instead of using findOne() + update() * with $set operation. One operations to MongoDb. vs two operations. */ BSONObjBuilder newSub; /* Entities (mandatory) */ BSONArrayBuilder entities; for (unsigned int ix = 0; ix < requestP->entityIdVector.size(); ++ix) { EntityId* en = requestP->entityIdVector[ix]; if (en->type == "") { entities.append(BSON(CASUB_ENTITY_ID << en->id << CASUB_ENTITY_ISPATTERN << en->isPattern)); } else { entities.append(BSON(CASUB_ENTITY_ID << en->id << CASUB_ENTITY_TYPE << en->type << CASUB_ENTITY_ISPATTERN << en->isPattern)); } } newSub.append(CASUB_ENTITIES, entities.arr()); /* Attributes (always taken into account) */ BSONArrayBuilder attrs; for (unsigned int ix = 0; ix < requestP->attributeList.size(); ++ix) { attrs.append(requestP->attributeList[ix]); } newSub.append(CASUB_ATTRS, attrs.arr()); /* Duration (optional) */ if (requestP->duration.isEmpty()) { newSub.append(CASUB_EXPIRATION, getField(sub, CASUB_EXPIRATION).numberLong()); } else { long long expiration = getCurrentTime() + requestP->duration.parse(); newSub.append(CASUB_EXPIRATION, expiration); LM_T(LmtMongo, ("New subscription expiration: %l", expiration)); } /* Reference is not updatable, so it is appended directly */ newSub.append(CASUB_REFERENCE, getStringField(sub, CASUB_REFERENCE)); int count = sub.hasField(CASUB_COUNT) ? getIntField(sub, CASUB_COUNT) : 0; /* The hasField check is needed due to lastNotification/count could not be present in the original doc */ if (sub.hasField(CASUB_LASTNOTIFICATION)) { newSub.append(CASUB_LASTNOTIFICATION, getIntField(sub, CASUB_LASTNOTIFICATION)); } if (sub.hasField(CASUB_COUNT)) { newSub.append(CASUB_COUNT, count); } /* Adding format to use in notifications */ newSub.append(CASUB_FORMAT, std::string(formatToString(notifyFormat))); /* Update document in MongoDB */ if (!collectionUpdate(getSubscribeContextAvailabilityCollectionName(tenant), BSON("_id" << OID(requestP->subscriptionId.get())), newSub.obj(), false, &err)) { reqSemGive(__FUNCTION__, "ngsi9 update subscription request (mongo db exception)", reqSemTaken); responseP->errorCode.fill(SccReceiverInternalError, err); return SccOk; } /* Send notifications for matching context registrations */ processAvailabilitySubscription(requestP->entityIdVector, requestP->attributeList, requestP->subscriptionId.get(), getStringField(sub, CASUB_REFERENCE), notifyFormat, tenant); /* Duration is an optional parameter, it is only added in the case they * was used for update */ if (!requestP->duration.isEmpty()) { responseP->duration = requestP->duration; } responseP->subscriptionId = requestP->subscriptionId; reqSemGive(__FUNCTION__, "ngsi9 update subscription request", reqSemTaken); return SccOk; }
bool BatteryMonitor::update(void) { struct BatteryProperties props; bool logthis; props.chargerAcOnline = false; props.chargerUsbOnline = false; props.chargerWirelessOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; props.batteryCurrentNow = INT_MIN; props.batteryChargeCounter = INT_MIN; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); else props.batteryPresent = true; props.batteryLevel = getIntField(mHealthdConfig->batteryCapacityPath); props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) props.batteryCurrentNow = getIntField(mHealthdConfig->batteryCurrentNowPath); if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) props.batteryChargeCounter = getIntField(mHealthdConfig->batteryChargeCounterPath); props.batteryTemperature = getIntField(mHealthdConfig->batteryTemperaturePath); const int SIZE = 128; char buf[SIZE]; String8 btech; if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0) props.batteryStatus = getBatteryStatus(buf); if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0) props.batteryHealth = getBatteryHealth(buf); if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); unsigned int i; for (i = 0; i < mChargerNames.size(); i++) { String8 path; path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); if (readFromFile(path, buf, SIZE) > 0) { if (buf[0] != '0') { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: props.chargerAcOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_USB: props.chargerUsbOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: props.chargerWirelessOnline = true; break; default: KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", mChargerNames[i].string()); } } } } logthis = !healthd_board_battery_update(&props); if (logthis) { char dmesgline[256]; snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d", props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "", abs(props.batteryTemperature / 10), abs(props.batteryTemperature % 10), props.batteryHealth, props.batteryStatus); if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { char b[20]; snprintf(b, sizeof(b), " c=%d", props.batteryCurrentNow / 1000); strlcat(dmesgline, b, sizeof(dmesgline)); } KLOG_INFO(LOG_TAG, "%s chg=%s%s%s\n", dmesgline, props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", props.chargerWirelessOnline ? "w" : ""); } char prop[PROP_VALUE_MAX]; // always report AC plug-in and capacity 100% if emulated.battery is set to 1 property_get("sys.emulated.battery", prop, "0"); if (!strcmp(prop, "1")) { props.chargerAcOnline = true; props.batteryLevel = 100; props.chargerWirelessOnline = false; } if (mBatteryPropertiesRegistrar != NULL) mBatteryPropertiesRegistrar->notifyListeners(props); if (!strcmp(prop, "1")) { return false; } else { if (0 == props.batteryTemperature) return false; else return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; } }
JNIEXPORT jint Java_com_mediatek_effect_filterpacks_Stereo3D2Dto3DFilter_process(JNIEnv* env, jobject thiz, jint inputTextureId, jobject smallBitmap, jint outputTextureId, jint outputFboId) { MRESULT result = 0; int small_img_width = 0; int small_img_heigh = 0; jclass cls; MTKTo3d *MyTo3d; TO3D_SET_ENV_INFO_STRUCT *MyTo3dInitInfo; TO3D_SET_PROC_INFO_STRUCT *MyTo3dProcInfo; TO3D_RESULT_STRUCT MyTo3dResult; XLOGD("Stereo3D 2Dto3D process()"); cls = env->GetObjectClass(thiz); MyTo3d = (MTKTo3d *)getIntField(env, cls, thiz, "mNativeMyTo3d"); MyTo3dInitInfo = (TO3D_SET_ENV_INFO_STRUCT *)getIntField(env, cls, thiz, "mNativeInitInfo"); MyTo3dProcInfo = (TO3D_SET_PROC_INFO_STRUCT *)getIntField(env, cls, thiz, "mNativeProcInfo"); XLOGD("get MyTo3d: 0x%x", MyTo3d); XLOGD("get MyTo3dInitInfo: 0x%x", MyTo3dInitInfo); XLOGD("get MyTo3dProcInfo: 0x%x", MyTo3dProcInfo); if (NULL == MyTo3d || (NULL == MyTo3dInitInfo || NULL == MyTo3dProcInfo)) { return 1; } SkBitmap* bm = GraphicsJNI::getNativeBitmap(env, smallBitmap); if (NULL == bm) { return 1; } char *smallpic = (char *)getBitmapPixels(bm, &small_img_width, &small_img_heigh); char *luma_y_plane_array; luma_y_plane_array = (char *)malloc(small_img_width * small_img_heigh); SW_RGBA8888toYV12(smallpic, luma_y_plane_array, small_img_width, small_img_heigh); MyTo3dProcInfo->small_image_addr = (MUINT32)luma_y_plane_array; MyTo3dInitInfo->small_image_width = small_img_width; MyTo3dInitInfo->small_image_height = small_img_heigh; result |= MyTo3d->To3dInit(MyTo3dInitInfo,0); printInitInfo(MyTo3dInitInfo); MyTo3dProcInfo->output_image_height = MyTo3dInitInfo->large_image_height; MyTo3dProcInfo->output_image_width = MyTo3dInitInfo->large_image_width; MyTo3dProcInfo->angle = 0; MyTo3dProcInfo->large_image_texID = inputTextureId; MyTo3dProcInfo->output_image_texID = outputTextureId; MyTo3dProcInfo->output_image_fboID = outputFboId; result |= MyTo3d->To3dFeatureCtrl(TO3D_FEATURE_SET_PROC_INFO, MyTo3dProcInfo, NULL); XLOGD("set process info"); printProcInfo(MyTo3dProcInfo); result |= MyTo3d->To3dMain(); XLOGD("run"); free(luma_y_plane_array); if (0 == result) { result |= MyTo3d->To3dFeatureCtrl(TO3D_FEATURE_GET_RESULT, 0, &MyTo3dResult); } return result; }
int SqlStatement::ResultRow::getIntField(const char* szField, int nNullValue/*=0*/) const { return getIntField(fieldIndex(szField), nNullValue); }
bool BatteryMonitor::update(void) { bool logthis; props.chargerAcOnline = false; props.chargerUsbOnline = false; props.chargerWirelessOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); else props.batteryPresent = mBatteryDevicePresent; props.batteryLevel = mBatteryFixedCapacity ? mBatteryFixedCapacity : getIntField(mHealthdConfig->batteryCapacityPath); props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; props.batteryTemperature = mBatteryFixedTemperature ? mBatteryFixedTemperature : getIntField(mHealthdConfig->batteryTemperaturePath); const int SIZE = 128; char buf[SIZE]; String8 btech; if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0) props.batteryStatus = getBatteryStatus(buf); if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0) props.batteryHealth = getBatteryHealth(buf); if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); unsigned int i; for (i = 0; i < mChargerNames.size(); i++) { String8 path; path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); if (readFromFile(path, buf, SIZE) > 0) { if (buf[0] != '0') { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: props.chargerAcOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_USB: props.chargerUsbOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: props.chargerWirelessOnline = true; break; default: KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", mChargerNames[i].string()); } } } } logthis = !healthd_board_battery_update(&props); if (logthis) { char dmesgline[256]; if (props.batteryPresent) { snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d", props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "", abs(props.batteryTemperature / 10), abs(props.batteryTemperature % 10), props.batteryHealth, props.batteryStatus); if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { int c = getIntField(mHealthdConfig->batteryCurrentNowPath); char b[20]; snprintf(b, sizeof(b), " c=%d", c / 1000); strlcat(dmesgline, b, sizeof(dmesgline)); } } else { snprintf(dmesgline, sizeof(dmesgline), "battery none"); } KLOG_WARNING(LOG_TAG, "%s chg=%s%s%s\n", dmesgline, props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", props.chargerWirelessOnline ? "w" : ""); } healthd_mode_ops->battery_update(&props); return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; }
bool BatteryMonitor::update(void) { bool logthis; props.chargerAcOnline = false; props.chargerUsbOnline = false; props.chargerWirelessOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); else props.batteryPresent = mBatteryDevicePresent; props.batteryLevel = mBatteryFixedCapacity ? mBatteryFixedCapacity : getIntField(mHealthdConfig->batteryCapacityPath); props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; props.batteryTemperature = mBatteryFixedTemperature ? mBatteryFixedTemperature : getIntField(mHealthdConfig->batteryTemperaturePath); const int SIZE = 128; char buf[SIZE]; String8 btech; if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0) props.batteryStatus = getBatteryStatus(buf); if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0) props.batteryHealth = getBatteryHealth(buf); if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); // reinitialize the mChargerNames vector everytime there is an update String8 path; DIR* dir = opendir(POWER_SUPPLY_SYSFS_PATH); if (dir == NULL) { KLOG_ERROR(LOG_TAG, "Could not open %s\n", POWER_SUPPLY_SYSFS_PATH); } else { struct dirent* entry; // reconstruct the charger strings mChargerNames.clear(); while ((entry = readdir(dir))) { const char* name = entry->d_name; if (!strcmp(name, ".") || !strcmp(name, "..")) continue; // Look for "type" file in each subdirectory path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_BATTERY: break; default: path.clear(); path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, name); if (access(path.string(), R_OK) == 0) { mChargerNames.add(String8(name)); if (readFromFile(path, buf, SIZE) > 0) { if (buf[0] != '0') { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, name); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: props.chargerAcOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_USB: props.chargerUsbOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: props.chargerWirelessOnline = true; break; default: KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", name); } } } } break; } //switch } //while closedir(dir); }//else logthis = !healthd_board_battery_update(&props); if (logthis) { char dmesgline[256]; if (props.batteryPresent) { snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d", props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "", abs(props.batteryTemperature / 10), abs(props.batteryTemperature % 10), props.batteryHealth, props.batteryStatus); if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { int c = getIntField(mHealthdConfig->batteryCurrentNowPath); char b[20]; snprintf(b, sizeof(b), " c=%d", c / 1000); strlcat(dmesgline, b, sizeof(dmesgline)); } } else { snprintf(dmesgline, sizeof(dmesgline), "battery none"); } KLOG_WARNING(LOG_TAG, "%s chg=%s%s%s\n", dmesgline, props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", props.chargerWirelessOnline ? "w" : ""); } healthd_mode_ops->battery_update(&props); return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; }
/* * Class: com_ibm_opencard_terminal_pcsc10_OCFPCSC1 * Method: SCardGetStatusChange * Signature: (II[Lcom/ibm/opencard/terminal/pcsc10/PcscReaderState;)V */ JNIEXPORT void JNICALL Java_com_ibm_opencard_terminal_pcsc10_OCFPCSC1_SCardGetStatusChange (JNIEnv *env, jobject obj, jint context, jint timeout, jobjectArray jReaderState) { SCARD_READERSTATE *readerState; int numReaderState; int ii; long returnCode; jobject objReaderState; jbyteArray jATR; /* First access the PcscReaderState structure to initialize the return */ /* value. Allocate a reader state array for each java ReaderState structure. */ numReaderState = env->GetArrayLength(jReaderState); if (numReaderState < 1) { throwPcscException(env, obj, "SCardGetStatusChange", "size of ReaderState array must be greater than 0 elements", 0); return; } readerState = (SCARD_READERSTATE *)malloc(numReaderState * sizeof(SCARD_READERSTATE)); if (readerState == NULL) { throwPcscException(env, obj, "SCardGetStatusChange", "error allocating memory for the readerState buffer", 0); return; } /* clear the allocated memory */ memset(readerState, 0x00, numReaderState * sizeof(SCARD_READERSTATE)); /* Now get each Java reader state structure and translate it into C++ */ for (ii=0; ii<numReaderState; ii++) { objReaderState = env->GetObjectArrayElement(jReaderState, ii); if (env->ExceptionOccurred() != NULL) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error getting elements from the readerState array", 0); return; } returnCode = getIntField(env, objReaderState, "CurrentState", (long *)&readerState[ii].dwCurrentState); if (returnCode) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error getting CurrentState field from the readerState record", 0); return; } returnCode = getIntField(env, objReaderState, "EventState", (long*)&readerState[ii].dwEventState); if (returnCode) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error getting EventState field from the readerState record", 0); return; } readerState[ii].szReader = (const char *)accessStringField(env, objReaderState, "Reader"); if (readerState[ii].szReader == NULL) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error getting Reader field from readerState record", 0); return; } int maxSize; returnCode = accessByteArray(env, objReaderState, "UserData", (unsigned char **)&readerState[ii].pvUserData, &maxSize); if (returnCode) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error getting UserData field from readerState record", 0); return; } } /* set the response timeout to 1000ms */ returnCode = SCardGetStatusChange((SCARDCONTEXT)context, 1000, readerState, numReaderState); if (returnCode != SCARD_S_SUCCESS) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error executing SCardGetStatusChange", returnCode); return; } readerState[0].dwCurrentState = readerState[0].dwEventState; /* write back the informations from the readerStatus to the java structures */ for (ii=0; ii<numReaderState; ii++) { objReaderState = env->GetObjectArrayElement(jReaderState, ii); if (env->ExceptionOccurred() != NULL) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error getting array elements", returnCode); return; } returnCode = setIntField(env, objReaderState, "EventState", readerState[ii].dwEventState); if (returnCode) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error setting the EventState field", returnCode); return; } returnCode = releaseStringField(env, objReaderState, "Reader", (const char *)readerState[ii].szReader); if (returnCode) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error setting the Reader field", returnCode); return; } returnCode = releaseByteArray(env, objReaderState, "UserData", (unsigned char *)readerState[ii].pvUserData); if (returnCode) { free(readerState); throwPcscException(env, obj, "SCardGetStatusChange", "error setting the UserData", returnCode); return; } // buffer for length of ATR jsize lenATR = (jsize)readerState[0].cbAtr; // check the length of the ATR in the PCSC ReaderState // if > 0 copy ATR to java ReaderState if (lenATR > 0) { // create new java bytearray with length of current ATR jATR = env->NewByteArray(lenATR); // copy PCSC ATR to jATR env->SetByteArrayRegion(jATR, 0, lenATR, (jbyte *)readerState[ii].rgbAtr); // find the ReaderState-Class jclass clsReaderState = env->GetObjectClass(objReaderState); // get the field ID from ATR-field jfieldID fldATR = env->GetFieldID(clsReaderState, "ATR", "[B"); // set the ATR-field within the ReaderStateObject env->SetObjectField(objReaderState, fldATR, jATR); } } free(readerState); return; }
void Java_ob_android_Stream_stream(JNIEnv *env, jobject obj) { jclass streamClazz = env->GetObjectClass(obj); if(streamClazz == NULL) return; jobject videoPipe, audioPipe; if(!getObjectField(env, obj, "video", "Ljnix/Pipe;", &videoPipe)) return; if(!getObjectField(env, obj, "audio", "Ljnix/Pipe;", &audioPipe)) return; jobject videoInputFD, audioInputFD; if(!getObjectField(env, videoPipe, "input", "Ljava/io/FileDescriptor;", &videoInputFD)) return; if(!getObjectField(env, audioPipe, "input", "Ljava/io/FileDescriptor;", &audioInputFD)) return; jint vfd, afd; if(!getIntField(env, videoInputFD, "descriptor", &vfd)) return; if(!getIntField(env, audioInputFD, "descriptor", &afd)) return; if((videoFile = fdopen(vfd, "rb")) == NULL) { throwException(env, "java/lang/RuntimeException", "Unable to open the video pipe as a file"); return; } logDebug("Video file descriptor opened as a file"); if((audioFile = fdopen(afd, "rb")) == NULL) { throwException(env, "java/lang/RuntimeException", "Unable to open the video pipe as a file"); return; } logDebug("Audio file descriptor opened as a file"); logDebug("Starting to stream"); BasicTaskScheduler* scheduler = BasicTaskScheduler::createNew(); logDebug("Loaded scheduler"); uenv = BasicUsageEnvironment::createNew(*scheduler); logDebug("Loaded environment"); DarwinInjector* injector = DarwinInjector::createNew(*uenv, "streamer"); logDebug("Loaded Darwin injector"); struct in_addr dummyDestAddress; dummyDestAddress.s_addr = 0; Groupsock rtpGroupsockVideo(*uenv, dummyDestAddress, 0, 0); Groupsock rtcpGroupsockVideo(*uenv, dummyDestAddress, 0, 0); Groupsock rtpGroupsockAudio(*uenv, dummyDestAddress, 0, 0); Groupsock rtcpGroupsockAudio(*uenv, dummyDestAddress, 0, 0); logDebug("Created group sockets"); // Create an 'MPEG-4 Video RTP' sink from the RTP 'groupsock': rtpVideoSink = MPEG4ESVideoRTPSink::createNew(*uenv, &rtpGroupsockVideo, 96); rtpAudioSink = AMRAudioRTPSink::createNew(*uenv, &rtpGroupsockVideo, 97); logDebug("Created a video sink"); logDebug("Created an audio sink"); logDebug("Beginning to play"); play(); if(!awaitConfigInfo(rtpVideoSink)) { *uenv << "Failed to get MPEG-4 'config' information from input file: " << uenv->getResultMsg() << "\n"; exit(1); } // Create (and start) a 'RTCP instance' for this RTP sink: const unsigned estimatedSessionBandwidthVideo = 200; // in kbps; for RTCP b/w share const unsigned maxCNAMElen = 100; unsigned char CNAME[maxCNAMElen+1]; gethostname((char*)CNAME, maxCNAMElen); CNAME[maxCNAMElen] = '\0'; // just in case logDebug((const char*)CNAME); RTCPInstance* videoRTCP = RTCPInstance::createNew(*uenv, &rtcpGroupsockVideo, estimatedSessionBandwidthVideo, CNAME, rtpVideoSink, NULL /* we're a server */); RTCPInstance* audioRTCP = RTCPInstance::createNew(*uenv, &rtcpGroupsockAudio, estimatedSessionBandwidthVideo, CNAME, rtpAudioSink, NULL /* we're a server */); // Note: This starts RTCP running automatically // Add these to our 'Darwin injector': injector->addStream(rtpVideoSink, videoRTCP); injector->addStream(rtpAudioSink, audioRTCP); if(!injector->setDestination( "192.168.1.100", "hero.sdp", "herosession", "", 554, "broadcast", "broadcast")) { *uenv << "injector->setDestination() failed: " << uenv->getResultMsg() << "\n"; exit(1); } *uenv << "Play this stream (from the Darwin Streaming Server) using the URL:\n" << "\trtsp://" << "localhost" << "/" << "test.sdp" << "\n"; uenv->taskScheduler().doEventLoop(); }
bool BatteryMonitor::update(void) { bool logthis; props.chargerAcOnline = false; props.chargerUsbOnline = false; props.chargerWirelessOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); else props.batteryPresent = mBatteryDevicePresent; props.batteryLevel = mBatteryFixedCapacity ? mBatteryFixedCapacity : getIntField(mHealthdConfig->batteryCapacityPath); props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; props.batteryTemperature = mBatteryFixedTemperature ? mBatteryFixedTemperature : getIntField(mHealthdConfig->batteryTemperaturePath); const int SIZE = 128; char buf[SIZE]; String8 btech; if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0) props.batteryStatus = getBatteryStatus(buf); if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0) props.batteryHealth = getBatteryHealth(buf); if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); unsigned int i; for (i = 0; i < mChargerNames.size(); i++) { String8 path; path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); if (readFromFile(path, buf, SIZE) > 0) { if (buf[0] != '0') { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: props.chargerAcOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_USB: props.chargerUsbOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: props.chargerWirelessOnline = true; break; default: KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", mChargerNames[i].string()); } } } } logthis = !healthd_board_battery_update(&props); if (logthis) { char dmesgline[256]; if (props.batteryPresent) { snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d", props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "", abs(props.batteryTemperature / 10), abs(props.batteryTemperature % 10), props.batteryHealth, props.batteryStatus); if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { int c = getIntField(mHealthdConfig->batteryCurrentNowPath); char b[20]; snprintf(b, sizeof(b), " c=%d", c / 1000); strlcat(dmesgline, b, sizeof(dmesgline)); } } else { snprintf(dmesgline, sizeof(dmesgline), "battery none"); } size_t len = strlen(dmesgline); snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s", props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", props.chargerWirelessOnline ? "w" : ""); log_time realtime(CLOCK_REALTIME); time_t t = realtime.tv_sec; struct tm *tmp = gmtime(&t); if (tmp) { static const char fmt[] = " %Y-%m-%d %H:%M:%S.XXXXXXXXX UTC"; len = strlen(dmesgline); if ((len < (sizeof(dmesgline) - sizeof(fmt) - 8)) // margin && strftime(dmesgline + len, sizeof(dmesgline) - len, fmt, tmp)) { char *usec = strchr(dmesgline + len, 'X'); if (usec) { len = usec - dmesgline; snprintf(dmesgline + len, sizeof(dmesgline) - len, "%09u", realtime.tv_nsec); usec[9] = ' '; } } } KLOG_WARNING(LOG_TAG, "%s\n", dmesgline); } healthd_mode_ops->battery_update(&props); return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; }
bool BatteryMonitor::update(void) { bool logthis; props.chargerAcOnline = false; props.chargerUsbOnline = false; props.chargerWirelessOnline = false; props.batteryStatus = BATTERY_STATUS_UNKNOWN; props.batteryHealth = BATTERY_HEALTH_UNKNOWN; props.maxChargingCurrent = 0; if (!mHealthdConfig->batteryPresentPath.isEmpty()) props.batteryPresent = getBooleanField(mHealthdConfig->batteryPresentPath); else props.batteryPresent = mBatteryDevicePresent; props.batteryLevel = mBatteryFixedCapacity ? mBatteryFixedCapacity : getIntField(mHealthdConfig->batteryCapacityPath); props.batteryVoltage = getIntField(mHealthdConfig->batteryVoltagePath) / 1000; if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) props.batteryCurrent = getIntField(mHealthdConfig->batteryCurrentNowPath) / 1000; if (!mHealthdConfig->batteryFullChargePath.isEmpty()) props.batteryFullCharge = getIntField(mHealthdConfig->batteryFullChargePath); if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) props.batteryCycleCount = getIntField(mHealthdConfig->batteryCycleCountPath); props.batteryTemperature = mBatteryFixedTemperature ? mBatteryFixedTemperature : getIntField(mHealthdConfig->batteryTemperaturePath); // For devices which do not have battery and are always plugged // into power souce. if (mAlwaysPluggedDevice) { props.chargerAcOnline = true; props.batteryPresent = true; props.batteryStatus = BATTERY_STATUS_CHARGING; props.batteryHealth = BATTERY_HEALTH_GOOD; } const int SIZE = 128; char buf[SIZE]; String8 btech; if (readFromFile(mHealthdConfig->batteryStatusPath, buf, SIZE) > 0) props.batteryStatus = getBatteryStatus(buf); if (readFromFile(mHealthdConfig->batteryHealthPath, buf, SIZE) > 0) props.batteryHealth = getBatteryHealth(buf); if (readFromFile(mHealthdConfig->batteryTechnologyPath, buf, SIZE) > 0) props.batteryTechnology = String8(buf); unsigned int i; for (i = 0; i < mChargerNames.size(); i++) { String8 path; path.appendFormat("%s/%s/online", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); if (readFromFile(path, buf, SIZE) > 0) { if (buf[0] != '0') { path.clear(); path.appendFormat("%s/%s/type", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); switch(readPowerSupplyType(path)) { case ANDROID_POWER_SUPPLY_TYPE_AC: props.chargerAcOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_USB: props.chargerUsbOnline = true; break; case ANDROID_POWER_SUPPLY_TYPE_WIRELESS: props.chargerWirelessOnline = true; break; default: KLOG_WARNING(LOG_TAG, "%s: Unknown power supply type\n", mChargerNames[i].string()); } path.clear(); path.appendFormat("%s/%s/current_max", POWER_SUPPLY_SYSFS_PATH, mChargerNames[i].string()); if (access(path.string(), R_OK) == 0) { int maxChargingCurrent = getIntField(path); if (props.maxChargingCurrent < maxChargingCurrent) { props.maxChargingCurrent = maxChargingCurrent; } } } } } logthis = !healthd_board_battery_update(&props); if (logthis) { char dmesgline[256]; size_t len; if (props.batteryPresent) { snprintf(dmesgline, sizeof(dmesgline), "battery l=%d v=%d t=%s%d.%d h=%d st=%d", props.batteryLevel, props.batteryVoltage, props.batteryTemperature < 0 ? "-" : "", abs(props.batteryTemperature / 10), abs(props.batteryTemperature % 10), props.batteryHealth, props.batteryStatus); len = strlen(dmesgline); if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) { len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " c=%d", props.batteryCurrent); } if (!mHealthdConfig->batteryFullChargePath.isEmpty()) { len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " fc=%d", props.batteryFullCharge); } if (!mHealthdConfig->batteryCycleCountPath.isEmpty()) { len += snprintf(dmesgline + len, sizeof(dmesgline) - len, " cc=%d", props.batteryCycleCount); } } else { snprintf(dmesgline, sizeof(dmesgline), "battery none"); } len = strlen(dmesgline); snprintf(dmesgline + len, sizeof(dmesgline) - len, " chg=%s%s%s", props.chargerAcOnline ? "a" : "", props.chargerUsbOnline ? "u" : "", props.chargerWirelessOnline ? "w" : ""); KLOG_WARNING(LOG_TAG, "%s\n", dmesgline); } healthd_mode_ops->battery_update(&props); return props.chargerAcOnline | props.chargerUsbOnline | props.chargerWirelessOnline; }
int SqliteQuery::getIntField(const std::string &fieldName, const int nullValue) { int fieldIndex = getFieldIndexByName(fieldName); return getIntField(fieldIndex, nullValue); }