/******************************************************************************
 * Copyright 2013-2014 Espressif Systems (Wuxi)
 *
 * FileName: espconn_tcp.c
 *
 * Description: tcp proto interface
 *
 * Modification history:
 *     2014/3/31, v1.0 create this file.
*******************************************************************************/

#include "lwip/netif.h"
#include "lwip/inet.h"
#include "netif/etharp.h"
#include "lwip/tcp.h"
#include "lwip/ip.h"
#include "lwip/init.h"
#include "lwip/tcp_impl.h"
#include "lwip/memp.h"

#include "ets_sys.h"
#include "os_type.h"
//#include "os.h"
#include "lwip/mem.h"
#include "lwip/app/espconn_tcp.h"

#ifdef MEMLEAK_DEBUG
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
#endif

extern espconn_msg *plink_active;
extern espconn_msg *pserver_list;
extern struct espconn_packet pktinfo[2];
extern struct tcp_pcb ** const tcp_pcb_lists[];

os_event_t espconn_TaskQueue[espconn_TaskQueueLen];

static err_t
espconn_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
static void
espconn_client_close(void *arg, struct tcp_pcb *pcb,u8 type);

static err_t
espconn_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
static void
espconn_server_close(void *arg, struct tcp_pcb *pcb,u8 type);

///////////////////////////////common function/////////////////////////////////
/******************************************************************************
 * FunctionName : espconn_kill_oldest
 * Description  : kill the oldest TCP block
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
espconn_kill_oldest(void)
{
	struct tcp_pcb *pcb, *inactive;
	u32_t inactivity;

	inactivity = 0;
	inactive = NULL;
	/* Go through the list of TIME_WAIT pcbs and get the oldest pcb. */
	for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
		if ((u32_t) (tcp_ticks - pcb->tmr) >= inactivity) {
			inactivity = tcp_ticks - pcb->tmr;
			inactive = pcb;
		}
	}
	if (inactive != NULL) {
		tcp_abort(inactive);
	}

	/* Go through the list of FIN_WAIT_2 pcbs and get the oldest pcb. */
	inactivity = 0;
	inactive = NULL;
	for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
		if (pcb->state == FIN_WAIT_1 || pcb->state == FIN_WAIT_2){
			if ((u32_t) (tcp_ticks - pcb->tmr) >= inactivity) {
				inactivity = tcp_ticks - pcb->tmr;
				inactive = pcb;
			}
		}
	}
	/*Purges the PCB, removes it from a PCB list and frees the memory*/
	if (inactive != NULL) {
		tcp_pcb_remove(&tcp_active_pcbs, inactive);
		memp_free(MEMP_TCP_PCB, inactive);
	}

	/* Go through the list of LAST_ACK pcbs and get the oldest pcb. */
	inactivity = 0;
	inactive = NULL;
	for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
		if (pcb->state == LAST_ACK) {
			if ((u32_t) (tcp_ticks - pcb->tmr) >= inactivity) {
				inactivity = tcp_ticks - pcb->tmr;
				inactive = pcb;
			}
		}
	}
	/*Purges the PCB, removes it from a PCB list and frees the memory*/
	if (inactive != NULL) {
		tcp_pcb_remove(&tcp_active_pcbs, inactive);
		memp_free(MEMP_TCP_PCB, inactive);
	}
}

/******************************************************************************
 * FunctionName : espconn_kill_oldest_pcb
 * Description  : find the oldest TCP block by state
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR espconn_kill_oldest_pcb(void)
{
	struct tcp_pcb *cpcb = NULL;
	uint8 i = 0;
	uint8 num_tcp_fin = 0;
	for(i = 2; i < 4; i ++){
		for (cpcb = *tcp_pcb_lists[i]; cpcb != NULL; cpcb = cpcb->next) {
			if (cpcb->state == TIME_WAIT){
				num_tcp_fin ++;
				if (num_tcp_fin == MEMP_NUM_TCP_PCB)
					break;
			}

			if (cpcb->state == FIN_WAIT_1 || cpcb->state == FIN_WAIT_2 || cpcb->state == LAST_ACK){
				num_tcp_fin++;
				if (num_tcp_fin == MEMP_NUM_TCP_PCB)
					break;
			}
		}

		if (num_tcp_fin == MEMP_NUM_TCP_PCB){
			num_tcp_fin = 0;
			espconn_kill_oldest();
		} else if (cpcb == NULL){
			num_tcp_fin = 0;
		}
	}
}

/******************************************************************************
 * FunctionName : espconn_kill_pcb
 * Description  : kill all the TCP block by port
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR espconn_kill_pcb(u16_t port)
{
	struct tcp_pcb *cpcb = NULL;
	uint8 i = 0;
	struct tcp_pcb *inactive = NULL;
	struct tcp_pcb *prev = NULL;
	u8_t pcb_remove;
	/* Check if the address already is in use (on all lists) */
	for (i = 1; i < 4; i++) {
		cpcb = *tcp_pcb_lists[i];
		while(cpcb != NULL){
			pcb_remove = 0;
			if (cpcb->local_port == port) {
				++pcb_remove;
			}
			/* If the PCB should be removed, do it. */
			if (pcb_remove) {
				/* Remove PCB from tcp_pcb_lists list. */
				inactive = cpcb;
				cpcb = inactive->next;
				tcp_pcb_remove(tcp_pcb_lists[i], inactive);
				memp_free(MEMP_TCP_PCB, inactive);
			} else {
				cpcb = cpcb->next;
			}
		}
	}
}

/******************************************************************************
 * FunctionName : espconn_find_current_pcb
 * Description  : find the TCP block which option
 * Parameters   : pcurrent_msg -- the node in the list which active
 * Returns      : TCP block point
*******************************************************************************/
struct tcp_pcb *ICACHE_FLASH_ATTR espconn_find_current_pcb(espconn_msg *pcurrent_msg)
{
	uint16 local_port = pcurrent_msg->pcommon.local_port;
	uint32 local_ip = pcurrent_msg->pcommon.local_ip;
	uint16 remote_port = pcurrent_msg->pcommon.remote_port;
	uint32 remote_ip = *((uint32*)&pcurrent_msg->pcommon.remote_ip);
	struct tcp_pcb *find_pcb = NULL;
	if (pcurrent_msg ->preverse == NULL){/*Find the server's TCP block*/
		if (local_ip == 0|| local_port == 0) return pcurrent_msg->pcommon.pcb;

		for (find_pcb = tcp_active_pcbs; find_pcb != NULL; find_pcb = find_pcb->next){
			if ((find_pcb->remote_port == remote_port) && (find_pcb->remote_ip.addr == remote_ip) &&
				(find_pcb->local_port == local_port) && (find_pcb->local_ip.addr == local_ip))
				return find_pcb;
		}

		for (find_pcb = tcp_tw_pcbs; find_pcb != NULL; find_pcb = find_pcb->next){
			if ((find_pcb->remote_port == remote_port) && (find_pcb->remote_ip.addr == remote_ip) &&
				(find_pcb->local_port == local_port) && (find_pcb->local_ip.addr == local_ip))
				return find_pcb;
		}
	} else {/*Find the client's TCP block*/
		if (remote_ip == 0|| remote_port == 0) return pcurrent_msg->pcommon.pcb;

		for (find_pcb = tcp_active_pcbs; find_pcb != NULL; find_pcb = find_pcb->next){
			if ((find_pcb->remote_port == remote_port) && (find_pcb->remote_ip.addr == remote_ip))
				return find_pcb;
		}

		for (find_pcb = tcp_tw_pcbs; find_pcb != NULL; find_pcb = find_pcb->next){
			if ((find_pcb->remote_port == remote_port) && (find_pcb->remote_ip.addr == remote_ip))
				return find_pcb;
		}
	}
	return NULL;
}

/******************************************************************************
 * FunctionName : espconn_tcp_memp_free
 * Description  : frees the connection memory in the server mode
 * Parameters   : arg -- Additional argument to pass to the function
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR espconn_tcp_memp_free(espconn_msg *pmemp)
{
	struct espconn *espconn = NULL;
	if (pmemp == NULL)
		return;

	/*Enable block option for fetches the data proactive*/
    if (espconn_manual_recv_disabled(pmemp))
        espconn_list_delete(&plink_active, pmemp);

	if (pmemp->espconn_mode == ESPCONN_TCPSERVER_MODE){
		if (pmemp->pespconn != NULL && pmemp->pespconn->proto.tcp != NULL)
			os_free(pmemp->pespconn->proto.tcp);
		pmemp->pespconn->proto.tcp = NULL;

		os_free(pmemp->pespconn);
		pmemp->pespconn = NULL;
	}

	if (pmemp->readbuf != NULL){
		ringbuf_free(&pmemp->readbuf);
	}
	os_free(pmemp);
	pmemp = NULL;
}

/******************************************************************************
 * FunctionName : espconn_tcp_reconnect
 * Description  : reconnect with host
 * Parameters   : arg -- Additional argument to pass to the callback function
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
espconn_tcp_reconnect(void *arg)
{
	espconn_msg *precon_cb = arg;
	sint8 re_err = 0;
	espconn_buf *perr_buf = NULL;
	espconn_buf *perr_back = NULL;
	espconn_kill_oldest_pcb();
	if (precon_cb != NULL) {
		struct espconn *espconn = precon_cb->preverse;

		re_err = precon_cb->pcommon.err;
		if (precon_cb->pespconn != NULL){
			if (espconn != NULL){/*Process the server's message block*/
				if (precon_cb->pespconn->proto.tcp != NULL){
					espconn_copy_partial(espconn, precon_cb->pespconn);
				}
			} else {/*Process the client's message block*/
				espconn = precon_cb->pespconn;
			}
		}

		/*to prevent memory leaks, ensure that each allocated is deleted*/
		perr_buf = precon_cb->pcommon.pbuf;
		while (perr_buf != NULL){
			perr_back = perr_buf;
			perr_buf = perr_back->pnext;
			espconn_pbuf_delete(&precon_cb->pcommon.pbuf,perr_back);
			os_free(perr_back);
			perr_back = NULL;
		}
		os_bzero(&pktinfo[1], sizeof(struct espconn_packet));
		os_memcpy(&pktinfo[1], (void*)&precon_cb->pcommon.packet_info, sizeof(struct espconn_packet));

		if (espconn && espconn->proto.tcp && espconn->proto.tcp->reconnect_callback != NULL) {
			espconn->proto.tcp->reconnect_callback(espconn, re_err);
		}

		/*frees the connection memory*/
		espconn_tcp_memp_free(precon_cb);
	} else {
		espconn_printf("espconn_tcp_reconnect err\n");
	}
}

/******************************************************************************
 * FunctionName : espconn_tcp_disconnect
 * Description  : disconnect with host
 * Parameters   : arg -- Additional argument to pass to the callback function
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
espconn_tcp_disconnect_successful(void *arg)
{
	espconn_msg *pdiscon_cb = arg;
	sint8 dis_err = 0;
	espconn_buf *pdis_buf = NULL;
	espconn_buf *pdis_back = NULL;
	espconn_kill_oldest_pcb();
	if (pdiscon_cb != NULL) {
		struct espconn *espconn = pdiscon_cb->preverse;

		dis_err = pdiscon_cb->pcommon.err;
		if (pdiscon_cb->pespconn != NULL){
			struct tcp_pcb *pcb = NULL;
			if (espconn != NULL){/*Process the server's message block*/
				if (pdiscon_cb->pespconn->proto.tcp != NULL && espconn->proto.tcp){
					espconn_copy_partial(espconn, pdiscon_cb->pespconn);
				}
			} else {/*Process the client's message block*/
				espconn = pdiscon_cb->pespconn;
			}

			/*process the current TCP block*/
			pcb = espconn_find_current_pcb(pdiscon_cb);
			if (pcb != NULL){
				if (espconn_reuse_disabled(pdiscon_cb)) {
					struct tcp_pcb *cpcb = NULL;
					struct tcp_pcb *prev = NULL;
					u8_t pcb_remove;
					espconn_printf("espconn_tcp_disconnect_successful %d, %d\n",	pcb->state, pcb->local_port);
					cpcb = tcp_tw_pcbs;
					while (cpcb != NULL) {
						pcb_remove = 0;
						if (cpcb->local_port == pcb->local_port) {
							++pcb_remove;
						}
						/* If the PCB should be removed, do it. */
						if (pcb_remove) {
							struct tcp_pcb *backup_pcb = NULL;
							tcp_pcb_purge(cpcb);
							/* Remove PCB from tcp_tw_pcbs list. */
							if (prev != NULL) {
								LWIP_ASSERT("espconn_tcp_delete: middle cpcb != tcp_tw_pcbs",cpcb != tcp_tw_pcbs);
								prev->next = cpcb->next;
							} else {
								/* This PCB was the first. */
								LWIP_ASSERT("espconn_tcp_delete: first cpcb == tcp_tw_pcbs",tcp_tw_pcbs == cpcb);
								tcp_tw_pcbs = cpcb->next;
							}
							backup_pcb = cpcb;
							cpcb = cpcb->next;
							memp_free(MEMP_TCP_PCB, backup_pcb);
						} else {
							prev = cpcb;
							cpcb = cpcb->next;
						}
					}

				} else {
					tcp_arg(pcb, NULL);
					tcp_err(pcb, NULL);
				}
			}
		}

		/*to prevent memory leaks, ensure that each allocated is deleted*/
		pdis_buf = pdiscon_cb->pcommon.pbuf;
		while (pdis_buf != NULL) {
			pdis_back = pdis_buf;
			pdis_buf = pdis_back->pnext;
			espconn_pbuf_delete(&pdiscon_cb->pcommon.pbuf, pdis_back);
			os_free(pdis_back);
			pdis_back = NULL;
		}
		os_bzero(&pktinfo[0], sizeof(struct espconn_packet));
		os_memcpy(&pktinfo[0], (void*)&pdiscon_cb->pcommon.packet_info, sizeof(struct espconn_packet));

		if (espconn->proto.tcp && espconn->proto.tcp->disconnect_callback != NULL) {
			espconn->proto.tcp->disconnect_callback(espconn);
		}

		/*frees the connection memory*/
		espconn_tcp_memp_free(pdiscon_cb);
	} else {
		espconn_printf("espconn_tcp_disconnect err\n");
	}
}

