Ejemplo n.º 1
0
void deleteTask(char* name, struct error* err) {
    err->error = NO_ERROR;
    
    if(!db) {
        if(!initializeConnection(NULL)) {
            exit(1);
        }
    }

    const char* unused;
    sqlite3_stmt* statement;
    char* sql   = "DELETE FROM TASKS WHERE TITLE = ?";
    int rc      = sqlite3_prepare(db, sql, -1, &statement, &unused);

    if(rc != SQLITE_OK) {
        err->error = DATABASE_DELETE;
        err->description = sqlite3_errmsg(db);
        return ;
    }

    sqlite3_bind_text(statement, 1, name, strlen(name), SQLITE_STATIC);
    sqlite3_step(statement);
    rc = sqlite3_finalize(statement);

    if(rc != SQLITE_OK) {
        err->error = DATABASE_DELETE;
        err->description = sqlite3_errmsg(db);
    }
}
Ejemplo n.º 2
0
list getTasks(struct error* err) {
    err->error = NO_ERROR;

    if(!db) {
        if(!initializeConnection(NULL)) {
            exit(1);
        }
    }

    sqlite3_stmt* statement;
    const char* sql = "select * from tasks";
    const char* unused;
    
    int rc = sqlite3_prepare(db, sql, -1, &statement, &unused);
    if(rc != SQLITE_OK) {
        err->error = DATABASE_SELECT;
        err->description = sqlite3_errmsg(db);
        return NULL;
    }

    list l = l_new();
    while(sqlite3_step(statement) == SQLITE_ROW) {
        populateList(l, statement);
    } 
    sqlite3_finalize(statement);
    return l;
}
Ejemplo n.º 3
0
VALUE rb_connection_new(VALUE database, VALUE user, VALUE password, VALUE options)

