SIM_DESC
sim_open (SIM_OPEN_KIND kind,
	  struct host_callback_struct *callback,
	  struct bfd *abfd, char **argv)
{
  if (open)
    fprintf (stderr, "rx minisim: re-opened sim\n");

  /* The 'run' interface doesn't use this function, so we don't care
     about KIND; it's always SIM_OPEN_DEBUG.  */
  if (kind != SIM_OPEN_DEBUG)
    fprintf (stderr, "rx minisim: sim_open KIND != SIM_OPEN_DEBUG: %d\n",
	     kind);

  set_callbacks (callback);

  /* We don't expect any command-line arguments.  */

  init_mem ();
  init_regs ();
  execution_error_init_debugger ();

  sim_disasm_init (abfd);
  open = 1;
  return &the_minisim;
}
Beispiel #2
0
SIM_DESC
sim_open (SIM_OPEN_KIND kind,
	  struct host_callback_struct *callback,
	  struct bfd *abfd, char **argv)
{
  setbuf (stdout, 0);
  if (open)
    fprintf (stderr, "m32c minisim: re-opened sim\n");

  /* The 'run' interface doesn't use this function, so we don't care
     about KIND; it's always SIM_OPEN_DEBUG.  */
  if (kind != SIM_OPEN_DEBUG)
    fprintf (stderr, "m32c minisim: sim_open KIND != SIM_OPEN_DEBUG: %d\n",
	     kind);

  if (abfd)
    m32c_set_mach (bfd_get_mach (abfd));

  /* We can use ABFD, if non-NULL to select the appropriate
     architecture.  But we only support the r8c right now.  */

  set_callbacks (callback);

  /* We don't expect any command-line arguments.  */

  init_mem ();
  init_regs ();

  open = 1;
  return &the_minisim;
}
Beispiel #3
0
void  do_some_work()

{
   int  event = 0;

   main_is_open = TRUE;

   open_rsc_window (START, 0, " STiK  Super Server ", " Main ", -1);
   set_callbacks (START, main_click, key_typed);
   set_callbacks (CB_MESSAGE, (FUNC) message_handler, (FUNC) 0L);

   while (event >= 0)
        if ((event = operate_events()) == -4)
             exit_inetd = TRUE;

   main_is_open = FALSE;
 }
Beispiel #4
0
int main()
{
    Packet p;
    IP4Hdr i4;
    IP6Hdr i6;

    /* This test assumes we get an IPv4 packet and verifies
     * that the correct callbacks are setup, and they return
     * the correct values. */

    set_callbacks(&p, AF_INET, CALLBACK_IP);

    /* Same test as above, but with IPv6 */
    set_callbacks(&p, AF_INET6, CALLBACK_IP);

    return 0;
}
bool Game_over_state::on_enter() {
	State_parser state_parser;
	state_parser.parse_state("../config/states.json", s_game_over_id, &m_game_objects, &m_texture_ids);

	m_callbacks.push_back(game_over_to_main);
	m_callbacks.push_back(game_over_to_play);
	set_callbacks(m_callbacks);

	return true;
}
Beispiel #6
0
void sfiph_orig_build(Packet *p, const void *hdr, int family)
{
    IP6RawHdr *hdr6;
    IPHdr *hdr4;

    if(!p || !hdr)
        return;

    /* If iph_api is already set, we've been here before.
     * That means this is a nested IP.  */
    if (p->orig_iph_api && (p->orig_iph_api->ver == IPH_API_V4))
    {
        memcpy(&p->outer_orig_ip4h, &p->inner_orig_ip4h, sizeof(IP4Hdr));
        p->outer_orig_iph_api = p->orig_iph_api;
    }
    else if (p->orig_iph_api && (p->orig_iph_api->ver == IPH_API_V6))
    {
        memcpy(&p->outer_orig_ip6h, &p->inner_orig_ip6h, sizeof(IP6Hdr));
        p->outer_orig_iph_api = p->orig_iph_api;
    }

    set_callbacks(p, family, CALLBACK_ICMP_ORIG);

    if(family == AF_INET)
    {
        hdr4 = (IPHdr*)hdr;

        /* The struct Snort uses is identical to the actual IP6 struct,
         * with the exception of the IP addresses. Copy over everything but
         * the IPs */
        memcpy(&p->inner_orig_ip4h, hdr4, sizeof(IPHdr) - 8);
        sfip_set_raw(&p->inner_orig_ip4h.ip_src, &hdr4->ip_src, p->family);
        sfip_set_raw(&p->inner_orig_ip4h.ip_dst, &hdr4->ip_dst, p->family);
        p->actual_ip_len = ntohs(p->inner_orig_ip4h.ip_len);
        p->orig_ip4h = &p->inner_orig_ip4h;
    }
    else
    {
        hdr6 = (IP6RawHdr*)hdr;

        /* The struct Snort uses is identical to the actual IP6 struct,
         * with the exception of the IP addresses. Copy over everything but
         * the IPs*/
        memcpy(&p->inner_orig_ip6h, hdr6, sizeof(IP6RawHdr) - 32);
        sfip_set_raw(&p->inner_orig_ip6h.ip_src, &hdr6->ip6_src, p->family);
        sfip_set_raw(&p->inner_orig_ip6h.ip_dst, &hdr6->ip6_dst, p->family);
        p->actual_ip_len = ntohs(p->inner_orig_ip6h.len) + IP6_HDR_LEN;
        p->orig_ip6h = &p->inner_orig_ip6h;
    }
}
Beispiel #7
0
int UIVR::act_on_command(int type, Command *c) {
  switch(type) {
  default:  return FALSE; 
    case Command::TOOL_OFFSET:
      {
      Tool *tool = gettool(((CmdToolScaleSpring *)c)->num);
      if (!tool) return FALSE;
      tool->setoffset(((CmdToolOffset *)c)->offset);
      }
      break;
    case Command::TOOL_ADD_DEVICE:
      {
      CmdToolAddDevice *cmd = (CmdToolAddDevice *)c; 
      Tool *tool = gettool(cmd->num);
      return add_device_to_tool(cmd->name, tool);
      }
      break;
    case Command::TOOL_DELETE_DEVICE:
      {
      CmdToolAddDevice *cmd = (CmdToolAddDevice *)c; 
      Tool *tool = gettool(cmd->num);
      if (!tool) return FALSE;
      if (!cmd->name) return FALSE;
      tool->remove_device(cmd->name);
      }
      break;
    case Command::TOOL_CALLBACK:
      {
      CmdToolCallback *cmd = (CmdToolCallback *)c;
      set_callbacks(cmd->on);
      break;
      }
    case Command::TOOL_REP:
      {
      CmdToolRep *cmd = (CmdToolRep *)c;
      Tool *tool = gettool(cmd->toolnum);
      if (!tool) return FALSE;
      if (cmd->molid < 0 || cmd->repnum < 0) {
        tool->clear_rep();
      } else {
        tool->assign_rep(cmd->molid, cmd->repnum);
      }
      }
      break;
  }
  return TRUE;
}
Beispiel #8
0
int main(int argc, char **argv) {
    pid_t pid = getpid();

    struct client_info info;
    memset(&info, 0, sizeof(info));
    info.pid = pid;

    struct mosquitto *m = init(&info);
    if (m == NULL) { die("init() failure\n"); }
    info.m = m;

    if (!set_callbacks(m)) { die("set_callbacks() failure\n"); }

    /* client_opts_set: set up the configuration */

    if (!connect(m)) { die("connect() failure\n"); }

    return run_loop(&info);
}
Beispiel #9
0
void
_IO_cookie_init (struct _IO_cookie_file *cfile, int read_write,
		 void *cookie, _IO_cookie_io_functions_t io_functions)
{
  _IO_init_internal (&cfile->__fp.file, 0);
  _IO_JUMPS (&cfile->__fp) = &_IO_cookie_jumps;

  cfile->__cookie = cookie;
  set_callbacks (&cfile->__io_functions, io_functions);

  _IO_new_file_init_internal (&cfile->__fp);

  _IO_mask_flags (&cfile->__fp.file, read_write,
		  _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);

  /* We use a negative number different from -1 for _fileno to mark that
     this special stream is not associated with a real file, but still has
     to be treated as such.  */
  cfile->__fp.file._fileno = -2;
}
Beispiel #10
0
void init_scenario()
{
    if(glfwInit() != GL_TRUE)
    {
        exit(EXIT_FAILURE);
    }

    window_state.main_window = glfwCreateWindow(window_state.window_length,
                                                window_state.window_height,
                                                "SimBot", NULL, NULL);

    if(!window_state.main_window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwMakeContextCurrent(window_state.main_window);

    set_callbacks(window_state.main_window);
}
Beispiel #11
0
int connect_callbacks(GModule* mod)
{
	void (*set_callbacks)(
		unsigned long (*dev_mem_size_ptr)(),
		void (*dev_message_ptr)(char*),
		void (*dev_mem_set_direct_ptr)(unsigned long int, unsigned char),
		void (*dev_mem_set_ptr)(unsigned long int, unsigned char, int),
		unsigned char (*dev_mem_get_ptr)(unsigned long int)
	);

	if(!g_module_symbol(mod, "set_callbacks", (void*)&set_callbacks))
		return 0;

	set_callbacks(
			(void*)&emu_mem_size,
			(void*)&emu_message,
			(void*)&emu_mem_set_direct,
			(void*)&emu_mem_set,
			(void*)&emu_mem_get
		     );

	return 1;
}
                  TITLE_FONT_TXT, TITLE_FONT_LONGTXT, true )
    add_loadfile( "projectm-menu-font", FONT_PATH_MENU,
                  MENU_FONT_TXT, MENU_FONT_LONGTXT, true )
#endif
    add_integer( "projectm-width", 800, WIDTH_TEXT, WIDTH_LONGTEXT,
                 false )
    add_integer( "projectm-height", 640, HEIGHT_TEXT, HEIGHT_LONGTEXT,
                 false )
    add_integer( "projectm-meshx", 32, MESHX_TEXT, MESHX_LONGTEXT,
                 false )
    add_integer( "projectm-meshy", 24, MESHY_TEXT, MESHY_LONGTEXT,
                 false )
    add_integer( "projectm-texture-size", 1024, TEXTURE_TEXT, TEXTURE_LONGTEXT,
                 false )
    add_shortcut( "projectm" )
    set_callbacks( Open, Close )
vlc_module_end ()


/*****************************************************************************
 * Local prototypes
 *****************************************************************************/
struct filter_sys_t
{
    /* */
    vlc_thread_t thread;
    vlc_sem_t    ready;
    bool         b_error;

    /* Opengl */
    vout_thread_t  *p_vout;
Beispiel #13
0
static int exa_select(struct exa_select *sel)
{
    int i;
    int one=0;
    int ret = -EFAULT;

    /* first phase register on each queue */
    for (i = 0; i < __FD_SETSIZE; i++)
    {
        __FD_CLR(i, &sel->result);
        if (__FD_ISSET(i, &sel->select))
        {
            sel->elt[i].socket = exa_getsock(i);
            if (sel->elt[i].socket == NULL)
            {
                ret  = -EINVAL;
                continue;
            }

            set_callbacks(sel->elt[i].socket, &sel->elt[i]);
            if (sel->operation == EXA_SELECT_IN)
            {
                if (sock_readable(sel->elt[i].socket) == 1)
                one = 1;
            }

            if (sel->operation == EXA_SELECT_OUT)
                if (sock_writable(sel->elt[i].socket) == 1)
                    one = 1;
        }
    }

    /* second phase : check if nothing arrived and wait if nothing arrived */
    if (one==0)
    {
        int timeout = SELECT_TIMEOUT ;

        set_current_state(TASK_INTERRUPTIBLE);
        for (i = 0; i < __FD_SETSIZE; i++)
        {
            if (__FD_ISSET(i, &sel->select) && (sel->elt[i].socket != NULL))
            {
                if (sel->operation == EXA_SELECT_IN)
                {
                    if (sock_readable(sel->elt[i].socket) == 1)
                    one = 1;
                }

                if (sel->operation == EXA_SELECT_OUT)
                {
                    if (sock_writable(sel->elt[i].socket) == 1)
                    one = 1;
                }
            }
        }

        if (one == 0) /* if some data already pending, we must not wait (or some race can occur)*/
            timeout = schedule_timeout(timeout);

        set_current_state(TASK_RUNNING);
    }

    /* third : find wich socket receive/sent something */
    for (i = __FD_SETSIZE - 1; i >= 0; i--)
    {
        if (__FD_ISSET(i, &sel->select))
        {
            if (sel->elt[i].socket == NULL)
                continue;
            if (sel->operation == EXA_SELECT_IN)
            {
                if (sock_readable(sel->elt[i].socket) == 1)
                __FD_SET(i, &sel->result);
            }

            if (sel->operation == EXA_SELECT_OUT)
            {
                if (sock_writable(sel->elt[i].socket) == 1)
                __FD_SET(i, &sel->result);
            }

            if ((__FD_ISSET(i, &sel->result)) && (ret == -EFAULT))
                ret = 0;

            restore_callbacks(sel->elt[i].socket, &sel->elt[i]);
            fput(sel->elt[i].socket->file);
            sel->elt[i].socket = NULL;
        }
    }

    /* XXX this is not an error, -EFAULT is used here as the timeout return
     * value....
     * FIXME use ETIME to have an explicit timeout. */
    if (ret == -EFAULT)
        __FD_ZERO(&sel->result);

    return ret;
}
Beispiel #14
0
void
SmcModifyCallbacks(SmcConn smcConn, unsigned long mask, SmcCallbacks *callbacks)
{
    set_callbacks (smcConn, mask, callbacks);
}
Beispiel #15
0
SmcConn
SmcOpenConnection(char *networkIdsList, SmPointer context,
		  int xsmpMajorRev, int xsmpMinorRev,
		  unsigned long mask, SmcCallbacks *callbacks,
		  char *previousId, char **clientIdRet,
		  int errorLength, char *errorStringRet)
{
    SmcConn			smcConn;
    IceConn			iceConn;
    char 			*ids;
    IceProtocolSetupStatus	setupstat;
    int				majorVersion;
    int				minorVersion;
    char			*vendor = NULL;
    char			*release = NULL;
    smRegisterClientMsg 	*pMsg;
    char 			*pData;
    int				extra, len;
    IceReplyWaitInfo		replyWait;
    _SmcRegisterClientReply	reply;
    Bool			gotReply, ioErrorOccured;

    const char *auth_names[] = {"MIT-MAGIC-COOKIE-1"};
    IcePoAuthProc auth_procs[] = {_IcePoMagicCookie1Proc};
    int auth_count = 1;

    IcePoVersionRec versions[] = {
        {SmProtoMajor, SmProtoMinor, _SmcProcessMessage}
    };
    int version_count = 1;


    *clientIdRet = NULL;

    if (errorStringRet && errorLength > 0)
	*errorStringRet = '\0';

    if (!_SmcOpcode)
    {
	/*
	 * For now, there is only one version of XSMP, so we don't
	 * have to check {xsmpMajorRev, xsmpMinorRev}.  In the future,
	 * we will check against versions and generate the list
	 * of versions the application actually supports.
	 */

	if ((_SmcOpcode = IceRegisterForProtocolSetup ("XSMP",
	    SmVendorString, SmReleaseString, version_count, versions,
            auth_count, auth_names, auth_procs, NULL)) < 0)
	{
	    if (errorStringRet && errorLength > 0) {
		strncpy (errorStringRet,
			 "Could not register XSMP protocol with ICE",
			 errorLength);
		errorStringRet[errorLength - 1] = '\0';
	    }

	    return (NULL);
	}
    }

    if (networkIdsList == NULL || *networkIdsList == '\0')
    {
	if ((ids = (char *) getenv ("SESSION_MANAGER")) == NULL)
	{
	    if (errorStringRet && errorLength > 0) {
		strncpy (errorStringRet,
			 "SESSION_MANAGER environment variable not defined",
			 errorLength);
		errorStringRet[errorLength - 1] = '\0';
	    }
	    return (NULL);
	}
    }
    else
    {
	ids = networkIdsList;
    }

    if ((iceConn = IceOpenConnection (
	ids, context, 0, _SmcOpcode, errorLength, errorStringRet)) == NULL)
    {
	return (NULL);
    }

    if ((smcConn = (SmcConn) malloc (sizeof (struct _SmcConn))) == NULL)
    {
	if (errorStringRet && errorLength > 0) {
	    strncpy (errorStringRet, "Can't malloc", errorLength);
	    errorStringRet[errorLength - 1] = '\0';
	}
	IceCloseConnection (iceConn);
	return (NULL);
    }

    setupstat = IceProtocolSetup (iceConn, _SmcOpcode,
	(IcePointer) smcConn,
	False /* mustAuthenticate */,
	&majorVersion, &minorVersion,
	&vendor, &release, errorLength, errorStringRet);

    if (setupstat == IceProtocolSetupFailure ||
	setupstat == IceProtocolSetupIOError)
    {
	IceCloseConnection (iceConn);
	free ((char *) smcConn);
	return (NULL);
    }
    else if (setupstat == IceProtocolAlreadyActive)
    {
	/*
	 * This case should never happen, because when we called
	 * IceOpenConnection, we required that the ICE connection
	 * may not already have XSMP active on it.
	 */

	free ((char *) smcConn);
	if (errorStringRet && errorLength > 0) {
	    strncpy (errorStringRet, "Internal error in IceOpenConnection",
		     errorLength);
	    errorStringRet[errorLength - 1] = '\0';
	}
	return (NULL);
    }

    smcConn->iceConn = iceConn;
    smcConn->proto_major_version = majorVersion;
    smcConn->proto_minor_version = minorVersion;
    smcConn->vendor = vendor;
    smcConn->release = release;
    smcConn->client_id = NULL;

    bzero ((char *) &smcConn->callbacks, sizeof (SmcCallbacks));
    set_callbacks (smcConn, mask, callbacks);

    smcConn->interact_waits = NULL;
    smcConn->phase2_wait = NULL;
    smcConn->prop_reply_waits = NULL;

    smcConn->save_yourself_in_progress = False;
    smcConn->shutdown_in_progress = False;


    /*
     * Now register the client
     */

    if (!previousId)
	previousId = "";
    len = strlen (previousId);
    extra = ARRAY8_BYTES (len);

    IceGetHeaderExtra (iceConn, _SmcOpcode, SM_RegisterClient,
	SIZEOF (smRegisterClientMsg), WORD64COUNT (extra),
	smRegisterClientMsg, pMsg, pData);

    STORE_ARRAY8 (pData, len, previousId);

    IceFlush (iceConn);

    replyWait.sequence_of_request = IceLastSentSequenceNumber (iceConn);
    replyWait.major_opcode_of_request = _SmcOpcode;
    replyWait.minor_opcode_of_request = SM_RegisterClient;
    replyWait.reply = (IcePointer) &reply;

    gotReply = False;
    ioErrorOccured = False;

    while (!gotReply && !ioErrorOccured)
    {
	ioErrorOccured = (IceProcessMessages (
	    iceConn, &replyWait, &gotReply) == IceProcessMessagesIOError);

	if (ioErrorOccured)
	{
	    if (errorStringRet && errorLength > 0) {
		strncpy (errorStringRet, "IO error occured opening connection",
			 errorLength);
		errorStringRet[errorLength - 1] = '\0';
	    }
	    free (smcConn->vendor);
	    free (smcConn->release);
	    free ((char *) smcConn);

	    return (NULL);
	}
	else if (gotReply)
	{
	    if (reply.status == 1)
	    {
		/*
		 * The client successfully registered.
		 */

		*clientIdRet = reply.client_id;

		smcConn->client_id = (char *) malloc (
		    strlen (*clientIdRet) + 1);

		strcpy (smcConn->client_id, *clientIdRet);
	    }
	    else
	    {
		/*
		 * Could not register the client because the previous ID
		 * was bad.  So now we register the client with the
		 * previous ID set to NULL.
		 */

		extra = ARRAY8_BYTES (0);

		IceGetHeaderExtra (iceConn, _SmcOpcode, SM_RegisterClient,
		    SIZEOF (smRegisterClientMsg), WORD64COUNT (extra),
		    smRegisterClientMsg, pMsg, pData);

		STORE_ARRAY8 (pData, 0, "");

		IceFlush (iceConn);

		replyWait.sequence_of_request =
		    IceLastSentSequenceNumber (iceConn);

		gotReply = False;
	    }
	}
    }

    return (smcConn);
}
Beispiel #16
0
Displace3( long version, GlobalFunc *global, LWDisplacementHandler *local,
   void *serverData )
{
   return set_callbacks( local, version, DISP_PNAME3, Flags3 );
}
Beispiel #17
0
void ScrollBoxTest(void)
{
  Ihandle *mnu, *_hbox_1, *_cnv_1, *_vbox_1, *dlg, *img, *_vbox_2,
    *_frm_1, *_frm_2, *_frm_3, *_frm_4, *_frm_5, *pbar, *val, *tabs,
    *_list_1, *_list_2, *_list_3, *_text_1, *_ml_1, *tree;

  //img = IupImage(32,32, img_bits1);
  //IupSetHandle ("img1", img); 
  //IupSetAttribute (img, "0", "0 0 0"); 
  //IupSetAttribute (img, "1", "BGCOLOR");
  //IupSetAttribute (img, "2", "255 0 0");

  img = load_image_Tecgraf();
  IupSetHandle ("img1", img); 

  img = IupImage(32,32, img_bits2);
  IupSetHandle ("img2", img); 
  IupSetAttribute (img, "0", "0 0 0"); 
  IupSetAttribute (img, "1", "0 255 0");
  IupSetAttribute (img, "2", "BGCOLOR");
  IupSetAttribute (img, "3", "255 0 0");

  mnu = IupMenu(
    IupSubmenu("IupSubmenu 1", IupMenu(
      IupSetAttributes(IupItem("IupItem 1 Checked", NULL), "VALUE=ON"),
      IupSeparator(),

      IupSetAttributes(IupItem("IupItem 2 Disabled", NULL), "ACTIVE=NO"),
      NULL)),
    IupItem("IupItem 3", NULL),
    IupItem("IupItem 4", NULL), 
    NULL);
  IupSetHandle("mnu",mnu);

  _frm_1 = IupFrame(
    IupVbox(
      set_callbacks(IupSetAttributes(IupButton("Button Text", NULL), "PADDING=5x5, TIP=\"Button TIP\"")), 
      IupSetCallbacks(set_callbacks(IupSetAttributes(IupButton("Text", NULL), "IMAGE=img1, PADDING=5x5")),"ACTION", action1_cb, NULL), 
      IupSetCallbacks(set_callbacks(IupSetAttributes(IupButton(NULL, NULL), "IMAGE=img1")),"ACTION", action2_cb, NULL), 
      IupSetCallbacks(set_callbacks(IupSetAttributes(IupButton("", NULL), "IMAGE=img1,IMPRESS=img2")),"ACTION", action3_cb, NULL), 
      IupSetCallbacks(set_callbacks(IupSetAttributes(IupButton(NULL, NULL), "BGCOLOR=\"255 0 128\", SIZE=20x10")),"ACTION", action3_cb, NULL), 
      NULL));
  IupSetAttribute(_frm_1,"TITLE","IupButton");

  _frm_2 = IupFrame(
    IupVbox(
      IupSetAttributes(IupLabel("Label Text"), "TIP=\"Label TIP\""),
      IupSetAttributes(IupLabel(NULL), "SEPARATOR=HORIZONTAL, NAME=SAMP_SEP"),
      IupSetAttributes(IupLabel(NULL), "IMAGE=img1"),
      NULL));
  IupSetAttribute(_frm_2,"TITLE","IupLabel");

  _frm_3 = IupFrame(
    IupVbox(
      set_callbacks(IupSetAttributes(IupToggle("Toggle Text", NULL), "VALUE=ON, TIP=\"Toggle TIP\"")),
      set_callbacks(IupSetAttributes(IupToggle(NULL, NULL), "VALUE=ON,IMAGE=img1,IMPRESS=img2")),
      set_callbacks(IupSetAttributes(IupToggle(NULL, NULL), "VALUE=ON,IMAGE=img1")),
      IupSetAttributes(IupFrame(IupRadio(IupVbox(
        set_callbacks(IupToggle("Toggle Text", NULL)), 
        set_callbacks(IupToggle("Toggle Text", NULL)), 
        NULL))), "TITLE=IupRadio"),
      NULL));
  IupSetAttribute(_frm_3,"TITLE","IupToggle");

  _text_1 = IupText( NULL);
  IupSetAttribute(_text_1,"VALUE","Single Line Text");
  IupSetAttribute(_text_1,"SIZE","80x");
  IupSetAttribute(_text_1,"TIP","Text TIP");

  _ml_1 = IupMultiLine( NULL);
  IupSetAttribute(_ml_1,"VALUE","Multiline Text\nSecond Line\nThird Line");
  IupSetAttribute(_ml_1,"EXPAND","YES");
  IupSetAttribute(_ml_1,"SIZE","80x40");
  IupSetAttribute(_ml_1,"TIP","Multiline TIP");

  _frm_4 = IupFrame(IupVbox(
    set_callbacks(_text_1),
    set_callbacks(_ml_1),
    NULL));
  IupSetAttribute(_frm_4,"TITLE","IupText");

  _list_1 = IupList( NULL);
//  IupSetAttribute(_list_1,"EXPAND","YES");
  IupSetAttribute(_list_1,"VALUE","1");
  IupSetAttribute(_list_1,"1","Item 1 Text");
  IupSetAttribute(_list_1,"2","Item 2 Text");
  IupSetAttribute(_list_1,"3","Item 3 Text");
  IupSetAttribute(_list_1,"TIP","List 1");

  _list_2 = IupList( NULL);
  IupSetAttribute(_list_2,"DROPDOWN","YES");
//  IupSetAttribute(_list_2,"EXPAND","YES");
  IupSetAttribute(_list_2,"VALUE","2");
  IupSetAttribute(_list_2,"1","Item 1 Text");
  IupSetAttribute(_list_2,"2","Item 2 Text");
  IupSetAttribute(_list_2,"3","Item 3 Text");
  IupSetAttribute(_list_2,"TIP","List 2");

  _list_3 = IupList( NULL);
  IupSetAttribute(_list_3,"EDITBOX","YES");
//  IupSetAttribute(_list_3,"EXPAND","YES");
  IupSetAttribute(_list_3,"VALUE","3");
  IupSetAttribute(_list_3,"1","Item 1 Text");
  IupSetAttribute(_list_3,"2","Item 2 Text");
  IupSetAttribute(_list_3,"3","Item 3 Text");
  IupSetAttribute(_list_3,"TIP","List 3");

  _frm_5 =  IupFrame(IupVbox(
      set_callbacks(_list_1),
      set_callbacks(_list_2),
      set_callbacks(_list_3),
      NULL));
  IupSetAttribute(_frm_5,"TITLE","IupList");

  _hbox_1 = IupHbox(
    _frm_1,
    _frm_2,
    _frm_3,
    _frm_4,
    _frm_5,
    NULL);

  val = IupVal(NULL);
  IupSetAttribute(val,"TIP","Valuator TIP");
  set_callbacks(val);
  
  pbar = IupProgressBar();
  IupSetAttribute(pbar, "VALUE", "0.5");
  IupSetAttribute(pbar,"TIP","ProgressBar TIP");
  set_callbacks(pbar);

  tabs = IupTabs(IupVbox(IupLabel("Tab0"), NULL), IupVbox(IupLabel("Tab1"), NULL), IupVbox(IupLabel("Tab2"), NULL), NULL);
  IupSetAttribute(tabs,"TABTITLE0","Tab Title 0");
  IupSetAttribute(tabs,"TABTITLE1","Tab Title 1");
  IupSetAttributeHandle(tabs,"TABIMAGE1", load_image_LogoTecgraf());
  IupSetAttribute(tabs,"TABTITLE2","Tab Title 2");
  IupSetAttribute(tabs,"RASTERSIZE","300x50");
  IupSetAttribute(tabs,"TIP","Tabs TIP");
//  IupSetAttribute(tabs,"PADDING","5x5");
  set_callbacks(tabs);

  tree = IupTree();
  IupSetAttribute(tree, "SHOWRENAME",   "YES");
  IupSetAttribute(tree,"RASTERSIZE","300x150");
  IupSetAttribute(tree,"TIP","Tree TIP");
  IupSetAttribute(tree,"EXPAND","NO");
  set_callbacks(tree);

  _cnv_1 = IupCanvas(NULL);
  IupSetAttribute(_cnv_1,"BGCOLOR","128 255 0");
  IupSetAttribute(_cnv_1,"SCROLLBAR","YES");
//  IupSetAttribute(_cnv_1,"EXPAND","HORIZONTAL");
  IupSetAttribute(_cnv_1,"EXPAND","NO");
  IupSetAttribute(_cnv_1,"RASTERSIZE","200x100");
  IupSetAttribute(_cnv_1,"TIP","Canvas TIP");
//  IupSetAttribute(_cnv_1,"CANFOCUS","NO");
  set_callbacks(_cnv_1);

  _vbox_1 = IupVbox(
    _hbox_1,
    IupHbox(IupSetAttributes(IupFrame(IupHbox(val, NULL)), "TITLE=IupVal"),
            IupSetAttributes(IupFrame(IupHbox(pbar, NULL)), "TITLE=IupProgressBar"),
            IupSetAttributes(IupFrame(IupHbox(tabs, NULL)), "TITLE=IupTabs"),
            NULL),
    IupHbox(IupSetAttributes(IupFrame(IupHbox(_cnv_1, NULL)), "TITLE=IupCanvas"),
            IupSetAttributes(IupFrame(IupHbox(tree, NULL)), "TITLE=IupTree"),
            NULL),
    IupHbox(IupSetAttributes(IupFrame(IupHbox(create_matrix(), NULL)), "TITLE=IupMatrix"),
            NULL),
    NULL);
  IupSetAttribute(_vbox_1,"MARGIN","5x5");
  IupSetAttribute(_vbox_1,"GAP","5");

//  _vbox_2 = IupVbox(IupSetAttributes(IupScrollBox(_vbox_1), "RASTERSIZE=400x300"), NULL);
  _vbox_2 = IupVbox(IupScrollBox(_vbox_1), NULL);
  IupSetAttribute(_vbox_2,"MARGIN","20x20");

  dlg = IupDialog(_vbox_2);
  IupSetHandle("dlg",dlg);
  IupSetAttribute(dlg,"MENU","mnu");
  IupSetAttribute(dlg,"TITLE","IupDialog Title");
//  IupSetAttribute(dlg,"COMPOSITED","YES");   /* Windows Only */
//  IupSetAttribute(dlg, "OPACITY", "192");
//  IupSetAttribute(dlg, "RESIZE", "NO");

//  IupSetAttribute(dlg, "BGCOLOR", "173 177 194");  // Motif BGCOLOR for documentation
//  IupSetAttribute(_vbox_1, "BGCOLOR", "92 92 255");
//  IupSetAttribute(dlg, "BGCOLOR", "92 92 255");
//  IupSetAttribute(dlg, "BACKGROUND", "200 10 80");

  //IupSetGlobal("DLGBGCOLOR", "92 92 255");
  //IupSetGlobal("TXTFGCOLOR", "255 92 92");
  //IupSetGlobal("TXTBGCOLOR", "92 92 255");

//  IupSetAttribute(dlg, "FONT", "Helvetica, 24");
//  IupSetAttribute(dlg, "FONT", "-*-helvetica-*-r-*-*-18-*-*-*-*-*-*-*");
  
//  IupSetAttribute(box, "FGCOLOR", "255 0 0");

  //IupSetAttribute(dlg,"RASTERSIZE","1000x800");
  IupSetAttribute(dlg,"RASTERSIZE","400x300");
  IupSetCallback(dlg, "RESIZE_CB", (Icallback)resize_cb);

  IupMap(dlg);

  IupSetAttribute(tree, "TITLE0",         "Figures");  
  IupSetAttribute(tree, "ADDLEAF0",      "Other");     /* new id=1 */
  IupSetAttribute(tree, "ADDBRANCH1",   "triangle");  /* new id=2 */     
  IupSetAttribute(tree, "ADDLEAF2",     "equilateral");  /* ... */
  IupSetAttribute(tree, "ADDLEAF3",     "isoceles");
  IupSetAttribute(tree, "ADDLEAF4",     "scalenus");

  IupShow(dlg);

  IupSetAttribute(dlg,"RASTERSIZE", NULL);
}
Beispiel #18
0
void ButtonTest(void)
{
  Ihandle *dlg, *button, *label, *image1, *image1i, *image1p, *image2, *image3, 
          *box1, *box2;

  box1 = IupVbox(NULL);
  IupSetAttribute(box1, "MARGIN", "5x5");
  IupSetAttribute(box1, "GAP", "5");
//  IupSetAttribute(box1, "BGCOLOR", "75 150 170");
//  IupSetAttribute(box1, "PADDING", "15x15");

  button = IupButton(NULL, NULL);
  IupSetStrAttribute(button, "TITLE", "_@IUP_OK");
  IupSetCallback(button, "ACTION", active_cb);
  IupAppend(box1, button);

  button = IupButton(NULL, NULL);
  if (IupGetInt(NULL, "UTF8MODE"))
    IupSetAttribute(button, "TITLE", "&Text && Test(çãõáóé)");
  else
    IupSetAttribute(button, "TITLE", "&Text && Test(ηγυασι)");
  IupSetAttribute(button, "TIP", "Button & Tip");
  //IupSetAttribute(button, "PADDING", "15x15");
  //IupSetAttribute(button, "BGCOLOR", "128 128 255");
//  IupSetAttribute(button, "SIZE", "40");
//  IupSetAttribute(button, "EXPAND", "Yes");
//  IupSetAttribute(button, "FGCOLOR", "0 0 255");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
  IupSetAttribute(button, "ALIGNMENT", "ACENTER:ACENTER");
//  IupSetAttribute(button, "ALIGNMENT", "ALEFT:ATOP");
  IupSetAttribute(button, "NAME", "button1");
  //IupSetAttribute(button, "CANFOCUS", "NO");
  set_callbacks(button);
  IupAppend(box1, button);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "TITLE", "Text1\nSecond Line");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
  IupSetAttribute(button, "ALIGNMENT", "ACENTER:ACENTER");
  IupSetAttribute(button, "FONT", "Helvetica, Underline 14");
  IupSetAttribute(button, "FLAT", "YES");
  IupSetAttribute(button, "NAME", "button2");
  set_callbacks(button);
  IupAppend(box1, button);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "TITLE", "Text2\n<b>Second Line</b>");
  IupSetAttribute(button, "RASTERSIZE", "200x100");
  IupSetAttribute(button, "ALIGNMENT", "ARIGHT:ABOTTOM");
  IupSetAttribute(button, "MARKUP", "YES");
  IupSetAttribute(button, "NAME", "button3");
  IupSetAttribute(button, "CANFOCUS", "NO");
  set_callbacks(button);
  IupAppend(box1, button);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "RASTERSIZE", "30x30");
  IupSetAttribute(button, "BGCOLOR", "255 128 92");
  IupSetAttribute(button, "NAME", "color");