/******************************************************************************
 * FunctionName : espconn_Task
 * Description  : espconn processing task
 * Parameters   : events -- contain the espconn processing data
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
espconn_Task(os_event_t *events)
{
	espconn_msg *plist = NULL;
	bool active_flag = false;
	espconn_msg *task_msg = NULL;
	struct espconn *pespconn = NULL;

	task_msg = (espconn_msg *) events->par;
	/*find the active connection node*/
	for (plist = plink_active; plist != NULL; plist = plist->pnext){
		if (task_msg == plist) {
			active_flag = true;
			break;
		}
	}

	if (active_flag){
		switch (events->sig) {
			case SIG_ESPCONN_WRITE: {
				pespconn = task_msg->pespconn;
				if (pespconn == NULL) {
					return;
				}

				if (pespconn->proto.tcp->write_finish_fn != NULL) {
					pespconn->proto.tcp->write_finish_fn(pespconn);
				}
			}
				break;
			case SIG_ESPCONN_ERRER:
				/*remove the node from the client's active connection list*/
			    if (espconn_manual_recv_enabled(task_msg))
			        espconn_list_delete(&plink_active, task_msg);
				espconn_tcp_reconnect(task_msg);
				break;
			case SIG_ESPCONN_CLOSE:
				/*remove the node from the client's active connection list*/
			    if (espconn_manual_recv_enabled(task_msg))
			        espconn_list_delete(&plink_active, task_msg);
				espconn_tcp_disconnect_successful(task_msg);
				break;
			default:
				break;
		}
	}
}

/******************************************************************************
 * FunctionName : espconn_tcp_sent
 * Description  : sent data for client or server
 * Parameters   : void *arg -- client or server to send
 *                uint8* psent -- Data to send
 *                uint16 length -- Length of data to send
 * Returns      : return espconn error code.
 * - ESPCONN_OK. Successful. No error occured.
 * - ESPCONN_MEM. Out of memory.
 * - ESPCONN_RTE. Could not find route to destination address.
 * - More errors could be returned by lower protocol layers.
*******************************************************************************/
err_t ICACHE_FLASH_ATTR
espconn_tcp_sent(void *arg, uint8 *psent, uint16 length)
{
	espconn_msg *ptcp_sent = arg;
    struct tcp_pcb *pcb = NULL;
    err_t err = 0;
    u16_t len = 0;
    u8_t data_to_send = false;

    espconn_printf("espconn_tcp_sent ptcp_sent %p psent %p length %d\n", ptcp_sent, psent, length);

    /*Check the parameters*/
    if (ptcp_sent == NULL || psent == NULL || length == 0) {
        return ESPCONN_ARG;
    }

    /*Set the packet length depend on the sender buffer space*/
    pcb = ptcp_sent->pcommon.pcb;
    if (tcp_sndbuf(pcb) < length) {
        len = tcp_sndbuf(pcb);
    } else {
        len = length;
        LWIP_ASSERT("length did not fit into uint16!", (len == length));
    }

    if (len > (2*pcb->mss)) {
        len = 2*pcb->mss;
    }

    /*Write data for sending, but does not send it immediately*/
	do {
		espconn_printf("espconn_tcp_sent writing %d bytes %p\n", len, pcb);
		if (espconn_copy_disabled(ptcp_sent))
			err = tcp_write(pcb, psent, len, 1);
		else
			err = tcp_write(pcb, psent, len, 0);

        if (err == ERR_MEM) {
			if(len < 3)
				len--;
			else
            	len /= 2;
        }

    } while (err == ERR_MEM && len > 0);

	/*Find out what we can send and send it, offset the buffer point for next send*/
    if (err == ERR_OK) {
    	ptcp_sent->pcommon.ptail->punsent = psent + len;
		ptcp_sent->pcommon.ptail->unsent = length - len;
		err = tcp_output(pcb);
		/*If enable the copy option, change the flag for next write*/
		if (espconn_copy_disabled(ptcp_sent)){
			if (ptcp_sent->pcommon.ptail->unsent == 0) {
				ptcp_sent->pcommon.write_flag = true;
				ets_post(espconn_TaskPrio, SIG_ESPCONN_WRITE, (uint32_t)ptcp_sent);
			}
		}
        espconn_printf("espconn_tcp_sent %d\n", err);
    }
    return err;
}

/******************************************************************************
 * FunctionName : espconn_close
 * Description  : The connection has been successfully closed.
 * Parameters   : arg -- Additional argument to pass to the callback function
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR espconn_tcp_disconnect(espconn_msg *pdiscon,u8 type)
{
	if (pdiscon != NULL){
		/*disconnect with the host by send the FIN frame*/
		if (pdiscon->preverse != NULL)
			espconn_server_close(pdiscon, pdiscon->pcommon.pcb,type);
		else
			espconn_client_close(pdiscon, pdiscon->pcommon.pcb,type);
	} else{
		espconn_printf("espconn_tcp_disconnect err.\n");
	}
}

/******************************************************************************
 * FunctionName : espconn_tcp_recv
 * Description  : Data has been received on this pcb.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb which received data
 *                p -- The received data (or NULL when the connection has been closed!)
 *                err -- An error code if there has been an error receiving
 * Returns      : ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
    espconn_msg *precv_cb = arg;
    struct pbuf *pthis = NULL;
    uint8_t *ring = NULL;
    size_t  bytes_used = 0;

    tcp_arg(pcb, arg);

    if (precv_cb->readbuf == NULL) {
        precv_cb->readbuf = ringbuf_new(TCP_WND);
        if (precv_cb->readbuf == NULL)
            return ESPCONN_MEM;
    }

    if (err == ERR_OK) {
        precv_cb->pcommon.recv_check = 0;
        if (p != NULL) {
            /*store the data to the adapter for application fetches it proactive*/
            for (pthis = p; pthis != NULL ; pthis = pthis->next) {
                ring = ringbuf_memcpy_into(precv_cb->readbuf, pthis->payload, pthis->len);
                if (ring)
                    pbuf_free(pthis);
                else
                    break;
            }
            bytes_used = ringbuf_bytes_used(precv_cb->readbuf);

            /*switch the state of espconn for application process*/
            precv_cb->pespconn->state = ESPCONN_READ;
            precv_cb->pcommon.pcb = pcb;
            if (precv_cb->pespconn->recv_callback != NULL) {
                precv_cb->pespconn->recv_callback(precv_cb->pespconn, NULL, bytes_used);
            }

            /*switch the state of espconn for next packet copy*/
            if (pcb->state == ESTABLISHED)
                precv_cb->pespconn->state = ESPCONN_CONNECT;
        } else {
            if (precv_cb->preverse) {
                espconn_server_close(precv_cb, pcb, 0);
            } else {
                espconn_client_close(precv_cb, pcb, 0);
            }
        }
    }

    return ERR_OK;
}

///////////////////////////////client function/////////////////////////////////
/******************************************************************************
 * FunctionName : espconn_client_close
 * Description  : The connection shall be actively closed.
 * Parameters   : pcb -- Additional argument to pass to the callback function
 *                pcb -- the pcb to close
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
espconn_client_close(void *arg, struct tcp_pcb *pcb, u8 type)
{
    err_t err;
    espconn_msg *pclose = arg;

	pclose->pcommon.pcb = pcb;
	/*avoid recalling the disconnect function*/
	tcp_recv(pcb, NULL);

	if(type == 0)
		err = tcp_close(pcb);
	else {
		tcp_sent(pcb, NULL);
		tcp_err(pcb, NULL);
		tcp_abort(pcb);
		err = ERR_OK;
	}

	if (err != ERR_OK) {
		/* closing failed, try again later */
		tcp_recv(pcb, espconn_client_recv);
	} else {
		/* closing succeeded */
		if (type == 0) {
			tcp_sent(pcb, NULL);
			tcp_err(pcb, NULL);
		}
		/*switch the state of espconn for application process*/
		pclose->pespconn->state = ESPCONN_CLOSE;
		ets_post(espconn_TaskPrio, SIG_ESPCONN_CLOSE, (uint32_t)pclose);
	}
}

//***********Code for WIFI_BLOCK from upper**************
sint8 ICACHE_FLASH_ATTR
espconn_recv_hold(struct espconn *pespconn)
{
	//1st, according to espconn code, have to find out the escpconn_msg by pespconn;
	espconn_msg *pnode = NULL;
	bool value = false;
    if (pespconn == NULL) {
        return ESPCONN_ARG;
    }
    value = espconn_find_connection(pespconn, &pnode);
	if(value != true)
	{
		os_printf("RecvHold, By pespconn,find conn_msg fail\n");
		return ESPCONN_ARG;
	}

	//2nd, the actual operation
	if(pnode->recv_hold_flag == 0)
	{
		pnode->recv_hold_flag = 1;
		pnode->recv_holded_buf_Len = 0;
	}
	return ESPCONN_OK;
}

sint8 ICACHE_FLASH_ATTR
espconn_recv_unhold(struct espconn *pespconn)
{
	//1st, according to espconn code, have to find out the escpconn_msg by pespconn;
	espconn_msg *pnode = NULL;
	bool value = false;
    if (pespconn == NULL) {
        return ESPCONN_ARG;
    }
    value = espconn_find_connection(pespconn, &pnode);
	if(value != true)
	{
		os_printf("RecvHold, By pespconn,find conn_msg fail\n");
		return ESPCONN_ARG;
	}

	//2nd, the actual operation
	if(pnode->recv_hold_flag == 1)
	{
		if(pespconn->type == ESPCONN_TCP) {
			tcp_recved(pnode->pcommon.pcb, pnode->recv_holded_buf_Len);
		}
		pnode->recv_holded_buf_Len = 0;
		pnode->recv_hold_flag = 0;
	}
	return ESPCONN_OK;
}

//***********Code for WIFI_BLOCK from upper**************
sint8 ICACHE_FLASH_ATTR
espconn_lock_recv(espconn_msg *plockmsg)
{
	if (plockmsg == NULL || plockmsg->pespconn == NULL) {
		return ESPCONN_ARG;
	}

	if (plockmsg->pespconn->recv_callback == NULL){
		if (plockmsg->readbuf == NULL){
			plockmsg->readbuf = ringbuf_new(TCP_WND);
			if (plockmsg->readbuf == NULL)
				return ESPCONN_MEM;
		}
		return espconn_recv_hold(plockmsg->pespconn);
	}

	return ESPCONN_OK;
}