{

   VALUE connection = allocateConnection(cConnection),

         parameters[4];

         

   parameters[0] = database;

   parameters[1] = user;

   parameters[2] = password;

   parameters[3] = options;

   

   initializeConnection(4, parameters, connection);



   return(connection);

}
Ejemplo n.º 4
0
int main(int argc, char** argv) {
    struct error err;
    char** m_argv = NULL;
    if(argc == 2) {
        m_argv = (char**)malloc(3*sizeof(char*));
        m_argv[0] = (char*)malloc(sizeof(char) * (strlen(argv[0]) + 1));
        m_argv[1] = (char*)malloc(sizeof(char) * (strlen("tasks.db") + 1));
        m_argv[2] = (char*)malloc(sizeof(char) * (strlen(argv[1]) + 1));

        strcpy(m_argv[0], argv[0]);
        strcpy(m_argv[1], "tasks.db");
        strcpy(m_argv[2], argv[1]);

        ++ argc;
    }
    else {
        initializeConnection(argv[1]);
    } 
 
    parse_command(m_argv == NULL ? argv : m_argv, argc, &err);
 
    if(m_argv) {
        int i = 0;
        for(; i < 3; ++ i) {
            free(m_argv[i]);
        }
        free(m_argv);
    }

    return 0;
}
Ejemplo n.º 5
0
list getBetweenDate(struct tm start, struct tm end, struct error* err) {
    err->error = NO_ERROR;

    if(!db) {
        if(!initializeConnection(NULL)) {
            exit(1);
        }
    }

    sqlite3_stmt* statement;
    const char* sql = "select * from tasks";
    const char* unused;

    
    int rc = sqlite3_prepare(db, sql, -1, &statement, &unused);
    if(rc != SQLITE_OK) {
        err->error = DATABASE_SELECT;
        err->description = sqlite3_errmsg(db);
        return NULL;
    }

    list l = l_new();
    while(sqlite3_step(statement) == SQLITE_ROW) {
        struct tm s;
        struct tm e;

        
        strptime((char*)sqlite3_column_text(statement, 2), "%a %b %d %H:%M:%S %Y%n", &s);
        strptime((char*)sqlite3_column_text(statement, 3), "%a %b %d %H:%M:%S %Y%n", &e);

        if(date_compare(start, s) > 0 || date_compare(end, e) < 0) {
            continue ;
        }

        char* title;
        char* description;
        
        int title_length = strlen((char*)sqlite3_column_text(statement, 0)) + 1;
        int descr_length = strlen((char*)sqlite3_column_text(statement, 1)) + 1;

        title       = (char*)malloc(title_length*sizeof(char));
        description = (char*)malloc(descr_length*sizeof(char));

        strcpy(title,(char*)sqlite3_column_text(statement, 0));
        strcpy(description, (char*)sqlite3_column_text(statement, 1));
    
        Task t          = (Task)malloc(sizeof(struct task));
        t->title        = title;
        t->description  = description;
        t->startDay     = s;
        t->dueDay       = e;
        l_push(l, t);
    } 

    sqlite3_finalize(statement);
    return l;

}
Ejemplo n.º 6
0
Task getTask(char* title, struct error* err) {
    err->error = NO_ERROR;
    sqlite3_stmt* statement;

    if(!db) {
        if(!initializeConnection(NULL)) {
            exit(1);
        }
    }

    char* sql = "select * from tasks where title = ?";
    const char* unused;
    int rc = sqlite3_prepare(db, sql, -1, &statement, &unused);

    if(rc != SQLITE_OK) {
        err->error = DATABASE_SELECT;
        err->description = sqlite3_errmsg(db);
        return NULL;
    }

    sqlite3_bind_text(statement, 1, title, strlen(title), SQLITE_STATIC);
     
    if(sqlite3_step(statement) != SQLITE_ROW) {
        err->error = DATABASE_SELECT;
        err->description = sqlite3_errmsg(db);
        sqlite3_finalize(statement);
        return NULL; 
    }
    
    char* task_title = (char*)malloc(sizeof(char) * (strlen((char*)sqlite3_column_text(statement, 0)) +1));
    strcpy(task_title, (char*)sqlite3_column_text(statement, 0));    

    char* task_description = (char*)malloc(sizeof(char) * (strlen((char*)sqlite3_column_text(statement, 1))+1));
    strcpy(task_description, (char*)sqlite3_column_text(statement, 1));    

    char* task_start = (char*)malloc(sizeof(char) * (strlen((char*)sqlite3_column_text(statement, 2))+1));
    strcpy(task_start, (char*)sqlite3_column_text(statement, 2)); 

    char* task_end = (char*)malloc(sizeof(char) * (strlen((char*)sqlite3_column_text(statement, 3))+1));
    strcpy(task_end, (char*)sqlite3_column_text(statement, 3));    

     
    Task t = (Task)malloc(sizeof(struct task));
    t->title        = task_title;
    t->description  = task_description;

    strptime(task_start, "%a %b %d %H:%M:%S %Y%n", &(t->startDay));
    strptime(task_end, "%a %b %d %H:%M:%S %Y%n", &(t->dueDay));
   
    free(task_start);
    free(task_end);
 
    sqlite3_finalize(statement);

    return t;
}
Ejemplo n.º 7
0
ODBCConnection* DBAccess::getConnection() 
{
#ifdef ALOGGER
	logger::Logger::getInstance().debug(__FILE__, __LINE__, __FUNCTION__, "" );
#endif

    if( conn_ == NULL)
        initializeConnection();
        	
	return conn_;
}
Ejemplo n.º 8
0
void extend_network(char *ip, char *port, int socketNo) {

	if (initializeConnection(ip, port, socketNo) == -1) {
		printf("The connection could not be established on socket: %d with Ip:  %s  ", socketNo, ip);
	}
	else {
		printf("Trying to extend network with %s on port %s and socket %u\n\n", ip, port, socketNo);

		printf("Join request was sent to %s on socket %d. Waiting for join response. \n", ip, socketNo);
		send_join_request(socketNo);
	}
}
Ejemplo n.º 9
0
void ChildProcess::initialize(const ChildProcessInitializationParameters& parameters)
{
    platformInitialize();

    initializeProcess(parameters);
    initializeProcessName(parameters);
    initializeSandbox(parameters);
    
    m_connection = CoreIPC::Connection::createClientConnection(parameters.connectionIdentifier, this, RunLoop::main());
    m_connection->setDidCloseOnConnectionWorkQueueCallback(didCloseOnConnectionWorkQueue);
    initializeConnection(m_connection.get());
    m_connection->open();
}
Ejemplo n.º 10
0
void createTask(char* title, char* description, struct tm startDate, struct tm endDate,
                    struct error* err) {
    
    err->error = NO_ERROR;    
    /*
    *   1. Establish connection with db
    *   2. Execute insert statement
    *   Always check for errors
    **/
    if(!db) {
        if(!initializeConnection(NULL)) {
            exit(1);
        }
    }
    if(!title || !description) {
        err->error = DATABASE_INSERT;
        err->description= sqlite3_errmsg(db);
        return ;
    }

    const char* unused;
    sqlite3_stmt* statement;
    char* sql = "INSERT INTO TASKS(TITLE, DESCRIPTION, START_DATE, END_DATE) VALUES(?,?,?,?)";

    int rc = sqlite3_prepare(db, sql, -1, &statement, &unused);

    if(!rc == SQLITE_OK) {
        err->error = DATABASE_INSERT;
        err->description= sqlite3_errmsg(db);
        return ;
    }

    sqlite3_bind_text(statement, 1, title, strlen(title), SQLITE_STATIC); 
    sqlite3_bind_text(statement, 2, description, strlen(description), SQLITE_STATIC);
    char* st_date_str = m_strdup(asctime(&startDate));
    sqlite3_bind_text(statement, 3, st_date_str, strlen(st_date_str)-1, SQLITE_STATIC);
    char* en_date_str = m_strdup(asctime(&endDate));
    sqlite3_bind_text(statement, 4, en_date_str, strlen(en_date_str)-1, SQLITE_STATIC);
    
    sqlite3_step(statement);
    rc = sqlite3_finalize(statement);

    if(rc != SQLITE_OK) {
        err->error = DATABASE_INSERT;
        err->description = sqlite3_errmsg(db); 
    }

    free(st_date_str);
    free(en_date_str);
}
Ejemplo n.º 11
0
int main()
{
	
	//ONCE VEHICLE DEGER ATA
	Vehicle vehicle;
	State state[4];
	
	state[0]=0;
	state[1]=1;
	state[2]=0;
	state[3]=1;
	
	char *name="audi";
	
	setVehicleName(&vehicle,name);
	setVehicleTemp(&vehicle, 1.0,2.0,3.5);
	setVehicleSpeed(&vehicle, 45);
	setVehicleDoor(&vehicle, state[0], state[1], state[2], state[3]);
	setVehicleWheelPressure(&vehicle, 25,30,30,25);
	
	printf("----------------------------------------------------\n");
	printf("Applied Vehicle Properties:\n");
	printf("----------------------------------------------------\n");
	printf("Name: %s\n",vehicle.name);
	printf("Speed: %d\n",vehicle.speed);
	printf("Temperature: (motor) %d , (indoor) %d , (outdoor) %d\n",vehicle.Temp.motor,vehicle.Temp.indoor,vehicle.Temp.outdoor);
	printf("Door: (frontLeft) %d ,(frontRight) %d,(rearLeft) %d,(rearRight) %d\n",vehicle.Door.frontLeft, vehicle.Door.frontRight,vehicle.Door.rearLeft, vehicle.Door.rearRight);
	printf("Wheel Pressure : (frontLeft) %d ,(frontRight) %d ,(rearLeft) %d, (rearRight) %d\n",vehicle.WheelPressure.frontLeft,vehicle.WheelPressure.frontRight,vehicle.WheelPressure.rearLeft,vehicle.WheelPressure.rearRight);
	printf("----------------------------------------------------\n");
	
	printf("open the server\n\n");
	
	int server, port,client;
	port=7777;
	if(initializeConnection(&server,port))
	{
		while(1)
		{
			client=makeConnection(&server);
			
			if(answerMessage(client,&vehicle));
		}
	}

return 0;
}	
Ejemplo n.º 12
0
MQTT::MQTT(QObject *parent) :
    QObject(parent)
{
    // re-initialize connection whenever the
    // host or the port changes
    QObject::connect(this, SIGNAL(hostChanged(QString)),
            this, SLOT(initializeConnection()));
    QObject::connect(this, SIGNAL(portChanged(int)),
            this, SLOT(initializeConnection()));
    qDebug()<<"Rahr: testing";
    numberOfData =0;
    udpSocket = new QUdpSocket(this);
    udpSocket->bind(3000, QUdpSocket::ShareAddress);

    QObject::connect(udpSocket, SIGNAL(readyRead()),
            this, SLOT(processPendingDatagrams()));
}
Ejemplo n.º 13
0
void editTask(char* title, Task newValue, struct error* err) {
    err->error = NO_ERROR;
    if(!newValue) {
        err->error = PARAMETER_ERROR;
        err->description = "Wrong parameters";
        return ;
    }
    
    if(!db) {
        if(!initializeConnection(NULL)) {
            exit(1);
        }
    }

    sqlite3_stmt* statement;
    const char* unused;
    char* sql = "update tasks set title = ?, description = ?, start_date = ?, end_date = ?\
                where title = ? ";

    int rc = sqlite3_prepare(db, sql, -1, &statement, &unused);
    if(rc != SQLITE_OK) {
        err->error          = DATABASE_UPDATE;
        err->description    = sqlite3_errmsg(db);
        return ;
    }
    sqlite3_bind_text(statement, 1, newValue->title, strlen(newValue->title), SQLITE_STATIC); 
    sqlite3_bind_text(statement, 2, newValue->description, strlen(newValue->description), SQLITE_STATIC);
    char* startDay_str  = m_strdup(asctime(&newValue->startDay));
    sqlite3_bind_text(statement, 3, startDay_str, strlen(startDay_str)-1, SQLITE_STATIC);
    char* dueDay_str    = m_strdup(asctime(&newValue->dueDay));
    sqlite3_bind_text(statement, 4, dueDay_str, strlen(dueDay_str)-1, SQLITE_STATIC);
    sqlite3_bind_text(statement, 5, title, strlen(title), SQLITE_STATIC);

    rc = sqlite3_step(statement);
    
    sqlite3_finalize(statement);

    if(rc != SQLITE_OK) {
        err->error      = DATABASE_UPDATE;
        err->description= sqlite3_errmsg(db);
    }

    free(startDay_str);
    free(dueDay_str);
}
Ejemplo n.º 14
0
void ClientConnection::run()
{
    try
    {
        if (initializeConnection())
        {
            while (_run)
            {
                handleCommand(_stream.readLine());
            }
        }
    }
    catch (std::exception& ex)
    {
        std::cerr << "Client exception: " << ex.what() << std::endl;
    }
    _server.removeClient(shared_from_this());
}
Ejemplo n.º 15
0
void ChildProcess::initialize(const ChildProcessInitializationParameters& parameters)
{
    platformInitialize();

#if PLATFORM(COCOA)
    m_priorityBoostMessage = parameters.priorityBoostMessage;
#endif

    initializeProcess(parameters);
    initializeProcessName(parameters);

    SandboxInitializationParameters sandboxParameters;
    initializeSandbox(parameters, sandboxParameters);
    
    m_connection = IPC::Connection::createClientConnection(parameters.connectionIdentifier, *this);
    m_connection->setDidCloseOnConnectionWorkQueueCallback(didCloseOnConnectionWorkQueue);
    initializeConnection(m_connection.get());
    m_connection->open();
}
Ejemplo n.º 16
0
/******************************************************************************
 * @fn          nwk_getNextConnection
 *
 * @brief       Return the next free connection structure if on is available.
 *
 * input parameters
 *
 * output parameters
 *      The returned structure has the Rx port number populated based on the
 *      free strucure found. This is the port queried when the app wants to
 *      do a receive.
 *
 * @return   pointer to the new connInfo_t structure. NULL if there is
 *           no room in connection structure array.
 */
