void launch(){
		RuntimeErrorValidator * validator = NULL;

		if(isInfoEnabled())
			info("Quedando a la espera de peticiones para realizar operaciones FSS");

		MpsMessage * request = NULL;

		while(isFssRunningStatus()){
			validator = buildErrorSuccessValidator();
			request = receiveMpsMessage(getFileSystemSocket(), validator);

			if(request == NULL || hasError(validator)){
				error("Se produjo un error en la recepcion, finalizando la aplicacion");
				close(getFileSystemSocket());
				exit(1);
			}

			if(isDebugEnabled())
				debug("Reciviendo peticion MPS");

			if(isDebugEnabled())
				debug(concatAll(3 , "Header.DescriptorId: '" , strndup(request->descriptorId , 16) , "'"));

			if(isDebugEnabled())
				debug( concatAll(3 , "Payload.Arguments: '" , formatListToPreetyString(request->commands) , "'"));

			if(isDebugEnabled())
				debug(concatAll(3 , "Payload.OperationName: '" , request->operationName , "'"));

			executeOperation(getFileSystemSocket() , request , validator);
		}

	}
Esempio n. 2
0
int vdadisk_read (const char *db_name, LogicalSector *sector, tSectorId idToSearch) {
	DB *base;
	DBT key, data;
	int ret;

	if ((ret = db_create(&base, NULL, 0)) != 0)
		return ret;
	/* Associate DB with a file (create a btree)*/
	//if ((ret = base->open(base, NULL, concat( getGlobalHeap(), 2, db_name, ".db"), NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
	if ((ret = base->open(base, NULL, db_name, NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
		if(isDebugEnabled()) error( "[BDB] Fallo al abrir la base" );
		//base->err(base, ret, "DB open failed\n");
		base->close(base,0);
		return ret;
	}
	loadDBT (&key, &data, sector);
	ret = base->get(base, NULL, &key, &data, 0);
	if((ret = base->get(base, NULL, &key, &data, 0)) != 0) {
		if(isDebugEnabled()) 
			debug(concat( getGlobalHeap() , 2 , "[BDB] No se encuentra el sector " ,itoa_buf(sector->sectorId)));
		//base->err(base, ret, "Not found.");
	}
	base->close(base,0);
	return ret;
}
Esempio n. 3
0
int vdadisk_write (const char *db_name, LogicalSector *sector) {
	DB *base;
	DBT key, data;
	int ret;

	if ((ret = db_create(&base, NULL, 0)) != 0)
		return ret;
	/* Associate DB with a file (create a btree)*/
	//if ((ret = base->open(base, NULL,concat( getGlobalHeap(), 2, db_name, ".db"), NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
	if ((ret = base->open(base, NULL, db_name, NULL, DB_BTREE, DB_CREATE, 0)) != 0) {
		if(isDebugEnabled()) error( "[BDB] Fallo al abrir la base" );
		//base->err(base, ret, "DB open failed\n");
		base->close(base,0);
		return ret;
	}
	loadDBT (&key, &data, sector);
	ret = base->put(base, NULL, &key, &data, DB_NOOVERWRITE);
	if (ret == DB_KEYEXIST) {
		//base->err(base, ret, "La clave %d ya existe!\n");*
		//_itoa_s(sector->sectorId, aux, 10, 10);
		if(isDebugEnabled()) debug(concat( getGlobalHeap() , 2 , "[BDB] Ya existe el sector ", itoa_buf(sector->sectorId)));
		if ((ret = base->del(base, NULL, &key, 0)) == 0 ){  /* Si existe lo borro y lo vuelvo a escribir */
			if(isDebugEnabled()) debug(concat( getGlobalHeap() , 2 , "[BDB] Reescribiendo el sector ", itoa_buf(sector->sectorId)));
			ret = base->put(base, NULL, &key, &data, DB_NOOVERWRITE);
		}
	}
	base->close(base,0);
	return ret;
}
bool TinyAmixerControlValue::writeControl(struct mixer_ctl *mixerControl,
                                          size_t elementCount,
                                          std::string &error)
{
    uint32_t elementNumber;

    // Write element
    // Go through all elements
    for (elementNumber = 0; elementNumber < elementCount; elementNumber++) {

        int32_t value;

        // Read data from blackboard (beware this code is OK on Little Endian machines only)
        value = fromBlackboard();

        if (isDebugEnabled()) {

            info() << "Writing alsa element " << getControlName()
                   << ", index " << elementNumber << " with value " << value;
        }

        // Write element
        int err;
        if ((err = mixer_ctl_set_value(mixerControl, elementNumber, value)) < 0) {

            error = "Failed to write value in mixer control: " + getControlName() + ": " +
                    strerror(-err);
            return false;
        }
    }
    return true;
}
	MpsStream * serializeMpsMessage(MpsMessage * msg , RuntimeErrorValidator * v , HeapHandler hh){
		int offset;
		char * justRetVals ;
		int payloadLength ;
		char * data ;
		MpsHeader header;

		if(isDebugEnabled())
			logDebug("windows-commons" , "Serializando Response MPS" , hh);

		justRetVals = serializeValueList(msg->commands , hh);
		payloadLength = calculatePayloadLength(justRetVals , hh);
		data = allocateMemory(hh , MPS_FIELD_LENTH_HEADER + payloadLength );
		ZeroMemory(data , MPS_FIELD_LENTH_HEADER + payloadLength);
		
		header.payloadSize = payloadLength;
		header.payloadDescriptor = msg->statusCode;

		memcpy(header.descriptorId , msg->descriptorId , MPS_FIELD_LENGTH_DESCRIPTOR_ID);
		memcpy(data , &header , MPS_FIELD_LENTH_HEADER);

		offset = MPS_FIELD_LENTH_HEADER;
		offset = serializePayloadOperationName(msg->operationName , data , offset);
		offset = serializePayloadSeparator(data , offset);

		if(msg->commands != NULL){
			offset = serializePayloadValuesList(justRetVals , msg->commands->size , data , offset , hh);
		}else{
			offset = serializePayloadValuesList(justRetVals , 0 , data , offset , hh);
		}

		return buildMpsStreamWithOffset(data, offset , hh);
	}
	void executeKssCommandList(char * arg , ListenSocket ls){
		RuntimeErrorValidator * validator = buildErrorSuccessValidator();
		//List params = getFirstParameter("Dispositivo o directorio a Listar");
		List params = buildStringsListWithValues(1 , arg);

		MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_LS , params);
		MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator);

		if(isDebugEnabled())
			debug(concatAll(2, "Codigo de resultado: " , resp->statusCode));

		Iterator * ite = buildIterator(resp->returnValues);

		if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){

			char * serializedFiles = next(ite);
			List files = deserializeList(serializedFiles);
			ite = buildIterator(files);

			printf("Contenido del directorio:\n");
			printf("--------------------------------------------------------------------------------------\n");

			while(hasMoreElements(ite)){
				char * elem = next(ite);
				printf("%s\n " , trim(elem));
			}
		}else{
			printf("%s" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error"));
		}
	}
	void processConfiguration(char * k , char * v){

		if( isDebugEnabled()) debug( concat(getGlobalHeap() , 4, " Seteando " , k , "=" , v ));

		if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_AVAILABLE_CACHE))
			setAvailableCache(getBooleanType(v));
		else if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_KSS_ADDRESS))
			setKssAddress(v);
		else if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_KSS_PORT))
			setKssPort(v);
		else if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_NAME))
			setVdaName(v);
		else if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_RPM)){
			setRpm(v);
			setiRpm(atoi(v));
		}else if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_SECTORS_COUNT))
			setVdaSectorsCount(atoi(v));
		else if(equalsStrings(k ,VDA_CONFIGURATION_KEY_VDA_TRACKS_COUNT))
			setVdaTracksCount(atoi(v));
		else if(equalsStrings(k ,VDA_CONFIGURATION_KEY_VDA_TRACKS_DELAY))
			setTrackDelay((float) atof(v));
		else if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_OFFLINE_MODE))
			setVdaOfflineMode(getBooleanType(v));
		else if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_LOGDIR))
			setLoggingDirectory(v);
		else if(equalsStrings(k , VDA_CONFIGURATION_KEY_VDA_LOGLEVEL))
			configureLoggingLevel(v);
	}