sint8 ICACHE_FLASH_ATTR
espconn_unlock_recv(espconn_msg *punlockmsg)
{
	if (punlockmsg == NULL || punlockmsg->pespconn == NULL) {
		return ESPCONN_ARG;
	}

	if (punlockmsg->pespconn->recv_callback != NULL)
		return espconn_recv_unhold(punlockmsg->pespconn);

	return ESPCONN_OK;
}
/******************************************************************************
 * FunctionName : espconn_client_recv
 * Description  : Data has been received on this pcb.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb which received data
 *                p -- The received data (or NULL when the connection has been closed!)
 *                err -- An error code if there has been an error receiving
 * Returns      : ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_client_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
	espconn_msg *precv_cb = arg;

	tcp_arg(pcb, arg);
	/*lock the window because of application layer don't need the data*/
	espconn_lock_recv(precv_cb);

    if (p != NULL) {
    	/*To update and advertise a larger window*/
		if(precv_cb->recv_hold_flag == 0)
        	tcp_recved(pcb, p->tot_len);
		else
			precv_cb->recv_holded_buf_Len += p->tot_len;
    }

    if (precv_cb->pespconn->recv_callback != NULL){
		if (err == ERR_OK && p != NULL) {
			char *pdata = NULL;
			u16_t length = 0;
			/*Copy the contents of a packet buffer to an application buffer.
			 *to prevent memory leaks, ensure that each allocated is deleted*/
			pdata = (char *)os_zalloc(p ->tot_len + 1);
			length = pbuf_copy_partial(p, pdata, p ->tot_len, 0);
			pbuf_free(p);

			if (length != 0) {
				/*switch the state of espconn for application process*/
				precv_cb->pespconn ->state = ESPCONN_READ;
				precv_cb->pcommon.pcb = pcb;
				precv_cb->pespconn->recv_callback(precv_cb->pespconn, pdata, length);

				/*switch the state of espconn for next packet copy*/
				if (pcb->state == ESTABLISHED)
					precv_cb->pespconn ->state = ESPCONN_CONNECT;
			}

			/*to prevent memory leaks, ensure that each allocated is deleted*/
			os_free(pdata);
			pdata = NULL;
		}
    } else{
    	/*unregister receive function*/
    	struct pbuf *pthis = NULL;
    	for (pthis = p; pthis != NULL; pthis = pthis->next) {
    		ringbuf_memcpy_into(precv_cb->readbuf, pthis->payload, pthis->len);
    		pbuf_free(pthis);
    	}
    }

    if (err == ERR_OK && p == NULL) {
        espconn_client_close(precv_cb, pcb,0);
    }

    return ERR_OK;
}

/******************************************************************************
 * FunctionName : espconn_tcp_write
 * Description  : write the packet which in the active connection's list.
 * Parameters   : arg -- the node pointer which reverse the packet
 * Returns      : ESPCONN_MEM: memory error
 * 				  ESPCONN_OK:have enough space for write packet
*******************************************************************************/
err_t ICACHE_FLASH_ATTR espconn_tcp_write(void *arg)
{
	espconn_msg *pwrite = arg;
	err_t err = ERR_OK;
	struct tcp_pcb *pcb = pwrite->pcommon.pcb;
	/*for one active connection,limit the sender buffer space*/
	if (tcp_nagle_disabled(pcb) && (pcb->snd_queuelen >= TCP_SND_QUEUELEN))
		return ESPCONN_MEM;

	while (tcp_sndbuf(pcb) != 0){
		if (pwrite->pcommon.ptail != NULL) {
			/*Find the node whether in the list's tail or not*/
			if (pwrite->pcommon.ptail->unsent == 0) {
				pwrite->pcommon.ptail = pwrite->pcommon.ptail->pnext;
				continue;
			}

			/*Send the packet for the active connection*/
			err = espconn_tcp_sent(pwrite, pwrite->pcommon.ptail->punsent,pwrite->pcommon.ptail->unsent);
			if (err != ERR_OK)
				break;
		} else
			break;
	}
	return err;
}

/******************************************************************************
 * FunctionName : espconn_tcp_reconnect
 * Description  : reconnect with host
 * Parameters   : arg -- Additional argument to pass to the callback function
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR espconn_tcp_finish(void *arg)
{
	espconn_msg *pfinish = arg;
	espconn_buf *premove = NULL;
	uint16 len = 0;
	espconn_tcp_write(pfinish);
	while (pfinish->pcommon.pbuf != NULL){
		premove = pfinish->pcommon.pbuf;
		pfinish->pcommon.pbuf->tot_len += len;
		/*application packet has been sent and acknowledged by the remote host,
		 * to prevent memory leaks, ensure that each allocated is deleted*/
		if (premove->tot_len >= premove->len){
			espconn_pbuf_delete(&pfinish->pcommon.pbuf,premove);
			len = premove->tot_len - premove->len;
			pfinish->pcommon.packet_info.sent_length = premove->len;
			os_free(premove);
			premove = NULL;
			pfinish->pespconn->state = ESPCONN_CONNECT;
			if (pfinish->pespconn->sent_callback != NULL) {
				pfinish->pespconn->sent_callback(pfinish->pespconn);
			}
			pfinish->pcommon.packet_info.sent_length = len;
		} else
			break;
	}
}

/******************************************************************************
 * FunctionName : espconn_client_sent
 * Description  : Data has been sent and acknowledged by the remote host.
 *                This means that more data can be sent.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb for which data has been acknowledged
 *                len -- The amount of bytes acknowledged
 * Returns      : ERR_OK: try to send some data by calling tcp_output
 *                ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_client_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
	espconn_msg *psent_cb = arg;

	psent_cb->pcommon.pcb = pcb;
	psent_cb->pcommon.pbuf->tot_len += len;
	psent_cb->pcommon.packet_info.sent_length = len;

	/*Send more data for one active connection*/
	espconn_tcp_finish(psent_cb);

    return ERR_OK;
}

/******************************************************************************
 * FunctionName : espconn_client_err
 * Description  : The pcb had an error and is already deallocated.
 *                The argument might still be valid (if != NULL).
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                err -- Error code to indicate why the pcb has been closed
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
espconn_client_err(void *arg, err_t err)
{
	espconn_msg *perr_cb = arg;
	struct tcp_pcb *pcb = NULL;
    LWIP_UNUSED_ARG(err);

    if (perr_cb != NULL) {
        pcb = perr_cb->pcommon.pcb;
        perr_cb->pespconn->state = ESPCONN_CLOSE;
        espconn_printf("espconn_client_err %d %d %d\n", pcb->state, pcb->nrtx, err);

//        /*remove the node from the client's active connection list*/
//        espconn_list_delete(&plink_active, perr_cb);

        /*Set the error code depend on the error type and control block state*/
        if (err == ERR_ABRT) {
        	switch (pcb->state) {
					case SYN_SENT:
						if (pcb->nrtx == TCP_SYNMAXRTX) {
							perr_cb->pcommon.err = ESPCONN_CONN;
						} else {
							perr_cb->pcommon.err = err;
						}

						break;

					case ESTABLISHED:
						if (pcb->nrtx == TCP_MAXRTX) {
							perr_cb->pcommon.err = ESPCONN_TIMEOUT;
						} else {
							perr_cb->pcommon.err = err;
						}
						break;

					case FIN_WAIT_1:
						if (pcb->nrtx == TCP_MAXRTX) {
							perr_cb->pcommon.err = ESPCONN_CLSD;
						} else {
							perr_cb->pcommon.err = err;
						}
						break;
					case FIN_WAIT_2:
						perr_cb->pcommon.err = ESPCONN_CLSD;
						break;
					case CLOSED:
						perr_cb->pcommon.err = ESPCONN_CONN;
						break;
				}
			} else {
				perr_cb->pcommon.err = err;
			}
        	/*post the singer to the task for processing the connection*/
        	ets_post(espconn_TaskPrio, SIG_ESPCONN_ERRER, (uint32_t)perr_cb);
		}
}

/******************************************************************************
 * FunctionName : espconn_client_connect
 * Description  : A new incoming connection has been connected.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                tpcb -- The connection pcb which is connected
 *                err -- An unused error code, always ERR_OK currently
 * Returns      : connection result
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_client_connect(void *arg, struct tcp_pcb *tpcb, err_t err)
{
    espconn_msg *pcon = arg;

    espconn_printf("espconn_client_connect pcon %p tpcb %p\n", pcon, tpcb);
    if (err == ERR_OK){
    	/*Reserve the remote information for current active connection*/
		pcon->pespconn->state = ESPCONN_CONNECT;
		pcon->pcommon.err = err;
		pcon->pcommon.pcb = tpcb;
		pcon->pcommon.local_port = tpcb->local_port;
		pcon->pcommon.local_ip = tpcb->local_ip.addr;
		pcon->pcommon.remote_port = tpcb->remote_port;
		pcon->pcommon.remote_ip[0] = ip4_addr1_16(&tpcb->remote_ip);
		pcon->pcommon.remote_ip[1] = ip4_addr2_16(&tpcb->remote_ip);
		pcon->pcommon.remote_ip[2] = ip4_addr3_16(&tpcb->remote_ip);
		pcon->pcommon.remote_ip[3] = ip4_addr4_16(&tpcb->remote_ip);
		pcon->pcommon.write_flag = true;
		tcp_arg(tpcb, (void *) pcon);

		/*Set the specify function that should be called
		 * when TCP data has been successfully delivered,
		 * when active connection receives data*/
		tcp_sent(tpcb, espconn_client_sent);
		tcp_recv(tpcb, espconn_client_recv);
		/*Disable Nagle algorithm default*/
		tcp_nagle_disable(tpcb);
		/*Default set the total number of espconn_buf on the unsent lists for one*/
		espconn_tcp_set_buf_count(pcon->pespconn, 1);

		if (pcon->pespconn->proto.tcp->connect_callback != NULL) {
			pcon->pespconn->proto.tcp->connect_callback(pcon->pespconn);
		}

		/*Enable block option for fetches the data proactive*/
        if (espconn_manual_recv_disabled(pcon))
            tcp_recv(tpcb, espconn_tcp_recv);

		/*Enable keep alive option*/
		if (espconn_keepalive_disabled(pcon))
			espconn_keepalive_enable(tpcb);

//		/*lock the window because of application layer don't need the data*/
//		espconn_lock_recv(pcon);
    } else{
    	os_printf("err in host connected (%s)\n",lwip_strerr(err));
    }
    return err;
}

/******************************************************************************
 * FunctionName : espconn_tcp_client
 * Description  : Initialize the client: set up a connect PCB and bind it to
 *                the defined port
 * Parameters   : espconn -- the espconn used to build client
 * Returns      : none
*******************************************************************************/
sint8 ICACHE_FLASH_ATTR
espconn_tcp_client(struct espconn *espconn)
{
    struct tcp_pcb *pcb = NULL;
    struct ip_addr ipaddr;
    espconn_msg *pclient = NULL;

    /*Creates a new client control message*/
	pclient = (espconn_msg *)os_zalloc(sizeof(espconn_msg));
	if (pclient == NULL){
		return ESPCONN_MEM;
 	}

	/*Set an IP address given for Little-endian.*/
    IP4_ADDR(&ipaddr, espconn->proto.tcp->remote_ip[0],
    		espconn->proto.tcp->remote_ip[1],
    		espconn->proto.tcp->remote_ip[2],
    		espconn->proto.tcp->remote_ip[3]);

    /*Creates a new TCP protocol control block*/
    pcb = tcp_new();

    if (pcb == NULL) {
    	/*to prevent memory leaks, ensure that each allocated is deleted*/
    	os_free(pclient);
    	pclient = NULL;
        return ESPCONN_MEM;
    } else {

    	/*insert the node to the active connection list*/
    	espconn_list_creat(&plink_active, pclient);
    	tcp_arg(pcb, (void *)pclient);
    	tcp_err(pcb, espconn_client_err);
    	pclient->preverse = NULL;
    	pclient->pespconn = espconn;
    	pclient->pespconn->state = ESPCONN_WAIT;
    	pclient->pcommon.pcb = pcb;
    	tcp_bind(pcb, IP_ADDR_ANY, pclient->pespconn->proto.tcp->local_port);
#if 0
    	pclient->pcommon.err = tcp_bind(pcb, IP_ADDR_ANY, pclient->pespconn->proto.tcp->local_port);
    	if (pclient->pcommon.err != ERR_OK){
    		/*remove the node from the client's active connection list*/
    		espconn_list_delete(&plink_active, pclient);
    		memp_free(MEMP_TCP_PCB, pcb);
    		os_free(pclient);
    		pclient = NULL;
    		return ERR_USE;
    	}
#endif
        /*Establish the connection*/
    	pclient->espconn_mode = ESPCONN_TCPCLIENT_MODE;
        pclient->pcommon.err = tcp_connect(pcb, &ipaddr,
        		pclient->pespconn->proto.tcp->remote_port, espconn_client_connect);
        if (pclient->pcommon.err == ERR_RTE){
			/*remove the node from the client's active connection list*/
			espconn_list_delete(&plink_active, pclient);
			espconn_kill_pcb(pcb->local_port);
			os_free(pclient);
			pclient = NULL;
			return ESPCONN_RTE;
		}
        return pclient->pcommon.err;
    }
}