//  IupSetAttribute(button, "EXPAND", "HORIZONTAL");
  //  IupSetAttribute(button, "FLAT", "Yes");
  set_callbacks(button);
  IupAppend(box1, button);

  box2 = IupVbox(NULL);
  IupSetAttribute(box2, "MARGIN", "5x5");
  IupSetAttribute(box2, "GAP", "5");
//  IupSetAttribute(box2, "BGCOLOR", "75 150 170");
//  IupSetAttribute(box2, "PADDING", "15x15");

  image1 = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8);
  IupSetAttribute(image1, "0", "BGCOLOR");
  IupSetAttribute(image1, "1", "255 0 0"); 
  IupSetAttribute(image1, "2", "0 255 0");
  IupSetAttribute(image1, "3", "0 0 255"); 
  IupSetAttribute(image1, "4", "255 255 255"); 
  IupSetAttribute(image1, "5", "0 0 0"); 

  image1i = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8_inactive);
  IupSetAttribute(image1i, "0", "BGCOLOR");
  IupSetAttribute(image1i, "1", "255 0 0"); 
  IupSetAttribute(image1i, "2", "0 255 0");
  IupSetAttribute(image1i, "3", "0 0 255"); 
  IupSetAttribute(image1i, "4", "255 255 255"); 
  IupSetAttribute(image1i, "5", "0 0 0"); 
  IupSetHandle("image1i", image1i); /* so it will be destroyed even when not used */