Esempio n. 8
0
void Logger::debug(std::string message) {
	if (!isDebugEnabled()) {
		return;
	}

	appendAll("DEBUG", message);
}
bool TinyAmixerControlValue::readControl(struct mixer_ctl *mixerControl,
                                         size_t elementCount,
                                         std::string &error)
{
    uint32_t elementNumber;

    // Read element
    // Go through all elements
    for (elementNumber = 0; elementNumber < elementCount; elementNumber++) {

        int32_t value;
        if ((value = mixer_ctl_get_value(mixerControl, elementNumber)) < 0) {

            error = "Failed to read value in mixer control: " + getControlName();
            return false;
        }

        if (isDebugEnabled()) {

            info() << "Reading alsa element " << getControlName()
                   << ", index " << elementNumber << " with value " << value;
        }

        toBlackboard(value);
    }
    return true;
}
	char * coreOperationListFiles(char * pattern , RuntimeErrorValidator * validator){
		if(isDebugEnabled())
			debug(concatAll(2 , "Listando Ruta: " , pattern));

		List elements = getPathContentElements(pattern  , validator);
		return serializeList(elements , ",");
	}
	Bool removeDirectory(char * dirname){
		//return !rmdir(dirname);

		char * cmd = concatAll(2 , "rm -r " , dirname);
		if(isDebugEnabled())
			logDebug("linux-commons" , concatAll(3 , "Ejecutando comando nativo del sistema: '" , cmd , "'"));
		return !system(cmd);
	}