///////////////////////////////server function/////////////////////////////////
/******************************************************************************
 * FunctionName : espconn_server_close
 * Description  : The connection shall be actively closed.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- the pcb to close
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
espconn_server_close(void *arg, struct tcp_pcb *pcb,u8 type)
{
    err_t err;
    espconn_msg *psclose = arg;

	psclose->pcommon.pcb = pcb;
	/*avoid recalling the disconnect function*/
	tcp_recv(pcb, NULL);

	if(type ==0)
		err = tcp_close(pcb);
	else {
		tcp_poll(pcb, NULL, 0);
	    tcp_sent(pcb, NULL);
		tcp_err(pcb, NULL);
		tcp_abort(pcb);
		err = ERR_OK;
	}

    if (err != ERR_OK) {
        /* closing failed, try again later */
        tcp_recv(pcb, espconn_server_recv);
    } else {
        /* closing succeeded */
    	if (type == 0) {
			tcp_poll(pcb, NULL, 0);
			tcp_sent(pcb, NULL);
			tcp_err(pcb, NULL);
    	}
        /*switch the state of espconn for application process*/
        psclose->pespconn->state = ESPCONN_CLOSE;
        ets_post(espconn_TaskPrio, SIG_ESPCONN_CLOSE, (uint32_t)psclose);
	}
}

/******************************************************************************
 * FunctionName : espconn_server_recv
 * Description  : Data has been received on this pcb.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb which received data
 *                p -- The received data (or NULL when the connection has been closed!)
 *                err -- An error code if there has been an error receiving
 * Returns      : ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_server_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
	espconn_msg *precv_cb = arg;

    tcp_arg(pcb, arg);
    espconn_printf("server has application data received: %d\n", system_get_free_heap_size());
    /*lock the window because of application layer don't need the data*/
    espconn_lock_recv(precv_cb);

    if (p != NULL) {
    	/*To update and advertise a larger window*/
		if(precv_cb->recv_hold_flag == 0)
        	tcp_recved(pcb, p->tot_len);
		else
			precv_cb->recv_holded_buf_Len += p->tot_len;
    }

    /*register receive function*/
	if (precv_cb->pespconn->recv_callback != NULL) {
		if (err == ERR_OK && p != NULL) {
			u8_t *data_ptr = NULL;
			u32_t data_cntr = 0;
			/*clear the count for connection timeout*/
			precv_cb->pcommon.recv_check = 0;
			/*Copy the contents of a packet buffer to an application buffer.
			 *to prevent memory leaks, ensure that each allocated is deleted*/
			data_ptr = (u8_t *) os_zalloc(p ->tot_len + 1);
			data_cntr = pbuf_copy_partial(p, data_ptr, p->tot_len, 0);
			pbuf_free(p);

			if (data_cntr != 0) {
				/*switch the state of espconn for application process*/
				precv_cb->pespconn->state = ESPCONN_READ;
				precv_cb->pcommon.pcb = pcb;
				precv_cb->pespconn->recv_callback(precv_cb->pespconn, data_ptr, data_cntr);

				/*switch the state of espconn for next packet copy*/
				if (pcb->state == ESTABLISHED)
					precv_cb->pespconn->state = ESPCONN_CONNECT;
			}

			/*to prevent memory leaks, ensure that each allocated is deleted*/
			os_free(data_ptr);
			data_ptr = NULL;
			espconn_printf("server's application data has been processed: %d\n", system_get_free_heap_size());
		}
	} else {
		/*unregister receive function*/
		struct pbuf *pthis = NULL;
		for (pthis = p; pthis != NULL; pthis = pthis->next) {
			ringbuf_memcpy_into(precv_cb->readbuf, pthis->payload, pthis->len);
			pbuf_free(pthis);
		}
	}

	if (err == ERR_OK && p == NULL) {
		espconn_server_close(precv_cb, pcb, 0);
	}
    return ERR_OK;
}

/******************************************************************************
 * FunctionName : espconn_server_sent
 * Description  : Data has been sent and acknowledged by the remote host.
 * This means that more data can be sent.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb for which data has been acknowledged
 *                len -- The amount of bytes acknowledged
 * Returns      : ERR_OK: try to send some data by calling tcp_output
 *                ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_server_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
	espconn_msg *psent_cb = arg;

	psent_cb->pcommon.pcb = pcb;
	psent_cb->pcommon.recv_check = 0;
	psent_cb->pcommon.pbuf->tot_len += len;
	psent_cb->pcommon.packet_info.sent_length = len;

	/*Send more data for one active connection*/
	espconn_tcp_finish(psent_cb);
    return ERR_OK;
}

/******************************************************************************
 * FunctionName : espconn_server_poll
 * Description  : The poll function is called every 3nd second.
 * If there has been no data sent (which resets the retries) in 3 seconds, close.
 * If the last portion of a file has not been sent in 3 seconds, close.
 *
 * This could be increased, but we don't want to waste resources for bad connections.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb for which data has been acknowledged
 * Returns      : ERR_OK: try to send some data by calling tcp_output
 *                ERR_ABRT: if you have called tcp_abort from within the function!
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_server_poll(void *arg, struct tcp_pcb *pcb)
{
	espconn_msg *pspoll_cb = arg;

	/*exception calling abandon the connection for send a RST frame*/
    if (arg == NULL) {
        tcp_abandon(pcb, 0);
        tcp_poll(pcb, NULL, 0);
        return ERR_OK;
    }

    espconn_printf("espconn_server_poll %d %d\n", pspoll_cb->pcommon.recv_check, pcb->state);
    pspoll_cb->pcommon.pcb = pcb;
    if (pcb->state == ESTABLISHED) {
		pspoll_cb->pcommon.recv_check++;
		if (pspoll_cb->pcommon.timeout != 0){/*no data sent in one active connection's set timeout, close.*/
			if (pspoll_cb->pcommon.recv_check >= pspoll_cb->pcommon.timeout) {
				pspoll_cb->pcommon.recv_check = 0;
				espconn_server_close(pspoll_cb, pcb,0);
			}
		} else {
			espconn_msg *ptime_msg = pserver_list;
			while (ptime_msg != NULL) {
				if (ptime_msg->pespconn == pspoll_cb->preverse){
					if (ptime_msg->pcommon.timeout != 0){/*no data sent in server's set timeout, close.*/
						if (pspoll_cb->pcommon.recv_check >= ptime_msg->pcommon.timeout){
							pspoll_cb->pcommon.recv_check = 0;
							espconn_server_close(pspoll_cb, pcb,0);
						}
					} else {/*don't close for ever*/
						pspoll_cb->pcommon.recv_check = 0;
					}
					break;
				}
				ptime_msg = ptime_msg->pnext;
			}
		}
    } else {
        espconn_server_close(pspoll_cb, pcb,0);
    }

    return ERR_OK;
}

/******************************************************************************
 * FunctionName : esponn_server_err
 * Description  : The pcb had an error and is already deallocated.
 *                The argument might still be valid (if != NULL).
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                err -- Error code to indicate why the pcb has been closed
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
esponn_server_err(void *arg, err_t err)
{
	espconn_msg *pserr_cb = arg;
	struct tcp_pcb *pcb = NULL;
    if (pserr_cb != NULL) {

    	pcb = pserr_cb->pcommon.pcb;
    	pserr_cb->pespconn->state = ESPCONN_CLOSE;

//		/*remove the node from the server's active connection list*/
//		espconn_list_delete(&plink_active, pserr_cb);

    	/*Set the error code depend on the error type and control block state*/
		if (err == ERR_ABRT) {
			switch (pcb->state) {
				case SYN_RCVD:
					if (pcb->nrtx == TCP_SYNMAXRTX) {
						pserr_cb->pcommon.err = ESPCONN_CONN;
					} else {
						pserr_cb->pcommon.err = err;
					}

					break;

				case ESTABLISHED:
					if (pcb->nrtx == TCP_MAXRTX) {
						pserr_cb->pcommon.err = ESPCONN_TIMEOUT;
					} else {
						pserr_cb->pcommon.err = err;
					}

					break;

				case CLOSE_WAIT:
					if (pcb->nrtx == TCP_MAXRTX) {
						pserr_cb->pcommon.err = ESPCONN_CLSD;
					} else {
						pserr_cb->pcommon.err = err;
					}
					break;
				case LAST_ACK:
					pserr_cb->pcommon.err = ESPCONN_CLSD;
					break;

				case CLOSED:
					pserr_cb->pcommon.err = ESPCONN_CONN;
					break;
				default :
					break;
			}
		} else {
			pserr_cb->pcommon.err = err;
		}
		/*post the singer to the task for processing the connection*/
		ets_post(espconn_TaskPrio, SIG_ESPCONN_ERRER, (uint32_t)pserr_cb);
    }
}

/******************************************************************************
 * FunctionName : espconn_tcp_accept
 * Description  : A new incoming connection has been accepted.
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                pcb -- The connection pcb which is accepted
 *                err -- An unused error code, always ERR_OK currently
 * Returns      : acception result
*******************************************************************************/
static err_t ICACHE_FLASH_ATTR
espconn_tcp_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
    struct espconn *espconn = arg;
    espconn_msg *paccept = NULL;
    remot_info *pinfo = NULL;
    LWIP_UNUSED_ARG(err);

    if (!espconn || !espconn->proto.tcp) {
    	return ERR_ARG;
    }

    tcp_arg(pcb, paccept);
    tcp_err(pcb, esponn_server_err);
    /*Ensure the active connection is less than the count of active connections on the server*/
    espconn_get_connection_info(espconn, &pinfo , 0);
	espconn_printf("espconn_tcp_accept link_cnt: %d\n", espconn->link_cnt);
	if (espconn->link_cnt == espconn_tcp_get_max_con_allow(espconn))
		return ERR_ISCONN;

	/*Creates a new active connect control message*/
    paccept = (espconn_msg *)os_zalloc(sizeof(espconn_msg));
    tcp_arg(pcb, paccept);

	if (paccept == NULL)
		return ERR_MEM;
	/*Insert the node to the active connection list*/
	espconn_list_creat(&plink_active, paccept);

    paccept->preverse = espconn;
    paccept->espconn_mode = ESPCONN_TCPSERVER_MODE;
	paccept->pespconn = (struct espconn *)os_zalloc(sizeof(struct espconn));
	if (paccept->pespconn == NULL)
		return ERR_MEM;
	paccept->pespconn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
	if (paccept->pespconn->proto.tcp == NULL)
		return ERR_MEM;

	/*Reserve the remote information for current active connection*/
	paccept->pcommon.pcb = pcb;

	paccept->pcommon.remote_port = pcb->remote_port;
	paccept->pcommon.remote_ip[0] = ip4_addr1_16(&pcb->remote_ip);
	paccept->pcommon.remote_ip[1] = ip4_addr2_16(&pcb->remote_ip);
	paccept->pcommon.remote_ip[2] = ip4_addr3_16(&pcb->remote_ip);
	paccept->pcommon.remote_ip[3] = ip4_addr4_16(&pcb->remote_ip);
	paccept->pcommon.write_flag = true;

	os_memcpy(espconn->proto.tcp->remote_ip, paccept->pcommon.remote_ip, 4);
	espconn->proto.tcp->remote_port = pcb->remote_port;
	espconn->state = ESPCONN_CONNECT;
	espconn_copy_partial(paccept->pespconn, espconn);

	/*Set the specify function that should be called
	 * when TCP data has been successfully delivered,
	 * when active connection receives data,
	 * or periodically from active connection*/
	tcp_sent(pcb, espconn_server_sent);
	tcp_recv(pcb, espconn_server_recv);
	tcp_poll(pcb, espconn_server_poll, 4); /* every 1 seconds */
	/*Disable Nagle algorithm default*/
	tcp_nagle_disable(pcb);
	/*Default set the total number of espconn_buf on the unsent lists for one*/
	espconn_tcp_set_buf_count(paccept->pespconn, 1);

	if (paccept->pespconn->proto.tcp->connect_callback != NULL) {
		paccept->pespconn->proto.tcp->connect_callback(paccept->pespconn);
	}

	/*Enable block option for fetches the data proactive*/
	if (espconn_manual_recv_disabled(paccept))
	    tcp_recv(pcb, espconn_tcp_recv);

	/*Enable keep alive option*/
	if (espconn_keepalive_disabled(paccept))
		espconn_keepalive_enable(pcb);

//	/*lock the window because of application layer don't need the data*/
//	espconn_lock_recv(paccept);
    return ERR_OK;
}

