Exemple #1
0
/* mouse over ">>" button - show tool tip */
static int mouseover_mixall_handler(window_info *win, int mx, int my)
{
	if (show_help_text)
		show_help(mixall_str, SLOT_SIZE*8-5, manufacture_menu_y_len+10);
	return 0;
}
Exemple #2
0
/* mouse over ">" button - show tool tip */
static int mouseover_mixone_handler(window_info *win, int mx, int my)
{
	if (show_help_text)
		show_help(mix_str, SLOT_SIZE*NUM_MIX_SLOTS+25, manufacture_menu_y_len+10);
	return 0;
}
int main(void){
	newtComponent hForm, button1, button2;
	newtComponent astIpLabel, astPortLabel, astUserLabel, astPassLabel;
	newtComponent astIpEntry, astPortEntry, astUserEntry, astPassEntry;
	const char *astIpVal, *astPortVal, *astUserVal, *astPassVal;

	newtComponent humbugHostLabel, humbugPortLabel, humbugApiLabel;
	newtComponent humbugHostEntry, humbugPortEntry, humbugApiEntry;
	const char *humbugHostVal, *humbugPortVal, *humbugApiVal;

	int i, y;

	newtComponent eventsLabel, eventsChk[EVENTS_SIZE], chkList;
	newtComponent encChk, encLabel, encEntry, chkLog;
	char encVal, logVal;
	const char *encKey;
	char eventsList[EVENTS_SIZE][16];
	char eventsResults[EVENTS_SIZE];
	strcpy(eventsList[0], "CDR");
	strcpy(eventsList[1], "NewExten");
	strcpy(eventsList[2], "Reload");
	strcpy(eventsList[3], "Shutdown");
	strcpy(eventsList[4], "Alarm");
	strcpy(eventsList[5], "AlarmClear");
	strcpy(eventsList[6], "CollectorAlarm");

	struct newtExitStruct es;

	params = (parameters*) calloc(1, sizeof(parameters));

	if(readHumbugConfig() < 0) {
		exit(EXIT_FAILURE);
	}

	newtInit();
	newtCls();

	newtDrawRootText(1, 0, "Text Mode Setup for humbug-collector  (c) 2011 Humbug Telecom Labs, Ltd.");
	newtPushHelpLine(" <Tab>/<Alt-Tab> between elements | <ESC> exits without save | <F12> for help");

	newtCenteredWindow(66, 17, "Humbug Setup");

	astIpLabel   = newtLabel(1, 1, "      Manager IP:");
	astIpEntry   = newtEntry(19, 1, params->astIpVal, 20, &astIpVal, 0);
	astPortLabel = newtLabel(1, 2, "    Manager Port:");
	astPortEntry = newtEntry(19, 2, params->astPortVal, 20, &astPortVal, 0);
	astUserLabel = newtLabel(1, 3, "Manager Username:"******"Manager Password:"******"     Humbug Host:");
	humbugHostEntry = newtEntry(19, 6, params->humbugHost, 20, &humbugHostVal, 0);
	humbugPortLabel = newtLabel(1, 7, "     Humbug Port:");
	humbugPortEntry = newtEntry(19, 7, params->humbugPort, 20, &humbugPortVal, 0);
	humbugApiLabel  = newtLabel(1, 8, "  Humbug API key:");
	humbugApiEntry  = newtEntry(19, 8, params->humbugApikey, 20, &humbugApiVal, NEWT_FLAG_SCROLL);

	if(1 == params->encrypted){
		encChk = newtCheckbox(19, 10, "Encrypted", 'X', " X", &encVal);
	}else{
		encChk = newtCheckbox(19, 10, "Encrypted", ' ', " X", &encVal);
	}
	encLabel = newtLabel(1, 11, "  Encryption key:");
	encEntry = newtEntry(19, 11, params->humbugKey, 42, &encKey, NEWT_FLAG_SCROLL);

	if(strlen(params->log_file) > 0 ){
		chkLog = newtCheckbox(19, 13, "Log ON/OFF", 'X', " X", &logVal);
	}else{
		chkLog = newtCheckbox(19, 13, "Log ON/OFF", ' ', " X", &logVal);
	}

	eventsLabel  = newtLabel(42, 1, "Events for analyze:");

	button1 = newtButton(36, 13, "Save & Exit");
	button2 = newtButton(53, 13, "Quit");

	chkList = newtForm(NULL, NULL, 0);
	newtFormSetBackground(chkList, NEWT_COLORSET_CHECKBOX);

	for(i=0; i<EVENTS_SIZE; i++) {
		int selected = 0;
		for(y=0; y<params->eventsSize; y++){
			if(0 == strcasecmp(eventsList[i], params->events[y])){
				selected = 1;
				break;
			}
		}
		if (1 == selected) {
			eventsChk[i] = newtCheckbox(47, 2 + i, eventsList[i], 'X', " X", &eventsResults[i]);
		} else {
			eventsChk[i] = newtCheckbox(47, 2 + i, eventsList[i], ' ', " X", &eventsResults[i]);
		}
		newtFormAddComponent(chkList, eventsChk[i]);
	}

	hForm = newtForm(NULL, NULL, 0);

	newtFormAddComponents(hForm, button1, button2,
			astIpLabel, astPortLabel, astUserLabel, astPassLabel,
			astIpEntry, astPortEntry, astUserEntry, astPassEntry,
			humbugHostLabel, humbugPortLabel, humbugApiLabel,
			humbugHostEntry, humbugPortEntry, humbugApiEntry,
			eventsLabel, chkList, encChk, encLabel, encEntry, chkLog,
			NULL);

	for(;;){
		do{
			newtFormRun(hForm, &es);
		}while(es.reason == NEWT_EXIT_TIMER);
		if (es.reason == NEWT_EXIT_HOTKEY) {
			int done = 0;
			switch (es.u.key) {
				case NEWT_KEY_ESCAPE:
					done = 1;
					break;
				case NEWT_KEY_F12:
					show_help();
					break;
			}
			if(done)
				break;
		}else if (es.reason == NEWT_EXIT_COMPONENT) {
			if(es.u.co == button1){
				strcpy(params->astIpVal, astIpVal);
				strcpy(params->astPortVal, astPortVal);
				strcpy(params->astUserVal, astUserVal);
				strcpy(params->astPassVal, astPassVal);
				strcpy(params->humbugApikey, humbugApiVal);

				params->eventsSize = 0;
				for(i=0; i<EVENTS_SIZE; i++) {
					if(eventsResults[i] == 'X') {
						strcpy(params->events[params->eventsSize], eventsList[i]);
						params->eventsSize++;
					}
				}
				params->encrypted = (encVal == 'X') ? 1 : 0;
				strcpy(params->humbugKey, encKey);
				strcpy(params->log_file, HBG_LOG_FILE);
				saveHumbugConfig();
			}
			break;
		}
	}
	newtPopWindow();
	newtPopHelpLine();
	newtFinished();
	newtFormDestroy(hForm);
	free(params);
	return(EXIT_SUCCESS);
}
int main(int argc, char **argv)
{
	unsigned long devt;
	int ldisc;
	struct input_types *type = NULL;
	const char *device = NULL;
	int daemon_mode = 0;
	int need_device = 0;
	unsigned long id, extra;
	int fd;
	int i;
	unsigned char c;
	int retval;
	int baud = -1;
	int ignore_init_res = 0;
	int no_init = 0;

	for (i = 1; i < argc; i++) {
		if (!strcasecmp(argv[i], "--help")) {
			show_help();
			return EXIT_SUCCESS;
		} else if (!strcasecmp(argv[i], "--daemon")) {
			daemon_mode = 1;
		} else if (!strcasecmp(argv[i], "--always")) {
			ignore_init_res = 1;
		} else if (!strcasecmp(argv[i], "--noinit")) {
			no_init = 1;
		} else if (need_device) {
			device = argv[i];
			need_device = 0;
		} else if (!strcasecmp(argv[i], "--baud")) {
			if (argc <= i + 1) {
				show_help();
				fprintf(stderr,
					"inputattach: require baud rate\n");
				return EXIT_FAILURE;
			}

			baud = atoi(argv[++i]);
		} else {
			if (type && type->name) {
				fprintf(stderr,
					"inputattach: '%s' - "
					"only one mode allowed\n", argv[i]);
				return EXIT_FAILURE;
			}
			for (type = input_types; type->name; type++) {
				if (!strcasecmp(argv[i], type->name) ||
				    !strcasecmp(argv[i], type->name2)) {
					break;
				}
			}
			if (!type->name) {
				fprintf(stderr,
					"inputattach: invalid mode '%s'\n",
					argv[i]);
				return EXIT_FAILURE;
			}
			need_device = 1;
		}
	}

	if (!type || !type->name) {
		fprintf(stderr, "inputattach: must specify mode\n");
		return EXIT_FAILURE;
        }

	if (need_device) {
		fprintf(stderr, "inputattach: must specify device\n");
		return EXIT_FAILURE;
	}

	fd = open(device, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (fd < 0) {
		fprintf(stderr, "inputattach: '%s' - %s\n",
			device, strerror(errno));
		return 1;
	}

	switch(baud) {
	case -1: break;
	case 2400: type->speed = B2400; break;
	case 4800: type->speed = B4800; break;
	case 9600: type->speed = B9600; break;
	case 19200: type->speed = B19200; break;
	case 38400: type->speed = B38400; break;
	default:
		fprintf(stderr, "inputattach: invalid baud rate '%d'\n",
				baud);
		return EXIT_FAILURE;
	}

	setline(fd, type->flags, type->speed);

	if (type->flush)
		while (!readchar(fd, &c, 100))
			/* empty */;

	id = type->id;
	extra = type->extra;

	if (type->init && !no_init) {
		if (type->init(fd, &id, &extra)) {
			if (ignore_init_res) {
				fprintf(stderr, "inputattach: ignored device initialization failure\n");
			} else {
				fprintf(stderr, "inputattach: device initialization failed\n");
				return EXIT_FAILURE;
			}
		}
	}

	ldisc = N_MOUSE;
	if (ioctl(fd, TIOCSETD, &ldisc) < 0) {
		fprintf(stderr, "inputattach: can't set line discipline\n");
		return EXIT_FAILURE;
	}

	devt = type->type | (id << 8) | (extra << 16);

	if (ioctl(fd, SPIOCSTYPE, &devt) < 0) {
		fprintf(stderr, "inputattach: can't set device type\n");
		return EXIT_FAILURE;
	}

	retval = EXIT_SUCCESS;
	if (daemon_mode && daemon(0, 0) < 0) {
		perror("inputattach");
		retval = EXIT_FAILURE;
	}

	do {
		i = read(fd, NULL, 0);
		if (i == -1) {
			if (RETRY_ERROR(errno))
				continue;
		}
	} while (!i);

	ldisc = 0;
	ioctl(fd, TIOCSETD, &ldisc);
	close(fd);

	return retval;
}
Exemple #5
0
static void *display_deltacast_init(struct module *parent, const char *fmt, unsigned int flags)
{
        UNUSED(parent);
        struct state_deltacast *s;
        ULONG             Result,DllVersion,NbBoards,ChnType;
        ULONG             BrdId = 0;

        s = (struct state_deltacast *)calloc(1, sizeof(struct state_deltacast));
        s->magic = DELTACAST_MAGIC;
        
        s->frame = vf_alloc(1);
        s->tile = vf_get_tile(s->frame, 0);
        s->frames = 0;
        
        gettimeofday(&s->tv, NULL);
        
        s->initialized = FALSE;
        if(flags & DISPLAY_FLAG_AUDIO_EMBEDDED) {
                s->play_audio = TRUE;
        } else {
                s->play_audio = FALSE;
        }
        
        s->BoardHandle = s->StreamHandle = s->SlotHandle = NULL;
        s->audio_configured = FALSE;

        if(fmt && strcmp(fmt, "help") == 0) {
                show_help();
                vf_free(s->frame);
                free(s);
                return &display_init_noerr;
        }
        
        if(fmt)
        {
                char *tmp = strdup(fmt);
                char *save_ptr = NULL;
                char *tok;
                
                tok = strtok_r(tmp, ":", &save_ptr);
                if(!tok)
                {
                        free(tmp);
                        show_help();
                        goto error;
                }
                if (strncasecmp(tok, "board=", strlen("board=")) == 0) {
                        BrdId = atoi(tok + strlen("board="));
                } else {
                        fprintf(stderr, "Unknown option: %s\n\n", tok);
                        free(tmp);
                        show_help();
                        goto error;
                }
                free(tmp);
        }

        /* Query VideoMasterHD information */
        Result = VHD_GetApiInfo(&DllVersion,&NbBoards);
        if (Result != VHDERR_NOERROR) {
                fprintf(stderr, "[DELTACAST] ERROR : Cannot query VideoMasterHD"
                                " information. Result = 0x%08X\n",
                                Result);
                goto error;
        }
        if (NbBoards == 0) {
                fprintf(stderr, "[DELTACAST] No DELTA board detected, exiting...\n");
                goto error;
        }
        
        if(BrdId >= NbBoards) {
                fprintf(stderr, "[DELTACAST] Wrong index %d. Found %d cards.\n", BrdId, NbBoards);
                goto error;
        }

        /* Open a handle on first DELTA-hd/sdi/codec board */
        Result = VHD_OpenBoardHandle(BrdId,&s->BoardHandle,NULL,0);
        if (Result != VHDERR_NOERROR)
        {
                fprintf(stderr, "[DELTACAST] ERROR : Cannot open DELTA board %u handle. Result = 0x%08X\n",BrdId,Result);
                goto error;
        }
        VHD_GetBoardProperty(s->BoardHandle, VHD_CORE_BP_TX0_TYPE, &ChnType);
        if((ChnType!=VHD_CHNTYPE_SDSDI)&&(ChnType!=VHD_CHNTYPE_HDSDI)&&(ChnType!=VHD_CHNTYPE_3GSDI)) {
                fprintf(stderr, "[DELTACAST] ERROR : The selected channel is not an SDI one\n");
                goto bad_channel;
        }
        
        /* Disable RX0-TX0 by-pass relay loopthrough */
        VHD_SetBoardProperty(s->BoardHandle,VHD_CORE_BP_BYPASS_RELAY_0,FALSE);
        
        /* Select a 1/1 clock system */
        VHD_SetBoardProperty(s->BoardHandle,VHD_SDI_BP_CLOCK_SYSTEM,VHD_CLOCKDIV_1);

        pthread_mutex_init(&s->lock, NULL);
                  
	return s;

bad_channel:
        VHD_CloseBoardHandle(s->BoardHandle);
error:
        vf_free(s->frame);
        free(s);
        return NULL;
}
Exemple #6
0
	// Draw the item list window
	//
	int List_Window::draw(window_info *win)
	{
		Vars::lists()->check_and_timed_save(false);

		// if resizing wait until we stop
		if (win->resized)
			resizing = true;
		// once we stop, snap the window size to fix nicely
		else if (resizing)
		{
			calc_num_show_names(win->len_y);
			resizing = false;
			resize_window (win->window_id, get_size_x(), get_size_y());
		}

		// check if we need to change the number of grid rows shown
		int new_num_grid_rows = min_grid_rows();
		if (Vars::lists()->valid_active_list())
			new_num_grid_rows = std::max(static_cast<size_t>(new_num_grid_rows), (Vars::lists()->get_list().get_num_items() +5) / 6);
		if (num_grid_rows != new_num_grid_rows)
		{
			num_grid_rows = new_num_grid_rows;
			resized_name_panel(win);
		}

		// if the left/right position flag has changed, restore the window to its default location
		if (last_items_list_on_left != items_list_on_left)
		{
			if (last_items_list_on_left != -1)
				reset_position();
			last_items_list_on_left = items_list_on_left;
		}

		glEnable(GL_TEXTURE_2D);

		// draw the images
		if (Vars::lists()->valid_active_list())
		{
			glColor3f(1.0f,1.0f,1.0f);
			for(size_t i=0; i<Vars::lists()->get_list().get_num_items() && i<static_cast<size_t>(6*num_grid_rows); i++)
			{
				int x_start, y_start;
				x_start = get_grid_size() * (i%6) + 1;
				y_start = get_grid_size() * (i/6);
				draw_item(Vars::lists()->get_list().get_image_id(i), x_start, y_start, get_grid_size());
			}
		}

		size_t help_lines_shown = 0;

		if (desc_str)
		{
			show_help(desc_str, 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown++));
			desc_str = 0;
		}

		// Display any name search text
		if (strlen(filter))
		{
			if (SDL_GetTicks() > (last_key_time+5000))
			{
				filter[0] = '\0';
				last_key_time = 0;
			}
			else
			{
				std::string tmp = std::string(item_list_find_str) + std::string("[") + std::string(filter) + std::string("]");
				show_help(tmp.c_str(), 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown++));
			}
		}

		// draw mouse over window help text
		if (show_help_text)
		{
			if (!resizing)
				for (size_t i=0; i<help_str.size(); ++i)
					show_help(help_str[i], 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown++));
			help_str.clear();
		}

		glDisable(GL_TEXTURE_2D);

		// draw the item grid
		glColor3f(newcol_r, newcol_g, newcol_b);
		rendergrid(6, num_grid_rows, 0, 0, get_grid_size(), get_grid_size());

		// if an object is selected, draw a green grid around it
		if (Vars::lists()->valid_active_list() && (quantities.selected == ITEM_EDIT_QUANT) && (selected_item_number < Vars::lists()->get_list().get_num_items()))
		{
			int x_start = selected_item_number%6 * get_grid_size();
			int y_start = static_cast<int>(selected_item_number/6) * get_grid_size();
			if ((SDL_GetTicks() - pickup_fail_time) < 250)
				glColor3f(0.8f,0.2f,0.2f);
			else
				glColor3f(0.0f, 1.0f, 0.3f);
			rendergrid(1, 1, x_start, y_start, get_grid_size(), get_grid_size());
			rendergrid(1, 1, x_start-1, y_start-1, get_grid_size()+2, get_grid_size()+2);
		}

		glEnable(GL_TEXTURE_2D);

		// draw the quantities over everything else so they always show
		if (Vars::lists()->valid_active_list())
		{
			glColor3f(1.0f,1.0f,1.0f);
			char str[80];
			for(size_t i=0; i<Vars::lists()->get_list().get_num_items() && i<static_cast<size_t>(6*num_grid_rows); i++)
			{
				int x_start, y_start, y_end;
				x_start = get_grid_size() * (i%6) + 1;
				y_start = get_grid_size() * (i/6);
				y_end = y_start + get_grid_size() - 1;
				safe_snprintf(str, sizeof(str), "%i", Vars::lists()->get_list().get_quantity(i));
				draw_string_small_shadowed(x_start, (i&1)?(y_end-15):(y_end-27), (unsigned char*)str, 1,1.0f,1.0f,1.0f, 0.0f, 0.0f, 0.0f);
			}
		}

		// Drawn the new list button (+) with highlight when mouse over
		if (mouse_over_add_button)
			glColor3f(0.99f,0.77f,0.55f);
		else
			glColor3f(newcol_r, newcol_g, newcol_b);
		draw_string_zoomed(add_button_x, add_button_y, (unsigned const char*)"+", 1, 2.0);

		// draw the item list names
		glColor3f(1.0f,1.0f,1.0f);
		int pos_y = get_grid_size()*num_grid_rows + get_list_gap();
		int num_shown = 0;
		const int top_entry = vscrollbar_get_pos (win_id, names_scroll_id);
		const std::vector<List> lists = Vars::lists()->get_lists();
		const int hl_width = static_cast<int>(win->len_x-ELW_BOX_SIZE-3);
		const int hl_height = static_cast<int>(names_list_height + get_list_gap());
		const size_t disp_chars = static_cast<size_t>((win->len_x-ELW_BOX_SIZE-2*get_list_gap()) / SMALL_FONT_X_LEN);
		for (size_t i = top_entry; i<lists.size() && num_shown<num_show_names_list; ++i)
		{
			if (i==Vars::lists()->get_active())
				draw_highlight(1, static_cast<int>(pos_y-get_list_gap()/2), hl_width, hl_height, 1);
			else if (i==name_under_mouse)
				draw_highlight(1, static_cast<int>(pos_y-get_list_gap()/2), hl_width, hl_height, 0);
			glColor3f(1.0f,1.0f,1.0f);
			if (lists[i].get_name().size() > disp_chars)
			{
				std::string todisp = lists[i].get_name().substr(0,disp_chars);
				draw_string_small(get_list_gap(), pos_y, reinterpret_cast<const unsigned char*>(todisp.c_str()), 1);
				if (i==name_under_mouse)
					show_help(lists[i].get_name().c_str(), 0, static_cast<int>(0.5 + win->len_y + 10 + SMALL_FONT_Y_LEN * help_lines_shown));
			}
			else
				draw_string_small(get_list_gap(), pos_y, reinterpret_cast<const unsigned char*>(lists[i].get_name().c_str()), 1);
			pos_y += static_cast<int>(names_list_height + get_list_gap());
			num_shown++;
		}

		if (clicked && (name_under_mouse < lists.size()))
		{
			do_click_sound();
			Vars::lists()->set_active(name_under_mouse);
		}

		if (clicked && mouse_over_add_button)
		{
			do_click_sound();
			new_or_rename_list(true);
		}
		name_under_mouse = static_cast<size_t>(-1);
		mouse_over_add_button = clicked = false;

#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
		return 1;
	}