Esempio n. 12
0
void obtenerSectores(tSectorId * slist, int argsCount) {
	int i;
	for	(i=0; i < argsCount; i++)
		if (sectorInvalido(slist[i])) {
			if (isDebugEnabled()) errorInvalidSector(slist[i]);
		}
		else getSectorFromCacheOrDisk2(slist[i]);
	myFree(slist);
}
Esempio n. 13
0
LogicalSector * getOneSector (int sid) {
	LogicalSector *ls;
	if (sectorInvalido(sid)) {
		if (isDebugEnabled()) errorInvalidSector(sid);
		ls = sector_BuildLogical(sid, NULL); /* lo lleno de \0 */
	}
	else ls = getSectorFromCacheOrDisk1(sid);
	return ls;
}
Esempio n. 14
0
/*!
    Returns \c true if a message of type \a msgtype for the category should be
    shown. Returns \c false otherwise.
*/
bool QLoggingCategory::isEnabled(QtMsgType msgtype) const
{
    switch (msgtype) {
    case QtDebugMsg: return isDebugEnabled();
    case QtWarningMsg: return isWarningEnabled();
    case QtCriticalMsg: return isCriticalEnabled();
    case QtFatalMsg: return true;
    }
    return false;
}
int TinyAmixerControlArray::doSetArrayMixer(struct mixer_ctl *mixerControl,
                                            const void *array,
                                            size_t elementCount)
{
    if (isDebugEnabled()) {
        logControlValues(false, array, elementCount);
    }

    return mixer_ctl_set_array(mixerControl, array, elementCount);
}
int TinyAmixerControlArray::doGetArrayMixer(struct mixer_ctl *mixerControl,
                                            void *array,
                                            size_t elementCount)
{
    int ret = mixer_ctl_get_array(mixerControl, array, elementCount);

    if (isDebugEnabled() && ret == 0) {
        logControlValues(true, array, elementCount);
    }

    return ret;
}
Esempio n. 17
0
int putOneSector(int sid, char * content) {
	int ret;
	LogicalSector *ls;
	if (content == NULL) /* sector que no quiero escribir y le puse NULL a proposito */
		return 0;
	if (sectorInvalido(sid)) {
		if (isDebugEnabled()) errorInvalidSector(sid);
		return 0;
		}
	ls = sector_BuildLogical (sid, content);
	ret = putSectorOnDisk(ls);
	myFree(ls);
	return ret;
}
Esempio n. 18
0
void writeRandom(tSectorId sid) {
	LogicalSector *ls;
	char *content;
	if (sectorInvalido(sid)) {
			if (isDebugEnabled()) errorInvalidSector(sid);
			return;
		}
	content = randomBytes(SECTOR_SIZE);
	ls = sector_BuildLogical(sid, content);
	putSectorOnDisk(ls);
	//vdadisk_write(getVdaName(), ls);
	printf ("Sector escrito: %d\n", sid);
	printf ("Contenido: %s\n", content);
	myFree(ls);
}
Esempio n. 19
0
void writeRandom(tSectorId sid) {
	LogicalSector *ls;
	char *content;
	if (sectorInvalido(sid)) {
			if (isDebugEnabled()) errorInvalidSector(sid);
			return;
		}
	content = randomBytes(SECTOR_SIZE , getGlobalHeap());
	ls = sector_BuildLogical(sid, content);
	putSectorOnDisk(ls);
	content[SECTOR_SIZE-1] = '\0';
	printf ("Sector escrito: %d\n", sid);
	printf ("Contenido: %s\n", content);
	myFree(ls);
}
	void executeKssCommandTddDump(ListenSocket ls){
		RuntimeErrorValidator * validator = buildErrorSuccessValidator();

		MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_TDD_DUMP , NULL);
		MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator);

		Iterator * ite = buildIterator(resp->returnValues);

		if(isDebugEnabled())
			debug(concatAll(2, "Codigo de resultado: " , resp->statusCode));

		if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){
			info("Resultado satisfactorio ");
		}else{
			printf("%s\n" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error"));
		}
	}
	void executeKssCommandFormat(char * arg , ListenSocket ls){

		RuntimeErrorValidator * validator = buildErrorSuccessValidator();
		//List params = getFirstParameter("Dispositivo a Formatear");
		List params = buildStringsListWithValues(1 , arg);

		MpsRequest * req = buildMpsRequest( generateRandomKey(16) , SHELL_FORMAT , params);
		MpsResponse * resp = sendAndReceiveMpsMessages(ls , req ,validator);

		if(isDebugEnabled())
			debug(concatAll(2, "Codigo de resultado: " , resp->statusCode));

		Iterator * ite = buildIterator(resp->returnValues);

		if( equalsStrings(resp->statusCode , MPS_RESPONSE_STATUS_CODE_SUCCESS)){
			printf("Dispositivo formateado\n");
		}else{
			printf("%s" , ( hasMoreElements(ite) ? (char *) next(ite) : "Ha ocurrido un error"));
		}
	}
	unsigned __stdcall doKssService( void* pArguments ){

		int error;
		char * message;

		if(isDebugEnabled()) debug( "Atendiendo peticiones Kss");

		do{
			message = receiveMessage( getKssConnection() , getGlobalHeap() , &error);

			/*
			 * recibir mensaje MPS y procesarlo
			 */
		}while( isContinueKssThread() );

		/*
		 * liberar recursos ocupados antes de finalizar
		 * el thread
		 */
		return EXIT_SUCCESS;
	}
	void processConfiguration(char * key , char * value){

		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_FTPS_LOGLEVEL) ){
			setLoggingLevel(value);
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_FTPS_DATADIR) ){
			setDataDirectory(value);
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_FTPS_CONTROLPORT) ){
			setServerControlPort(value);
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_FTPS_DATAPORT) ){
			setServerDataPort(value);
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_FTPS_ADDRESS) ){
			setServerAddress(value);
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_FTPS_LOGDIR) ){
			setLoggingDirectory(value);
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_MAX_RETRIES) ){
			setMaxRetriesFindingDataPort( atoi(value) );
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_FTPS_STARTMODE) ){
			if(!strcmp("true" , value)){
				setOfflineStartMode(TRUE);
			}else{
				setOfflineStartMode(FALSE);
			}
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_KSS_ADDRESS) ){
			setKssAddress(value);
		}
		if( equalsStrings(key , FTPS_CONFIGURATION_KEY_KSS_PORT) ){
			setKssPort(value);
		}

		if( isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4, " Seteando " , key , "=" , value ));
	}
	void insertLine(const char * line , File * file){
		int inserted = fwrite(line , sizeof(char) , strlen(line) , file);
		if(isDebugEnabled()) logDebug("linux-commons" , concatAll(3 , "Se han insertado " , itoa(inserted) , " bytes en el archivo"));
		fputc('\n' , file);
	}