/******************************************************************************
 * FunctionName : espconn_tcp_server
 * Description  : Initialize the server: set up a listening PCB and bind it to
 *                the defined port
 * Parameters   : espconn -- the espconn used to build server
 * Returns      : none
*******************************************************************************/
sint8 ICACHE_FLASH_ATTR
espconn_tcp_server(struct espconn *espconn)
{
    struct tcp_pcb *pcb = NULL;
    espconn_msg *pserver = NULL;

    /*Creates a new server control message*/
    pserver = (espconn_msg *)os_zalloc(sizeof(espconn_msg));
    if (pserver == NULL){
    	return ESPCONN_MEM;
    }

    /*Creates a new TCP protocol control block*/
    pcb = tcp_new();
    if (pcb == NULL) {
    	/*to prevent memory leaks, ensure that each allocated is deleted*/
    	os_free(pserver);
    	pserver = NULL;
        return ESPCONN_MEM;
    } else {
    	struct tcp_pcb *lpcb = NULL;
    	/*Binds the connection to a local port number and any IP address*/
        tcp_bind(pcb, IP_ADDR_ANY, espconn->proto.tcp->local_port);
        lpcb = pcb;
        /*malloc and set the state of the connection to be LISTEN*/
        pcb = tcp_listen(pcb);
        if (pcb != NULL) {
        	/*insert the node to the active connection list*/
        	espconn_list_creat(&pserver_list, pserver);
        	pserver->preverse = pcb;
        	pserver->pespconn = espconn;
        	pserver->count_opt = MEMP_NUM_TCP_PCB;
			pserver->pcommon.timeout = 0x0a;
            espconn ->state = ESPCONN_LISTEN;
            /*set the specify argument that should be passed callback function*/
            tcp_arg(pcb, (void *)espconn);
            /*accept callback function to call for this control block*/
            tcp_accept(pcb, espconn_tcp_accept);
            return ESPCONN_OK;
        } else {
        	/*to prevent memory leaks, ensure that each allocated is deleted*/
        	memp_free(MEMP_TCP_PCB,lpcb);
        	os_free(pserver);
        	pserver = NULL;
            return ESPCONN_MEM;
        }
    }
}

/******************************************************************************
 * FunctionName : espconn_tcp_delete
 * Description  : delete the server: delete a listening PCB and free it
 * Parameters   : pdeletecon -- the espconn used to delete a server
 * Returns      : none
*******************************************************************************/
sint8 ICACHE_FLASH_ATTR espconn_tcp_delete(struct espconn *pdeletecon)
{
	err_t err;
	remot_info *pinfo = NULL;
	espconn_msg *pdelete_msg = NULL;
	struct tcp_pcb *pcb = NULL;

	if (pdeletecon == NULL)
		return ESPCONN_ARG;

	espconn_get_connection_info(pdeletecon, &pinfo , 0);
	/*make sure all the active connection have been disconnect*/
	if (pdeletecon->link_cnt != 0)
		return ESPCONN_INPROGRESS;
	else {
		espconn_printf("espconn_tcp_delete %p\n",pdeletecon);
		pdelete_msg = pserver_list;
		while (pdelete_msg != NULL){
			if (pdelete_msg->pespconn == pdeletecon){
				/*remove the node from the client's active connection list*/
				espconn_list_delete(&pserver_list, pdelete_msg);
				pcb = pdelete_msg->preverse;
				os_printf("espconn_tcp_delete %d, %d\n",pcb->state, pcb->local_port);
				espconn_kill_pcb(pcb->local_port);
				err = tcp_close(pcb);
				os_free(pdelete_msg);
				pdelete_msg = NULL;
				break;
			}
			pdelete_msg = pdelete_msg->pnext;
		}
		if (err == ERR_OK)
			return err;
		else
			return ESPCONN_ARG;
	}
}

