Exemplo n.º 1
0
long long findLowestNumberOfSeconds( char *numString ) {
  
  int currChar = 0 , numChars = 0;
  int highestNumber = 1 ;
  int isZeroAssigned = 0 ;

  char c ;

  /* Iterate through the string and assign the lowest possible
     value for each unique character encountered. This means you
     assign 1 to the first char, 0 to the next, 2, 3, etc. 
  */
  while( c = numString[currChar] ) {
    
    if ( getKeyValue(c) == -1 ) {
      if ( highestNumber > 1 && !isZeroAssigned ) {
	setKeyValue(c, 0) ;
	isZeroAssigned = 1;
      }
      else {
	setKeyValue(c, highestNumber++) ;
      }
    }
    currChar++;
    numChars++;
  }

  return convertAlienToDecimal(numString, numChars, highestNumber ) ;
}
Exemplo n.º 2
0
/*插入叶子节点*/
void LeafNode::insert(KeyType key, const DataType &data) {
	int i;
	for (i = m_KeyNum; i >= 1 && m_KeyValues[i - 1] > key; --i) {
		setKeyValue(i, m_KeyValues[i - 1]);
		setData(i, m_Datas[i - 1]);
	}
	setKeyValue(i, key);
	setData(i, data);
	setKeyNum(m_KeyNum + 1);
}
Exemplo n.º 3
0
/*插入内部结点*/
void InternalNode::insert(int keyIndex, int childIndex, KeyType key, FatherNode* childNode) {
	int i;
	for (i = getKeyNum(); i > keyIndex; --i) {
		setChild(i + 1, m_Childs[i]);
		setKeyValue(i, m_KeyValues[i - 1]);
	} //将父节点的childIndex后所有键值对后移一个单位
	if (i == childIndex) {
		setChild(i + 1, m_Childs[i]);
	}
	setChild(childIndex, childNode); //插入新结点
	setKeyValue(keyIndex, key);
	setKeyNum(m_KeyNum + 1);
}
RddResultCode SsbQ1_1Transformer::transform(TransformerContext* ctx, const BaseRddPartition* input, PairRddPartition* output) {
  auto param = ctx->getParamRdds().at(0);
  if (input->empty() || param->empty()) {
    return RRC_SUCCESS;
  }

  auto op = ctx->getRddOperator();
  auto paramOp = op->paramOperators.at(0);
  auto exprCtx = ctx->getExpressionContext();

  auto keyTemplate = param->getKeyTemplate();
  auto valueTemplate = param->getValueTemplate();
  auto dateDes = keyTemplate->GetDescriptor();
  auto dateRef = keyTemplate->GetReflection();
  auto dateField = dateDes->FindFieldByName("d_datekey");

  set<uint64_t> marchedDate;

  param->foreach([&marchedDate, paramOp, &exprCtx, dateRef, dateField] (const PbMessagePtr& key, const PbMessagePtr& value) {
    idgs::actor::PbMessagePtr outkey, outvalue;
    exprCtx->setKeyValue(&key, &value);
    exprCtx->setOutputKeyValue(&outkey, &outvalue);

    if (paramOp->evaluate(exprCtx)) {
      marchedDate.insert(dateRef->GetUInt64(* key, dateField));
    }
  });

  valueTemplate = input->getValueTemplate();
  auto orderDes = valueTemplate->GetDescriptor();
  auto orderRef = valueTemplate->GetReflection();
  auto orderDateField = orderDes->FindFieldByName("lo_orderdate");

  input->foreach([marchedDate, output, op, &exprCtx, orderRef, orderDateField] (const PbMessagePtr& key, const PbMessagePtr& value) {
    idgs::actor::PbMessagePtr outkey, outvalue;
    exprCtx->setKeyValue(&key, &value);
    exprCtx->setOutputKeyValue(&outkey, &outvalue);

    if (op->evaluate(exprCtx)) {
      uint64_t orderdate = orderRef->GetUInt64(* value, orderDateField);

      if(marchedDate.find(orderdate) != marchedDate.end()) {
        output->put(key, value);
      }
    }
  });

  return RRC_SUCCESS;
}
Exemplo n.º 5
0
void CInternalNode::insert(int keyIndex, int childIndex, KeyType key, CNode* childNode) {
    int i;
    for (i=getKeyNum(); i>keyIndex; --i)//将父节点中的childIndex后的所有关键字的值和子树指针向后移一位
    {
        setChild(i+1,m_Childs[i]);
        setKeyValue(i,m_KeyValues[i-1]);
    }
    if (i==childIndex)
    {
        setChild(i+1, m_Childs[i]);
    }
    setChild(childIndex, childNode);
    setKeyValue(keyIndex, key);
    setKeyNum(m_KeyNum+1);
}
void GuiPreferences::changePasswd(void)
{
  QString userPasswd;
  QString passwd;
  QString newPasswd;
  QString renewPasswd;
  QString key;

  if (m_userRole == ngrt4n::AdmUserRole) {
    key = Settings::ADM_PASSWD_KEY;
    userPasswd = value(key, QString::fromStdString(ngrt4n::AdmUser));
  } else {
    key = Settings::OP_PASSWD_KEY;
    userPasswd = value(key, QString::fromStdString(ngrt4n::OpUser));
  }
  passwd = QCryptographicHash::hash(ngrt4n::toByteArray(m_oldPwdField->text()), QCryptographicHash::Md5);
  newPasswd = QCryptographicHash::hash(ngrt4n::toByteArray(m_pwdField->text()), QCryptographicHash::Md5);
  renewPasswd = QCryptographicHash::hash(ngrt4n::toByteArray(m_rePwdField->text()), QCryptographicHash::Md5);

  if (userPasswd == passwd) {
    if(newPasswd == renewPasswd) {
      setKeyValue(key, newPasswd);
      QMessageBox::information(m_dialog,
                               APP_NAME,
                               tr("Password updated"),
                               QMessageBox::Ok);
      m_dialog->done(0);
    } else {
      Q_EMIT errorOccurred(tr("Sorry the passwords do not match"));
    }
  } else {
    Q_EMIT errorOccurred(tr("Authentication failed"));
  }
}
Exemplo n.º 7
0
FakeSMCSensor *FakeSMCPlugin::addTachometer(UInt32 index, const char* name, SInt8 *fanIndex)
{
    SInt8 vacantFanIndex = takeVacantFanIndex();
    
    if (vacantFanIndex >= 0) {
        char key[5];
        snprintf(key, 5, KEY_FORMAT_FAN_SPEED, vacantFanIndex);
        
        if (FakeSMCSensor *sensor = addSensor(key, TYPE_FPE2, 2, kFakeSMCTachometerSensor, index)) {
            if (name) {
                snprintf(key, 5, KEY_FORMAT_FAN_ID, vacantFanIndex);
                
                if (!setKeyValue(key, TYPE_CH8, strlen(name), name))
                    HWSensorsWarningLog("failed to add tachometer name for key %s", key);
            }
            
            if (fanIndex) *fanIndex = vacantFanIndex;
            
            return sensor;
        }
        else HWSensorsErrorLog("failed to add tachometer sensor for key %s", key);
    }
    else HWSensorsErrorLog("failed to take vacant Fan index");
	
	return 0;
}
pb::RddResultCode ReduceByKeyTransformer::transform(TransformerContext* ctx, const BaseRddPartition* input, PairRddPartition* output) {
  ReduceOperator* reduceOp = dynamic_cast<ReduceOperator*>(ctx->getRddOperator());
  size_t reduceSize = reduceOp->options.size();
  auto exprCtx = ctx->getExpressionContext();

  input->foreachGroup([reduceOp, reduceSize, &ctx, &exprCtx, &output] (const PbMessagePtr& key, const vector<PbMessagePtr>& values) {
    PbMessagePtr outkey, outvalue;

    auto& reduceOptions = ctx->getReduceOption(key, reduceSize);
    auto it = values.begin();
    for (; it != values.end(); ++ it) {
      exprCtx->setKeyValue(&key, &(* it));
      exprCtx->setOutputKeyValue(&outkey, &outvalue);

      if (reduceOp->evaluate(exprCtx)) {
        for (int32_t i = 0; i < reduceSize; ++ i) {
          reduceOp->options[i]->reduce(exprCtx, reduceOptions[i]);
        }
      }
    }

    if (outkey && outvalue) {
      output->put(outkey, outvalue);
    }
  });

  return pb::RRC_SUCCESS;
}
Exemplo n.º 9
0
XMP_Uns64 TagTree::digest64u(LFA_FileRef file,const std::string key /* ="" */, bool BigEndian /*=false*/,bool hexDisplay /*=false*/ )
{
	XMP_Uns64 r;
	if (8 != LFA_Read ( file, &r, 8, false)) // require all == false => leave the throwing to this routine
		Log::error("could not read 8-byte value from file (end of file?)");
	if ( ((kBigEndianHost==1) &&  !BigEndian ) ||  ((kBigEndianHost==0) && BigEndian ))  // "XOR"
		Flip8(&r);
	if (!key.empty()) {
		char out[25]; //largets 64 bit no: 18446744073709551616 -1 (20 digits)
		if (!hexDisplay)
		{
			//not working, 0x1244e7780 ==> 609122176 decimal (== 0x244e7780)
			#if WIN_ENV
				snprintf(out , 24 , "%I64u" , r);
			#else 
				// MAC, UNIX
				snprintf(out , 24 , "%llu" , r);
			#endif
		}
		else
		{	
			//not working, upper 32 bit empty:  			
			#if WIN_ENV
				snprintf( out , 24 , "0x%.16I64X" , r );
			#else
				snprintf( out , 24 , "0x%.16llX" , r );
			#endif
		}
		setKeyValue(key,out);
	}
	return r;
}
Exemplo n.º 10
0
void LeafNode::removeKey(int keyIndex, int childIndex) {
	for (int i = keyIndex; i < getKeyNum() - 1; ++i) {
		setKeyValue(i, getKeyValue(i + 1));
		setData(i, getData(i + 1));
	}
	setKeyNum(getKeyNum() - 1);
}
Exemplo n.º 11
0
void TagTree::digest(LFA_FileRef file,const std::string key /*=NULL*/,
					   void* returnValue /*=""*/,
					   XMP_Int32 numOfBytes /*=0*/ )
{
	if (numOfBytes==0) {
		//0-byte requests *are* legitimate, reducing codeforks for the caller
		if ( !key.empty() )
			setKeyValue(key,"(0 bytes)");
		return;
	}

	//do we need own space or will it be provided?
	char* value;
	if (returnValue)
		value=(char*)returnValue;
	else
		value=new char[numOfBytes+1];

										// require all == false => leave the throwing to this routine
	if (numOfBytes != LFA_Read ( file, value, numOfBytes, false))	// saying 1,4 guarantes read as ordered (4,1 would not)
		Log::error("could not read %d number of files (End of File reached?)",numOfBytes);
#if !IOS_ENV
	char* out=new char[2 + numOfBytes*3 + 5]; //'0x12 34 45 78 '   length formula: 2 ("0x") + numOfBytes x 3 + 5 (padding)
	if (!key.empty()) {
		snprintf(out,3,"0x");
		XMP_Int64 i; // *)
		for (i=0; i < numOfBytes; i++)
			snprintf(&out[2+i*3],4,"%.2X ",value[i]); //always must allow that extra 0-byte on mac (overwritten again and again)
		snprintf(&out[2+i*3],1,"%c",'\0'); // *) using i one more time (needed while bug 1613297 regarding snprintf not fixed)
		setKeyValue(key,out);
	}
#else
    char* out=new char[2 + numOfBytes*9 + 5]; //'0x12 34 45 78 '   length formula: 2 ("0x") + numOfBytes x 3 + 5 (padding)
	if (!key.empty()) {
		snprintf(out,3,"0x");
		XMP_Int64 i; // *)
		for (i=0; i < numOfBytes; i++)
			snprintf(&out[2+i*9],10,"%.8X ",value[i]); //always must allow that extra 0-byte on mac (overwritten again and again)
		snprintf(&out[2+i*9],1,"%c",'\0'); // *) using i one more time (needed while bug 1613297 regarding snprintf not fixed)
		setKeyValue(key,out);
	}

#endif
    delete [] out;
	if (!returnValue) delete [] value; //if we own it, we delete it
}
Exemplo n.º 12
0
void CInternalNode::removeKey(int keyIndex, int childIndex)
{
    for (int i=0; i<getKeyNum()-keyIndex-1; ++i)
    {
        setKeyValue(keyIndex+i, getKeyValue(keyIndex+i+1));
        setChild(childIndex+i, getChild(childIndex+i+1));
    }
    setKeyNum(getKeyNum()-1);
}
Exemplo n.º 13
0
void SkinPropertyEditor::_onBrowseButton()
{
	// Display the SkinChooser to get a skin from the user
	std::string modelName = _entity->getKeyValue("model");
	std::string prevSkin = _entity->getKeyValue(_key);
	std::string skin = SkinChooser::chooseSkin(modelName, prevSkin);

	// Apply the key to the entity
	setKeyValue(_key, skin);
}
Exemplo n.º 14
0
void TagTree::comment(const char* format, ...)
{
	char buffer[XMPQE_BUFFERSIZE];
	va_list args;
	va_start(args, format);
		vsprintf(buffer, format, args);
	va_end(args);

	setKeyValue("","",buffer);
}
Exemplo n.º 15
0
/*删除内部结点的键值*/
void InternalNode::removeKey(int keyIndex, int childIndex) {
	for (int i = 0; i < getKeyNum() - childIndex; i++)
	{
		setChild(childIndex + i, getChild(childIndex + i + 1));
	}
	for (int i = 0; i < getKeyNum() - keyIndex - 1; ++i) {
		setKeyValue(keyIndex + i, getKeyValue(keyIndex + i + 1));
	}//键值对依次向前移动
	setKeyNum(getKeyNum() - 1);
}
Exemplo n.º 16
0
//adding a subnode to tagMap and current node
//(do "go in", pushes onto nodeStack, making this the current node)
void TagTree::pushNode(const std::string key)
{
	//TODO: adding fromArgs("offset:%s",LFA_Seek( file, offset_CD ,SEEK_SET )); <== requires file to be passed in
	setKeyValue(key,"","");
	//_and_ push reference to that one on stack
	Node* pCurNode=*nodeStack.rbegin();
	nodeStack.push_back( &*pCurNode->children.rbegin() );

	if ( verbose )
		Log::info( "pushing %d: %s",nodeStack.size(), key.c_str() );
}
Exemplo n.º 17
0
ProtoMessage ProtoMessage::operator=(const Variant& value)
{
	if (m_key == -1)
	{
		m_key = PROTO_GLOBAL;
	}
	setKeyValue(m_dataKey, value, m_key);
	m_dataKey = -1;
	m_key = -1;
	return *this;
}
Exemplo n.º 18
0
std::string TagTree::digestString(LFA_FileRef file,const std::string key /*=""*/, size_t length /* =0 */, bool verifyZeroTerm /* =false */, bool allowEarlyZeroTerm /* =false */ )
{
	std::string r(256,'\0');	//give some room in advance (performance)
	r.clear();					// safety measure (may be needed on mac)

	bool outside = false;	// toggle-flag: outside ASCII

	for ( XMP_Uns32 i = 0; ( i<length ) || (length==0) ; i++ )
	{
		XMP_Uns8 ch = (XMP_Uns8)LFA_GetChar(file);

		// allow early zero termination (useful for fixed length field that may or may not end prematurely)
		if ( allowEarlyZeroTerm && ( ch == 0 ) && ( length != 0 ) )
		{
			i++;
			LFA_Seek( file, length - i, SEEK_CUR ); // compensate for skipped bytes
			break;
		}

		if ( (0x20 <= ch) && (ch <= 0x7E) ) 
		{	//outside-case
			if ( outside )
				r.push_back('>');
			r.push_back(ch);
			outside = false;
		} else {
			if ( (length==0) && (ch == '\0' ) )
				break; // lenght zero => watch for zero termination...
			if ( !outside ) 
				r.push_back('<');	//first inside
			else if (!((length==0) && (ch =='\0')))
				r.push_back(' ');	//further inside (except very last)
			outside = true;
			char tmp[4];
			sprintf(tmp, "%.2X", ch ); 
			r+=tmp;			
		}
	}

	if ( outside ) r.push_back('>'); //last one

	if ( verifyZeroTerm )
	{
		XMP_Uns8 ch = (XMP_Uns8)LFA_GetChar(file);
		if ( ch != 0 )
			Log::error("string for key %s not terminated with zero as requested but with 0x%.2X",key.c_str(),ch);
	}


	if (!key.empty())
		setKeyValue(key,r);

	return r;
}
Exemplo n.º 19
0
void ModelPropertyEditor::_onParticleButton()
{
	// Invoke ParticlesChooser
    std::string currentSelection = _entity->getKeyValue(_key);
	std::string particle = ParticlesChooser::chooseParticle(currentSelection);

	if (!particle.empty())
	{
		setKeyValue(_key, particle);
	}
}
Exemplo n.º 20
0
void ModelPropertyEditor::_onModelButton()
{
	// Use the ModelSelector to choose a model
	ModelSelectorResult result = ModelSelector::chooseModel(
		_entity->getKeyValue(_key), false, false // pass the current model, don't show options or skins
	);

	if (!result.model.empty())
	{
		setKeyValue(_key, result.model);
	}
}
Exemplo n.º 21
0
// Browse button callback
void TexturePropertyEditor::_onBrowse()
{
	// Light texture chooser (self-destructs on close)
	LightTextureChooser chooser;
	std::string texture = chooser.chooseTexture();

	if (!texture.empty())
	{
		// Apply the keyvalue immediately
		setKeyValue(_key, texture);
	}
}
Exemplo n.º 22
0
XMP_Int16 TagTree::digest16s(LFA_FileRef file,const std::string key /* ="" */ , bool BigEndian /*=false*/ )
{
	XMP_Int16 r;
	if (2 != LFA_Read ( file, &r, 2, false)) // require all == false => leave the throwing to this routine
		Log::error("could not read 2-byte value from file (end of file?)");
	if ( ((kBigEndianHost==1) &&  !BigEndian ) ||  ((kBigEndianHost==0) && BigEndian ))  // "XOR"
		Flip2(&r);
	if (!key.empty()) {
		char out[10]; //longest signed int is "�768", 6 chars 	
		snprintf(out,9,"%d",r);
		setKeyValue(key,out);
	}
	return r;
}
Exemplo n.º 23
0
XMP_Int32 TagTree::digest32s(LFA_FileRef file,const std::string key /* ="" */ , bool BigEndian /*=false*/ )
{
	XMP_Int32 r;
	if (4 != LFA_Read ( file, &r, 4, false)) // require all == false => leave the throwing to this routine
		Log::error("could not read 4-byte value from file (end of file?)");
	if ( ((kBigEndianHost==1) &&  !BigEndian ) ||  ((kBigEndianHost==0) && BigEndian ))  // "XOR"
		Flip4(&r);
	if (!key.empty()) {
		char out[15]; //longest signed int is "�47483648", 11 chars 	
		snprintf(out,14,"%d",r); //signed, mind the trailing \0 on Mac btw
		setKeyValue(key,out);
	}
	return r;
}
Exemplo n.º 24
0
////////////////////////////////////////////////////////////////////////////////////
// numeric digest routines
//
XMP_Int64 TagTree::digest64s(LFA_FileRef file,const std::string key /* ="" */ , bool BigEndian /*=false*/ )
{
	XMP_Int64 r;
	if (8 != LFA_Read ( file, &r, 8, false)) // require all == false => leave the throwing to this routine
		Log::error("could not read 8-byte value from file (end of file?)");
	if ( ((kBigEndianHost==1) &&  !BigEndian ) ||  ((kBigEndianHost==0) && BigEndian ))  // "XOR"
		Flip8(&r);

	if (!key.empty()) {
		char out[25]; //longest is "18446744073709551615", 21 chars ==> 25
		snprintf(out,24,"%lld",r); //signed, mind the trailing \0 on Mac btw
		setKeyValue(key,out);
	}
	return r;
}
Exemplo n.º 25
0
bool LPCSensors::addTachometerSensors(OSDictionary *configuration)
{
    HWSensorsDebugLog("adding tachometer sensors...");

    char key[7];
    UInt16 value = 0;

    // FAN manual control key
    addSensorForKey(KEY_FAN_MANUAL, SMC_TYPE_UI16, SMC_TYPE_UI16_SIZE, kLPCSensorsFanManualSwitch, 0);

    int location = LEFT_LOWER_FRONT;

    for (int i = 0; i < tachometerSensorsLimit(); i++) {
        
        UInt8 fanIndex;

        snprintf(key, 7, "FANIN%X", i);

        if (OSString* name = OSDynamicCast(OSString, configuration->getObject(key))){
            if (addTachometer(i, name->getLength() > 0 ? name->getCStringNoCopy() : 0, FAN_RPM, 0, (FanLocationType)location++, &fanIndex)){

                if (isTachometerControlable(i) && fanIndex < UINT8_MAX) {

                    tachometerControls[i].number = fanIndex;
                    tachometerControls[i].target = -1;
                    tachometerControls[i].minimum = -1;

                    // Minimum RPM and fan control sensor
                    snprintf(key, 5, KEY_FORMAT_FAN_MIN, fanIndex);
                    addSensorForKey(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, kLPCSensorsFanMinController, i);

                    // Maximum RPM
                    snprintf(key, 5, KEY_FORMAT_FAN_MAX, fanIndex);
                    FakeSMCKey::encodeFloatValue(kLPCSensorsMaxRPM, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, &value);
                    setKeyValue(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, &value);

                    // Target RPM and fan control sensor
                    snprintf(key, 5, KEY_FORMAT_FAN_TARGET, fanIndex);
                    addSensorForKey(key, SMC_TYPE_FPE2, SMC_TYPE_FPXX_SIZE, kLPCSensorsFanTargetController, i);
                }
            }
            else HWSensorsWarningLog("failed to add tachometer sensor %d", i);
        }
    }

    return true;
}
Exemplo n.º 26
0
XMP_Uns32 TagTree::digest32u(LFA_FileRef file,const std::string key /* ="" */, bool BigEndian /*=false*/,bool hexDisplay /*=false*/ )
{
	XMP_Uns32 r;
	if (4 != LFA_Read ( file, &r, 4, false)) // require all == false => leave the throwing to this routine
		Log::error("could not read 4-byte value from file (end of file?)");
	if ( ((kBigEndianHost==1) &&  !BigEndian ) ||  ((kBigEndianHost==0) && BigEndian ))  // "XOR"
		Flip4(&r);
	if (!key.empty()) {
		char out[19]; //longest unsigned int is "2147483648", 10 chars resp. 0xFFFFFFFF 10 chars
		if (!hexDisplay)
			snprintf(out,18,"%u",r); //unsigned, mind the trailing \0 on Mac btw
		else
			snprintf(out,18,"0x%.8X",r); //unsigned, mind the trailing \0 on Mac btw
		setKeyValue(key,out);
	}
	return r;
}
Exemplo n.º 27
0
XMP_Uns16 TagTree::digest16u(LFA_FileRef file,const std::string key /* ="" */, bool BigEndian /*=false*/,bool hexDisplay /*=false*/ )
{
	XMP_Uns16 r;
	if (2 != LFA_Read ( file, &r, 2, false)) // require all == false => leave the throwing to this routine
		Log::error("could not read 2-byte value from file (end of file?)");
	if ( ((kBigEndianHost==1) &&  !BigEndian ) ||  ((kBigEndianHost==0) && BigEndian ))  // "XOR"
		Flip2(&r);
	if (!key.empty()) {
		char out[15]; //longest unsigned int is "65536", 5 chars resp.  0xFFFF = 6 chars
		if (!hexDisplay)
			snprintf(out,14,"%u",r);
		else
			snprintf(out,14,"0x%.4X",r);
		setKeyValue(key,out);
	}
	return r;
}
Exemplo n.º 28
0
idgs::rdd::pb::RddResultCode Transformer::transform(TransformerContext* ctx, const idgs::rdd::BaseRddPartition* input, idgs::rdd::PairRddPartition* output) {
  if (!input->empty()) {
    input->foreach([this, ctx, output] (const idgs::actor::PbMessagePtr& key, const idgs::actor::PbMessagePtr& value) {
      idgs::actor::PbMessagePtr outkey, outvalue;

      auto exprCtx = ctx->getExpressionContext();
      exprCtx->setKeyValue(&key, &value);
      exprCtx->setOutputKeyValue(&outkey, &outvalue);

      auto code = transform(ctx, output);
      if (code != idgs::rdd::pb::RRC_SUCCESS) {
        LOG(ERROR) << output->getPartitionName() << " transformer " << getName() << " error, caused by " << RddResultCode_Name(code);
      }
    });
  }

  return idgs::rdd::pb::RRC_SUCCESS;
}
Exemplo n.º 29
0
FakeSMCSensor *FakeSMCPlugin::addTachometer(UInt32 index, const char *name, FanType type, UInt8 zone, FanLocationType location, SInt8 *fanIndex)
{
    SYNCLOCK;
    
    SInt8 vacantFanIndex = takeVacantFanIndex();
    
    if (vacantFanIndex >= 0) {
        char key[5];
        snprintf(key, 5, KEY_FORMAT_FAN_SPEED, vacantFanIndex);
        
        if (FakeSMCSensor *sensor = addSensor(key, TYPE_FPE2, TYPE_FPXX_SIZE, kFakeSMCTachometerSensor, index)) {
            FanTypeDescStruct fds;
            
            bzero(&fds, sizeof(fds));
            
            fds.type = type;
            fds.ui8Zone = zone;
            fds.location = location;
            
            if (name)
                strlcpy(fds.strFunction, name, DIAG_FUNCTION_STR_LEN);
            else
                snprintf(fds.strFunction, DIAG_FUNCTION_STR_LEN, "MB Fan %X", index);
            
            snprintf(key, 5, KEY_FORMAT_FAN_ID, vacantFanIndex);
            
            if (!setKeyValue(key, TYPE_FDS, sizeof(fds), &fds))
                HWSensorsWarningLog("failed to add tachometer name for key %s", key);
            
            if (fanIndex) *fanIndex = vacantFanIndex;
            
            SYNCUNLOCK;
            
            return sensor;
        }
        else HWSensorsErrorLog("failed to add tachometer sensor for key %s", key);
    }
    else HWSensorsErrorLog("failed to take vacant Fan index");
	
    SYNCUNLOCK;
    
	return 0;
}
Exemplo n.º 30
0
FakeSMCSensor *FakeSMCPlugin::addTachometer(UInt32 index, const char* name, UInt8 *fanIndex)
{
    UInt8 length = 0;
	void * data = 0;
    
	if (kIOReturnSuccess == storageProvider->callPlatformFunction(kFakeSMCGetKeyValue, true, (void *)KEY_FAN_NUMBER, (void *)&length, (void *)&data, 0)) {
		length = 0;
		
		bcopy(data, &length, 1);
		
        for (int i = 0; i <= 0xf; i++) {
            char key[5];
            
            snprintf(key, 5, KEY_FORMAT_FAN_SPEED, i); 
            
            if (!isKeyHandled(key)) {
                if (FakeSMCSensor *sensor = addSensor(key, TYPE_FPE2, 2, kFakeSMCTachometerSensor, index)) {
                    if (name) {
                        snprintf(key, 5, KEY_FORMAT_FAN_ID, i); 
                        
                        if (!setKeyValue(key, TYPE_CH8, strlen(name), name))
                            HWSensorsWarningLog("failed to add tachometer name for key %s", key);
                    }
                    
                    if (i + 1 > length) {
                        length++;
                        
                        if (kIOReturnSuccess != storageProvider->callPlatformFunction(kFakeSMCSetKeyValue, true, (void *)KEY_FAN_NUMBER, (void *)(UInt8)1, (void *)&length, 0))
                            HWSensorsWarningLog("failed to update FNum value");
                    }
                    
                    if (fanIndex) *fanIndex = i;
                    
                    return sensor;
                }
                else HWSensorsWarningLog("failed to add tachometer sensor for key %s", key);
            }
        }
	}
	else HWSensorsWarningLog("failed to read FNum value");
	
	return 0;
}