?? php_server.cpp.svn-base
字號:
/* ------------------------------------------------------------------------- * php_server.cpp - php server functions * Copyright (C) 2008 Dimitar Atanasov <datanasov@deisytechbg.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ------------------------------------------------------------------------- */#include "common.h"#include "servers.h"#include <fcntl.h>void billing(std::string &req, int cfd){ int RoomNo = 0; DECODE_BEGIN(req) EXTRACT("RN(\\d+)", RoomNo) DECODE_END() BEGIN_DB() std::ostringstream guest_q; guest_q << "SELECT GuestNo FROM Room WHERE RoomID=" << RoomNo; mysqlpp::StoreQueryResult guest_res = qr.store(guest_q.str().c_str()); if(guest_res.num_rows() == 0) { END_DB_RETURN() return; } int GuestNo = guest_res[0][0]; if(ctxt.is_in_php(RoomNo)) { ctxt.insert_php(cfd, RoomNo, 0, 0); std::ostringstream msg; std::string RoomName = get_room_name(qr, RoomNo); msg << "XR|RN"<<RoomName<<"|G#"<< GuestNo << "|"; if(ctxt.conf->second_interface) send_to_pms(msg, ctxt.pmssock2); else send_to_pms(msg); } END_DB()}void posting(std::string &req, int cfd){ int RoomNo = 0; int Amount = 0; int PostingType = 0; DECODE_BEGIN(req) EXTRACT("RN(\\d+)", RoomNo) EXTRACT("TA(\\d+)", Amount) EXTRACT("TP(\\d+)", PostingType) DECODE_END() if(RoomNo == 0) return; make_gen(RoomNo, Amount, PostingType, cfd, "PHP", 0, "", 0);}void who_is (std::string &req, int cfd){ int RoomNo = 0; DECODE_BEGIN(req) EXTRACT("RN(\\d+)", RoomNo) DECODE_END() BEGIN_DB() int HType = get_h_type(qr, RoomNo); std::ostringstream msg; msg << "WI|RN" << RoomNo << "|TV"; if(HType == 0) msg << "TN|\r\n"; else if(HType == 1) msg << "TU|\r\n"; else msg << "TM|\r\n"; send(cfd, msg.str().c_str(), msg.str().length(), 0); END_DB()}void target_temp(std::string &req, int cfd){ int RoomNo = 0; int Amount = 0; DECODE_BEGIN(req) EXTRACT("RN(\\d+)", RoomNo) EXTRACT("MP(\\d+)", Amount) DECODE_END() if(Amount >= 15 and Amount <= 30) { BEGIN_DB() std::ostringstream temp_zone; temp_zone << "UPDATE RoomTZone SET TargetT = " << Amount <<" WHERE RoomID =" << RoomNo; mysqlpp::SimpleResult res = qr.execute(temp_zone.str().c_str()); std::ostringstream msg; msg << "TS|RN" << RoomNo; //if(res.rows() > 0) { int season = get_season(qr); std::ostringstream temp_q; temp_q << "SELECT TZoneID, DefaultGuestT_EmptyRoom,Mode FROM RoomTZone WHERE RoomID=" << RoomNo; mysqlpp::StoreQueryResult temp_res = qr.store(temp_q.str().c_str()); for(uint16 i = 0; i < temp_res.num_rows(); i++) { std::ostringstream msg_rc; msg_rc.fill('0'); msg_rc << "CLMT:"<< std::setw(2) << temp_res[i][0] - 1 << season << std::setw(2) << Amount << std::setw(2) << temp_res[i][1] << temp_res[i][2] << "*"; std::string ip = get_rc_ip(qr, RoomNo); send_to_rc(ip, msg_rc); } msg << "|ASOK|\r\n"; } //else // msg << "|ASUR|\r\n"; send(cfd, msg.str().c_str(), msg.str().length(), 0); END_DB() }}void wake_up(std::string &req, int cfd){ int RoomNo = 0; DECODE_BEGIN(req) EXTRACT("RN(\\d+)", RoomNo) DECODE_END() std::ostringstream msg; msg << "WA|RN" << RoomNo << "|ASOK|\r\n"; send(cfd, msg.str().c_str(), msg.str().length(), 0); process_command(req);}void indicator(std::string &req, int cfd){ int RoomNo = 0; int GreenIndic = 0; int RedIndic = 0; DECODE_BEGIN(req) EXTRACT("RN(\\d+)", RoomNo) EXTRACT("GI(\\d+)", GreenIndic) EXTRACT("RI(\\d+)", RedIndic) DECODE_END() BEGIN_DB() std::ostringstream room_status_q; room_status_q << "UPDATE RoomStatus SET GreenIndic=" << GreenIndic << ", RedIndic=" << RedIndic << " WHERE RoomID=" << RoomNo; mysqlpp::SimpleResult res = qr.execute(room_status_q.str().c_str()); std::ostringstream msg; msg << "CS|RN" << RoomNo; //if(res.rows() > 0) { std::ostringstream msg_rc; msg_rc.fill('0'); msg_rc << "INDC:"<< GreenIndic << RedIndic << "*"; std::string ip = get_rc_ip(qr, RoomNo); send_to_rc(ip, msg_rc); msg << "|ASOK|\r\n"; } // else // msg << "|ASUR|\r\n"; send(cfd, msg.str().c_str(), msg.str().length(), 0); END_DB()}#define DIRTY_VACANT 1#define CLEAN_VACANT 3#define INSPECTED_VACANT 5void status(std::string &req, int cfd){ int RoomNo = 0; int PHPRoomStatus = 0; int RoomStatus = 0; DECODE_BEGIN(req) EXTRACT("RN(\\d+)", RoomNo) EXTRACT("RS(\\d+)", PHPRoomStatus) DECODE_END() switch (PHPRoomStatus) { case 1: RoomStatus = DIRTY_VACANT; break; case 2: RoomStatus = CLEAN_VACANT ;break; case 3: RoomStatus = INSPECTED_VACANT ;break; } BEGIN_DB() std::ostringstream guest_q; guest_q << "SELECT GuestNo FROM Room WHERE RoomID=" << RoomNo; mysqlpp::StoreQueryResult guest_res = qr.store(guest_q.str().c_str()); std::ostringstream msg; msg << "CS|RN" << RoomNo; if(guest_res.num_rows() > 0) { if((int) guest_res[0][0] != 0) RoomStatus++; } if(RoomStatus >=1 && RoomStatus <= 6) { std::ostringstream room_status_q; room_status_q << "UPDATE RoomStatus SET Status=" << RoomStatus << " WHERE RoomID=" << RoomNo; mysqlpp::SimpleResult room_status_res = qr.execute(room_status_q.str().c_str()); // if(room_status_res.rows() > 0) { if(ctxt.conf->using_pms) { std::string sRoomName = get_room_name(qr, RoomNo); std::ostringstream msg_pms; msg_pms << "RE|RN" << sRoomName << "|RS" << RoomStatus << "|"; if(ctxt.conf->second_interface) send_to_pms(msg_pms, ctxt.pmssock2); else send_to_pms(msg_pms); } msg << "|ASOK|\r\n"; } //else //{ // msg << "|ASNR|\r\n"; // logger(ERROR, "Error setting room stattus in RE room %d", RoomNo); //} } else msg << "|ASNR|\r\n"; send(cfd, msg.str().c_str(), msg.str().length(), 0); END_DB()}void posting_simple_mini(std::string &req, int cfd){ int RoomNo = 0; int MA = 0; int MN = 0; DECODE_BEGIN(req) EXTRACT("RN(\\d+)", RoomNo) EXTRACT("MA(\\d+)", MA) EXTRACT("M\\#(\\d+)", MN) DECODE_END() BEGIN_DB() if(ctxt.is_in_php(RoomNo)) { ctxt.insert_php(cfd, RoomNo, 0, 0); std::string sRoomName = get_room_name(qr, RoomNo); std::ostringstream msg; msg << "PS|RN" << sRoomName << "|PTM|MA" << MA << "|M#" << MN << "|DA" << get_date << "|TI" << get_time <<"|"; if(ctxt.conf->second_interface) send_to_pms(msg, ctxt.pmssock2); else send_to_pms(msg); } END_DB()}void php_msg_handler(void* msg){ msg_t* _msg = static_cast<msg_t*> (msg); mysqlpp::Connection::thread_start(); pcrecpp::RE("(\\s{2})").Replace("", &_msg->command); std::vector<std::string> msg_decomposed; pcrecpp::StringPiece input(_msg->command); std::string command;// int KC_ID = get_KCWS(_msg->ip); while(pcrecpp::RE("([\\x20-\\x7B\\x7D-\\xFF]+)\\|").Consume(&input, &command)) { msg_decomposed.push_back(command); } if(msg_decomposed[0] == "XR") { billing(_msg->command, _msg->sd); } else if(msg_decomposed[0] == "PS") { posting(_msg->command, _msg->sd); } else if(msg_decomposed[0] == "WH") { who_is(_msg->command, _msg->sd); } else if(msg_decomposed[0] == "TT") { target_temp(_msg->command, _msg->sd); }else if(msg_decomposed[0] == "WD") { wake_up(_msg->command, _msg->sd); } else if(msg_decomposed[0] == "WC") { wake_up(_msg->command, _msg->sd); } else if(msg_decomposed[0] == "CI") { indicator(_msg->command, _msg->sd); } else if(msg_decomposed[0] == "RE") { status(_msg->command, _msg->sd); } else if(msg_decomposed[0] == "MS") { posting_simple_mini(_msg->command, _msg->sd); } if(_msg) { delete _msg; _msg = NULL; } mysqlpp::Connection::thread_end();}void*php_server(void* ){ return server(ctxt.phpsock, ctxt.conf->php_port, ctxt.conf->php_host, php_msg_handler);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -