Example #1
0
static int perform_window_task(aroop_txt_t*msg, int*offset, int*cur_key, int*cur_type, int*cur_len) {
	// check the task ..
	static int ready = 0;
	ready++;
	int cmd = msg_numeric_value(msg, offset, cur_type, cur_len);
	SYNC_ASSERT(msg_next(msg, offset, cur_key, cur_type, cur_len) != -1);
	SYNC_ASSERT(*cur_key == ENUM_ROOPKOTHA_GUI_CORE_TASK_ARG);
	int wid = msg_numeric_value(msg, offset, cur_type, cur_len);
	x11_window_t*win = get_window(wid);
	switch(cmd) {
	case ENUM_ROOPKOTHA_GUI_WINDOW_TASK_SHOW_WINDOW:
		if(win == NULL) {
			win = create_window(gcore.disp, RootWindow (gcore.disp, gcore.scrn), wid);
		}
		watchdog_log_string("Show window\n");
		break;
	case ENUM_ROOPKOTHA_GUI_WINDOW_TASK_DESTROY:
		aroop_indexed_list_set(&gcore.pwins, wid, NULL);
		if(win != NULL) {
			// TODO destroy window
		}
	break;
#if 0
	case ENUM_ROOPKOTHA_GUI_WINDOW_TASK_PAINT_COMPLETE:
		qw->setPage(qtg->page);
		qtg->painter->end();
		qw->repaint();
	break;
#endif
	}
	if(win)
		OPPUNREF(win);
	return 0;
}
Example #2
0
static int repaint_x11() {
	int i = 0;
	for(i = 0; i < 24; i++) {
		aroop_txt_t*msg = opp_indexed_list_get(&gcore.layers, i);
		if(!msg)continue;
		x11_window_t*win = NULL;
		int offset = 0;
		int cur_key = 0;
		int cur_type = 0;
		int cur_len = 0;
		while(msg_next(msg, &offset, &cur_key, &cur_type, &cur_len) != -1) {
			switch(cur_key) {
			case ENUM_ROOPKOTHA_GUI_CORE_TASK_GRAPHICS_TASK:
				perform_graphics_task(msg, &offset, &cur_key, &cur_type, &cur_len, &win);
				break;
			default:
				break;
			}
		}
		aroop_object_unref(aroop_txt_t*,0,msg);
		if(win)
			OPPUNREF(win);
	}
	return 0;
}
Example #3
0
static int perform_task() {
	aroop_txt_t*msg = NULL;
	x11_window_t*win = NULL;
	while((msg = (aroop_txt_t*)opp_dequeue(&gcore.incoming))) {
		int offset = 0;
		int cur_key = 0;
		int cur_type = 0;
		int cur_len = 0;
		while(msg_next(msg, &offset, &cur_key, &cur_type, &cur_len) != -1) {
			switch(cur_key) {
			case ENUM_ROOPKOTHA_GUI_CORE_TASK_WINDOW_TASK:
				perform_window_task(msg, &offset, &cur_key, &cur_type, &cur_len);
				break;
			case ENUM_ROOPKOTHA_GUI_CORE_TASK_GRAPHICS_TASK:
				perform_graphics_task(msg, &offset, &cur_key, &cur_type, &cur_len, &win);
				break;
			case ENUM_ROOPKOTHA_GUI_CORE_TASK_MISC_TASK:
				perform_misc_task(msg, &offset, &cur_key, &cur_type, &cur_len);
				break;
			default:
				break;
			}
		}
		aroop_object_unref(aroop_txt_t*,0,msg);
	}
	perform_x11_task();
	return 0;
}
Example #4
0
static int perform_graphics_task(aroop_txt_t*msg, int*offset, int*cur_key, int*cur_type, int*cur_len, x11_window_t**gwin) {
	// check the task ..
	int cmd = msg_numeric_value(msg, offset, cur_type, cur_len);
	x11_window_t*win = *gwin;
	switch(cmd) {
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_DRAW_IMAGE:
		{
			SYNC_ASSERT(msg_next(msg, offset, cur_key, cur_type, cur_len) != -1);
			SYNC_ASSERT(*cur_key == ENUM_ROOPKOTHA_GUI_CORE_TASK_ARG);
			aroop_txt_t img_data;
			msg_binary_value(msg, offset, cur_type, cur_len, &img_data);
			unsigned int x,y,anc;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 3, &x, &y, &anc);
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_DRAW_LINE:
		{
			unsigned int x1,x2,y1,y2;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 4, &x1, &y1, &x2, &y2);
	    		if(win) {
				XDrawLine (gcore.disp, win->w, win->gc, x1, y1, x2, y2);
			}
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_DRAW_RECT:
		{
			unsigned int x,y,width,height;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 4, &x, &y, &width, &height);
	    		if(win) {
				XDrawRectangle (gcore.disp, win->w, win->gc, x, y, width, height);
			}
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_DRAW_ROUND_RECT:
		{
			int x,y,width,height,arcWidth,arcHeight;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 6, &x, &y, &width, &height, &arcWidth, &arcHeight);
	    		if(win) {
				XDrawRectangle (gcore.disp, win->w,win->gc, x, y, width, height);
			}
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_FILL_RECT:
		{
			unsigned int x,y,width,height;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 4, &x, &y, &width, &height);
	    		if(win) {
				XFillRectangle (gcore.disp, win->w,win->gc, x, y, width, height);
			}
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_FILL_ROUND_RECT:
		{
			int x,y,width,height,arcWidth,arcHeight;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 6, &x, &y, &width, &height, &arcWidth, &arcHeight);
	    		if(win) {
				XFillRectangle (gcore.disp, win->w,win->gc, x, y, width, height);
			}
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_FILL_TRIANGLE:
		{
			int x1,y1,x2,y2,x3,y3;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 6, &x1, &y1, &x2, &y2, &x3, &y3);
			// TODO draw line
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_DRAW_STRING:
		{
			SYNC_ASSERT(msg_next(msg, offset, cur_key, cur_type, cur_len) != -1);
			SYNC_ASSERT(*cur_key == ENUM_ROOPKOTHA_GUI_CORE_TASK_ARG);
			aroop_txt_t content;
			msg_string_value(msg, offset, cur_type, cur_len, &content);
			int x,y,width,height,anc;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 5, &x, &y, &width, &height, &anc);
	    		if(!win) {
				break;
			}
			int xpos = x;
			if(anc & ENUM_ROOPKOTHA_GRAPHICS_ANCHOR_RIGHT) {
				xpos = x+width-5*content.len;
			}
			int ypos = y+10;
			if(anc & ENUM_ROOPKOTHA_GRAPHICS_ANCHOR_BOTTOM) {
				ypos = y+height;
			}
			XDrawString (gcore.disp, win->w,win->gc, xpos, ypos, aroop_txt_to_string(&content), content.len);
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_SET_COLOR: // TODO abolish this task
		{
			SYNC_ASSERT(msg_next(msg, offset, cur_key, cur_type, cur_len) != -1);
			SYNC_ASSERT(*cur_key == ENUM_ROOPKOTHA_GUI_CORE_TASK_ARG);
			unsigned int rgb = msg_numeric_value(msg, offset, cur_type, cur_len);
	    		if(!win) {
				break;
			}
			Colormap colormap;
			colormap = DefaultColormap(gcore.disp, gcore.scrn);
			XColor rgbc;
#define RGBC rgbc
//#define RGBC gcore.rgbc
			unsigned char red = ((rgb & 0XFF0000)>>16) & 0xFF;
			unsigned char green = ((rgb & 0XFF00)>>8) & 0xFF;
			unsigned char blue = rgb & 0XFF;
			char spec[32];
			snprintf(spec, 32, "#%02x%02x%02x", red, green, blue);
			XParseColor (gcore.disp, colormap, spec, &RGBC);
			XAllocColor(gcore.disp, colormap, &RGBC);
			// TODO free color !
			XSetForeground (gcore.disp, win->gc, RGBC.pixel);
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_SET_FONT: // TODO abolish this task
		{
			SYNC_ASSERT(msg_next(msg, offset, cur_key, cur_type, cur_len) != -1);
			SYNC_ASSERT(*cur_key == ENUM_ROOPKOTHA_GUI_CORE_TASK_ARG);
			int fontid = msg_numeric_value(msg, offset, cur_type, cur_len);
			// TODO set font
			break;
		}
	case ENUM_ROOPKOTHA_GRAPHICS_TASKS_START_LAYER:
		{
			int wid,layer;
			msg_scan(msg, offset, cur_key, cur_type, cur_len, 2, &wid, &layer);
			win = get_window(wid);
			*gwin = win;
			// save the layer
			aroop_txt_t*oldTasks = opp_indexed_list_get(&gcore.layers, layer);
			if(oldTasks != msg) {
				opp_indexed_list_set(&gcore.layers, layer, msg);
			}
			if(oldTasks) {
				aroop_object_unref(aroop_txt_t*,0,oldTasks);
			}
			break;
		}
	}
	return 0;
}
int main(int argc, char *argv[])
{
  char urlbuf[1024];
  size_t n;
  int m, tcp;
  sip_t *sip;
  int exitcode = 0;
  msg_mclass_t const *sip_mclass = sip_default_mclass();
  msg_t *msg = msg_create(sip_mclass, MSG_FLG_EXTRACT_COPY);
  msg_iovec_t iovec[1];

  tcp = argv[1] && strcmp(argv[1], "-t") == 0;

  test_msg_class(sip_mclass);

  for (n = 0, m = 0;;) {
    if (msg_recv_iovec(msg, iovec, 1, 1, 0) < 0) {
      perror("msg_recv_iovec");
      exit(1);
    }
    assert(iovec->mv_len >= 1);

    n = read(0, iovec->mv_base, 1);

    if (n < 0) {
      perror("test_sip_msg read");
      exit(1);
    }

    msg_recv_commit(msg, n, n == 0);

    if (tcp)
      m = msg_extract(msg);

    if (n == 0 || m < 0)
      break;
  }

  if (!tcp)
    m = msg_extract(msg);

  sip = msg_object(msg);
  if (sip)
    fprintf(stdout, "sip flags = %x\n", sip->sip_flags);

  if (m < 0) {
    fprintf(stderr, "test_sip_msg: parsing error ("MOD_ZD")\n", n);
    exit(1);
  }

  if (sip->sip_flags & MSG_FLG_TRUNC) {
    fprintf(stderr, "test_sip_msg: message truncated\n");
    exit(1);
  }

  if (msg_next(msg)) {
    fprintf(stderr, "test_sip_msg: stuff after message\n");
    exit(1);
  }

#if 0
  fprintf(stderr, "test_sip_msg: %d headers (%d short ones), %d unknown\n",
	  msg->mh_n_headers, msg->mh_n_short, msg->mh_n_unknown);

  if (msg->mh_payload) {
    fprintf(stderr, "\twith payload of %d bytes\n",
	    msg->mh_payload->pl_len);
  }
#endif

  if (MSG_HAS_ERROR(sip->sip_flags) || sip->sip_error) {
    fprintf(stderr, "test_sip_msg: parsing error\n");
    exit(1);
  }
  else if (sip_sanity_check(sip) < 0) {
    fprintf(stderr, "test_sip_msg: message failed sanity check\n");
    exit(1);
  }

  if (sip->sip_request) {
    fprintf(stdout, "\trequest %s (%d) %s %s\n",
	    sip->sip_request->rq_method_name,
	    sip->sip_request->rq_method,
	    url_print(sip->sip_request->rq_url, urlbuf),
	    sip->sip_request->rq_version);
    if (sip->sip_request->rq_url->url_type == url_unknown) {
      exitcode = 1;
      fprintf(stderr, "test_sip_msg: invalid request URI\n");
    }
  }

  if (sip->sip_status)
    fprintf(stdout, "\tstatus %s %03d %s\n",
	    sip->sip_status->st_version,
	    sip->sip_status->st_status,
	    sip->sip_status->st_phrase);

  if (sip->sip_cseq)
    fprintf(stdout, "\tCSeq: %u %s (%d)\n",
	    sip->sip_cseq->cs_seq,
	    sip->sip_cseq->cs_method_name,
	    sip->sip_cseq->cs_method);

  if (sip->sip_call_id)
    fprintf(stdout, "\tCall-ID: %s (%x)\n",
	    sip->sip_call_id->i_id,
	    sip->sip_call_id->i_hash);

  if (sip->sip_from)
    fprintf(stdout, "\tFrom: %s@%s%s%s\n",
	    sip->sip_from->a_user ? sip->sip_from->a_user : "******",
	    sip->sip_from->a_host ? sip->sip_from->a_host : "[nowhere]",
	    sip->sip_from->a_tag ? " ;tag=" : "",
	    sip->sip_from->a_tag ? sip->sip_from->a_tag : "");

  if (sip->sip_to)
    fprintf(stdout, "\tTo: %s@%s%s%s\n",
	    sip->sip_to->a_user ? sip->sip_to->a_user : "******",
	    sip->sip_to->a_host ? sip->sip_to->a_host : "[nowhere]",
	    sip->sip_to->a_tag ? " ;tag=" : "",
	    sip->sip_to->a_tag ? sip->sip_to->a_tag : "");

  if (sip->sip_contact)
    print_contact(stdout, sip->sip_contact);
  if (sip->sip_via)
    print_via(stdout, sip->sip_via);

  if (sip->sip_content_length) {
    fprintf(stdout, "\tcontent length %u\n",
	    sip->sip_content_length->l_length);
  }

  if (msg_next(msg)) {
    fprintf(stderr, "test_sip_msg: extra stuff after valid message\n");
    exit(1);
  }

  return exitcode;
}