/******************************************************************************
 * FunctionName : espconn_init
 * Description  : used to init the function that should be used when
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR espconn_init(void)
{
  ets_task(espconn_Task, espconn_TaskPrio, espconn_TaskQueue, espconn_TaskQueueLen);
}

{'repo_name': 'imliubo/makingfunxyz-esp8266', 'stars': '141', 'repo_language': 'Assembly', 'file_name': 'dh', 'mime_type': 'text/plain', 'hash': 5291346310225453452, 'source_dataset': 'data'}


<resources>

    <style name="SingleLineTextView" parent="@android:style/Widget.TextView">
        <item name="android:singleLine">true</item>
        <item name="android:ellipsize">end</item>
    </style>

    <style name="SingleLineSmallTextView" parent="SingleLineTextView">
        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
    </style>

    <style name="SingleLineLargeTextView" parent="SingleLineTextView">
        <item name="android:textAppearance">?android:attr/textAppearanceLarge</item>
    </style>

</resources>

{'repo_name': 'MostafaGazar/soas', 'stars': '694', 'repo_language': 'Java', 'file_name': 'ProviderConstants.java', 'mime_type': 'text/plain', 'hash': -2293824289279532406, 'source_dataset': 'data'}


from __future__ import absolute_import

from datetime import timedelta

from django.db import models
from django.db.models.signals import post_delete, post_save
from django.utils import timezone

from sentry.db.models import (
    BaseManager,
    BoundedPositiveIntegerField,
    FlexibleForeignKey,
    JSONField,
    Model,
    sane_repr,
)
from sentry.utils.cache import cache

class GroupSnooze(Model):
    """
    A snooze marks an issue as ignored until a condition is hit.

    - If ``until`` is set, the snooze is lifted at the given datetime.
    - If ``count`` is set, the snooze is lifted when total occurrences match.
    - If ``window`` is set (in addition to count), the snooze is lifted when
      the rate of events matches.
    - If ``user_count`` is set, the snooze is lfited when unique users match.
    - If ``user_window`` is set (in addition to count), the snooze is lifted
      when the rate unique users matches.

    NOTE: `window` and `user_window` are specified in minutes
    """

    __core__ = False

    group = FlexibleForeignKey("sentry.Group", unique=True)
    until = models.DateTimeField(null=True)
    count = BoundedPositiveIntegerField(null=True)
    window = BoundedPositiveIntegerField(null=True)
    user_count = BoundedPositiveIntegerField(null=True)
    user_window = BoundedPositiveIntegerField(null=True)
    state = JSONField(null=True)
    actor_id = BoundedPositiveIntegerField(null=True)

    objects = BaseManager(cache_fields=("group",))

    class Meta:
        db_table = "sentry_groupsnooze"
        app_label = "sentry"

    __repr__ = sane_repr("group_id")

    @classmethod
    def get_cache_key(cls, group_id):
        return "groupsnooze_group_id:1:%s" % (group_id)

    def is_valid(self, group=None, test_rates=False):
        if group is None:
            group = self.group
        elif group.id != self.group_id:
            raise ValueError

        if self.until:
            if self.until <= timezone.now():
                return False

        if self.count:
            if self.window:
                if test_rates:
                    if not self.test_frequency_rates():
                        return False
            elif self.count <= group.times_seen - self.state["times_seen"]:
                return False

        if self.user_count and test_rates:
            if self.user_window:
                if not self.test_user_rates():
                    return False
            elif self.user_count <= group.count_users_seen() - self.state["users_seen"]:
                return False
        return True

    def test_frequency_rates(self):
        from sentry import tsdb

        end = timezone.now()
        start = end - timedelta(minutes=self.window)

        rate = tsdb.get_sums(model=tsdb.models.group, keys=[self.group_id], start=start, end=end)[
            self.group_id
        ]
        if rate >= self.count:
            return False

        return True

    def test_user_rates(self):
        from sentry import tsdb

        end = timezone.now()
        start = end - timedelta(minutes=self.user_window)

        rate = tsdb.get_distinct_counts_totals(
            model=tsdb.models.users_affected_by_group, keys=[self.group_id], start=start, end=end
        )[self.group_id]

        if rate >= self.user_count:
            return False

        return True

post_save.connect(
    lambda instance, **kwargs: cache.set(
        GroupSnooze.get_cache_key(instance.group_id), instance, 3600
    ),
    sender=GroupSnooze,
    weak=False,
)
post_delete.connect(
    lambda instance, **kwargs: cache.set(GroupSnooze.get_cache_key(instance.group_id), False, 3600),
    sender=GroupSnooze,
    weak=False,
)

{'repo_name': 'getsentry/sentry', 'stars': '25486', 'repo_language': 'Python', 'file_name': 'sentry.less', 'mime_type': 'text/plain', 'hash': 8232284664419105320, 'source_dataset': 'data'}


/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "bladerunner/script/scene_script.h"

namespace BladeRunner {

void SceneScriptRC04::InitializeScene() {
	Setup_Scene_Information(45.0f, 0.15f, 68.0f, 1018);
	Game_Flag_Reset(kFlagRC03toRC04);

	Scene_Exit_Add_2D_Exit(0, 225, 47, 359, 248, 0);

	if (!Game_Flag_Query(kFlagRC04McCoyShotBob)) {
		Actor_Put_In_Set(kActorBulletBob, kSetRC04);
		Actor_Set_At_XYZ(kActorBulletBob, -60.0f, -11.0f, 62.0f, 12);
	}
	if (Game_Flag_Query(kFlagRC04McCoyShotBob)) {
		Actor_Change_Animation_Mode(kActorBulletBob, 88);
	}

	Ambient_Sounds_Add_Looping_Sound(kSfxRAIN10, 100, 1, 1);
	Ambient_Sounds_Add_Sound(kSfxRCCARBY1, 5, 30, 10, 20, -100, 100, -101, -101, 0, 0);
	Ambient_Sounds_Add_Sound(kSfxRCCARBY2, 5, 30, 10, 20, -100, 100, -101, -101, 0, 0);
	Ambient_Sounds_Add_Sound(kSfxRCCARBY3, 5, 30, 10, 20, -100, 100, -101, -101, 0, 0);
}

void SceneScriptRC04::SceneLoaded() {
	Obstacle_Object("Door New 01", true);
	Obstacle_Object("GRNDNEON05", true);
	Obstacle_Object("GRNDNEON06", true);
	Obstacle_Object("GRNDNEON07", true);
	Unobstacle_Object("DisplayTrim", true);
	Unobstacle_Object("Display01", true);
	Actor_Set_Goal_Number(kActorGenwalkerA, kGoalGenwalkerABulletBobsTrackGun);
}

bool SceneScriptRC04::MouseClick(int x, int y) {
	return false;
}

bool SceneScriptRC04::ClickedOn3DObject(const char *objectName, bool a2) {
	return false;
}

void SceneScriptRC04::dialogueWithBulletBob() {
	Dialogue_Menu_Clear_List();
	if ( Actor_Clue_Query(kActorMcCoy, kClueLabShellCasings)
	 && !Actor_Clue_Query(kActorMcCoy, kClueRadiationGoggles)
	) {
		DM_Add_To_List_Never_Repeat_Once_Selected(580, -1, 4, 9); // WEAPONS
	}
	if ( Actor_Clue_Query(kActorMcCoy, kClueShellCasings)
	 && !Actor_Clue_Query(kActorMcCoy, kClueLabShellCasings)
	 && !Actor_Clue_Query(kActorMcCoy, kClueRadiationGoggles)
	) {
		DM_Add_To_List_Never_Repeat_Once_Selected(590, 6, 5, 3); // SHELL CASINGS
	}
	if (Actor_Clue_Query(kActorMcCoy, kClueHasanInterview)) {
		DM_Add_To_List_Never_Repeat_Once_Selected(600, -1, 3, 7); // HASAN
		DM_Add_To_List_Never_Repeat_Once_Selected(1310, -1, 2, 8); // VOIGT-KAMPFF
	}
	if ( Actor_Clue_Query(kActorMcCoy, kClueRadiationGoggles)
	 && !Actor_Clue_Query(kActorMcCoy, kClueGogglesReplicantIssue)
	) {
		DM_Add_To_List_Never_Repeat_Once_Selected(610, 4, 5, 6); // GOGGLES
	}
	if (!Game_Flag_Query(kFlagRC04BobTalkAmmo)) {
		DM_Add_To_List_Never_Repeat_Once_Selected(1280, 1, 2, 3); // AMMO
	}
	if ( Actor_Clue_Query(kActorMcCoy, kClueHoldensBadge)
	 && !Actor_Clue_Query(kActorBulletBob, kClueHoldensBadge)
	) {
		DM_Add_To_List_Never_Repeat_Once_Selected(620, 1, -1, -1); // HOLDEN'S BADGE
	}
	Dialogue_Menu_Add_DONE_To_List(630); // DONE

	Dialogue_Menu_Appear(320, 240);
	int answer = Dialogue_Menu_Query_Input();
	Dialogue_Menu_Disappear();

	switch (answer) {
	case 580: // WEAPONS
		Actor_Says(kActorMcCoy, 4955, 30);
		Actor_Says(kActorBulletBob, 210, 37);
		Actor_Says(kActorBulletBob, 220, 37);
		Actor_Says(kActorBulletBob, 230, 37);
		Actor_Says(kActorBulletBob, 240, 37);
		Actor_Says(kActorMcCoy, 4990, 16);
		Actor_Says(kActorMcCoy, 4995, 11);
		Actor_Says(kActorBulletBob, 270, 31);
		Actor_Says(kActorMcCoy, 5005, 16);
		Actor_Says(kActorBulletBob, 280, 32);
		Actor_Says(kActorBulletBob, 290, 30);
		Actor_Says(kActorBulletBob, 300, 33);
		Actor_Says(kActorBulletBob, 310, 31);
		Actor_Says(kActorMcCoy, 5010, 11);
		Actor_Says(kActorBulletBob, 320, 30);
		Actor_Says(kActorBulletBob, 330, 33);
		Actor_Says(kActorBulletBob, 340, 37);
		Actor_Says(kActorMcCoy, 5015, 11);
		if (Game_Flag_Query(kFlagIzoIsReplicant)) {
			Actor_Says(kActorBulletBob, 350, 32);
			Actor_Says(kActorBulletBob, 360, 33);
			Actor_Says(kActorBulletBob, 370, 30);
			Actor_Says(kActorMcCoy, 5020, 16);
			Actor_Says(kActorBulletBob, 380, 37);
			Actor_Says(kActorBulletBob, 390, 11);
			Actor_Says(kActorBulletBob, 400, 37);
#if BLADERUNNER_ORIGINAL_BUGS
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview1, true, kActorMcCoy);  // A bug? Shouldn't the last argument be -1 or kActorBulletBob here?
#else
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview1, true, kActorBulletBob);
#endif // BLADERUNNER_ORIGINAL_BUGS
		} else {
			Actor_Says(kActorBulletBob, 410, 11);
			Actor_Says(kActorBulletBob, 420, 37);
			Actor_Says(kActorMcCoy, 5025, 16);
			Actor_Says(kActorBulletBob, 430, 30);
			Actor_Says(kActorBulletBob, 440, 31);
			Actor_Says(kActorBulletBob, 450, 32);
			Actor_Says(kActorMcCoy, 5030, 16);
			Actor_Says(kActorBulletBob, 460, 37);
#if BLADERUNNER_ORIGINAL_BUGS
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview2, true, kActorMcCoy);  // A bug? Shouldn't the last argument be -1 or kActorBulletBob here?
#else
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview2, true, kActorBulletBob);
#endif // BLADERUNNER_ORIGINAL_BUGS
		}
		return;

	case 590: // SHELL CASINGS
		Actor_Says(kActorMcCoy, 4960, 13);
		Actor_Says(kActorBulletBob, 250, 30);
		Actor_Says(kActorBulletBob, 260, 33);
		Actor_Says(kActorMcCoy, 4995, 15);
		Actor_Says(kActorBulletBob, 270, 32);
		Actor_Says(kActorMcCoy, 5005, 11);
		Actor_Says(kActorBulletBob, 280, 33);
		Actor_Says(kActorBulletBob, 290, 30);
		Actor_Says(kActorBulletBob, 300, 32);
		Actor_Says(kActorBulletBob, 310, 37);
		Actor_Says(kActorMcCoy, 5010, 13);
		Actor_Says(kActorBulletBob, 320, 37);
		Actor_Says(kActorBulletBob, 330, 33);
		Actor_Says(kActorBulletBob, 340, 11);
		Actor_Says(kActorMcCoy, 5015, 16);
		Actor_Modify_Friendliness_To_Other(kActorBulletBob, kActorMcCoy, 3);
		if (Game_Flag_Query(kFlagIzoIsReplicant)) {
			Actor_Says(kActorBulletBob, 350, 32);
			Actor_Says(kActorBulletBob, 360, 30);
			Actor_Says(kActorBulletBob, 370, 33);
			Actor_Says(kActorMcCoy, 5020, 15);
			Actor_Says(kActorBulletBob, 380, 33);
			Actor_Says(kActorBulletBob, 390, 37);
			Actor_Says(kActorBulletBob, 400, 32);
#if BLADERUNNER_ORIGINAL_BUGS
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview1, true, kActorMcCoy);  // A bug? Shouldn't the last argument be -1 or kActorBulletBob here?
#else
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview1, true, kActorBulletBob);
#endif // BLADERUNNER_ORIGINAL_BUGS
		} else {
			Actor_Says(kActorBulletBob, 410, 32);
			Actor_Says(kActorBulletBob, 420, 30);
			Actor_Says(kActorMcCoy, 5025, 13);
			Actor_Says(kActorBulletBob, 430, 33);
			Actor_Says(kActorBulletBob, 440, 32);
			Actor_Says(kActorBulletBob, 450, 37);
			Actor_Says(kActorMcCoy, 5030, 16);
			Actor_Says(kActorBulletBob, 460, 30);
#if BLADERUNNER_ORIGINAL_BUGS
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview2, true, kActorMcCoy);  // A bug? Shouldn't the last argument be -1 or kActorBulletBob here?
#else
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview2, true, kActorBulletBob);
#endif // BLADERUNNER_ORIGINAL_BUGS
		}
		break;

	case 600: // HASAN
		Actor_Says(kActorMcCoy, 4965, 11);
		Actor_Says(kActorBulletBob, 470, 11);
		Actor_Says(kActorMcCoy, 5035, 15);
		Actor_Says(kActorBulletBob, 480, 30);
		Actor_Says(kActorBulletBob, 490, 31);
		Actor_Says(kActorBulletBob, 500, 32);
		Actor_Says(kActorBulletBob, 510, 33);
		Actor_Says(kActorBulletBob, 520, 34);
		Actor_Says(kActorBulletBob, 530, 35);
		Actor_Says(kActorBulletBob, 540, 36);
		Actor_Says(kActorMcCoy, 5040, 16);
		Actor_Says(kActorBulletBob, 550, 11);
		Actor_Modify_Friendliness_To_Other(kActorBulletBob, kActorMcCoy, -6);
		if (_vm->_cutContent) {
			Actor_Modify_Friendliness_To_Other(kActorHasan, kActorMcCoy, 6);
		}
		Game_Flag_Set(kFlagMcCoyTalkedToBulletBobAboutHasan);
		break;

	case 610: // GOGGLES
		Actor_Says(kActorMcCoy, 4970, 16);
		if (Actor_Query_Friendliness_To_Other(kActorBulletBob, kActorMcCoy) < 50) {
			Actor_Says(kActorBulletBob, 700, 11);
			Actor_Says(kActorMcCoy, 5070, 11);
			Actor_Says(kActorBulletBob, 710, 11);
			Actor_Says(kActorMcCoy, 5075, 15);
			Actor_Says(kActorBulletBob, 720, 30);
			Actor_Says(kActorMcCoy, 5080, 11);
			Actor_Says(kActorBulletBob, 730, 37);
#if BLADERUNNER_ORIGINAL_BUGS
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview1, true, kActorMcCoy);  // A bug? Shouldn't the last argument be -1 or kActorBulletBob here?
#else
			Actor_Clue_Acquire(kActorMcCoy, kClueBobInterview1, true, kActorBulletBob);
#endif // BLADERUNNER_ORIGINAL_BUGS
		} else {
			Actor_Says(kActorBulletBob, 560, 37);
			Actor_Says(kActorMcCoy, 5070, 13);
			Actor_Says(kActorBulletBob, 570, 36);
			Actor_Says(kActorBulletBob, 580, 37);
			Actor_Says(kActorBulletBob, 590, 31);
			Actor_Says(kActorBulletBob, 600, 32);
			Actor_Says(kActorBulletBob, 610, 30);
			Actor_Says(kActorMcCoy, 5050, 16);
			Actor_Says(kActorBulletBob, 620, 35);
			Actor_Says(kActorBulletBob, 630, 35);
			Actor_Says(kActorMcCoy, 5055, 11);
			Actor_Says(kActorBulletBob, 640, 36);
			Actor_Says(kActorBulletBob, 650, 35);
			Actor_Says(kActorBulletBob, 660, 30);
			Actor_Says(kActorMcCoy, 5060, 13);
#if BLADERUNNER_ORIGINAL_BUGS
			Actor_Clue_Acquire(kActorMcCoy, kClueGogglesReplicantIssue, true, kActorMcCoy);  // A bug? Shouldn't the last argument be -1 or kActorBulletBob here?
#else
			Actor_Clue_Acquire(kActorMcCoy, kClueGogglesReplicantIssue, true, kActorBulletBob);
#endif // BLADERUNNER_ORIGINAL_BUGS
		}
		break;

	case 620: // HOLDEN'S BADGE
		Actor_Says(kActorMcCoy, 4985, 11);
		Actor_Says(kActorBulletBob, 850, 35);
		Actor_Says(kActorMcCoy, 5105, 13);
		Actor_Says(kActorMcCoy, 5110, 11);
		Actor_Says(kActorBulletBob, 860, 30);
		Actor_Says(kActorMcCoy, 5115, 16);
		Actor_Says(kActorBulletBob, 870, 31);
		Actor_Says(kActorMcCoy, 5120, 15);
		Actor_Says(kActorBulletBob, 880, 34);
		Actor_Clue_Acquire(kActorBulletBob, kClueHoldensBadge, true, kActorMcCoy);
		Actor_Modify_Friendliness_To_Other(kActorBulletBob, kActorMcCoy, 8);
		if (Query_Difficulty_Level() != kGameDifficultyEasy) {
			Global_Variable_Increment(kVariableChinyen, 60);
		}
		break;

	case 630: // DONE
		Actor_Says(kActorMcCoy, 1315, 12);
		break;

	case 1280: // AMMO
		Actor_Says(kActorMcCoy, 9040, 16);
		if (!Game_Flag_Query(kFlagRC04BobTalkAmmo)) {
			Actor_Says(kActorBulletBob, 2080, 30);
			Actor_Says(kActorBulletBob, 2090, 37);
			Actor_Says(kActorMcCoy, 9045, 14);
			Actor_Says(kActorBulletBob, 2100, 32);
			Actor_Says(kActorBulletBob, 2110, 37);
			Game_Flag_Set(kFlagRC04BobTalkAmmo);
		}
		Actor_Says(kActorBulletBob, 2120, 31);
		if (Global_Variable_Query(kVariableChinyen) > 40
		 || Query_Difficulty_Level() == kGameDifficultyEasy
		) {
			Actor_Says(kActorMcCoy, 4940, 13);
			if (Query_Difficulty_Level() != kGameDifficultyEasy) {
				Global_Variable_Decrement(kVariableChinyen, 40);
			}
			Item_Pickup_Spin_Effect(kModelAnimationAmmoType01, 405, 192);
			Give_McCoy_Ammo(1, 24);
		} else {
			Actor_Says(kActorMcCoy, 125, 13);
			Actor_Modify_Friendliness_To_Other(kActorBulletBob, kActorMcCoy, -2);
		}
		break;

	case 1310: // VOIGT-KAMPFF
		Actor_Says(kActorMcCoy, 4980, 11);
		if (Actor_Query_Friendliness_To_Other(kActorBulletBob, kActorMcCoy) > 49) {
			Actor_Says(kActorBulletBob, 740, 37);
			Actor_Says(kActorMcCoy, 5085, 16);
			Actor_Says(kActorBulletBob, 750, 37);
			Actor_Says(kActorBulletBob, 760, 37);
			Voight_Kampff_Activate(kActorBulletBob, 50);
			Actor_Modify_Friendliness_To_Other(kActorBulletBob, kActorMcCoy, 3);
			Actor_Says(kActorBulletBob, 810, 37);
			Actor_Says(kActorMcCoy, 5025, 13);
			Actor_Says(kActorBulletBob, 820, 32);
			Actor_Says(kActorMcCoy, 5100, 11);
			Actor_Says(kActorBulletBob, 830, 31);
			Actor_Says(kActorBulletBob, 840, 35);
		} else {
			Actor_Says(kActorBulletBob, 770, 36);
			Actor_Says(kActorBulletBob, 780, 36);
			Actor_Says(kActorMcCoy, 5090, 16);
			Actor_Says(kActorBulletBob, 790, 36);
			Actor_Says(kActorBulletBob, 800, 35);
			Voight_Kampff_Activate(kActorBulletBob, 50);
			Actor_Says(kActorBulletBob, 810, 30);
			Actor_Says(kActorMcCoy, 5025, 13);
			Actor_Says(kActorBulletBob, 820, 31);
			Actor_Says(kActorMcCoy, 5100, 15);
			Actor_Says(kActorBulletBob, 830, 34);
			Actor_Says(kActorBulletBob, 840, 34);
		}
		break;
	}
}

bool SceneScriptRC04::ClickedOnActor(int actorId) {
	if (Player_Query_Combat_Mode()) {
		return false;
	}

	if (actorId == kActorBulletBob) {
		if ( Global_Variable_Query(kVariableChapter) == 2
		 && !Game_Flag_Query(kFlagRC04McCoyShotBob)
		) {
			Loop_Actor_Walk_To_Waypoint(kActorMcCoy, 104, 0, false, false);
			Actor_Face_Actor(kActorMcCoy, kActorBulletBob, true);
			if ( Game_Flag_Query(kFlagRC04Entered)
			 && !Game_Flag_Query(kFlagRC04BobTalk2)
			 &&  Actor_Query_Friendliness_To_Other(kActorBulletBob, kActorMcCoy) > 45
			) {
				Actor_Says(kActorBulletBob, 30, 30);
				Actor_Says(kActorMcCoy, 4875, 13);
				Actor_Says(kActorBulletBob, 80, 31);
				Actor_Says(kActorMcCoy, 4900, 15);
				Actor_Says(kActorBulletBob, 90, 33);
				Actor_Says(kActorBulletBob, 100, 34);
				Actor_Says(kActorMcCoy, 4905, 15);
				Game_Flag_Set(kFlagRC04BobTalk2);
			} else if ( Game_Flag_Query(kFlagRC04Entered)
					&& !Game_Flag_Query(kFlagRC04BobTalk1)
					&& Actor_Query_Friendliness_To_Other(kActorBulletBob, kActorMcCoy) < 45
			) {
				Actor_Says(kActorBulletBob, 40, 30);
				Actor_Says(kActorMcCoy, 4880, 13);
				Actor_Says(kActorBulletBob, 50, 35);
				Actor_Says(kActorMcCoy, 4875, 16);
				Actor_Says(kActorBulletBob, 60, 36);
				Actor_Says(kActorMcCoy, 4890, 13);
				Actor_Says(kActorBulletBob, 70, 33);
				Actor_Says(kActorMcCoy, 4895, 16);
				Actor_Modify_Friendliness_To_Other(kActorBulletBob, kActorMcCoy, -5);
				Game_Flag_Set(kFlagRC04BobTalk1);
			} else if ( Actor_Query_Friendliness_To_Other(kActorBulletBob, kActorMcCoy) > 51
					&& !Game_Flag_Query(kFlagRC04BobTalk3)
			) {
				Actor_Says(kActorBulletBob, 1870, 30);
				Actor_Says(kActorBulletBob, 1880, 30);
				Actor_Says(kActorMcCoy, 8960, 13);
				Actor_Says(kActorBulletBob, 1890, 36);
				Actor_Says(kActorBulletBob, 1900, 35);
				Actor_Says(kActorMcCoy, 8965, 16);
				Actor_Says(kActorBulletBob, 1920, 36);
				Actor_Says(kActorBulletBob, 1930, 33);
				Actor_Says(kActorBulletBob, 1940, 36);
				Actor_Says(kActorBulletBob, 1950, 30);
				Actor_Says(kActorMcCoy, 8970, 13);
				Actor_Says(kActorBulletBob, 1960, 33);
				Actor_Says(kActorBulletBob, 1970, 30);
				Actor_Says(kActorBulletBob, 1980, 36);
				Delay(1000);
				Actor_Says(kActorBulletBob, 2010, 35);
				if (Global_Variable_Query(kVariableChinyen) > 50
				 || Query_Difficulty_Level() == kGameDifficultyEasy
				) {
					Actor_Says(kActorMcCoy, 8975, 16);
					if (Query_Difficulty_Level() != kGameDifficultyEasy) {
						Global_Variable_Decrement(kVariableChinyen, 50);
					}
					Delay(3000);
					Item_Pickup_Spin_Effect(kModelAnimationDNADataDisc, 405, 192);
					Actor_Says(kActorBulletBob, 2030, 30);
					Game_Flag_Set(kFlagKIAPrivacyAddon);
				} else {
					Actor_Says(kActorMcCoy, 8980, 16);
					Actor_Says(kActorBulletBob, 2040, 30);
					Actor_Says(kActorMcCoy, 8985, 15);
					Actor_Says(kActorBulletBob, 2050, 33);
				}
				Game_Flag_Set(kFlagRC04BobTalk3);
			} else if ( Actor_Clue_Query(kActorMcCoy, kClueLabShellCasings)
			        ||  Actor_Clue_Query(kActorMcCoy, kClueShellCasings)
			        ||  Actor_Clue_Query(kActorMcCoy, kClueRadiationGoggles)
			        ||  Actor_Clue_Query(kActorMcCoy, kClueHoldensBadge)
			        ||  Actor_Clue_Query(kActorMcCoy, kClueHasanInterview)
			        || !Game_Flag_Query(kFlagRC04BobTalkAmmo)
			) {
				dialogueWithBulletBob();
			} else {
				Actor_Says(kActorBulletBob, 1820, 30);
			}
			return true;
		}

		if (Game_Flag_Query(kFlagRC04McCoyShotBob)) {
			Actor_Face_Actor(kActorMcCoy, kActorBulletBob, true);
			if (Actor_Clue_Query(kActorMcCoy, kClueVKBobGorskyReplicant)) {
				Actor_Says(kActorMcCoy, 8590, -1);
			} else {
				Actor_Voice_Over(2100, kActorVoiceOver);
				Actor_Voice_Over(2110, kActorVoiceOver);
			}
			return true;
		}
	}
	return false;
}

bool SceneScriptRC04::ClickedOnItem(int itemId, bool a2) {
	return false;
}

bool SceneScriptRC04::ClickedOnExit(int exitId) {
	if (exitId == 0) {
		if (!Loop_Actor_Walk_To_XYZ(kActorMcCoy, 45.0f, 0.15f, 68.0f, 0, true, false, false)) {
			Game_Flag_Set(kFlagRC04toRC03);
			Set_Enter(kSetRC03, kSceneRC03);
		}
		return true;
	}
	return false;
}

bool SceneScriptRC04::ClickedOn2DRegion(int region) {
	return false;
}

void SceneScriptRC04::SceneFrameAdvanced(int frame) {
}

void SceneScriptRC04::ActorChangedGoal(int actorId, int newGoal, int oldGoal, bool currentSet) {
}

void SceneScriptRC04::PlayerWalkedIn() {
	Loop_Actor_Walk_To_Waypoint(kActorMcCoy, 103, 0, false, false);

	if ( Global_Variable_Query(kVariableChapter) == 2
	 && !Game_Flag_Query(kFlagRC04Entered)
	 && !Player_Query_Combat_Mode()
	) {
		Actor_Says(kActorBulletBob, 0, 31);
		Loop_Actor_Walk_To_Waypoint(kActorMcCoy, 104, 0, false, false);
		Actor_Face_Actor(kActorMcCoy, kActorBulletBob, true);
		Actor_Says(kActorMcCoy, 4865, 13);
		Actor_Says(kActorBulletBob, 10, 32);
		Actor_Says(kActorMcCoy, 4870, 16);
		Actor_Says(kActorBulletBob, 20, 31);
		Game_Flag_Set(kFlagRC04Entered);
		return; //true;
	}

	if ( Global_Variable_Query(kVariableChapter) == 4
	 && !Game_Flag_Query(kFlagRC04McCoyShotBob)
	 && !Game_Flag_Query(kFlagNotUsed306)
	) {
		Actor_Says(kActorDispatcher, 40, 3);
		Actor_Says(kActorBulletBob, 890, 37);
		Actor_Set_Goal_Number(kActorBulletBob, kGoalBulletBobShootMcCoy);
	}

	Game_Flag_Set(kFlagRC04Entered);

	//return false;
}

void SceneScriptRC04::PlayerWalkedOut() {
	Game_Flag_Reset(kFlagRC04McCoyWarned);
}

void SceneScriptRC04::DialogueQueueFlushed(int a1) {
}

} // End of namespace BladeRunner

{'repo_name': 'scummvm/scummvm', 'stars': '1322', 'repo_language': 'C++', 'file_name': 'coktel_decoder.cpp', 'mime_type': 'text/x-c++', 'hash': 5476337537225567926, 'source_dataset': 'data'}


package org.reveno.atp.acceptance.handlers;

import org.reveno.atp.acceptance.api.commands.CreateNewAccountCommand;
import org.reveno.atp.acceptance.api.commands.NewOrderCommand;
import org.reveno.atp.acceptance.api.transactions.AcceptOrder;
import org.reveno.atp.acceptance.api.transactions.CreateAccount;
import org.reveno.atp.acceptance.api.transactions.Credit;
import org.reveno.atp.acceptance.api.transactions.Debit;
import org.reveno.atp.acceptance.model.Account;
import org.reveno.atp.acceptance.model.Order;
import org.reveno.atp.acceptance.model.Position;
import org.reveno.atp.api.commands.CommandContext;

import java.util.Optional;
import java.util.stream.Stream;

import static java.lang.String.format;

public abstract class Commands {

    public static Long createAccount(CreateNewAccountCommand cmd, CommandContext ctx) {
        long accountId = ctx.id(Account.class);
        ctx.executeTxAction(new CreateAccount(accountId, cmd.currency));

        if (cmd.balance > 0)
            ctx.executeTxAction(new Credit(accountId, cmd.balance, System.currentTimeMillis()));

        return accountId;
    }

    public static void credit(Credit credit, CommandContext ctx) {
        if (!ctx.repo().has(Account.class, credit.accountId))
            throw new RuntimeException();

        ctx.executeTxAction(credit);
    }

    public static void debit(Debit debit, CommandContext ctx) {
        if (!ctx.repo().has(Account.class, debit.accountId))
            throw new RuntimeException();

        ctx.executeTxAction(debit);
    }

    public static Long newOrder(NewOrderCommand cmd, CommandContext ctx) {
        long orderId = ctx.id(Order.class);
        Account account = ctx.repo().get(Account.class, cmd.accountId);

        if (cmd.positionId != null) {
            long positionId = cmd.positionId;
            require(account.positions().positions().containsKey(positionId), format("Can't find position %d in account %d", positionId, account.id()));
            Position position = ctx.repo().get(Position.class, cmd.positionId);
            long sum = position.sum() + account.orders().stream().map(oid -> ctx.repo().getO(Order.class, oid))
                    .flatMap(Commands::streamopt).filter(o -> o.positionId().isPresent() && o.positionId().get() == positionId)
                    .map(Order::size).reduce(0L, Long::sum);
            require(sum != 0, format("The position %d is already filled.", positionId));
        }

        ctx.executeTxAction(new AcceptOrder(orderId, cmd.accountId, cmd.positionId, cmd.symbol, cmd.price, cmd.size, cmd.orderType));

        return orderId;
    }

    static void require(boolean value, String message) {
        if (!value)
            throw new RuntimeException(message);
    }

    static <T> Stream<T> streamopt(Optional<T> opt) {
        return opt.map(Stream::of).orElseGet(Stream::empty);
    }
}

{'repo_name': 'dmart28/reveno', 'stars': '273', 'repo_language': 'Java', 'file_name': 'gradle-wrapper.properties', 'mime_type': 'text/plain', 'hash': -6768720119798744209, 'source_dataset': 'data'}


<template>

 0" class="item-search-result" :data-contact="item.id" :data-name="item.name">

        {{ item.initials }}

      <template v-if="withName">
        {{ item.complete_name }}
      </template>

      +

    {{ $t('people.people_add_new') }}

</template>

{'repo_name': 'monicahq/monica', 'stars': '9937', 'repo_language': 'PHP', 'file_name': 'la.json', 'mime_type': 'text/plain', 'hash': 2943707746450237474, 'source_dataset': 'data'}


/*******************************************************************************
 * * Copyright 2015 Impetus Infotech.
 *  *
 *  * Licensed under the Apache License, Version 2.0 (the "License");
 *  * you may not use this file except in compliance with the License.
 *  * You may obtain a copy of the License at
 *  *
 *  *      http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  * Unless required by applicable law or agreed to in writing, software
 *  * distributed under the License is distributed on an "AS IS" BASIS,
 *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  * See the License for the specific language governing permissions and
 *  * limitations under the License.
 ******************************************************************************/
