int main(int argc, char*argv[]) { char* test = (char *) malloc(500*sizeof(char)); json_error_t error; json_t *root; json_t *data; json_t *j_type; json_t *j_data; json_t *phone; const char *type; const char *customer_phone; int server_sockfd, client_sockfd; int server_len, client_len; struct sockaddr_in server_address; struct sockaddr_in client_address; server_sockfd = socket(PF_INET, SOCK_STREAM, 0); server_address.sin_family = PF_INET; // server_address.sin_addr.s_addr = inet_addr("127.0.0.1"); server_address.sin_addr.s_addr = htonl(INADDR_ANY); server_address.sin_port = htons(9733); server_len = sizeof(server_address); bind(server_sockfd, (struct sockaddr *)&server_address, server_len); listen(server_sockfd, 5); while (1) { test = (char *) malloc(500*sizeof(char)); printf("server waitting\n"); client_len = sizeof(client_address); client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len); read(client_sockfd, test, 500); root = json_loads(test, 0, &error); free(test); if(!root) { fprintf(stderr, "error: on line %d: %s\n", error.line, error.text); // Response error to client response_data(0, json_object(), client_sockfd); } else { j_type = json_object_get(root, "type"); j_data = json_object_get(root, "data"); if (!j_type || !j_data) { response_data(0, json_object(), client_sockfd); } else { type = json_string_value(j_type); printf("Type: %s\n", type); if (strcmp(type, "gcustomerinfo") == 0) { const char * phone = get_value(root, "phone"); json_t *data = get_customer(phone); response_data(1, data, client_sockfd); } else if (strcmp(type, "pcustomerinfo") == 0) { const char * name = get_value(root, "name"); const char * email = get_value(root, "email"); const char * address = get_value(root, "address"); const char * phone = get_value(root, "phone"); const char * gender = get_value(root, "gender"); json_t *data = new_customer(name, email, address, phone, gender, "test"); response_data(1, data, client_sockfd); } else if (strcmp(type, "ucustomerinfo") == 0) { const char * id = get_value(root, "id"); const char * name = get_value(root, "name"); const char * email = get_value(root, "email"); const char * address = get_value(root, "address"); const char * gender = get_value(root, "gender"); json_t *data = update_customer(id, name, email, address, gender); response_data(1, data, client_sockfd); } else if (strcmp(type, "porder") == 0) { const char * customer_id = get_value(root, "id"); const char * message = get_value(root, "message"); json_t *data = new_order(customer_id, message); response_data(1, data, client_sockfd); } else if (strcmp(type, "porderdetail") == 0) { const char * order_id = get_value(root, "oid"); const char * product_id = get_value(root, "pid"); const char * quantity = get_value(root, "quantity"); json_t *data = new_order_detail(order_id, product_id, quantity); response_data(1, data, client_sockfd); // Default } else { response_data(0, json_object(), client_sockfd); } } } close(client_sockfd); } }
int main(int argc, char ** argv) { LoopQueue * line; /* 模拟队列 */ Data temp; /* 关于新顾客的数据 */ int hours; /* 模拟的小时数 */ int per_hour; /* 每小时顾客的平均数 */ long cycle, cycle_limit; /* 循环计数器, 计数器的上界 */ long turn_aways = 0; /* 因队列已满而被拒绝的顾客数 */ long customer = 0; /* 被加入队列的顾客数 */ long served = 0; /* 在模拟期间得到服务的顾客数 */ long sum_line = 0; /* 累计的队列长度 */ int wait_time = 0; /* 从当前到Sigmund空闲所需的时间*/ double min_per_cust; /* 顾客到来的平均间隔时间 */ long line_wait = 0; /* 队列累计等待时间 */ line = createLoopQueue(10); srand(time(0)); /* 随机初始化rand()函数 */ //输入模拟的小时数 fputs("Case Study: Sigmund Lander's Advice Booth\n", stdout); fputs("Enter the number of simulation hours:\n", stdout); scanf_s("%d", &hours); cycle_limit = MIN_PER_HR * hours; //每顾客到达时间 fputs("Enter the average number of customers per hour: \n", stdout); scanf_s("%d", &per_hour); min_per_cust = MIN_PER_HR / per_hour; //对队列进行处理 for (cycle = 0; cycle < cycle_limit; cycle++) { //如果这1分钟内有顾客到来 if (new_customer(min_per_cust)){ if (LoopQueueIsFull(line)){ turn_aways++; //顾客被拒绝 } else{ customer++; //进入队列的人数 temp = customer_time(cycle); EnLoopQueue(line, temp); //顾客入队 } } //如果此时队列无等待 if (wait_time <= 0 && !LoopQueueIsEmpty(line)) { Data * de = DeLoopQueue(line); wait_time = de->process_time; line_wait += cycle - de->arrive; served++; } if (wait_time > 0) wait_time--; sum_line += countLoopQueue(line); } if (customer > 0){ printf("customers accepted: %ld\n", customer); printf(" customers served: %ld\n", served); printf(" turnaways: %ld\n", turn_aways); printf("average queue size: %.2f\n", (double)sum_line / cycle_limit); printf(" average wait time: %.2f minutes\n", (double)line_wait / served); }else{ fputs("No customers\n", stdout); } destroyLoopQueue(line); fputs("Bye!\n", stdout); _CrtDumpMemoryLeaks(); return EXIT_SUCCESS; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); this->tracking_status=FALSE; QIcon* icon =new QIcon((QString)APATH+"clock.png"); ui->pushHour->setEnabled(FALSE); ui->pushHour->setIcon(*icon); ui->pushHour->setIconSize(QSize( ui->pushHour->size().width()-5,ui->pushHour->size().height()-5 )); QIcon* icon1 =new QIcon((QString)APATH+"add.png"); ui->pushAddEarlier->setIcon(*icon1); ui->pushAddEarlier->setIconSize(QSize( ui->pushAddEarlier->size().width()-5,ui->pushAddEarlier->size().height()-5 )); QIcon* icon3 =new QIcon((QString)APATH+"delete.png"); ui->pushDelete->setIcon(*icon3); ui->pushDelete->setIconSize(QSize( ui->pushDelete->size().width()-5,ui->pushDelete->size().height()-5 )); ui->pushDelete->setFocusPolicy(Qt::NoFocus); ui->pushAddEarlier->setFocusPolicy(Qt::NoFocus); ui->pushDelete->setEnabled(FALSE); QIcon* icon2 =new QIcon((QString)APATH+"hourglass.png"); this->setWindowIcon(*icon2); db1=QSqlDatabase::addDatabase("QMYSQL","hourglass"); db1.setDatabaseName("hourglass"); db1.setHostName(g_HOST); db1.setUserName(g_USER); db1.setPassword(g_PASS); db1=QSqlDatabase::database("hourglass"); // QPluginLoader *thePlugin = new QPluginLoader("/home/jim/qt/qt-4.6.3/plugins/sqldrivers/libqsqlmysql.so"); //qDebug() << thePlugin->load(); //qDebug() << thePlugin->isLoaded(); //qDebug() << thePlugin->errorString(); if (!db1.open()) { qDebug()<<"Απέτυχε η σύνδεση με τη βάση"; exit(0); } db2=QSqlDatabase::addDatabase("QMYSQL","asterisk"); db2.setDatabaseName("asterisk"); db2.setHostName(g_ASTERISK_SERVER); db2.setUserName(g_AST_MYSQL_USER); db2.setPassword(g_AST_MYSQL_PASS); db2=QSqlDatabase::database("asterisk"); if (!db2.open()) { qDebug()<<"Απέτυχε η σύνδεση με τη βάση"; //exit(0); } this->customer_model=new QSqlQueryModel(); this->project_model=new QSqlQueryModel(); this->places_model=new QSqlQueryModel(); this->tasks_model=new QSqlQueryModel(); this->tasks_full_model=new QSqlQueryModel(); this->daily_calls_model=new QSqlQueryModel(); this->full_calls_model=new QSqlQueryModel(); refresh_customers(); refresh_tasks(); refresh_full_tasks(); refresh_daily_calls(); refresh_full_calls(); this->timer=new QTimer; this->timer_asterisk=new QTimer; timer_asterisk->start(60000); QStringList sl; ui->comboGraph->insertItem(0,trUtf8("ΕΒΔΟΜΑΔΑ")); ui->comboGraph->insertItem(1,trUtf8("ΕΤΟΣ")); ui->comboGraph->insertItem(2,trUtf8("ΔΙΑΧΡΟΝΙΚΟ")); /* QDate simera; simera=QDate::currentDate(); int dayno=simera.dayOfWeek(); QList <int> minut; for (int i=0;i<dayno;++i) { QSqlQuery query(db1); query.exec("select sum(TIMESTAMPDIFF(MINUTE,t.start_time,t.end_time)) from tasks t where date(start_time)='"+simera.addDays(-i).toString("yy/M/d")+"'"); query.next(); minut.prepend(query.value(0).toInt()); qDebug()<<"MINUT:"<<minut; } WeekGraph *drb=new WeekGraph(this); drb->set_list(minut); drb->setFixedWidth(921); drb->setFixedHeight(181); drb->repaint(); */ drb=new WeekGraph(this); drb->setGeometry(180,10,611,151); //drb->setFixedWidth(621); //drb->setFixedHeight(161); connect(timer_asterisk,SIGNAL(timeout()),this,SLOT(refresh_calls())); connect(timer, SIGNAL(timeout()),this, SLOT(refresh_time())); connect(ui->action,SIGNAL(triggered()),this,SLOT(new_customer())); connect(ui->tableCustomers,SIGNAL(clicked(QModelIndex)),this,SLOT(customer_selection_changed())); connect(ui->tableCustomers,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(edit_customer())); connect(ui->pushHour,SIGNAL(released()),this,SLOT(tracking_pressed())); connect(ui->textEdit,SIGNAL(textChanged()),this,SLOT(remove_invalid_chars())); connect(ui->tableView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(edit_task())); connect(ui->tableView_2,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(edit_task_full())); connect(ui->pushAddEarlier,SIGNAL(released()),this,SLOT(add_earlier_task())); connect(ui->actionMigration,SIGNAL(triggered()),this,SLOT(do_migration())); connect(ui->action_2,SIGNAL(triggered()),this,SLOT(invoicing())); connect(ui->actionEmail,SIGNAL(triggered()),this,SLOT(email_tasks())); connect(ui->comboGraph,SIGNAL(currentIndexChanged(int)),this,SLOT(change_graph(int))); connect(ui->actionProjects,SIGNAL(triggered()),this,SLOT(projects())); connect(ui->actionReview,SIGNAL(triggered()),this,SLOT(invoice_review())); connect(ui->tableView,SIGNAL(clicked(QModelIndex)),this,SLOT(table_clicked())); connect(ui->tableView_2,SIGNAL(clicked(QModelIndex)),this,SLOT(table2_clicked())); connect(ui->pushDelete,SIGNAL(released()),this,SLOT(delete_clicked())); connect(ui->tabWidget,SIGNAL(currentChanged(int)),this,SLOT(tab_changed(int))); ui->comboGraph->setCurrentIndex(-1); ui->comboGraph->setCurrentIndex(0); ui->tableView->setContextMenuPolicy(Qt::CustomContextMenu); ui->tableTodayCalls->setContextMenuPolicy(Qt::CustomContextMenu); ui->tableAllCalls->setContextMenuPolicy(Qt::CustomContextMenu); ui->tableCustomers->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->tableView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(context_menu(const QPoint&))); connect(ui->tableView_2->horizontalHeader(),SIGNAL(sectionClicked(int)),this,SLOT(sortbycolumn(int))); connect(ui->tableCustomers,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(dial_customer(const QPoint&))); connect(ui->tableTodayCalls,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(context_menu_daily_calls(QPoint))); connect(ui->tableAllCalls,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(context_menu_full_calls(QPoint))); Asterisk_CallerID_Monitor *ast_monitor=new Asterisk_CallerID_Monitor(this); connect (ast_monitor,SIGNAL(incoming_call(QString)),this,SLOT(incoming_call(QString))); ast_monitor->start_monitor(); }