#if 0
  image1p = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8_pressed);
  IupSetAttribute(image1p, "0", "BGCOLOR");
  IupSetAttribute(image1p, "1", "255 0 0"); 
  IupSetAttribute(image1p, "2", "0 255 0");
  IupSetAttribute(image1p, "3", "0 0 255"); 
  IupSetAttribute(image1p, "4", "255 255 255"); 
  IupSetAttribute(image1p, "5", "0 0 0"); 
#endif

  image2 = IupImageRGB(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_24);

  image3 = IupImageRGBA(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_32);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "TITLE", "Images");
  IupSetAttributeHandle(button, "IMAGE", load_image_FileSave());
  
  //IupSetAttribute(button, "IMAGE", "TECGRAF_BITMAP");
  IupAppend(box2, button);

  button = IupButton(NULL, NULL);
//  IupSetAttribute(button, "ALIGNMENT", "ALEFT:ATOP");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
//  IupSetAttribute(button, "IMAGEPOSITION", "BOTTOM");
//  IupSetAttribute(button, "PADDING", "5x5");
//  IupSetAttribute(button, "TITLE", "Text1");
//  IupSetAttribute(button, "FONT", "Helvetica, 14");
//  IupSetAttribute(button, "IMAGE", "IUP_Tecgraf");
  IupSetAttributeHandle(button, "IMAGE", image1);
  IupSetAttributeHandle(button, "IMINACTIVE", image1i);