bool TinyAmixerControl::accessHW(bool receive, std::string &error)
{
    CAutoLog autoLog(getConfigurableElement(), "ALSA", isDebugEnabled());

    // Mixer handle
    struct mixer *mixer;
    // Mixer control handle
    struct mixer_ctl *mixerControl;
    uint32_t elementCount;
    std::string controlName = getControlName();

    // Debug conditionnaly enabled in XML
    logControlInfo(receive);

    // Check parameter type is ok (deferred error, no exceptions available :-()
    if (!isTypeSupported()) {

        error = "Parameter type not supported.";
        return false;
    }

    // Check card number
    int32_t cardIndex = getCardNumber();
    if (cardIndex < 0) {

        error = "Card " + getCardName() + " not found. Error: " + strerror(-cardIndex);
        return false;
    }

    // Open alsa mixer
    // getMixerHandle is non-const; we need to forcefully remove the constness
    // then, we need to cast the generic subsystem into a TinyAlsaSubsystem.
    mixer = static_cast<TinyAlsaSubsystem *>(
        const_cast<CSubsystem *>(getSubsystem()))->getMixerHandle(cardIndex);

    if (!mixer) {

        error = "Failed to open mixer for card: " + getCardName();
        return false;
    }

    // Get control handle
    if (isdigit(controlName[0])) {

        mixerControl = mixer_get_ctl(mixer, asInteger(controlName));
    } else {

        mixerControl = mixer_get_ctl_by_name(mixer, controlName.c_str());
    }

    // Check control has been found
    if (!mixerControl) {
        error = "Failed to open mixer control: " + controlName;

        return false;
    }

    // Get element count
    elementCount = getNumValues(mixerControl);

    uint32_t scalarSize = getScalarSize();

    // Check available size
    if (elementCount * scalarSize != getSize()) {

        error = "ALSA: Control element count (" + asString(elementCount) +
                ") and configurable scalar element count (" +
                asString(getSize() / scalarSize) + ") mismatch";

        return false;
    }

    // Read/Write element
    bool success;
    if (receive) {

        success = readControl(mixerControl, elementCount, error);

    } else {

        success = writeControl(mixerControl, elementCount, error);

    }

    return success;
}
	void setUpConfiguration(){

		char * dataDir = getConfigurationStrValue( getGlobalHeap() , 
			CONFIGURATION_FILE , FTPS_SECTION , FTPS_CONFIGURATION_KEY_FTPS_DATADIR);
				
		char * ctrlPort = getConfigurationStrValue( getGlobalHeap() ,
			CONFIGURATION_FILE , FTPS_SECTION , FTPS_CONFIGURATION_KEY_FTPS_CONTROLPORT);

		char * dataPort = getConfigurationStrValue( getGlobalHeap() ,
			CONFIGURATION_FILE , FTPS_SECTION , FTPS_CONFIGURATION_KEY_FTPS_DATAPORT);
	
		char * serverAddr = getConfigurationStrValue( getGlobalHeap() ,
			CONFIGURATION_FILE , FTPS_SECTION , FTPS_CONFIGURATION_KEY_FTPS_ADDRESS);
		
		char * logDir = getConfigurationStrValue( getGlobalHeap() ,
			CONFIGURATION_FILE , FTPS_SECTION , FTPS_CONFIGURATION_KEY_FTPS_LOGDIR);
		
		char * logLevel = getConfigurationStrValue( getGlobalHeap() ,
			CONFIGURATION_FILE , FTPS_SECTION , FTPS_CONFIGURATION_KEY_FTPS_LOGLEVEL);

		char * startMode = getConfigurationStrValue( getGlobalHeap() ,
			CONFIGURATION_FILE , FTPS_SECTION , FTPS_CONFIGURATION_KEY_FTPS_STARTMODE);

		char * kssAddress = getConfigurationStrValue( getGlobalHeap() , 
			CONFIGURATION_FILE , KSS_SECTION , FTPS_CONFIGURATION_KEY_KSS_ADDRESS);

		char * kssPort = getConfigurationStrValue( getGlobalHeap() , 
			CONFIGURATION_FILE , KSS_SECTION , FTPS_CONFIGURATION_KEY_KSS_PORT);

		char * maxRetries = getConfigurationStrValue( getGlobalHeap() ,
			CONFIGURATION_FILE , FTPS_SECTION , FTPS_CONFIGURATION_KEY_MAX_RETRIES);

		info("Cargando la configuracion");
		
		setDataDirectory(dataDir);
		setServerControlPort(ctrlPort);
		setServerDataPort(dataPort);
		setServerAddress(serverAddr);
		setLoggingDirectory(logDir);
		setLoggingLevel(logLevel);
		setMaxRetriesFindingDataPort(atoi(maxRetries));
		setKssAddress(kssAddress);
		setKssPort(kssPort);

		if(!strcmp("true" , startMode)){
			setOfflineStartMode(TRUE);
		}else{
			setOfflineStartMode(FALSE);
		}

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_FTPS_DATADIR , "=" , dataDir));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_FTPS_CONTROLPORT , "=" , ctrlPort));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_FTPS_DATAPORT , "=" , dataPort));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_FTPS_ADDRESS , "=" , serverAddr));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_FTPS_LOGDIR , "=" , logDir));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_FTPS_LOGLEVEL , "=" , logLevel));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_FTPS_STARTMODE , "=" , startMode));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_MAX_RETRIES , "=" , maxRetries));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_KSS_ADDRESS , "=" , kssAddress));

		if(isDebugEnabled()) 
			debug(concat(getGlobalHeap() , 4 , "Seteando " , 
				FTPS_CONFIGURATION_KEY_KSS_ADDRESS , "=" , kssPort));			
		
		
	}