connInfo_t *nwk_getNextConnection()
{
  uint8_t  i;

  for (i=0; i<SYS_NUM_CONNECTIONS; ++i)
  {
    if (sPersistInfo.connStruct[i].connState == CONNSTATE_CONNECTED)
    {
      continue;
    }
    break;
  }

  if (SYS_NUM_CONNECTIONS == i)
  {
    return (connInfo_t *)0;
  }

  initializeConnection(&sPersistInfo.connStruct[i]);

  return &sPersistInfo.connStruct[i];
}
Ejemplo n.º 17
0
/***********************************************************************************
 * @fn          nwk_findAlreadyJoined
 *
 * @brief       Used when AP is a data hub to look for an address match in the
 *              Connection table for a device that is already enterd in the joined
 *              state. This means that the Connection Table resource is already
 *              allocated so the link-listen doesn't have to do it again. Match is
 *              based on source address in frame. Thsi shoudl only be called from
 *              the Link-listen context during the link frame reply.
 *
 *              If found the Connection Table entry is initialized as if it were
 *              found using the nwk_getNextConnection() method.
 *
 * input parameters
 * @param   frame    - pointer to frame in question
 *
 * output parameters
 *
 * @return   Returns pointer to Connection Table entry if match is found, otherwise
 *           0. This call will only fail if the Connection Table was full when the
 *           device tried to join initially.
 */
