示例#1
0
/**
 * Sets project options.
 * @param	opt	A structure containing the new parameters to set
 */
void Project::setOptions(const Options& opt)
{
	// Write the options to the configuration nfile
	writeOptions(m_pConf, opt);
				
	// Update project parameters
	initOptions();
}
示例#2
0
CotpIndication
CotpConnection_sendConnectionResponseMessage(CotpConnection* self)
{
    allocateWriteBuffer(self);

    int optionsLength = getOptionsLength(self);
    int messageLength = 11 + optionsLength;

    writeRfc1006Header(self, messageLength);

    writeStaticConnectResponseHeader(self, optionsLength);

    writeOptions(self);

    if (sendBuffer(self))
        return COTP_OK;
    else
        return COTP_ERROR;
}
示例#3
0
/* client side */
CotpIndication
CotpConnection_sendConnectionRequestMessage(CotpConnection* self, IsoConnectionParameters isoParameters)
{
    allocateWriteBuffer(self);

    const int CON_REQUEST_SIZE = 22;

    if(self->writeBuffer->maxSize < CON_REQUEST_SIZE)
        return COTP_ERROR;

    uint8_t* buffer = self->writeBuffer->buffer;

    writeRfc1006Header(self, CON_REQUEST_SIZE);

    /* LI */
    buffer[4] = 17;

    /* TPDU CODE */
    buffer[5] = 0xe0;

    /* DST REF */
    buffer[6] = 0x00;
    buffer[7] = 0x00;

    /* SRC REF */
    buffer[8] = 0x00;
    buffer[9] = 0x02; /* or 0x01 ? */

    /* Class */
    buffer[10] = 0x00;

    self->writeBuffer->size = 11;

    self->options.tsap_id_dst = isoParameters->remoteTSelector;
    self->options.tsap_id_src = 0;

    writeOptions(self);

    if (sendBuffer(self))
        return COTP_OK;
    else
        return COTP_ERROR;
}
示例#4
0
bool Project::create(const QString& sName, const QString& sPath,
	const Options& opt)
{
	// Prepare the project's files
	KConfig conf(sPath + "/cscope.proj");

	// Write the configuration file version
	conf.setGroup("");
	conf.writeEntry("Version", PROJECT_CONFIG_VER);
	
	// Write project properties in the configuration file
	conf.setGroup("Project");
	conf.writeEntry("Name", sName);
	writeOptions(&conf, opt);
	
	// Flush the config file data, so the project is created even if KScope
	// crashes...
	conf.sync();

	return true;
}
示例#5
0
bool keyboardBindingFilter( const SDL_Event& event )
{
  if (event.type != SDL_KEYDOWN ) return false;

  int key = event.key.keysym.sym;
  bool bindingKeyPressed = ( key == SDLK_EQUALS || key == SDLK_QUESTION );

  if ( keyBindingMode == NOT_BINDING )
  {
    if ( bindingKeyPressed )
    {
      //Enter key-binding mode.
      keyBindingMode = NOT_BINDING;
      keyBindingMode++;
      return true;
    } else
    {
      //We're not presently binding, and they're not trying to bind.
      //Carry on!
      return false;
    }
  }

  //We're in key-binding mode...
  if ( bindingKeyPressed )
  {
    //cancel;
    keyBindingMode = NOT_BINDING;
    S9xSetInfoString( "Cancelled binding!" );
  }

  //Check that this is a valid key.
  //XXX: right now we don't support
  //orange, shift, or sym as keys b/c they are meta keys.
  int valid = 0
    || ( key >= SDLK_a && key <= SDLK_z ) //Alpha
    || key == SDLK_BACKSPACE
    || key == SDLK_RETURN
    || key == SDLK_COMMA
    || key == SDLK_PERIOD
    || key == SDLK_SPACE
    || key == SDLK_AT;

  if ( valid )
  {
    //We're in binding mode, and they pressed a bindable key!
    bindingJoypad[keyBindingMode] = key;
    keyBindingMode++;
  }

  if ( keyBindingMode == BINDING_DONE )
  {
    //make this the current joy
    memcpy( Config.joypad1Mapping, bindingJoypad, sizeof(bindingJoypad) );
    
    //Save their settings...
    writeOptions( BINDING_CFG, controllerOptions,
        sizeof(controllerOptions)/sizeof(controllerOptions[0]), true );

    //Tell user we're done...
    updateBindingMessage();

    //we're done here!
    keyBindingMode = NOT_BINDING;
  }

  return true;
}
示例#6
0
void CDMRNetwork::clock(unsigned int ms)
{
	if (m_status == WAITING_CONNECT) {
		m_retryTimer.clock(ms);
		if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
			bool ret = m_socket.open();
			if (ret) {
				ret = writeLogin();
				if (!ret)
					return;

				m_status = WAITING_LOGIN;
				m_timeoutTimer.start();
			}

			m_retryTimer.start();
		}

		return;
	}

	in_addr address;
	unsigned int port;
	int length = m_socket.read(m_buffer, BUFFER_LENGTH, address, port);
	if (length < 0) {
		LogError("DMR, Socket has failed, retrying connection to the master");
		close();
		open();
		return;
	}

	// if (m_debug && length > 0)
	//	CUtils::dump(1U, "Network Received", m_buffer, length);

	if (length > 0 && m_address.s_addr == address.s_addr && m_port == port) {
		if (::memcmp(m_buffer, "DMRD", 4U) == 0) {
			if (m_enabled) {
				if (m_debug)
					CUtils::dump(1U, "Network Received", m_buffer, length);

				unsigned char len = length;
				m_rxData.addData(&len, 1U);
				m_rxData.addData(m_buffer, len);
			}
		} else if (::memcmp(m_buffer, "MSTNAK",  6U) == 0) {
			if (m_status == RUNNING) {
				LogWarning("DMR, The master is restarting, logging back in");
				m_status = WAITING_LOGIN;
				m_timeoutTimer.start();
				m_retryTimer.start();
			} else {
				/* Once the modem death spiral has been prevented in Modem.cpp
				   the Network sometimes times out and reaches here.
				   We want it to reconnect so... */
				LogError("DMR, Login to the master has failed, retrying ...");
				close();
				open();
				return;
			}
		} else if (::memcmp(m_buffer, "RPTACK",  6U) == 0) {
			switch (m_status) {
				case WAITING_LOGIN:
					::memcpy(m_salt, m_buffer + 6U, sizeof(uint32_t));  
					writeAuthorisation();
					m_status = WAITING_AUTHORISATION;
					m_timeoutTimer.start();
					m_retryTimer.start();
					break;
				case WAITING_AUTHORISATION:
					if (m_options.empty()) {
						writeConfig();
						m_status = WAITING_CONFIG;
					} else {
						writeOptions();
						m_status = WAITING_OPTIONS;
					}
					m_timeoutTimer.start();
					m_retryTimer.start();
					break;
				case WAITING_OPTIONS:
					writeConfig();
					m_status = WAITING_CONFIG;
					m_timeoutTimer.start();
					m_retryTimer.start();
					break;
				case WAITING_CONFIG:
					LogMessage("DMR, Logged into the master successfully");
					m_status = RUNNING;
					m_timeoutTimer.start();
					m_retryTimer.start();
					break;
				default:
					break;
			}
		} else if (::memcmp(m_buffer, "MSTCL",   5U) == 0) {
			LogError("DMR, Master is closing down");
			close();
			open();
		} else if (::memcmp(m_buffer, "MSTPONG", 7U) == 0) {
			m_timeoutTimer.start();
		} else if (::memcmp(m_buffer, "RPTSBKN", 7U) == 0) {
			m_beacon = true;
		} else {
			CUtils::dump("Unknown packet from the master", m_buffer, length);
		}
	}

	m_retryTimer.clock(ms);
	if (m_retryTimer.isRunning() && m_retryTimer.hasExpired()) {
		switch (m_status) {
			case WAITING_LOGIN:
				writeLogin();
				break;
			case WAITING_AUTHORISATION:
				writeAuthorisation();
				break;
			case WAITING_OPTIONS:
				writeOptions();
				break;
			case WAITING_CONFIG:
				writeConfig();
				break;
			case RUNNING:
				writePing();
				break;
			default:
				break;
		}

		m_retryTimer.start();
	}

	m_timeoutTimer.clock(ms);
	if (m_timeoutTimer.isRunning() && m_timeoutTimer.hasExpired()) {
		LogError("DMR, Connection to the master has timed out, retrying connection");
		close();
		open();
	}
}
示例#7
0
int readOptions(char *path)
{
    FILE *opt;
    char buf[400];    /* Flawfinder: ignore */
    char option[200];    /* Flawfinder: ignore */
    char value[200];    /* Flawfinder: ignore */
    int temp1=0;
    int temp2=0;
    int i, k, buf_len;    /* Flawfinder: ignore */

    opt = fopen(settings, "r");    /* Flawfinder: ignore */

    if (!opt)
    {
        if ( (quiet == 0) && (strcmp(path, "") != 0) )
        {
            fprintf(stderr, _("Could not locate settings file\n"));
            fprintf(stdout, _("Creating folder: %s\n"), path);
#ifdef _WIN32
            mkdir(path);
#else
            mkdir(path, (S_IRWXU | S_IRWXG | S_IRWXO));
#endif

            fprintf(stdout, _("Creating file: %s\n"), personal);
            createPersonalText();
            fprintf(stdout, _("Creating file: %s\n"), internat);
            createInternationalDaysText();
            fprintf(stdout, _("Saving options: %s\n"), settings);
            writeOptions();
        }
        return 1;
    }

    while (!feof(opt))
    {
        fgets(buf, 400, opt);
        buf[399] = '\0';
        if (!feof(opt) && (buf[0]!='#' && buf[0]!='\n'))
        {
            sscanf(buf, "%200s : %200s", option, value);

            /* value may have space, keep string between "" */
            buf_len=strlen(buf);
            for(i=0; i < buf_len && buf[i]!='"'; i++);
            i++;
            for(k=0;i<buf_len&&buf[i]!='"';value[k++]=buf[i++]);

            value[k]='\0';   /* terminate the value string */

            if (strcmp(option, "quiet") == 0)
            {
                if (strcmp(value, "TRUE") == 0)
                {
                    quiet=1;
                }
                else if (strcmp(value, "FALSE") == 0)
                {
                    quiet=0;
                }
                else
                {
                    if (quiet == 0)
                    {
                        fprintf(stderr, _("Invalid value at quiet setting in options file: %s\n"), value);
                    }
                }
            }
            else if (strcmp(option, "show_X_next_days") == 0)
            {
                X = checkNumber(value, strlen(value));
                if (X>365)
                {
                    while(X>365) X-=365;
                    if (quiet == 0)
                    {
                        fprintf(stderr, _("Very big number at show_X_next_days setting in options file: %s\nChanging to %d\n"), value, X);
                    }

                }
                if (X<=0)
                {
                    if (quiet == 0)
                    {
                        fprintf(stderr, _("Invalid value at show_X_next_days setting in options file: %s\n"), value);
                    }
                    X = 5;
                }
            }
            else if (strcmp(option, "name_database_file") == 0)
            {
                strncpy(database, value, BUFFER);
            }
            else if (strcmp(option, "personal_database_file") == 0)
            {
                strncpy(personal, value, BUFFER);
            }
            else if (strcmp(option, "international_days_database_file") == 0)
            {
                strncpy(internat, value, BUFFER);
            }

#ifndef NO_GUI
            else if (strcmp(option, "autoclose_after_X_seconds") == 0)
            {
                auto_close = checkNumber(value, strlen(value));
                if (auto_close == 0)
                {
                    auto_close_flag = 1;
                }
            }
#endif
            else if (strcmp(option, "show_personal_database") == 0)
            {
                if (strcmp(value, "TRUE") == 0)
                {
                    temp1=0;
                }
                else if (strcmp(value, "FALSE") == 0)
                {
                    temp1=1;
                }
                else
                {
                    if (quiet == 0)
                    {
                        fprintf(stderr, _("Invalid value at show_personal_database setting in options file: %s\n"), value);
                    }
                }
            }
            else if (strcmp(option, "show_international_days_database") == 0)
            {
                if (strcmp(value, "TRUE") == 0)
                {
                    temp2=0;
                }
                else if (strcmp(value, "FALSE") == 0)
                {
                    temp2=1;
                }
                else
                {
                    if (quiet == 0)
                    {
                        fprintf(stderr, _("Invalid value at show_international_days_database setting in options file: %s\n"), value);
                    }
                }
            }
            else
            {
                if (quiet == 0)
                {
                    fprintf(stderr, _("Unknown settings in your options file:\n%s\n"), buf);
                }
            }
        }
    }

    if (temp1==1 && temp2==1)
    {
        no_database = 'a';
    }
    else if (temp1==0 && temp2==1)
    {
        no_database = 'i';
    }
    else if (temp1==1 && temp2==0)
    {
        no_database = 'p';
    }
    else no_database = 'n';

    fclose(opt);
    return 0;
}
void    OptionsContactsWidget::writeOptions(void)
{
    QSettings settings("QNetSoul", "QNetsoul");
    writeOptions(settings);
}