package com.impetus.client.query;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Calendar;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * The Class Student.
 *
 * @author Devender Yadav
 */
@Entity
@Table(name = "STUDENTS", schema = "HBaseNew@queryTest")
public class Student
{
    // Primitive Types
    /** The student id. */
    @Id
    @Column(name = "STUDENT_ID")
    private long studentId;

    /** The student name. */
    @Column(name = "STUDENT_NAME")
    private String studentName;

    /** The is exceptional. */
    @Column(name = "IS_EXCEPTIONAL")
    private boolean isExceptional;

    /** The age. */
    @Column(name = "AGE")
    private int age;

    /** The semester. */
    @Column(name = "SEMESTER")
    private char semester; // A,B,C,D,E,F for i to vi

    /** The digital signature. */
    @Column(name = "DIGITAL_SIGNATURE")
    private byte digitalSignature;

    /** The cgpa. */
    @Column(name = "CGPA")
    private short cgpa; // 1-10

    /** The percentage. */
    @Column(name = "PERCENTAGE")
    private float percentage;

    /** The height. */
    @Column(name = "HEIGHT")
    private double height;

    // Date-time types
    /** The enrolment date. */
    @Column(name = "ENROLMENT_DATE")
    @Temporal(TemporalType.DATE)
    private java.util.Date enrolmentDate;

