本文整理汇总了C++中Queue类的典型用法代码示例。如果您正苦于以下问题:C++ Queue类的具体用法?C++ Queue怎么用?C++ Queue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Queue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Reader
int HuffmanCode::zip(char* inputFile, char* outputFile) {
CStopWatch time;
time.startTimer();
cout<<"Zipping.."<<endl;
// Declare variable
Reader *reader = new Reader(inputFile); // Readfile object
Writer *writer = new Writer(outputFile); // Writefile object
HCZHeader header; // Header object
Queue priQueue; // Creat a Queue
Node* huffmantree = NULL; // root of Huffman tree
char **codemap;// Map of chareacter code
char *code; // temp of code
int bodysize = 0; // Sum of bit in body
int totalcharater = 0; // Sum of character in text
int usedcharacter = 0; // Number of character used in txt
int totalbit = 0; // Total bit of coding map
// Initialize the table of character code
codemap = new char*[256];
for(int i = 0; i < 256; i++){
codemap[i] = new char[16];
memset(codemap[i],'\0',strlen(codemap[i]));
}
// Initialize the temp variable to save encode
code = new char[16];
memset(code,'\0',strlen(code));
code[0]='0';
// Count character and add to the Queue
while(reader->isHasNext()){
priQueue.freq(reader->readChar());
}
delete reader;
// Get number of used character
usedcharacter = priQueue.getCount();
// Sort the Queue
priQueue.sort();
// Get the huffman tree
huffmantree = priQueue.creatHuffmanTree();
// Conver huffman tree to code map and get nessessary information
convertHuffmanToMap(codemap,huffmantree,code,bodysize,totalcharater,totalbit);
// Set important info to Header
header.setBodySize(bodysize);
header.setTotal(usedcharacter,totalbit);
// Set codelist to header
for(int i = 0 ; i < 256 ; i++){
if(codemap[i][0] != '\0'){
header.set(i,strlen(codemap[i]),codemap[i]);
}
}
// Writer header to file
header.write(writer);
// Encode file
reader = new Reader(inputFile);
char k;
int limit;
while(reader->isHasNext()){
k = reader->readChar();
limit = strlen(codemap[char2Int(k)]);
for(char j = 0 ; j < limit ; j++){
writer->writeBit(codemap[char2Int(k)][char2Int(j)] - '0');
}
}
delete reader;
delete writer;
cout<< "Total character encoded: "<<totalcharater<<endl;
cout<<"Done!..."<<endl;
time.stopTimer();
cout<<"Excution time: "<<time.getElapsedTime()<<"s"<<endl;
return SUCCESS;
}
示例2: computeBC
Mylist<double>* BCAlg:: computeBC(Mylist<BCUser*> &userList)//Bc method
{
for (int i=0; i<userList.size(); i++){
userList.at(i)->bc=0;//sets all of the bc scores of the users to 0.
}
for(int i=0; i<userList.size(); i++){
for (int j=0; j<userList.size(); j++){
userList.at(j)->clearPred();//clears the predecessor array of the user
userList.at(j)->numsp=0;//sets the num of shortest paths from user i to user j to 0
userList.at(j)->dist=-1;//sets the distance from user i to user j to 0
userList.at(j)->delta=0.0;//sets the change value to 0
}
userList.at(i)->numsp=1;//sets the # of shortest paths for user i to 1
userList.at(i)->dist=0;// sets the distance for user 1 to 0
Stack<BCUser*> st;//creates a stack of BCuser*'s
Queue<BCUser*> q;//creates a queue of BCuser*'s
q.push_back(userList.at(i));//adds specified user to the queue
while (!q.empty()){//first in first out, while queue isn't empty
BCUser* v;//creates a bcuser*
v = q.front();//sets temp v to first value of the queue
q.pop_front();//remove top of the queue
st.push(v);//push the temp bcuser to the stack
for(int w =0; w< v->getFriendsSize(); w++){
int u= v->getFriendAt(w);
if (userList.at(u)->dist == -1){//if user v's friend at w, has a dist of -1
q.push_back(userList.at(u));//push back user v's friend at w onto the queue
userList.at(u)->dist=v->dist+1;//set user v's friend at w distance equal to one more than user v's distance
}
if (userList.at(u)->dist == v->dist+1){//if user v's friend at w distance is equal to one more than user v's distance
userList.at(u)->numsp = userList.at(u)->numsp + v->numsp;//user v's friend at w number of shortest paths is itself plus v's number of shortest paths
userList.at(u)->preds.push_back(v->getId());//push back v onto predecessor of user v's friend at w
}
}
}
while (!st.empty()){//last in first out
BCUser* w = st.top(); //creates a temp bcuser
st.pop(); //removes w from the stack
for(int v=0; v < w->preds.size(); v++){//loops through preds of w
int u= w->preds.at(v);//sets u to the pred of w at v
//sets the delta of the userList at u
userList.at(u)->delta =userList.at(u)->delta + ((userList.at(u)->numsp)/(w->numsp))*(1+(w->delta));
}
w->bc = w->bc + w->delta;//makes bc at w equal to itself plus the change (delta)
}
}
Mylist<double>*scores= new Mylist<double>();//dynamically allocates scores Mylist<double>
for (int i=0; i<userList.size(); i++){
(*scores).push_back(userList.at(i)->bc);//pushes back all of the userList bc values to the scores Mylist
}
double min, max;
min = userList.at(0)->bc;//sets min to first value
max = userList.at(0)->bc;//sets max to first value
for(int x=0; x<userList.size(); x++){
if (userList.at(x)->bc >=max){
max= userList.at(x)->bc;//goes through userlist, if bc value at x is greater than max, sets max to that userlist bc
}
if (userList.at(x)->bc <=min){
min = userList.at(x)->bc;//goes through userlist, if bc value at x is less than min, sets min to that userlist bc
}
}
for (int y=0; y<userList.size(); y++){
(*scores)[(userList.at(y)->getId())]= (((*scores).at(y))-min)/(max-min);//sets scores at userlist of the id
}
for (int i=0; i<userList.size(); i++){
userList.at(i)->bc= (*scores).at(i);//sets the bc values of userlist to the normalized bc scores
}
return scores;
return 0;
}
示例3: sizeof
//.........这里部分代码省略.........
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
str_sprintf(buf, "requestTuppIndex = %d, replyTuppIndex = %d",
(Int32) requestTuppIndex_, (Int32) replyTuppIndex_);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
str_sprintf(buf, "udrType = %d, languageType = %d",
(Int32) udrType_, (Int32) languageType_);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
str_sprintf(buf, "parameterStyle = %d, sqlAccessMode = %d",
(Int32) paramStyle_, (Int32) sqlAccessMode_);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
str_sprintf(buf, "transactionAttributes = %d", (Int32) transactionAttrs_);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
str_sprintf(buf, "externalSecurity = %d, routineOwnerId = %d",
(Int32) externalSecurity_, (Int32) routineOwnerId_);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
UInt32 i;
for (i = 0; i < numParams_; i++)
{
const UdrFormalParamInfo *p = paramInfo_[i];
str_sprintf(buf, "\nParameter %d", (Int32) i);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
str_sprintf(buf, " name [%s]", p->getParamName());
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
str_sprintf(buf, " flags %b, type %d", p->getFlags(),
(Int32) p->getType());
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
str_sprintf(buf, " precision %d, scale %d, charset %d, collation %d",
(Int32) p->getPrecision(), (Int32) p->getScale(),
(Int32) p->getEncodingCharSet(), (Int32) p->getCollation());
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
}
Queue *optData = getOptionalData();
if (optData)
{
UInt32 dataElems = optData->numEntries();
str_sprintf(buf, "\nNumber of optional data elements: %d",
(Int32) dataElems);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
const char *s = NULL;
i = 0;
optData->position();
while ((s = (const char *) optData->getNext()) != NULL)
{
// Each data element is prefixed by a 4-byte length field
UInt32 len = 0;
str_cpy_all((char *)&len, s, 4);
str_sprintf(buf, "\nOptional data %d (length %d):",
(Int32) i++, (Int32) len);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
if (len > 0)
{
// Create a buffer containing at most 200 bytes of data
if (len > 200)
len = 200;
char truncatedBuf[201];
str_cpy_all(truncatedBuf, s + 4, len);
truncatedBuf[len] = 0;
// Change NULL bytes and non-ASCII characters to '.' for
// display purposes
for (UInt32 j = 0; j < len; j++)
{
if (truncatedBuf[j] == 0 || !isascii(truncatedBuf[j]))
truncatedBuf[j] = '.';
}
space->allocateAndCopyToAlignedSpace(truncatedBuf, len, sz);
}
}
}
if (javaDebugPort_ > 0)
{
str_sprintf(buf, "\njavaDebugPort = %d, javaDebugTimeout = %d",
javaDebugPort_, javaDebugTimeout_);
space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sz);
}
} // if (flag & 0x00000008)
if (flag & 0x00000001)
{
displayExpression(space,flag);
displayChildren(space,flag);
}
}
示例4: main
int main(int argc, char **argv) {
EventList eventlist;
eventlist.setEndtime(timeFromSec(5000));
Clock c(timeFromSec(50/100.), eventlist);
int algo = UNCOUPLED;
double epsilon = 1;
int crt = 2;
if (argc>1) {
if (!strcmp(argv[1],"UNCOUPLED"))
algo = UNCOUPLED;
else if (!strcmp(argv[1],"COUPLED_INC"))
algo = COUPLED_INC;
else if (!strcmp(argv[1],"FULLY_COUPLED"))
algo = FULLY_COUPLED;
else if (!strcmp(argv[1],"COUPLED_TCP"))
algo = COUPLED_TCP;
else if (!strcmp(argv[1],"COUPLED_EPSILON")) {
algo = COUPLED_EPSILON;
if (argc>2) {
epsilon = atof(argv[2]);
crt++;
printf("Using epsilon %f\n",epsilon);
}
}
else
exit_error(argv[0]);
}
linkspeed_bps SERVICE1 = speedFromPktps(400);
linkspeed_bps SERVICE2;
if (argc>crt)
SERVICE2 = speedFromPktps(atoi(argv[crt++]));
else
SERVICE2 = speedFromPktps(400);
simtime_picosec RTT1=timeFromMs(100);
simtime_picosec RTT2;
if (argc>crt)
RTT2 = timeFromMs(atoi(argv[crt]));
else
RTT2 = timeFromMs(100);
mem_b BUFFER1=memFromPkt(RANDOM_BUFFER+timeAsSec(RTT1)*speedAsPktps(SERVICE1));//NUMFLOWS * targetwnd);
mem_b BUFFER2=memFromPkt(RANDOM_BUFFER+timeAsSec(RTT2)*speedAsPktps(SERVICE2));//NUMFLOWS * targetwnd);
srand(time(NULL));
// prepare the loggers
stringstream filename(ios_base::out);
filename << "../data/logout." << speedAsPktps(SERVICE2) << "pktps." <<timeAsMs(RTT2) << "ms."<< rand();
cout << "Outputting to " << filename.str() << endl;
Logfile logfile(filename.str(),eventlist);
logfile.setStartTime(timeFromSec(0.5));
QueueLoggerSimple logQueue = QueueLoggerSimple();
logfile.addLogger(logQueue);
// QueueLoggerSimple logPQueue1 = QueueLoggerSimple(); logfile.addLogger(logPQueue1);
//QueueLoggerSimple logPQueue3 = QueueLoggerSimple(); logfile.addLogger(logPQueue3);
QueueLoggerSimple logPQueue = QueueLoggerSimple();
logfile.addLogger(logPQueue);
MultipathTcpLoggerSimple mlogger = MultipathTcpLoggerSimple();
logfile.addLogger(mlogger);
//TrafficLoggerSimple logger;
//logfile.addLogger(logger);
SinkLoggerSampling sinkLogger = SinkLoggerSampling(timeFromMs(1000),eventlist);
logfile.addLogger(sinkLogger);
QueueLoggerSampling qs1 = QueueLoggerSampling(timeFromMs(1000),eventlist);
logfile.addLogger(qs1);
QueueLoggerSampling qs2 = QueueLoggerSampling(timeFromMs(1000),eventlist);
logfile.addLogger(qs2);
TcpLoggerSimple* logTcp = NULL;
logTcp = new TcpLoggerSimple();
logfile.addLogger(*logTcp);
// Build the network
Pipe pipe1(RTT1, eventlist);
pipe1.setName("pipe1");
logfile.writeName(pipe1);
Pipe pipe2(RTT2, eventlist);
pipe2.setName("pipe2");
logfile.writeName(pipe2);
Pipe pipe_back(timeFromMs(.1), eventlist);
pipe_back.setName("pipe_back");
logfile.writeName(pipe_back);
RandomQueue queue1(SERVICE1, BUFFER1, eventlist,&qs1,memFromPkt(RANDOM_BUFFER));
queue1.setName("Queue1");
logfile.writeName(queue1);
RandomQueue queue2(SERVICE2, BUFFER2, eventlist,&qs2,memFromPkt(RANDOM_BUFFER));
queue2.setName("Queue2");
logfile.writeName(queue2);
Queue pqueue2(SERVICE2*2, memFromPkt(FEEDER_BUFFER), eventlist,NULL);
pqueue2.setName("PQueue2");
//.........这里部分代码省略.........
示例5: while
ExWorkProcRetcode ExHbaseAccessDDLTcb::work()
{
short retcode = 0;
short rc = 0;
// if no parent request, return
if (qparent_.down->isEmpty())
return WORK_OK;
while (1)
{
switch (step_)
{
case NOT_STARTED:
{
matches_ = 0;
if (hbaseAccessTdb().accessType_ == ComTdbHbaseAccess::CREATE_)
step_ = CREATE_TABLE;
else if (hbaseAccessTdb().accessType_ == ComTdbHbaseAccess::DROP_)
step_ = DROP_TABLE;
else
step_ = HANDLE_ERROR;
}
break;
case CREATE_TABLE:
{
table_.val = hbaseAccessTdb().getTableName();
table_.len = strlen(hbaseAccessTdb().getTableName());
Queue * cfnl = hbaseAccessTdb().getColFamNameList();
cfnl->position();
HBASE_NAMELIST colFamList;
HbaseStr colFam;
while(NOT cfnl->atEnd())
{
char * cfName = (char*)cfnl->getCurr();
colFam.val = cfName;
colFam.len = strlen(cfName);
colFamList.insert(colFam);
cfnl->advance();
}
step_ = DONE;
}
break;
case DROP_TABLE:
{
step_ = DONE;
}
break;
case HANDLE_ERROR:
{
if (handleError(rc))
return rc;
step_ = DONE;
}
break;
case DONE:
{
if (handleDone(rc))
return rc;
step_ = NOT_STARTED;
return WORK_OK;
}
break;
}// switch
} // while
}
示例6: MessageQueue
#include <future>
#include <iostream>
using namespace std;
template<typename T>
class MessageQueue
{
private:
using Queue = vector<T>;
using QueueIterator = typename Queue::iterator;
Queue m_A;
Queue m_B;
Queue* m_Producer{ &m_A };
Queue* m_Consumer{ &m_B };
QueueIterator m_ConsumerIterator{ m_B.end() };
condition_variable& m_MessageCondition;
condition_variable m_ConsumptionFInished;
mutex m_MutexProducer;
mutex m_MutexConsumer;
unsigned int m_SwapCount{ 0 };
public:
MessageQueue(condition_variable& messageCondition)
:m_MessageCondition{ messageCondition }
{
示例7: Topology
/*
* PFabric topology with 144 hosts (16, 9, 4)
*/
PFabricTopology::PFabricTopology(
uint32_t num_hosts,
uint32_t num_agg_switches,
uint32_t num_core_switches,
double bandwidth,
uint32_t queue_type
) : Topology () {
uint32_t hosts_per_agg_switch = num_hosts / num_agg_switches;
this->num_hosts = num_hosts;
this->num_agg_switches = num_agg_switches;
this->num_core_switches = num_core_switches;
//Capacities
double c1 = bandwidth;
double c2 = hosts_per_agg_switch * bandwidth / num_core_switches;
// Create Hosts
for (uint32_t i = 0; i < num_hosts; i++) {
hosts.push_back(Factory::get_host(i, c1, queue_type, params.host_type));
}
// Create Switches
for (uint32_t i = 0; i < num_agg_switches; i++) {
AggSwitch* sw = new AggSwitch(i, hosts_per_agg_switch, c1, num_core_switches, c2, queue_type);
agg_switches.push_back(sw); // TODO make generic
switches.push_back(sw);
}
for (uint32_t i = 0; i < num_core_switches; i++) {
CoreSwitch* sw = new CoreSwitch(i + num_agg_switches, num_agg_switches, c2, queue_type);
core_switches.push_back(sw);
switches.push_back(sw);
}
//Connect host queues
for (uint32_t i = 0; i < num_hosts; i++) {
hosts[i]->queue->set_src_dst(hosts[i], agg_switches[i/16]);
//std::cout << "Linking Host " << i << " to Agg " << i/16 << "\n";
}
// For agg switches -- REMAINING
for (uint32_t i = 0; i < num_agg_switches; i++) {
// Queues to Hosts
for (uint32_t j = 0; j < hosts_per_agg_switch; j++) { // TODO make generic
Queue *q = agg_switches[i]->queues[j];
q->set_src_dst(agg_switches[i], hosts[i * 16 + j]);
//std::cout << "Linking Agg " << i << " to Host" << i * 16 + j << "\n";
}
// Queues to Core
for (uint32_t j = 0; j < num_core_switches; j++) {
Queue *q = agg_switches[i]->queues[j + 16];
q->set_src_dst(agg_switches[i], core_switches[j]);
//std::cout << "Linking Agg " << i << " to Core" << j << "\n";
}
}
//For core switches -- PERFECT
for (uint32_t i = 0; i < num_core_switches; i++) {
for (uint32_t j = 0; j < num_agg_switches; j++) {
Queue *q = core_switches[i]->queues[j];
q->set_src_dst(core_switches[i], agg_switches[j]);
//std::cout << "Linking Core " << i << " to Agg" << j << "\n";
}
}
}
示例8: main
int main() {
pc.baud(115200);
float temp;
pc.printf("Hello!");
//implement XBee communication
send.attach(&sendPackage,0.7);
//implement EMG signal processing
adc_aqr.attach(&adc_acquire,0.05);
adc_aqr_temp.attach(&adc_acquire_temp,0.05);
get_position.attach(&position_decide,0.05);
get_position_temp.attach(&position_decide_temp,0.05);
xbee.baud(57600);
rst = 0;
led1 = 0;
wait_ms(1);
rst = 1;
wait_ms(1);
led1 = 1;
led2 = 0;
// xbee send data
msg.id = 0;
msg.mode_send = 1;
msgIface.sendPacket( MsgTypeModeSend, (uint8_t*)&msg, sizeof(MsgModeSend) );
while ( !msgIface.sendComplete() ) {
msgIface.sendNow();
}
wait_ms(250);
led2 = 1;
wait_ms(250);
led2 = 0;
msg.id = 0;
msg.mode_send = 1;
msgIface.sendPacket( MsgTypeModeSend, (uint8_t*)&msg, sizeof(MsgModeSend) );
while ( !msgIface.sendComplete() ) {
msgIface.sendNow();
}
wait_ms(250);
led2 = 1;
wait_ms(250);
led2 = 0;
msg.id = 0;
msg.mode_send = 1;
msgIface.sendPacket( MsgTypeModeSend, (uint8_t*)&msg, sizeof(MsgModeSend) );
//Implement IMU function
imu_mpu6050.setAcceleroRange(MPU6050_ACCELERO_RANGE_2G); // set the scale of the accelerometer
imu_mpu6050.setGyroRange(MPU6050_GYRO_RANGE_250); // set the scale of the gyro
float angle_x;
float angle_y; // store the angle of x-axis and angle of y-axis
bool success_flag; // indicate the iic connection
success_flag = imu_hand.testCommunication(); // if successful, return 1
//train and get the train sample
init();
while(!success_flag) // wait until connection
{
myled = 1;
}
// while loop
t.start();
while(1) {
imu_hand.getAngleXY(&angle_x, &angle_y); // get angle_x and angle_y
myQueue.Put(&adc);
myQueue_temp.Put(&adc_temp);
//pc.printf("y: %f",angle_y);
if(pos==2&&pos==2&& angle_y>65)
{
if(mode_enable==1)
{
t.reset();
mode_enable=0;
pc.printf("SHOOT\r\n");
msg.id = 0;
msg.mode_send = SHOOT;
}
}
// pc.printf("time : %f\r\n", t.read());
// pc.printf("mode_enable : %d\r\n", mode_enable);
if(t.read()>3)
{
t.reset();
mode_enable=1;
}
if(pos==0&&pos_temp==0)
{
pc.printf("IDLE\r\n");
msg.id = 0;
//.........这里部分代码省略.........
示例9: main
int main (void) {
try {
Queue queue (5);
queue.push (10);
queue.push (20);
queue.push (30);
queue.push (40);
queue.push (50);
// queue.push (60);
cout << queue.pop () << endl; // 10
queue.push (60);
cout << queue.pop () << endl; // 20
cout << queue.pop () << endl; // 30
queue.push (70);
queue.push (80);
cout << queue.pop () << endl; // 40
cout << queue.pop () << endl; // 50
cout << queue.pop () << endl; // 60
cout << queue.pop () << endl; // 70
cout << queue.pop () << endl; // 80
// queue.pop ();
}
catch (exception& ex) {
cout << ex.what () << endl;
return -1;
}
return 0;
}
示例10: main
int main() {
try {
Queue<int> q;
q.add(1); q.add(2); q.add(3);
q.remove(); q.remove(); q.remove();
for (int i=10; i<=28; i++)
q.add(i);
Queue<int> r = q;
while (!q.empty()) {
cout << q.front() << ' ';
q.remove();
}
cout << endl;
while (!r.empty()) {
cout << r.front() << ' ';
r.remove();
}
cout << endl;
}
catch (const char* s) {
cout << "chyba: " << s << endl;
}
//system("PAUSE");
return 0;
}
示例11: main
int main(){
Queue a = Queue();
a.add("a");
cout << a.getUsed() << endl;
a.add("b");
a.add("c");
a.add("d");
cout << a.remove() << endl;
cout << a.remove() << endl;
cout << a.getUsed() << endl;
a.add("e");
a.add("f");
a.add("break");
cout << a.getUsed() << endl;
cout << a.remove() << endl;
cout << a.remove() << endl;
cout << a.remove() << endl;
a.add("fake");
cout << a.getUsed() << endl;
cout << a.remove() << endl;
cout << a.remove() << endl;
cout << a.remove() << endl;
cout << a.getUsed() << endl;
//system("pause");
return 0;
} //main()
示例12: memset
//.........这里部分代码省略.........
{
sprintf(stRta.szCodAut, getCodAutLocal(trx_data.CodTar()));
sprintf(stRta.szTermin, term_data.nro_caj_ca);
sprintf(stRta.szComerc, term_data.nro_com);
sprintf(stRta.szPlnIso, term_data.plan_iso);
sprintf(stRta.szNroLot, term_data.nro_lot);
sprintf(stRta.szFecOri, trx_data.FecOri());
sprintf(stRta.szTicOri, trx_data.NroTicOri());
sprintf(stRta.szPlanSF, term_data.plan_sf);
sprintf(stRta.szRespCA, "000");
switch (DBTipoProtocoloISO(term_data.nro_ca))
{
case PROT_ISO_AMEX:
sprintf(stRta.szProtoc, "A");
break;
default:
sprintf(stRta.szProtoc, "B");
break;
}
Armar_y_Enviar_Respuesta("00", &stRta);
}
else
{
sprintf(stRta.szRespCA, "103");
if ( (atoi(trx_data.CodTrx())==T_PAGO) || (atoi(trx_data.CodTrx())==T_DEVP) )
{
Armar_y_Enviar_Respuesta("11", &stRta);
}
else
{
Armar_y_Enviar_Respuesta("38", &stRta);
}
}
return OK;
}
else /* El vinculo esta activo */
{
/* Arma los datos para el heap */
mensaje_price->GetHeapData(&heap_data);
if (heap_data.anul_onl[0]=='1')
{
strcpy(heap_data.nro_term, CajVenta);
strcpy(heap_data.nro_trans, TrxVenta);
}
strcpy(heap_data.plan_sf, term_data.plan_sf);
strcpy(heap_data.nro_caj_ca,term_data.nro_caj_ca);
heap_data.orig_pid=orig_pid;
char idHeap[20];
/* Arma clave para el heap */
sprintf(idHeap,"%2.2s%3.3s%5.5s%8.8s",
term_data.nro_ca, term_data.nro_suc, term_data.nro_caj, mensaje_iso->GetField(11));
/* Pone los datos en el heap */
LogAlarm.Put(95, "PriceOn: idHeap [%s] \n", idHeap);
LogAlarm.Put(95, "PriceOn: anul_onl[%s] plan_iso[%s] plan_sf[%s] nro_com[%s]\n",
heap_data.anul_onl, heap_data.plan_iso, heap_data.plan_sf, heap_data.nro_com);
//LogAlarm.Put(0, "PriceOn: heap_data.rowid [%s] \n", heap_data.rowid);
ret=Heap.PutData(idHeap,(char *)&heap_data, sizeof(heap_data));
if (ret==NOOK)
{
LogAlarm.Put(0, "PriceOn: ERROR (%d) al poner info en Heap\n", Heap.GetErrno());
return NOOK;
}
/* Registrar en la TimeoutQueue */
Cfg.GetItem("TimeOutDaemon", "MsgTimeOut1", aux_str);
ret=timeout_queue.SetTimeOut(idHeap,atoi(aux_str), GetType(), "");
if (ret==NOOK)
{
LogAlarm.Put(0, "PriceOn: ERROR (%d) al agregar a TimeOutQueue!!\n", timeout_queue.GetErrno());
return NOOK;
}
/* Aplana el mensaje */
memset(msg_str,'\0',sizeof(msg_str));
len=mensaje_iso->GetMsgString(msg_str);
/* Envia el mensaje al CA */
LogAlarm.Put(0, "PriceOn: Envia a X.25. CAut [%s]\n", term_data.nro_ca);
ret=XQueue.SendMsg(atoi(term_data.nro_ca)+1, msg_str, len);
if (ret==OK)
{
/* Bloquea la caja */
ret = P.SetPosBusy(term_data.nro_ca, term_data.nro_suc, term_data.nro_caj);
if (ret!=OK)
{
LogAlarm.Put(0, "PriceOn: No se pudo bloquear la caja!!\n");
}
LogAlarm.Put(2, "PriceOn: Respuesta enviada OK\n");
}
else
{
LogAlarm.Put(0, "PriceOn: ERROR al enviar a X25\n");
return NOOK;
}
}
return OK;
}
示例13: track_queue
void Acknowledge::
track_queue (Address const& addr, Queue& q, Messages& msgs)
{
unsigned short max_payload_size (
params_.max_packet_size () - max_service_size);
u32 max_elem (NAK::max_count (max_payload_size));
u32 count (0);
Queue::iterator i (q.begin ()), e (q.end ());
// Track existing losses.
//
while (i != e)
{
auto_ptr<NAK> nak (new NAK (addr));
// Inner loop that fills NAK profile with up to max_elem elements.
//
for (; i != e && nak->count () < max_elem; ++i)
{
u64 sn ((*i).ext_id_);
Descr& d = (*i).int_id_;
if (d.lost ())
{
d.timer (d.timer () - 1);
if (d.timer () == 0)
{
//@@ Need exp fallback.
//
d.nak_count (d.nak_count () + 1);
d.timer ((d.nak_count () + 1) * params_.nak_timeout ());
nak->add (sn);
++count;
// cerr << 6 << "NAK # " << d.nak_count () << ": "
// << addr << " " << sn << endl;
}
}
}
// Send this NAK.
//
if (nak->count ())
{
// cerr << 5 << "NAK: " << addr << " " << nak->count () << " sns"
// << endl;
Message_ptr m (new Message);
m->add (Profile_ptr (nak.release ()));
msgs.push_back (m);
}
}
// Detect and record new losses.
//
for (u64 sn (q.sn () + 1), end (q.max_sn ()); sn < end; ++sn)
{
if (q.find (sn) == -1)
{
q.bind (sn, Descr (1));
}
}
}
示例14: close
void close() {
AutoLock hold(lock);
closed = true;
queue.clear();
JS_NOTIFY_ALL_CONDVAR(condvar);
}
示例15: display
void display() {
cout << iq.front() << " " << iq.size() << " ";
cout << lfq.front() << " " << lfq.size() << endl;
}