예제 #1
0
// Takes the first request and responds as ACK.
// Assuming all the errors are checked at the coordinator-server
char * exec_rqst(char * request){
		printf("Executing Request : %s\n", request);
		/* code to validate the request*/
		const char s[2] = ":";
		char *token;
		/* get the first token */
		token = strtok(request, s);            
		char allTokens[3][26];             
		int i = 0;
		while( token != NULL && i < 3)   
		{ 
					 printf("%s\n", token);	
						strcpy(allTokens[i],token);
						token = strtok(NULL, s);
						i++;
		}
		if(strcmp(allTokens[0],"GET") == 0){ 
//					callLog("Called method GET \n", log_filename);
						printf("Called method GET\n");
						int key = atoi(allTokens[1]);
						char *getValue = _GET(key);
//					send(newsock, getValue, strlen(getValue), 0);    
						FILE *fp = fopen(GET_FILE, "w");
						fputs(getValue, fp);
						fclose(fp);
		} 
		else if(strcmp(allTokens[0],"PUT") == 0){
//					callLog("Called method PUT \n", log_filename);
						printf("Inside PUT %s %s\n", allTokens[1], allTokens[2]);
						bool putValue = _PUT(atoi(allTokens[1]), allTokens[2]); 
						if(putValue){
//							callLog("Successfully Updated\n", log_filename);
								return "COMMIT";
						}

						else{
//						callLog("Error in updating \n", log_filename);
							return "PUT_ERROR";
						}

		}
		else if(strcmp(allTokens[0],"DELETE") == 0){
						printf("Inside DELETE\n");
						bool delValue = _DELETE(atoi(allTokens[1]));
						if(delValue){
							return "COMMIT";
						}
						else{
							return "DELETE_ERROR";
						}                
		}
		return "UN_KNOWN_REQUEST";
}
예제 #2
0
/*==============================================================================
 * - _cal_cb_release()
 *
 * - try to recognise a character
 */