//  IupSetAttributeHandle(button, "IMPRESS", image1p);
  IupSetAttribute(button, "TIP", "Image Label");
  IupSetAttribute(button, "NAME", "button4");
  IupSetAttribute(button, "PADDING", "5x5");
//  IupSetAttribute(button, "FLAT", "Yes");
  set_callbacks(button);
  IupAppend(box2, button);

  button = IupButton(NULL, NULL);
  IupSetAttributeHandle(button, "IMAGE", image2);
//  IupSetAttribute(button, "TITLE", "Text2");
//  IupSetAttribute(button, "IMAGEPOSITION", "TOP");
//  IupSetAttribute(button, "SPACING", "30");
//  IupSetAttribute(button, "ALIGNMENT", "ALEFT");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
  IupSetAttribute(button, "FLAT", "YES");
//  IupSetAttributeHandle(button, "IMPRESS", image2);
  IupSetAttribute(button, "CANFOCUS", "NO");
  IupSetAttribute(button, "PADDING", "10x10");
  //  IupSetAttribute(button, "RASTERSIZE", "15x15");
  IupSetAttribute(button, "NAME", "button5");
  set_callbacks(button);
  IupAppend(box2, button);

  button = IupButton(NULL, NULL);
  IupSetAttributeHandle(button, "IMAGE", image3);
  IupSetAttribute(button, "TITLE", "Text3");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
//  IupSetAttribute(button, "ALIGNMENT", "ARIGHT");
  IupSetAttribute(button, "NAME", "button6");
  set_callbacks(button);
  IupAppend(box2, button);

  label = IupLabel(NULL);
  IupSetAttribute(label, "SEPARATOR", "VERTICAL");
  IupSetHandle("seplabel", label);

  dlg = IupDialog(IupHbox(box1, label, box2, NULL));
  IupSetAttribute(dlg, "TITLE", "IupButton Test");
//  IupSetAttribute(box1, "BGCOLOR", "128 0 0");
//  IupSetAttribute(dlg, "BGCOLOR", "0 128 0");
//  IupSetAttribute(dlg, "BACKGROUND", "255 128 128");
//  IupSetAttributeHandle(dlg, "BACKGROUND", image2);
//  IupSetAttribute(dlg, "BGCOLOR", "173 177 194");  // Motif BGCOLOR for documentation
//  IupSetAttribute(dlg, "SAVEUNDER", "NO");

  IupSetAttributeHandle(dlg, "STARTFOCUS", button);

//  IupSetGlobal("CLIENTAREAANIMATION", "No");
//  IupSetGlobal("HOTTRACKING", "No");

  IupShow(dlg);

//  IupSetAttribute(dlg, "PARENTDIALOG", "BIGTEST");
//  IupShowXY(dlg, IUP_CENTERPARENT, IUP_CENTERPARENT);
  //  IupShowXY(dlg,IUP_LEFT,IUP_TOP);