bool LegacyAmixerControl::accessHW(bool receive, string &error)
{
    CAutoLog autoLog(getConfigurableElement(), "ALSA", isDebugEnabled());

#ifdef SIMULATION
    if (receive) {

        memset(getBlackboardLocation(), 0, getSize());
    }
    log_info("%s ALSA Element Instance: %s\t\t(Control Element: %s)",
             receive ? "Reading" : "Writing",
             getConfigurableElement()->getPath().c_str(),
             getControlName().c_str());

    return true;
#endif

    int ret;
    // Mixer handle
    snd_ctl_t *sndCtrl;
    uint32_t value;
    uint32_t index;
    uint32_t elementCount;
    snd_ctl_elem_id_t *id;
    snd_ctl_elem_info_t *info;
    snd_ctl_elem_value_t *control;

    logControlInfo(receive);

    // Check parameter type is ok (deferred error, no exceptions available :-()
    if (!isTypeSupported()) {

        error = "Parameter type not supported.";

        return false;
    }

    int cardNumber = getCardNumber();

    if (cardNumber < 0) {

        error = "Card " + getCardName() + " not found. Error: " + strerror(cardNumber);

        return false;
    }
#ifdef ANDROID
    if ((ret = snd_ctl_hw_open(&sndCtrl, NULL, cardNumber, 0)) < 0) {

        error = snd_strerror(ret);

        return false;
    }
#else
    // Create device name
    ostringstream deviceName;

    deviceName << "hw:" << cardNumber;

    // Open sound control
    if ((ret = snd_ctl_open(&sndCtrl, deviceName.str().c_str(), 0)) < 0) {

        error = snd_strerror(ret);

        return false;
    }
#endif

    // Allocate in stack
    snd_ctl_elem_id_alloca(&id);
    snd_ctl_elem_info_alloca(&info);
    snd_ctl_elem_value_alloca(&control);

    // Set interface
    snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);

    string controlName = getControlName();

    // Set name or id
    if (isdigit(controlName[0])) {

        snd_ctl_elem_id_set_numid(id, asInteger(controlName));
    } else {

        snd_ctl_elem_id_set_name(id, controlName.c_str());
    }
    // Init info id
    snd_ctl_elem_info_set_id(info, id);

    // Get info
    if ((ret = snd_ctl_elem_info(sndCtrl, info)) < 0) {

        error = "ALSA: Unable to get element info " + controlName +
                ": " + snd_strerror(ret);

        // Close sound control
        snd_ctl_close(sndCtrl);

        return false;
    }
    // Get type
    snd_ctl_elem_type_t eType = snd_ctl_elem_info_get_type(info);

    // Get element count
    elementCount = snd_ctl_elem_info_get_count(info);

    uint32_t scalarSize = getScalarSize();

    // If size defined in the PFW different from alsa mixer control size, return an error
    if (elementCount * scalarSize != getSize()) {

        error = "ALSA: Control element count (" + asString(elementCount) +
                ") and configurable scalar element count (" +
                asString(getSize() / scalarSize) + ") mismatch";

        // Close sound control
        snd_ctl_close(sndCtrl);

        return false;
    }
    // Set value id
    snd_ctl_elem_value_set_id(control, id);

    if (receive) {

        // Read element
        if ((ret = snd_ctl_elem_read(sndCtrl, control)) < 0) {

            error = "ALSA: Unable to read element " + controlName +
                    ": " + snd_strerror(ret);

            // Close sound control
            snd_ctl_close(sndCtrl);

            return false;
        }
        // Go through all indexes
        for (index = 0; index < elementCount; index++) {

            switch (eType) {
            case SND_CTL_ELEM_TYPE_BOOLEAN:
                value = snd_ctl_elem_value_get_boolean(control, index);
                break;
            case SND_CTL_ELEM_TYPE_INTEGER:
                value = snd_ctl_elem_value_get_integer(control, index);
                break;
            case SND_CTL_ELEM_TYPE_INTEGER64:
                value = snd_ctl_elem_value_get_integer64(control, index);
                break;
            case SND_CTL_ELEM_TYPE_ENUMERATED:
                value = snd_ctl_elem_value_get_enumerated(control, index);
                break;
            case SND_CTL_ELEM_TYPE_BYTES:
                value = snd_ctl_elem_value_get_byte(control, index);
                break;
            default:
                error = "ALSA: Unknown control element type while reading alsa element " +
                        controlName;
                return false;
            }

            if (isDebugEnabled()) {

                log_info("Reading alsa element %s, index %u with value %u",
                         controlName.c_str(), index, value);
            }

            // Write data to blackboard (beware this code is OK on Little Endian machines only)
            toBlackboard(value);
        }

    } else {

        // Go through all indexes
        for (index = 0; index < elementCount; index++) {

            // Read data from blackboard (beware this code is OK on Little Endian machines only)
            value = fromBlackboard();

            if (isDebugEnabled()) {

                log_info("Writing alsa element %s, index %u with value %u",
                         controlName.c_str(), index, value);
            }

            switch (eType) {
            case SND_CTL_ELEM_TYPE_BOOLEAN:
                snd_ctl_elem_value_set_boolean(control, index, value);
                break;
            case SND_CTL_ELEM_TYPE_INTEGER:
                snd_ctl_elem_value_set_integer(control, index, value);
                break;
            case SND_CTL_ELEM_TYPE_INTEGER64:
                snd_ctl_elem_value_set_integer64(control, index, value);
                break;
            case SND_CTL_ELEM_TYPE_ENUMERATED:
                snd_ctl_elem_value_set_enumerated(control, index, value);
                break;
            case SND_CTL_ELEM_TYPE_BYTES:
                snd_ctl_elem_value_set_byte(control, index, value);
                break;
            default:
                error = "ALSA: Unknown control element type while writing alsa element " +
                        controlName;
                return false;
            }
        }

        // Write element
        if ((ret = snd_ctl_elem_write(sndCtrl, control)) < 0) {

            error = "ALSA: Unable to write element " + controlName +
                    ": " + snd_strerror(ret);


            // Close sound control
            snd_ctl_close(sndCtrl);

            return false;
        }
    }
    // Close sound control
    snd_ctl_close(sndCtrl);

    return true;
}
Esempio n. 28
0
void MY_Scene_Base::toggleDebug(){
	isDebugEnabled() ? disableDebug() : enableDebug();
}