void LLInspectObject::onClickTakeFreeCopy() { LLObjectSelection* selection = LLSelectMgr::getInstance()->getSelection(); if (!selection) return; LLSelectNode* nodep = selection->getFirstRootNode(); if (!nodep) return; // Figure out if this is a "free buy" or a "take copy" bool for_copy = anyone_copy_selection(nodep); // Prefer to just take a free copy if (for_copy) { handle_take_copy(); } else { // Buy for free (confusing, but that's how it is) handle_buy(); } closeFloater(); }
// static void LLToolPie::selectionPropertiesReceived() { // Make sure all data has been received. // This function will be called repeatedly as the data comes in. if (!LLSelectMgr::getInstance()->selectGetAllValid()) { return; } LLObjectSelection* selection = LLToolPie::getInstance()->getLeftClickSelection(); if (selection) { LLViewerObject* selected_object = selection->getPrimaryObject(); // since we don't currently have a way to lock a selection, it could have changed // after we initially clicked on the object if (selected_object == LLToolPie::getInstance()->getClickActionObject()) { U8 click_action = LLToolPie::getInstance()->getClickAction(); switch (click_action) { case CLICK_ACTION_BUY: handle_buy(NULL); break; case CLICK_ACTION_PAY: handle_give_money_dialog(); break; case CLICK_ACTION_OPEN: handle_object_open(); break; default: break; } } } LLToolPie::getInstance()->resetSelection(); }
void testall() { //initial start up machine *p_machine_test=malloc(sizeof(machine)); memset(p_machine_test,0,sizeof(machine)); p_machine_test->log = fopen("log.txt", "w"); p_machine_test->item_num=3; int32_t i; p_machine_test->item= malloc(p_machine_test->item_num*sizeof(struct item_info)); p_machine_test->item[0].label="APPLE"; p_machine_test->item[1].label="BANANA"; p_machine_test->item[2].label="CARROT"; for (i=0;i<3;i++) { p_machine_test->item[i].num=3; } p_machine_test->item[0].price=1; p_machine_test->item[1].price=22; p_machine_test->item[2].price=10; //start up finished printf("INITIAL MACHINE FINISHED\n"); //for testall we only test the handle_client function //for register , prepare_socket , //we leave it to test in really communication or makefile test printf("buy A1:\n"); printf("the torecv detail:\n"); // struct sockaddr_storage *client_addr=NULL; struct ser_tran torecv; torecv.code=1; torecv.seq_num=htonl(10); torecv.item_index=1; torecv.money_available=htonl(100); int client = 0; handle_buy(&torecv,client,p_machine_test); printf("what you should see: 04 00 00 00 0a 00 00 00 01 05 01 41 50 50 4c 45\n"); printf("code: 04 \nseq: 00 00 00 0a \nprice:00 00 00 01 \nname length: 05 \nstatus code: \ 01 \nname: 41 50 50 4c 45\n"); printf("\nbuy A1 again:\n"); printf("the torecv detail:\n"); torecv.code=1; torecv.seq_num=htonl(20); torecv.item_index=1; torecv.money_available=htonl(100); handle_buy(&torecv,client,p_machine_test); printf("what you should see: 04 00 00 00 14 00 00 00 02 05 01 41 50 50 4c 45\n"); printf("code: 04 \nseq: 00 00 00 0a \nprice:00 00 00 02 \nname length: 05 \nstatus code: \ 01 \nname: 41 50 50 4c 45\n"); printf("\nbuy A1 again:\n"); printf("the torecv detail:\n"); torecv.code=1; torecv.seq_num=htonl(30); torecv.item_index=1; torecv.money_available=htonl(100); handle_buy(&torecv,client,p_machine_test); printf("what you should see is: 04 00 00 00 1e 00 00 00 1b 05 01 41 50 50 4c 45\n"); printf("code: 04 \nseq: 00 00 00 1e \nprice:00 00 00 1b \nname length: 05 \nstatus code: \ 01 \nname: 41 50 50 4c 45\n"); /* for(i=0;i<p_machine_test->item_num;i++) { free(p_machine_test->item[i].label); } */ free(p_machine_test->item); fclose(p_machine_test->log); free(p_machine_test); printf("\nTest has passed!\n"); }
void LLInspectObject::onClickBuy() { handle_buy(); closeFloater(); }
/* * Authors: Weiyan Lin * * Purpose: It makes a version-independent TCP socket and establishes * the connection with the User * then it would use handle_function to do the buying process. * * Expected input: It takes the machine informationi, argc ,argv, * which contains the ip address and port information of the user, * and a ser_tran packet, * which contains the translated information from Authentication Center * * * Implementation details: * * connect_user function would initial the connection * between the Authentication Center and the vending_server. * Once connection established, the receive_center function would use * handle_buy function to handle the buying process. * * */ void connect_user(machine* p_machine,struct ser_tran *torecv, int argc, char *argv[]) { // initial the connect with the user // criteria for address match struct addrinfo lookup_addr; // zero out the structure memset(&lookup_addr, 0, sizeof(struct addrinfo)); // set address family lookup_addr.ai_family = AF_UNSPEC; // set sockets type lookup_addr.ai_socktype = SOCK_STREAM; // set protocol type lookup_addr.ai_protocol = IPPROTO_TCP; // get addresses struct addrinfo *send_addr; if (getaddrinfo(argv[2], argv[3], &lookup_addr, &send_addr) != 0) { vending_exit_with_error("getaddrinfo failed",p_machine); } int sock_s = -1; // Create a reliable, stream socket using TCP sock_s = socket(send_addr->ai_family, send_addr->ai_socktype,send_addr->ai_protocol); // Socket creation failed; try next address if (sock_s < 0) { vending_exit_with_error("setup socket failed, unable to connect",p_machine); } // Establish the connection if(connect(sock_s, send_addr->ai_addr,send_addr->ai_addrlen) <0) { vending_exit_with_error("connect failed",p_machine); } //handle the do buying do process depend on the message we get //if it is a status message //we would use a loop to send all the item information to //the user if (torecv->code==STATUS_CODE) { int index=p_machine->item_num; torecv->item_index=1; int i=0; for(i=0;i<index;i++) { handle_buy(torecv,sock_s,p_machine); torecv->item_index+=1; torecv->seq_num+=1; } } // if it is not a status message // we only need to run the program one time else { handle_buy(torecv,sock_s,p_machine); } free(send_addr); //close connection close(sock_s); sleep(2); }