//  IupShowXY(dlg, IUP_RIGHT, IUP_BOTTOM);
//  IupShowXY(dlg, IUP_RIGHT, IUP_CENTER);
//  IupShowXY(dlg,0,0);
}
Beispiel #19
0
void ListTest(void)
{
  Ihandle *dlg, *list1, *list2, *list3, *list4, *text, *btok, *btcancel,
          *box, *lists, *buttons1, *buttons2, *buttons3, *label;

  list1 = IupList(NULL);
  list2 = IupList(NULL);
  list3 = IupList(NULL);
  list4 = IupList(NULL);                              

  IupSetAttributes(list1, "1=\"US$ 1000\", 2=\"US$ 2000\", 3=\"US$ 300.000.000\", 4=\"US$ 4000\","
                          "EDITBOX=YES, DROPDOWN=YES, TIP=Edit+Drop, VALUE=\"Edit Here\", NAME=list1");
  IupSetAttributes(list2, "1=\"R$ 1000\", 2=\"R$ 2000\", 3=\"R$ 123456789\", 4=\"R$ 4000\", 5=\"R$ 5000\","
                          "DROPDOWN=YES, NAME=list2, TIP=Drop, VALUE=2");
  IupSetAttributes(list3, "1=\"Char A\", 2=\"Char B\", 3=\"Char CCCCC\", 4=\"Char D\", 5=\"Char E\", 6=\"Char F\","
                          "EDITBOX=YES, NAME=list3, TIP=Edit+List, VALUE=\"Edit Here\"");
  IupSetAttributes(list4, "1=\"Number 1\", 2=\"Number 2\", 3=\"Number 3\", 4=\"Number 4\", 5=\"Number 5\", 6=\"Number 6\", 7=\"Number 7\","
                          "MULTIPLE=YES, NAME=list4, TIP=List, VALUE=+--++--");

  set_callbacks(list1);
  set_callbacks(list2);
  set_callbacks(list3);
  set_callbacks(list4);

  //IupSetAttributes(list2, "6=\"R$ 1000\", 7=\"R$ 2000\", 8=\"R$ 123456789\", 9=\"R$ 4000\", 10=\"R$ 5000\",");
  //IupSetAttributes(list2, "11=\"R$ 1000\", 12=\"R$ 2000\", 13=\"R$ 123456789\", 14=\"R$ 4000\", 15=\"R$ 5000\",");
  //IupSetAttributes(list2, "16=\"R$ 1000\", 17=\"R$ 2000\", 18=\"R$ 123456789\", 19=\"R$ 4000\", 20=\"R$ 5000\",");
  
  IupSetCallback(list4, "MULTISELECT_CB", (Icallback)multilist_cb);

//  IupSetAttribute(list1, "READONLY", "YES");
//  IupSetAttribute(list3, "READONLY", "YES");
//  IupSetAttribute(list1, "PADDING", "10x10");
//  IupSetAttribute(list3, "PADDING", "10x10");

//  IupSetAttribute(list3, "SPACING", "10");
//  IupSetAttribute(list4, "SPACING", "10");

  printf("COUNT(list1)=%s\n", IupGetAttribute(list1, "COUNT"));
  printf("COUNT(list2)=%s\n", IupGetAttribute(list2, "COUNT"));
  printf("COUNT(list3)=%s\n", IupGetAttribute(list3, "COUNT"));
  printf("COUNT(list4)=%s\n", IupGetAttribute(list4, "COUNT"));

  lists = IupHbox(
    IupVbox(
      IupSetAttributes(IupFrame(IupVbox(list1, NULL)), "TITLE=EDITBOX+DROPDOWN"),
      IupSetAttributes(IupFrame(IupVbox(list2, NULL)), "TITLE=DROPDOWN"),
      NULL), 
    IupSetAttributes(IupFrame(IupVbox(list3, NULL)), "TITLE=EDITBOX"),
    IupSetAttributes(IupFrame(IupVbox(list4, NULL)), "TITLE=MULTIPLE"),
    IupVbox(
      btok = IupSetCallbacks(IupButton("Default Enter", NULL), "ACTION", btok_cb, NULL),
      btcancel = IupSetCallbacks(IupButton("Default Esc", NULL), "ACTION", btcancel_cb, NULL),
      NULL),
    NULL);

  text = IupText(NULL);
  IupSetAttribute(text, "EXPAND", "HORIZONTAL");
  IupSetAttribute(text, "NAME", "text");

  buttons1 = IupHbox(
    IupSetCallbacks(IupButton("Get(VALUE)", NULL), "ACTION", getvalue_cb, NULL),
    IupSetCallbacks(IupButton("Set(VALUE)", NULL), "ACTION", setvalue_cb, NULL),
    IupSetCallbacks(IupButton("Get(COUNT)", NULL), "ACTION", getcount_cb, NULL),
    NULL);
  buttons2 = IupHbox(
    IupSetCallbacks(IupButton("INSERTITEM3", NULL), "ACTION", insertitem_cb, NULL),
    IupSetCallbacks(IupButton("APPENDITEM", NULL), "ACTION", appenditem_cb, NULL),
    IupSetCallbacks(IupButton("REMOVEITEM", NULL), "ACTION", removeitem_cb, NULL),
    IupSetCallbacks(IupButton("SHOWDROPDOWN", NULL), "ACTION", showdropdown_cb, NULL),
    IupSetCallbacks(IupButton("TOPITEM", NULL), "ACTION", topitem_cb, NULL),
    NULL);
  buttons3 = IupHbox(
    IupSetCallbacks(IupButton("APPEND", NULL), "ACTION", append_cb, NULL),
    IupSetCallbacks(IupButton("Get(CARET)", NULL), "ACTION", getcaret_cb, NULL),
    IupSetCallbacks(IupButton("Set(READONLY)", NULL), "ACTION", readonly_cb, NULL),
    IupSetCallbacks(IupButton("Get(SELECTEDTEXT)", NULL), "ACTION", selectedtext_cb, NULL),
    IupSetCallbacks(IupButton("Get(SELECTION)", NULL), "ACTION", selection_cb, NULL),
    NULL);

  box = IupVbox(lists, IupHbox(IupLabel("Attrib. Value:  "), text, NULL), buttons1, buttons2, buttons3, IupHbox(IupLabel("Current List:  "), label = IupLabel(NULL), NULL), NULL);
  IupSetAttributes(buttons1,"MARGIN=5x5, GAP=5");
  IupSetAttributes(buttons2,"MARGIN=5x5, GAP=5");
  IupSetAttributes(buttons3,"MARGIN=5x5, GAP=5");
  IupSetAttributes(lists,"MARGIN=10x10, GAP=10");
  IupSetAttribute(label,"EXPAND", "HORIZONTAL");

  dlg = IupDialog(box);
  IupSetAttribute(dlg, "TITLE", "IupList Test");
  IupSetAttributeHandle(dlg, "DEFAULTENTER", btok);
  IupSetAttributeHandle(dlg, "DEFAULTESC", btcancel);
  IupSetAttribute(dlg, "_LABEL", (char*)label);

//  IupSetAttribute(box, "BGCOLOR", "92 92 255");
//  IupSetAttribute(dlg, "BGCOLOR", "92 92 255");
//  IupSetAttribute(dlg, "BACKGROUND", "200 10 80");
//  IupSetAttribute(dlg, "BGCOLOR", "173 177 194");  // Motif BGCOLOR for documentation

//  IupSetAttribute(dlg, "FONT", "Helvetica, 24");
//  IupSetAttribute(box, "FGCOLOR", "255 0 0");

  IupShowXY(dlg, IUP_CENTER, IUP_CENTER);
}
Beispiel #20
0
Datei: tox.c Projekt: Boerde/uTox
void tox_thread(void *UNUSED(args))
{
    Tox *tox;
    ToxAv *av;
    uint8_t id[TOX_FRIEND_ADDRESS_SIZE];

TOP:;
    debug("new tox object ipv6: %u no_udp: %u proxy: %u %s %u\n", options.ipv6enabled, options.udp_disabled, options.proxy_enabled, options.proxy_address, options.proxy_port);
    if((tox = tox_new(&options)) == NULL) {
        debug("trying without proxy\n");
        if(!options.proxy_enabled || (options.proxy_enabled = 0, (tox = tox_new(&options)) == NULL)) {
            debug("trying without ipv6\n");
            if(!options.ipv6enabled || (options.ipv6enabled = 0, (tox = tox_new(&options)) == NULL)) {
                debug("tox_new() failed\n");
                exit(1);
            }
            dropdown_ipv6.selected = dropdown_ipv6.over = 1;
        }
        dropdown_proxy.selected = dropdown_proxy.over = 0;
    }

    if(!load_save(tox)) {
        debug("No save file, using defaults\n");
        load_defaults(tox);
    }

    edit_setstr(&edit_name, self.name, self.name_length);
    edit_setstr(&edit_status, self.statusmsg, self.statusmsg_length);

    tox_get_address(tox, id);
    id_to_string(self.id, id);

    debug("Tox ID: %.*s\n", (int)sizeof(self.id), self.id);

    set_callbacks(tox);

    do_bootstrap(tox);

    av = toxav_new(tox, MAX_CALLS);

    set_av_callbacks(av);


    global_av = av;
    tox_thread_init = 1;

    thread(audio_thread, av);
    thread(video_thread, av);
    thread(toxav_thread, av);

    _Bool connected = 0, reconfig;
    uint64_t last_save = get_time(), time;
    while(1) {
        tox_do(tox);

        if(tox_isconnected(tox) != connected) {
            connected = !connected;
            postmessage(DHT_CONNECTED, connected, 0, NULL);

            debug("Connected to DHT: %u\n", connected);
        }

        time = get_time();

        if(time - last_save >= (uint64_t)10 * 1000 * 1000 * 1000) {
            last_save = time;

            if(!connected) {
                do_bootstrap(tox);
            }

            write_save(tox);
        }

        if(tox_thread_msg) {
            TOX_MSG *msg = &tox_msg;
            if(!msg->msg) {
                reconfig = msg->param1;
                tox_thread_msg = 0;
                break;
            }
            tox_thread_message(tox, av, time, msg->msg, msg->param1, msg->param2, msg->data);
            tox_thread_msg = 0;
        }

        utox_thread_work_for_transfers(tox, time);
        utox_thread_work_for_typing_notifications(tox, time);

        uint32_t interval = tox_do_interval(tox);
        yieldcpu((interval > 20) ? 20 : interval);
    }

    write_save(tox);

    while(audio_thread_init || video_thread_init || toxav_thread_init) {
        yieldcpu(1);
    }

    debug("av_thread exit, tox thread ending\n");

    toxav_kill(av);
    tox_kill(tox);

    if(reconfig) {
        goto TOP;
    }

    tox_thread_init = 0;
}
/**
 * SOAP content handler.
 *
 * @return the value that instructs the caller concerning what happened and what to do next.
 *  OK ("we did our thing")
 *  DECLINED ("this isn't something with which we want to get involved")
 *  HTTP_mumble ("an error status should be reported")
 */