    /** The enrolment time. */
    @Column(name = "ENROLMENT_TIME")
    @Temporal(TemporalType.TIME)
    private java.util.Date enrolmentTime;

    /** The joining date and time. */
    @Column(name = "JOINING_DATE_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private java.util.Date joiningDateAndTime;

    // Wrapper types

    /** The years spent. */
    @Column(name = "YEARS_SPENT")
    private Integer yearsSpent;

    /** The roll number. */
    @Column(name = "ROLL_NUMBER")
    private Long rollNumber;

    /** The monthly fee. */
    @Column(name = "MONTHLY_FEE")
    private Double monthlyFee;

    /** The sql date. */
    @Column(name = "SQL_DATE")
    private java.sql.Date sqlDate;

    /** The sql timestamp. */
    @Column(name = "SQL_TIMESTAMP")
    private java.sql.Timestamp sqlTimestamp;

    /** The sql time. */
    @Column(name = "SQL_TIME")
    private java.sql.Time sqlTime;

    /** The big integer. */
    @Column(name = "BIG_INT")
    private BigInteger bigInteger;

    /** The big decimal. */
    @Column(name = "BIG_DECIMAL")
    private BigDecimal bigDecimal;

    /** The calendar. */
    @Column(name = "CALENDAR")
    private Calendar calendar;

    /**
     * Gets the student id.
     *
     * @return the studentId
     */
    public long getStudentId()
    {
        return studentId;
    }

    /**
     * Sets the student id.
     *
     * @param studentId
     *            the studentId to set
     */
    public void setStudentId(long studentId)
    {
        this.studentId = studentId;
    }

    /**
     * Gets the student name.
     *
     * @return the studentName
     */
    public String getStudentName()
    {
        return studentName;
    }

    /**
     * Sets the student name.
     *
     * @param studentName
     *            the studentName to set
     */
    public void setStudentName(String studentName)
    {
        this.studentName = studentName;
    }

    /**
     * Checks if is exceptional.
     *
     * @return the isExceptional
     */
    public boolean isExceptional()
    {
        return isExceptional;
    }

    /**
     * Sets the exceptional.
     *
     * @param isExceptional
     *            the isExceptional to set
     */
    public void setExceptional(boolean isExceptional)
    {
        this.isExceptional = isExceptional;
    }

    /**
     * Gets the age.
     *
     * @return the age
     */
    public int getAge()
    {
        return age;
    }

    /**
     * Sets the age.
     *
     * @param age
     *            the age to set
     */
    public void setAge(int age)
    {
        this.age = age;
    }

    /**
     * Gets the semester.
     *
     * @return the semester
     */
    public char getSemester()
    {
        return semester;
    }

    /**
     * Sets the semester.
     *
     * @param semester
     *            the semester to set
     */
    public void setSemester(char semester)
    {
        this.semester = semester;
    }

    /**
     * Gets the digital signature.
     *
     * @return the digitalSignature
     */
    public byte getDigitalSignature()
    {
        return digitalSignature;
    }

    /**
     * Sets the digital signature.
     *
     * @param digitalSignature
     *            the digitalSignature to set
     */
    public void setDigitalSignature(byte digitalSignature)
    {
        this.digitalSignature = digitalSignature;
    }

    /**
     * Gets the cgpa.
     *
     * @return the cgpa
     */
    public short getCgpa()
    {
        return cgpa;
    }

    /**
     * Sets the cgpa.
     *
     * @param cgpa
     *            the cgpa to set
     */
    public void setCgpa(short cgpa)
    {
        this.cgpa = cgpa;
    }

    /**
     * Gets the percentage.
     *
     * @return the percentage
     */
    public float getPercentage()
    {
        return percentage;
    }

    /**
     * Sets the percentage.
     *
     * @param percentage
     *            the percentage to set
     */
    public void setPercentage(float percentage)
    {
        this.percentage = percentage;
    }

    /**
     * Gets the height.
     *
     * @return the height
     */
    public double getHeight()
    {
        return height;
    }

    /**
     * Sets the height.
     *
     * @param height
     *            the height to set
     */
    public void setHeight(double height)
    {
        this.height = height;
    }

    /**
     * Gets the enrolment date.
     *
     * @return the enrolmentDate
     */
    public java.util.Date getEnrolmentDate()
    {
        return enrolmentDate;
    }

    /**
     * Sets the enrolment date.
     *
     * @param enrolmentDate
     *            the enrolmentDate to set
     */
    public void setEnrolmentDate(java.util.Date enrolmentDate)
    {
        this.enrolmentDate = enrolmentDate;
    }

    /**
     * Gets the enrolment time.
     *
     * @return the enrolmentTime
     */
    public java.util.Date getEnrolmentTime()
    {
        return enrolmentTime;
    }

    /**
     * Sets the enrolment time.
     *
     * @param enrolmentTime
     *            the enrolmentTime to set
     */
    public void setEnrolmentTime(java.util.Date enrolmentTime)
    {
        this.enrolmentTime = enrolmentTime;
    }

    /**
     * Gets the joining date and time.
     *
     * @return the joiningDateAndTime
     */
    public java.util.Date getJoiningDateAndTime()
    {
        return joiningDateAndTime;
    }

    /**
     * Sets the joining date and time.
     *
     * @param joiningDateAndTime
     *            the joiningDateAndTime to set
     */
    public void setJoiningDateAndTime(java.util.Date joiningDateAndTime)
    {
        this.joiningDateAndTime = joiningDateAndTime;
    }

    /**
     * Gets the years spent.
     *
     * @return the yearsSpent
     */
    public Integer getYearsSpent()
    {
        return yearsSpent;
    }

    /**
     * Sets the years spent.
     *
     * @param yearsSpent
     *            the yearsSpent to set
     */
    public void setYearsSpent(Integer yearsSpent)
    {
        this.yearsSpent = yearsSpent;
    }

    /**
     * Gets the roll number.
     *
     * @return the rollNumber
     */
    public Long getRollNumber()
    {
        return rollNumber;
    }

    /**
     * Sets the roll number.
     *
     * @param rollNumber
     *            the rollNumber to set
     */
    public void setRollNumber(Long rollNumber)
    {
        this.rollNumber = rollNumber;
    }

    /**
     * Gets the monthly fee.
     *
     * @return the monthlyFee
     */
    public Double getMonthlyFee()
    {
        return monthlyFee;
    }

    /**
     * Sets the monthly fee.
     *
     * @param monthlyFee
     *            the monthlyFee to set
     */
    public void setMonthlyFee(Double monthlyFee)
    {
        this.monthlyFee = monthlyFee;
    }

    /**
     * Gets the sql date.
     *
     * @return the sql date
     */
    public java.sql.Date getSqlDate()
    {
        return sqlDate;
    }

    /**
     * Sets the sql date.
     *
     * @param sqlDate
     *            the new sql date
     */
    public void setSqlDate(java.sql.Date sqlDate)
    {
        this.sqlDate = sqlDate;
    }

    /**
     * Gets the sql timestamp.
     *
     * @return the sqlTimestamp
     */
    public java.sql.Timestamp getSqlTimestamp()
    {
        return sqlTimestamp;
    }

    /**
     * Sets the sql timestamp.
     *
     * @param sqlTimestamp
     *            the sqlTimestamp to set
     */
    public void setSqlTimestamp(java.sql.Timestamp sqlTimestamp)
    {
        this.sqlTimestamp = sqlTimestamp;
    }

    /**
     * Gets the sql time.
     *
     * @return the sqlTime
     */
    public java.sql.Time getSqlTime()
    {
        return sqlTime;
    }

    /**
     * Sets the sql time.
     *
     * @param sqlTime
     *            the sqlTime to set
     */
    public void setSqlTime(java.sql.Time sqlTime)
    {
        this.sqlTime = sqlTime;
    }

    /**
     * Gets the big integer.
     *
     * @return the bigInteger
     */
    public BigInteger getBigInteger()
    {
        return bigInteger;
    }

    /**
     * Sets the big integer.
     *
     * @param bigInteger
     *            the bigInteger to set
     */
    public void setBigInteger(BigInteger bigInteger)
    {
        this.bigInteger = bigInteger;
    }

    /**
     * Gets the big decimal.
     *
     * @return the bigDecimal
     */
    public BigDecimal getBigDecimal()
    {
        return bigDecimal;
    }

    /**
     * Sets the big decimal.
     *
     * @param bigDecimal
     *            the bigDecimal to set
     */
    public void setBigDecimal(BigDecimal bigDecimal)
    {
        this.bigDecimal = bigDecimal;
    }

    /**
     * Gets the calendar.
     *
     * @return the calendar
     */
    public Calendar getCalendar()
    {
        return calendar;
    }

    /**
     * Sets the calendar.
     *
     * @param calendar
     *            the calendar to set
     */
    public void setCalendar(Calendar calendar)
    {
        this.calendar = calendar;
    }

}

{'repo_name': 'Impetus/Kundera', 'stars': '887', 'repo_language': 'Java', 'file_name': 'CassandraGeneratedIdWithOutTableGenerator.java', 'mime_type': 'text/x-java', 'hash': -3524489825313380878, 'source_dataset': 'data'}


//<snippet7>
using System;
using System.IO;

class MyStream
{
    private const string FILE_NAME = "Test.data";

    public static void Main()
    {
        if (File.Exists(FILE_NAME))
        {
            Console.WriteLine($"{FILE_NAME} already exists!");
            return;
        }

        using (FileStream fs = new FileStream(FILE_NAME, FileMode.CreateNew))
        {
            using (BinaryWriter w = new BinaryWriter(fs))
            {
                for (int i = 0; i < 11; i++)
                {
                    w.Write(i);
                }
            }
        }

        using (FileStream fs = new FileStream(FILE_NAME, FileMode.Open, FileAccess.Read))
        {
            using (BinaryReader r = new BinaryReader(fs))
            {
                for (int i = 0; i < 11; i++)
                {
                    Console.WriteLine(r.ReadInt32());
                }
            }
        }
    }
}

// The example creates a file named "Test.data" and writes the integers 0 through 10 to it in binary format.
// It then writes the contents of Test.data to the console with each integer on a separate line.
//</snippet7>

{'repo_name': 'dotnet/docs', 'stars': '2342', 'repo_language': 'PowerShell', 'file_name': 'class1.vb', 'mime_type': 'text/plain', 'hash': 2165807881355620164, 'source_dataset': 'data'}


Synopsis

    cordova-cli run [MODE] [BUILDOPTS] [TARGET] [PLATS] [BUILDCONFIG] [-- POPTS]

      MODE:        --list|--debug|--release
      BUILDOPTS:   --noprepare --nobuild
      TARGET:      DEVICECLASS|--target=FOO
      PLATS:       PLATFORM [...]
      BUILDCONFIG: --buildConfig=CONFIGFILE
      POPTS:       platformopts
      DEVICECLASS: --device|--emulator

Deploys app on specified platform devices / emulators

    --list ............................. Lists available targets
                                         Will display both device and emulator
                                         unless DEVICECLASS option is provided

    --debug ............................ Deploy a debug build
    --release .......................... Deploy a release build

    --noprepare ........................ Don't prepare
    --nobuild .......................... Don't build

    --device ........................... Deploy to a device
    --emulator ......................... Deploy to an emulator
    --target ........................... Deploy to a specific target

    --buildConfig....................... Use the specified build configuration
                                         instead of default build.json

To provide platform specific options, you must include them after `--`.

Technical details
    calls cordova prepare (unless --noprepare)
    calls PLATFORM run
        PLATFORM run calls PLATFORM build (unless --nobuild)

Examples
    cordova-cli run android --release --buildConfig=..\myBuildConfig.json --target=myEmulator
    cordova-cli run android --nobuild
    cordova-cli run ios --device
    cordova-cli run ios --list

{'repo_name': 'apache/cordova-cli', 'stars': '834', 'repo_language': 'JavaScript', 'file_name': 'prepare.txt', 'mime_type': 'text/plain', 'hash': -4838081909588850154, 'source_dataset': 'data'}