static OS_STATUS _cal_cb_release (GUI_CBI *pCBI, GUI_COOR *p_cbi_coor)
{
    static int  last_x;
    char rec_ch = ' ';

    /* end the direction sequence */
    _PUT ('\0');

    /*
     * start recognise
     */

    /* process second strock */
    if (_G_igno_second_strock) { /* igno */
        _PUT2 ((char)_G_igno_second_strock, GUI_COLOR_WHITE);
        _G_igno_second_strock = 0;
        goto _finish;
    }

    if (_G_want_second_strock == 1) { /* check */
        int i;
        int e_num = 0;
        int c_num = 0;
        for (i = 0; i < _G_dir_num; i++) {
            if (_G_dirs[i] == 'e') {
                e_num++;
            } else if (_G_dirs[i] == 'c') {
                c_num++;
            }
        }

        if (_G_coors[0].x > last_x) { /* this is a new char */
            rec_ch = '-';
        } else if (_G_dir_num <= 3) { /* this strock is little */
            rec_ch = '/'; _G_no_dot = 1;
        } else if (e_num >= _G_dir_num / 2) { /* this strock almost all 'e' dir */
            rec_ch = '+';
        } else if (c_num >= _G_dir_num / 2) { /* this strock almost all 'c' dir */
            rec_ch = '=';
        }

        _PUT2 ('<', GUI_BG_COLOR);
        _PUT2 (rec_ch, GUI_COLOR_WHITE);

        _G_want_second_strock = 0;

        if (rec_ch != '-') {
            goto _finish;
        }
    }

    /* process first strock */
    if (_G_dir_num >= 3) {
        rec_ch = rec_strock (_G_dirs);

        switch (rec_ch) {
            case '1':
                {
                    int i;
                    int e_num = 0;
                    int c_num = 0;
                    int f_num = 0;

                    for (i = 0; i < _G_dir_num; i++) {
                        if (_G_dirs[i] == 'e') {
                            e_num++;
                        } else if (_G_dirs[i] == 'c') {
                            c_num++;
                        } else if (_G_dirs[i] == 'f') {
                            f_num++;
                        }
                    }

                    if (e_num >= _G_dir_num / 2) {
                    } else if (c_num >= _G_dir_num / 2) {
                        last_x = _G_coors[_G_coor_num-1].x;
                        _PUT2 ('-', GUI_COLOR_WHITE);
                        _G_want_second_strock = 1;
                    } else if (f_num >= _G_dir_num / 2) {
                        _G_igno_second_strock = '*';
                    } else {
                        //GUI_ASSERT(0);
                    }
                    break;
                }
            case '4':
            case '5':
                _G_igno_second_strock = rec_ch;
                break;
            default:
                break;
        }

        if (_G_want_second_strock == 0 &&
            _G_igno_second_strock == 0) {
            _PUT2 (rec_ch, GUI_COLOR_WHITE);
        }
    } else {
        if (_G_no_dot) {
            _G_no_dot = 0;
        } else {
            _PUT2 ('.', GUI_COLOR_WHITE);
        }
    }

_finish:
    cbf_default_release (pCBI, p_cbi_coor);
    return OS_STATUS_OK;
}
예제 #3
0
size_t _udi_marshal_step(void *buf, size_t cur_ofs, const udi_layout_t **layoutp, va_list *values)
{
	size_t	ofs = cur_ofs;
	const udi_layout_t	*layout = *layoutp;
	switch(*layout++)
	{
	case UDI_DL_UBIT8_T:	_PUT(udi_ubit8_t, UDI_VA_UBIT8_T);	break;
	case UDI_DL_SBIT8_T:	_PUT(udi_sbit8_t, UDI_VA_SBIT8_T);	break;
	case UDI_DL_UBIT16_T:	_PUT(udi_ubit16_t, UDI_VA_UBIT16_T);	break;
	case UDI_DL_SBIT16_T:	_PUT(udi_sbit16_t, UDI_VA_SBIT16_T);	break;
	case UDI_DL_UBIT32_T:	_PUT(udi_ubit32_t, UDI_VA_UBIT32_T);	break;
	case UDI_DL_SBIT32_T:	_PUT(udi_sbit32_t, UDI_VA_SBIT16_T);	break;
	case UDI_DL_BOOLEAN_T:	_PUT(udi_boolean_t, UDI_VA_BOOLEAN_T);	break;
	case UDI_DL_STATUS_T:	_PUT(udi_status_t, UDI_VA_STATUS_T);	break;
	
	case UDI_DL_INDEX_T:	_PUT(udi_index_t, UDI_VA_INDEX_T);	break;
	
	case UDI_DL_CHANNEL_T:	_PUT(udi_channel_t, UDI_VA_CHANNEL_T);	break;
	case UDI_DL_ORIGIN_T:	_PUT(udi_origin_t, UDI_VA_ORIGIN_T);	break;

	case UDI_DL_BUF:
		_PUT(udi_buf_t*,UDI_VA_POINTER);
		layout += 3;
		break;
	case UDI_DL_CB:
		_PUT(udi_cb_t*,UDI_VA_POINTER);
		break;
	case UDI_DL_INLINE_UNTYPED:
		_PUT(void*,UDI_VA_POINTER);
		break;
	case UDI_DL_INLINE_DRIVER_TYPED:
		_PUT(void*,UDI_VA_POINTER);
		break;
	case UDI_DL_MOVABLE_UNTYPED:
		_PUT(void*,UDI_VA_POINTER);
		break;
	
	case UDI_DL_INLINE_TYPED:
	case UDI_DL_MOVABLE_TYPED:
		_PUT(void*,UDI_VA_POINTER);
		while(*layout++ != UDI_DL_END)
			;
		break;

	default:
		Log_Error("UDI", "_udi_marshal_step - Unknown layout code %i", layout[-1]);
		return 0;
	}
	*layoutp = layout;
	return ofs;
}
예제 #4
0
/*==============================================================================
 * - _cal_cb_drag()
 *
 * - update screen coodinate and draw link line
 */