static int
gsoap_handler(request_rec * r)
{
    static const int nResponseBufferLen = IOBUF_CHUNK_SIZE;
    const char *pszError = NULL;
    struct soap *psoap = NULL;
    struct apache_soap_interface *pIntf = NULL;
    int nRet = 0;
    char *pszResponse = NULL;
    gsoapConfiguration *pConfig = getConfiguration(r);
    gsoapRequestConfiguration *pRqConf = NULL;

    /*
     * only handle soap requests 
     */
    if (!strstr(r->handler, "soap"))
        return DECLINED;

    /*
     * only handle POST requests 
     */
    if (r->method_number != M_POST && r->method_number != M_GET)
        return DECLINED;

    pszResponse = apr_pcalloc(r->pool, nResponseBufferLen);
    assert(NULL != pConfig);

    psoap = (struct soap *)apr_pcalloc(r->pool, sizeof(struct soap));
    pRqConf = apr_pcalloc(r->pool, sizeof(gsoapRequestConfiguration));
    pszError = SoapSharedLibraries_loadAllLibraries(pConfig->m_pLibraries, r->pool, r);

    pIntf = pConfig->m_pLibraries->m_pIntf;

    ap_update_mtime(r, r->request_time);
    ap_set_last_modified(r);
    if (NULL != pszError)
    {
        static Bool bFirstTime = TRUE;

        if (bFirstTime)
        {
            ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "mod_gsoap: %s", pszError);
            bFirstTime = FALSE;
        }
    }

    /*
     * as a next step, we prepare a buffer that sends the request as first line to gsoap. 
     * Then the remaining data. 
     * We start returning bytes on frecv from this buffer, until it is empty. 
     * then it is not necessary to fiddle around with gsoap's request line parsing.
     */
    if (NULL == pszError)
    {
        pRqConf->r = r;
        pRqConf->headers_sent = FALSE;
        pRqConf->headers_received = FALSE;
        pRqConf->m_pszAllHeaders = NULL;
        pRqConf->m_nHeaderLength = strlen(r->the_request) + 2;
        pRqConf->m_pszCurrentHeaderReadingPosition = NULL;
        pRqConf->m_nOutBufCount = 0;
        pRqConf->m_nOutBufLength = nResponseBufferLen;
        pRqConf->m_pOutBuf = apr_pcalloc(r->pool, nResponseBufferLen);
        pRqConf->http_parse = NULL;
        pRqConf->m_pszAllHeaders = apr_pcalloc(r->pool, pRqConf->m_nHeaderLength + 1);
        pRqConf->m_pszCurrentHeaderReadingPosition = pRqConf->m_pszAllHeaders;
        strcpy(pRqConf->m_pszAllHeaders, r->the_request);
        strcat(pRqConf->m_pszAllHeaders, "\r\n");
        pRqConf->pIntf = pIntf;
    }

    /*
     * We're about to start sending content, so we need to force the HTTP
     * headers to be sent at this point.  Otherwise, no headers will be sent
     * at all.  We can set any we like first, of course.  **NOTE** Here's
     * where you set the "Content-type" header, and you do so by putting it in
     * r->content_type, *not* r->headers_out("Content-type").  If you don't
     * set it, it will be filled in with the server's default type (typically
     * "text/plain").  You *must* also ensure that r->content_type is lower
     * case.
     *
     */

    /*
     * If we're only supposed to send header information (HEAD request), we're
     * already there.
     */
    if (r->header_only)
    {
        return OK;
    }
    if (NULL != pszError)
    {
        SendErrorMessage(r, pszError);
        return OK;
    }
    nRet = ap_setup_client_block(r, REQUEST_CHUNKED_DECHUNK);
    if (OK != nRet)
    {
        SendErrorMessage(r, "Failed to start receiving POST buffer");
        return OK;
    }
    nRet = ap_should_client_block(r);

    /* we check whether this request is HTTP GET or not and handle the GET request */
    if (r->method_number == M_GET)
    {  
	HTTPGet_SendWSDL(r, pConfig->m_pLibraries->m_pSOAPLibrary->m_pszPath);
	return OK;
    }

    if (0 == nRet)
    {
        SendErrorMessage(r, "No body received");
        return OK;
    }

    if (NULL != pszError)
    {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server, "mod_gsoap: %s", pszError);
        SendErrorMessage(r, pszError);
        return OK;
    }

    if (NULL != pIntf->fsoap_init)
    {
        (*pIntf->fsoap_init) (psoap, r);
        psoap->namespaces = pIntf->namespaces;
        set_callbacks(r, pRqConf, psoap);
        if (NULL != pIntf->fsoap_serve)
        {
            nRet = (*pIntf->fsoap_serve) (psoap, r);
        }
        else
        {
            SendErrorMessage(r, "no soap_serve entry point");
            return OK;
        }
        if (NULL != pIntf->fsoap_destroy)
        {
            pIntf->fsoap_destroy(psoap, r); /* not an error in 2.1.10 anymore */
        }
        if (NULL != pIntf->fsoap_end)
        {
            pIntf->fsoap_end(psoap, r);
        }
        else
        {
            SendErrorMessage(r, "no soap_end entry point");
        }
        if (NULL != pIntf->fsoap_done)
        {
            pIntf->fsoap_done(psoap, r);
        }
        else
        {
            SendErrorMessage(r, "no soap_done entry point");
        }
    }
    else
    {
        SendErrorMessage(r, "no soap_init entry point");
        return OK;
    }

    /*
     * We did what we wanted to do, so tell the rest of the server we
     * succeeded. We need not delete pszResponse, because it was allocated from the request pool.
     */
    return OK;
}
Beispiel #22
0
void  main()

{
   int   message[8], flag;
   char  string[6];

   gl_apid = appl_init();

   if (! _app) {
        menu_register (gl_apid, "  Super Server");
        evnt_timer (1000, 0);
      }

   if (! rsrc_load ("IND.RSC")) {
        form_alert (1, "[1][ |   Cannot find IND.RSC !   ][ Cancel ]");
        terminate();   return;
      }

   get_path();

   if (initialise_windows (4, ICONIFY) == 0) {
        leave_windows();   rsrc_free();   terminate();
        return;
      }

   if (get_version (string) > 0) {
        form_alert (1, 
                "[1][ |   STiK is not loaded,    | |      or corrupted !][ Cancel ]");
        leave_windows();   rsrc_free();   terminate();
        return;
      }
   change_freestring (START, ST_VERS,  -1, string, 5);
   change_freestring (START, SS_VERS,  -1, version, 5);

   set_api_struct();

   if (init_modules() == 0) {
        leave_windows();   rsrc_free();   terminate();
        return;
      }
   set_callbacks (CB_EVENT, (FUNC) check_modules, (FUNC) 0L);

   init_configs();

   graf_mouse (ARROW, NULL);

   if (_app) {
        do_some_work();
        while (! exit_inetd) {
             evnt_mesag (message);
             message_handler (message);
             while ((flag = operate_events()) >= 0);
             if (flag == -4)
                  exit_inetd = TRUE;
           }
      }
     else {
        FOREVER {
             evnt_mesag (message);
             message_handler (message);
           }
      }

   if (strings)   Mfree (strings);

   terminate_modules();

   leave_windows();

   rsrc_free();

   appl_exit();
 }
Beispiel #23
0
int main(int argc, char* argv[]) {
	if (argc != 1) uso();

#ifdef DAEMON
	//Adapted from http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html
	pid_t pid, sid;

	openlog("Gatewayd", LOG_PID, LOG_USER);

	pid = fork();
	if (pid < 0) {
		LOG_E("fork failed");
		exit(EXIT_FAILURE);
	}
	/* If we got a good PID, then
		 we can exit the parent process. */
	if (pid > 0) {
		LOG("Child spawned, pid %d\n", pid);
		exit(EXIT_SUCCESS);
	}

	/* Change the file mode mask */
	umask(0);

	/* Create a new SID for the child process */
	sid = setsid();
	if (sid < 0) {
		LOG_E("setsid failed");
		exit(EXIT_FAILURE);
	}
        
	/* Change the current working directory */
	if ((chdir("/")) < 0) {
	  LOG_E("chdir failed");
	  exit(EXIT_FAILURE);
	}
        
	/* Close out the standard file descriptors */
	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);