connInfo_t *nwk_findAlreadyJoined(mrfiPacket_t *frame)
{
  uint8_t     i;
  connInfo_t *ptr = sPersistInfo.connStruct;

  for (i=0; i<NUM_CONNECTIONS; ++i,++ptr)
  {
    /* Look for an entry in the JOINED state */
    if (CONNSTATE_JOINED == ptr->connState)
    {
      /* Is this it? */
      if (!(memcmp(&ptr->peerAddr, MRFI_P_SRC_ADDR(frame), NET_ADDR_SIZE)))
      {
        /* Yes. Initilize tabel entry and return the pointer. */
        initializeConnection(ptr);
        return ptr;
      }
    }
  }

  /* Nothing found... */
  return (connInfo_t *)NULL;
}
Ejemplo n.º 18
0
int main(int argc, char **argv) {
    if(signal(SIGINT, catch_function) == SIG_ERR){
        printf("An error occurred while setting a signal handler\n");
        return EXIT_FAILURE;
    }
	int cli_len;
	struct sockaddr_in cli_addr;


	if (argc != 2) {
		printf("usage: %s <TCP port>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	// create the socket (add missing arguments)
    sock_fd=initializeConnection(atoi(argv[1]));
    cli_fd=accept(sock_fd, (struct sockaddr*)&cli_addr, &cli_len);
    getAndSaveFile();

    close(sock_fd);
    close(cli_fd);

	return EXIT_SUCCESS;
}