static OS_STATUS _cal_cb_drag (GUI_CBI *pCBI, GUI_COOR *p_offset_coor)
{
    static GUI_COOR sum_offset = {0, 0};

    /* check coor number */
    if (_G_coor_num >= MAX_COOR_NUM) {
        return OS_STATUS_ERROR;
    }

    /* store current coor */
    _G_coors[_G_coor_num].x = _G_coors[_G_coor_num - 1].x + p_offset_coor->x;
    _G_coors[_G_coor_num].y = _G_coors[_G_coor_num - 1].y + p_offset_coor->y;

    /* draw point and line */
    _draw_big_point (_G_coors[_G_coor_num], GUI_COLOR_YELLOW);
    gra_line_u (&_G_coors[_G_coor_num - 1], &_G_coors[_G_coor_num], GUI_COLOR_GREEN, 2);

    /* first drag, so we clear <sum_offset> */
    if (_G_coor_num == 1) {
        sum_offset.x = 0;
        sum_offset.y = 0;
    }

    /* adding offset */
    sum_offset.x += p_offset_coor->x;
    sum_offset.y += p_offset_coor->y;

    /* check the sum offset */
    if (GUI_ABS(sum_offset.x) + GUI_ABS(sum_offset.y) > _MIN_OFFSET) { 
        p_offset_coor->x = sum_offset.x;
        p_offset_coor->y = sum_offset.y;
    }

    /* according as offset, to get the direction */
    if (GUI_ABS(p_offset_coor->x) + GUI_ABS(p_offset_coor->y) > _MIN_OFFSET) {
        double dx = p_offset_coor->x;
        double dy = p_offset_coor->y;
        double dtan = GUI_ABS(dy) / GUI_ABS(dx);

        /* reverse the y axis */
        p_offset_coor->y = -p_offset_coor->y;

        /* in y axis */
        if (p_offset_coor->x == 0) {
            _PUT ((p_offset_coor->y > 0) ? 'a' : 'e');
        }

        /* check tan value */
        if ((p_offset_coor->x > 0) && (p_offset_coor->y >= 0)) {        /* first quadrant */
            if (dtan <= TAN_225) {
                _PUT('c');
            } else if ((dtan > TAN_225) && ((dtan < TAN_675))) {
                _PUT('b');
            } else if ((dtan >= TAN_675)) {
                _PUT('a');
            }
        } else if ((p_offset_coor->x > 0) && (p_offset_coor->y < 0)) {  /* fourth quadrant */
            if (dtan <= TAN_225) {
                _PUT('c');
            } else if ((dtan > TAN_225) && ((dtan < TAN_675))) {
                _PUT('d');
            } else if ((dtan >= TAN_675)) {
                _PUT('e');
            }
        } else if ((p_offset_coor->x < 0) && (p_offset_coor->y >= 0)) { /* second quadrant */
            if (dtan <= TAN_225) {
                _PUT('g');
            } else if ((dtan > TAN_225) && ((dtan < TAN_675))) {
                _PUT('h');
            } else if ((dtan >= TAN_675)) {
                _PUT('a');
            }
        } else if ((p_offset_coor->x < 0) && (p_offset_coor->y < 0)) {  /* third quadrant */
            if (dtan <= TAN_225) {
                _PUT('g');
            } else if ((dtan > TAN_225) && ((dtan < TAN_675))) {
                _PUT('f');
            } else if ((dtan >= TAN_675)) {
                _PUT('e');
            }
        }

        sum_offset.x = 0;
        sum_offset.y = 0;
    }

    /* inc <_G_coor_num> */
    _G_coor_num++;

    return OS_STATUS_OK;
}