#endif //DAEMON

	// Mosquitto ----------------------
	struct mosquitto *m = mosquitto_new(MQTT_CLIENT_ID, true, null);
	if (m == NULL) { die("init() failure\n"); }

	if (!set_callbacks(m)) { die("set_callbacks() failure\n"); }
	if (!connect(m)) { die("connect() failure\n"); }

	//RFM69 ---------------------------
	theConfig.networkId = 101;
	theConfig.nodeId = 12;
	theConfig.frequency = RF69_868MHZ;
	theConfig.keyLength = 16;
	memcpy(theConfig.key, "pecmosg110028225", 16);
	theConfig.isRFM69HW = true;
	theConfig.promiscuousMode = true;
	theConfig.messageWatchdogDelay = 1800000; // 1800 seconds (30 minutes) between two messages 

	rfm69 = new RFM69();
	rfm69->initialize(theConfig.frequency,theConfig.nodeId,theConfig.networkId);
	initRfm(rfm69);

	// Mosquitto subscription ---------
	char subsciptionMask[128];
	sprintf(subsciptionMask, "%s/%03d/#", MQTT_ROOT, theConfig.networkId);
	LOG("Subscribe to Mosquitto topic: %s\n", subsciptionMask);
	mosquitto_subscribe(m, NULL, subsciptionMask, 0);
	
	LOG("setup complete\n");
	return run_loop(m);
}  // end of setup
Beispiel #24
0
void ButtonTest(void)
{
  Ihandle *dlg, *button, *label, *image1, *image1i, *image1p, *image2, *image3, 
          *box1, *box2;

  /* IupImageLibOpen(); */

  box1 = IupVbox(NULL);
  IupSetAttribute(box1, "MARGIN", "5x5");
  IupSetAttribute(box1, "GAP", "5");
//  IupSetAttribute(box1, "BGCOLOR", "75 150 170");
//  IupSetAttribute(box1, "PADDING", "15x15");

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "TITLE", "Button Text");
  IupSetCallback(button, "ACTION", active_cb);
  IupAppend(box1, button);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "TITLE", "&Text (згн)");
  IupSetAttribute(button, "TIP", "Button Tip");
  //IupSetAttribute(button, "PADDING", "15x15");
  //IupSetAttribute(button, "BGCOLOR", "128 128 255");
  IupSetAttribute(button, "SIZE", "40");
//  IupSetAttribute(button, "FGCOLOR", "0 0 255");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
  IupSetAttribute(button, "ALIGNMENT", "ACENTER:ACENTER");
//  IupSetAttribute(button, "ALIGNMENT", "ALEFT:ATOP");
  IupSetAttribute(button, "NAME", "button1");
  IupSetAttribute(button, "CANFOCUS", "NO");
  set_callbacks(button);
  IupAppend(box1, button);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "TITLE", "Text Button\nSecond Line");
  IupSetAttribute(button, "RASTERSIZE", "200x100");
  IupSetAttribute(button, "ALIGNMENT", "ACENTER:ACENTER");
  IupSetAttribute(button, "FONT", "Helvetica, 14");
  IupSetAttribute(button, "FLAT", "YES");
  IupSetAttribute(button, "NAME", "button2");
  set_callbacks(button);
  IupAppend(box1, button);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "TITLE", "Text Button\n<b>Second Line</b>");
  IupSetAttribute(button, "RASTERSIZE", "200x100");
  IupSetAttribute(button, "ALIGNMENT", "ARIGHT:ABOTTOM");
  IupSetAttribute(button, "MARKUP", "YES");
  IupSetAttribute(button, "NAME", "button3");
  IupSetAttribute(button, "CANFOCUS", "NO");
  set_callbacks(button);
  IupAppend(box1, button);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "RASTERSIZE", "30x30");
  IupSetAttribute(button, "BGCOLOR", "255 128 92");
  IupSetAttribute(button, "NAME", "color");
  set_callbacks(button);
  IupAppend(box1, button);

  box2 = IupVbox(NULL);
  IupSetAttribute(box2, "MARGIN", "5x5");
  IupSetAttribute(box2, "GAP", "5");
//  IupSetAttribute(box2, "BGCOLOR", "75 150 170");
//  IupSetAttribute(box2, "PADDING", "15x15");

  image1 = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8);
  IupSetAttribute(image1, "0", "BGCOLOR");
  IupSetAttribute(image1, "1", "255 0 0"); 
  IupSetAttribute(image1, "2", "0 255 0");
  IupSetAttribute(image1, "3", "0 0 255"); 
  IupSetAttribute(image1, "4", "255 255 255"); 
  IupSetAttribute(image1, "5", "0 0 0"); 

  image1i = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8_inactive);
  IupSetAttribute(image1i, "0", "BGCOLOR");
  IupSetAttribute(image1i, "1", "255 0 0"); 
  IupSetAttribute(image1i, "2", "0 255 0");
  IupSetAttribute(image1i, "3", "0 0 255"); 
  IupSetAttribute(image1i, "4", "255 255 255"); 
  IupSetAttribute(image1i, "5", "0 0 0"); 
  IupSetHandle("image1i", image1i); /* so it will be destroyed even when not used */

  image1p = IupImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_8_pressed);
  IupSetAttribute(image1p, "0", "BGCOLOR");
  IupSetAttribute(image1p, "1", "255 0 0"); 
  IupSetAttribute(image1p, "2", "0 255 0");
  IupSetAttribute(image1p, "3", "0 0 255"); 
  IupSetAttribute(image1p, "4", "255 255 255"); 
  IupSetAttribute(image1p, "5", "0 0 0"); 

  image2 = IupImageRGB(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_24);

  image3 = IupImageRGBA(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, image_data_32);

  button = IupButton(NULL, NULL);
  IupSetAttribute(button, "TITLE", "Images");
  IupSetAttributeHandle(button, "IMAGE", load_image_FileSave());
  IupAppend(box2, button);

  button = IupButton(NULL, NULL);
//  IupSetAttribute(button, "ALIGNMENT", "ALEFT:ATOP");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
//  IupSetAttribute(button, "IMAGEPOSITION", "BOTTOM");
//  IupSetAttribute(button, "PADDING", "5x5");
//  IupSetAttribute(button, "TITLE", "Text1");
//  IupSetAttribute(button, "FONT", "Helvetica, 14");
//  IupSetAttribute(button, "IMAGE", "IUP_Tecgraf");
  IupSetAttributeHandle(button, "IMAGE", image1);
//  IupSetAttributeHandle(button, "IMINACTIVE", image1i);
  IupSetAttributeHandle(button, "IMPRESS", image1p);
  IupSetAttribute(button, "TIP", "Image Label");
  IupSetAttribute(button, "NAME", "button4");
  set_callbacks(button);
  IupAppend(box2, button);

  button = IupButton(NULL, NULL);
  IupSetAttributeHandle(button, "IMAGE", image2);
//  IupSetAttribute(button, "TITLE", "Text2");
//  IupSetAttribute(button, "IMAGEPOSITION", "TOP");
//  IupSetAttribute(button, "SPACING", "30");
//  IupSetAttribute(button, "ALIGNMENT", "ALEFT");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
//  IupSetAttribute(button, "FLAT", "YES");
//  IupSetAttributeHandle(button, "IMPRESS", image2);
  IupSetAttribute(button, "CANFOCUS", "NO");
//  IupSetAttribute(button, "RASTERSIZE", "15x15");
  IupSetAttribute(button, "NAME", "button5");
  set_callbacks(button);
  IupAppend(box2, button);

  button = IupButton(NULL, NULL);
  IupSetAttributeHandle(button, "IMAGE", image3);
  IupSetAttribute(button, "TITLE", "Text3");
//  IupSetAttribute(button, "RASTERSIZE", "200x100");
//  IupSetAttribute(button, "ALIGNMENT", "ARIGHT");
  IupSetAttribute(button, "NAME", "button6");
  set_callbacks(button);
  IupAppend(box2, button);

  label = IupLabel(NULL);
  IupSetAttribute(label, "SEPARATOR", "VERTICAL");
  IupSetHandle("seplabel", label);

  dlg = IupDialog(IupHbox(box1, label, box2, NULL));
  IupSetAttribute(dlg, "TITLE", "IupButton Test");
//  IupSetAttribute(box1, "BGCOLOR", "128 0 0");
//  IupSetAttribute(dlg, "BGCOLOR", "0 128 0");
//  IupSetAttribute(dlg, "BACKGROUND", "255 128 128");
//  IupSetAttributeHandle(dlg, "BACKGROUND", image2);
//  IupSetAttribute(dlg, "BGCOLOR", "173 177 194");  // Motif BGCOLOR for documentation

  IupSetAttributeHandle(dlg, "STARTFOCUS", button);

  IupShow(dlg);
}