Beispiel #1
0
/**
 * Sets the #DBusError with an explanation of why the spawned
 * child process exited (on a signal, or whatever). If
 * the child process has not exited, does nothing (error
 * will remain unset).
 *
 * @param sitter the babysitter
 * @param error an error to fill in
 */
void
_dbus_babysitter_set_child_exit_error (DBusBabysitter *sitter,
                                       DBusError      *error)
{
  PING();
  if (!_dbus_babysitter_get_child_exited (sitter))
    return;

  PING();
  if (sitter->have_spawn_errno)
    {
      dbus_set_error (error, DBUS_ERROR_SPAWN_EXEC_FAILED,
                      "Failed to execute program %s: %s",
                      sitter->executable, _dbus_strerror (sitter->spawn_errno));
    }
  else if (sitter->have_child_status)
    {
      PING();
      dbus_set_error (error, DBUS_ERROR_SPAWN_CHILD_EXITED,
                      "Process %s exited with status %d",
                      sitter->executable, sitter->child_status);
    }
  else
    {
      PING();
      dbus_set_error (error, DBUS_ERROR_FAILED,
                      "Process %s exited, status unknown",
                      sitter->executable);
    }
  PING();
}
Beispiel #2
0
void
_dbus_babysitter_kill_child (DBusBabysitter *sitter)
{
  PING();
  if (sitter->child_handle == NULL)
    return; /* child is already dead, or we're so hosed we'll never recover */

  PING();
  TerminateProcess (sitter->child_handle, 12345);
}
static void
free_cache_entry (LOGFONTW            *logfont,
		  CacheEntry          *entry,
		  PangoWin32FontCache *cache)
{
  if (!DeleteObject (entry->hfont))
    PING (("DeleteObject for hfont %p failed", entry->hfont));

  g_slice_free (CacheEntry, entry);
}
Beispiel #4
0
/**
 * Increment the reference count on the babysitter object.
 *
 * @param sitter the babysitter
 * @returns the babysitter
 */
DBusBabysitter *
_dbus_babysitter_ref (DBusBabysitter *sitter)
{
  PING();
  _dbus_assert (sitter != NULL);
  _dbus_assert (sitter->refcount > 0);

  sitter->refcount += 1;

  return sitter;
}
static void
cache_entry_unref (PangoWin32FontCache *cache,
		   CacheEntry          *entry)
{
  if (g_atomic_int_dec_and_test (&entry->ref_count))
    {
      PING (("removing cache entry %p", entry->hfont));

      g_hash_table_remove (cache->forward, &entry->logfontw);
      g_hash_table_remove (cache->back, entry->hfont);

      free_cache_entry (NULL, entry, cache);
    }
}
Beispiel #6
0
static dbus_bool_t
handle_watch (DBusWatch       *watch,
              unsigned int     condition,
              void            *data)
{
  DBusBabysitter *sitter = data;

  /* On Unix dbus-spawn uses a babysitter *process*, thus it has to
   * actually send the exit statuses, error codes and whatnot through
   * sockets and/or pipes. On Win32, the babysitter is jus a thread,
   * so it can set the status fields directly in the babysitter struct
   * just fine. The socket pipe is used just so we can watch it with
   * select(), as soon as anything is written to it we know that the
   * babysitter thread has recorded the status in the babysitter
   * struct.
   */

  PING();
  _dbus_close_socket (sitter->socket_to_babysitter, NULL);
  PING();
  sitter->socket_to_babysitter = -1;

  return TRUE;
}
Beispiel #7
0
dbus_bool_t
_dbus_babysitter_set_watch_functions (DBusBabysitter            *sitter,
                                      DBusAddWatchFunction       add_function,
                                      DBusRemoveWatchFunction    remove_function,
                                      DBusWatchToggledFunction   toggled_function,
                                      void                      *data,
                                      DBusFreeFunction           free_data_function)
{
  PING();
  return _dbus_watch_list_set_functions (sitter->watches,
                                         add_function,
                                         remove_function,
                                         toggled_function,
                                         data,
                                         free_data_function);
}
Beispiel #8
0
dbus_bool_t
_dbus_spawn_async_with_babysitter (DBusBabysitter           **sitter_p,
                                   char                     **argv,
                                   char                     **envp,
                                   DBusSpawnChildSetupFunc    child_setup,
                                   void                      *user_data,
                                   DBusError                 *error)
{
  DBusBabysitter *sitter;
  HANDLE sitter_thread;
  int sitter_thread_id;

  _DBUS_ASSERT_ERROR_IS_CLEAR (error);

  *sitter_p = NULL;

  PING();
  sitter = _dbus_babysitter_new ();
  if (sitter == NULL)
    {
      _DBUS_SET_OOM (error);
      return FALSE;
    }

  sitter->child_setup = child_setup;
  sitter->user_data = user_data;

  sitter->executable = _dbus_strdup (argv[0]);
  if (sitter->executable == NULL)
    {
      _DBUS_SET_OOM (error);
      goto out0;
    }

  PING();
  if (!_dbus_full_duplex_pipe (&sitter->socket_to_babysitter,
                               &sitter->socket_to_main,
                               FALSE, error))
    goto out0;

  sitter->sitter_watch = _dbus_watch_new (sitter->socket_to_babysitter,
                                          DBUS_WATCH_READABLE,
                                          TRUE, handle_watch, sitter, NULL);
  PING();
  if (sitter->sitter_watch == NULL)
    {
      _DBUS_SET_OOM (error);
      goto out0;
    }

  PING();
  if (!_dbus_watch_list_add_watch (sitter->watches,  sitter->sitter_watch))
    {
      _DBUS_SET_OOM (error);
      goto out0;
    }

  sitter->argc = protect_argv (argv, &sitter->argv);
  if (sitter->argc == -1)
    {
      _DBUS_SET_OOM (error);
      goto out0;
    }
  sitter->envp = envp;

  PING();
  sitter_thread = (HANDLE) _beginthreadex (NULL, 0, babysitter,
                  sitter, 0, &sitter_thread_id);

  if (sitter_thread == 0)
    {
      PING();
      dbus_set_error_const (error, DBUS_ERROR_SPAWN_FORK_FAILED,
                            "Failed to create new thread");
      goto out0;
    }
  CloseHandle (sitter_thread);

  PING();
  WaitForSingleObject (sitter->start_sync_event, INFINITE);

  PING();
  if (sitter_p != NULL)
    *sitter_p = sitter;
  else
    _dbus_babysitter_unref (sitter);

  _DBUS_ASSERT_ERROR_IS_CLEAR (error);

  PING();
  return TRUE;

out0:
  _dbus_babysitter_unref (sitter);

  return FALSE;
}
Beispiel #9
0
static unsigned __stdcall
babysitter (void *parameter)
{
  DBusBabysitter *sitter = (DBusBabysitter *) parameter;
  int fd;
  PING();
  _dbus_babysitter_ref (sitter);

  if (sitter->child_setup)
    {
      PING();
      (*sitter->child_setup) (sitter->user_data);
    }

  _dbus_verbose ("babysitter: spawning %s\n", sitter->executable);

  PING();
  if (sitter->envp != NULL)
    sitter->child_handle = (HANDLE) spawnve (P_NOWAIT, sitter->executable,
                           (const char * const *) sitter->argv,
                           (const char * const *) sitter->envp);
  else
    sitter->child_handle = (HANDLE) spawnv (P_NOWAIT, sitter->executable,
                                            (const char * const *) sitter->argv);

  PING();
  if (sitter->child_handle == (HANDLE) -1)
    {
      sitter->child_handle = NULL;
      sitter->have_spawn_errno = TRUE;
      sitter->spawn_errno = errno;
    }

  PING();
  SetEvent (sitter->start_sync_event);

  if (sitter->child_handle != NULL)
    {
      int ret;
      DWORD status;

      PING();
      WaitForSingleObject (sitter->child_handle, INFINITE);

      PING();
      ret = GetExitCodeProcess (sitter->child_handle, &status);

      sitter->child_status = status;
      sitter->have_child_status = TRUE;

      CloseHandle (sitter->child_handle);
      sitter->child_handle = NULL;
    }

#ifdef DBUS_BUILD_TESTS
  SetEvent (sitter->end_sync_event);
#endif

  PING();
  send (sitter->socket_to_main, " ", 1, 0);

  _dbus_babysitter_unref (sitter);

  return 0;
}
Beispiel #10
0
 void foo(int)           const { PING(); }
Beispiel #11
0
 int foo(double, double) const { PING(); return 1; }
Beispiel #12
0
/**
 * Checks whether the child has exited, without blocking.
 *
 * @param sitter the babysitter
 */
dbus_bool_t
_dbus_babysitter_get_child_exited (DBusBabysitter *sitter)
{
  PING();
  return (sitter->child_handle == NULL);
}
Beispiel #13
0
/**
 * Decrement the reference count on the babysitter object.
 *
 * @param sitter the babysitter
 */
void
_dbus_babysitter_unref (DBusBabysitter *sitter)
{
  int i;

  PING();
  _dbus_assert (sitter != NULL);
  _dbus_assert (sitter->refcount > 0);

  sitter->refcount -= 1;

  if (sitter->refcount == 0)
    {
      if (sitter->socket_to_babysitter != -1)
        {
          _dbus_close_socket (sitter->socket_to_babysitter, NULL);
          sitter->socket_to_babysitter = -1;
        }

      if (sitter->socket_to_main != -1)
        {
          _dbus_close_socket (sitter->socket_to_main, NULL);
          sitter->socket_to_main = -1;
        }

      PING();
      if (sitter->argv != NULL)
        {
          for (i = 0; i < sitter->argc; i++)
            if (sitter->argv[i] != NULL)
              {
                dbus_free (sitter->argv[i]);
                sitter->argv[i] = NULL;
              }
          dbus_free (sitter->argv);
          sitter->argv = NULL;
        }

      if (sitter->envp != NULL)
        {
          char **e = sitter->envp;

          while (*e)
            dbus_free (*e++);
          dbus_free (sitter->envp);
          sitter->envp = NULL;
        }

      if (sitter->child_handle != NULL)
        {
          CloseHandle (sitter->child_handle);
          sitter->child_handle = NULL;
        }

      if (sitter->sitter_watch)
        {
          _dbus_watch_invalidate (sitter->sitter_watch);
          _dbus_watch_unref (sitter->sitter_watch);
          sitter->sitter_watch = NULL;
        }

      if (sitter->watches)
        _dbus_watch_list_free (sitter->watches);

      if (sitter->start_sync_event != NULL)
        {
          PING();
          CloseHandle (sitter->start_sync_event);
          sitter->start_sync_event = NULL;
        }

#ifdef DBUS_BUILD_TESTS
      if (sitter->end_sync_event != NULL)
        {
          CloseHandle (sitter->end_sync_event);
          sitter->end_sync_event = NULL;
        }
#endif

      dbus_free (sitter->executable);

      dbus_free (sitter);
    }
}
/**
 * pango_win32_font_cache_loadw:
 * @cache: a #PangoWin32FontCache
 * @logfont: a pointer to a LOGFONTW structure describing the font to load.
 *
 * Creates a HFONT from a LOGFONTW. The
 * result may be newly loaded, or it may have been previously
 * stored
 *
 * Return value: The font structure, or %NULL if the font could
 * not be loaded. In order to free this structure, you must call
 * pango_win32_font_cache_unload().
 *
 * Since: 1.16
 **/
HFONT
pango_win32_font_cache_loadw (PangoWin32FontCache *cache,
			      const LOGFONTW      *lfp)
{
  CacheEntry *entry;
  LOGFONTW lf;
  HFONT hfont;
  int tries;

  g_return_val_if_fail (cache != NULL, NULL);
  g_return_val_if_fail (lfp != NULL, NULL);

  entry = g_hash_table_lookup (cache->forward, lfp);

  if (entry)
    {
      g_atomic_int_inc (&entry->ref_count);
      PING (("increased refcount for cache entry %p: %d", entry->hfont, entry->ref_count));
    }
  else
    {
      BOOL font_smoothing;
      lf = *lfp;
      SystemParametersInfo (SPI_GETFONTSMOOTHING, 0, &font_smoothing, 0);
      /* If on XP or better, try to use ClearType if the global system
       * settings ask for it.
       */
      if (font_smoothing &&
	  (_pango_win32_os_version_info.dwMajorVersion > 5 ||
	   (_pango_win32_os_version_info.dwMajorVersion == 5 &&
	    _pango_win32_os_version_info.dwMinorVersion >= 1)))
	{
	  UINT smoothing_type;

#ifndef SPI_GETFONTSMOOTHINGTYPE
#define SPI_GETFONTSMOOTHINGTYPE 0x200a
#endif
#ifndef FE_FONTSMOOTHINGCLEARTYPE
#define FE_FONTSMOOTHINGCLEARTYPE 2
#endif
#ifndef CLEARTYPE_QUALITY
#define CLEARTYPE_QUALITY 5
#endif
	  SystemParametersInfo (SPI_GETFONTSMOOTHINGTYPE, 0, &smoothing_type, 0);
	  lf.lfQuality =
	    (font_smoothing ?
	     (smoothing_type == FE_FONTSMOOTHINGCLEARTYPE ?
	      CLEARTYPE_QUALITY : ANTIALIASED_QUALITY) :
	     DEFAULT_QUALITY);
	}
      else
	lf.lfQuality = (font_smoothing ? ANTIALIASED_QUALITY : DEFAULT_QUALITY);
      lf.lfCharSet = DEFAULT_CHARSET;
      for (tries = 0; ; tries++)
	{
	  PING (("... trying CreateFontIndirect "
		 "height=%ld,width=%ld,escapement=%ld,orientation=%ld,"
		 "weight=%ld,%s%s%s"
		 "charset=%d,outprecision=%d,clipprecision=%d,"
		 "quality=%d,pitchandfamily=%#.02x,facename=\"%S\")",
		 lf.lfHeight, lf.lfWidth, lf.lfEscapement, lf.lfOrientation,
		 lf.lfWeight, (lf.lfItalic ? "italic," : ""),
		 (lf.lfUnderline ? "underline," : ""),
		 (lf.lfStrikeOut ? "strikeout," : ""),
		 lf.lfCharSet, lf.lfOutPrecision, lf.lfClipPrecision,
		 lf.lfQuality, lf.lfPitchAndFamily, lf.lfFaceName));
	  hfont = CreateFontIndirectW (&lf);

	  if (hfont != NULL)
	    {
	      PING (("Success! hfont=%p", hfont));
	      break;
	    }

	  /* If we fail, try some similar fonts often found on Windows. */
	  if (tries == 0)
	    {
	      gchar *p = g_utf16_to_utf8 (lf.lfFaceName, -1, NULL, NULL, NULL);
	      if (!p)
		; /* Nothing */
	      else if (g_ascii_strcasecmp (p, "helvetica") == 0)
		wcscpy (lf.lfFaceName, L"arial");
	      else if (g_ascii_strcasecmp (p, "new century schoolbook") == 0)
		wcscpy (lf.lfFaceName, L"century schoolbook");
	      else if (g_ascii_strcasecmp (p, "courier") == 0)
		wcscpy (lf.lfFaceName, L"courier new");
	      else if (g_ascii_strcasecmp (p, "lucida") == 0)
		wcscpy (lf.lfFaceName, L"lucida sans unicode");
	      else if (g_ascii_strcasecmp (p, "lucidatypewriter") == 0)
		wcscpy (lf.lfFaceName, L"lucida console");
	      else if (g_ascii_strcasecmp (p, "times") == 0)
		wcscpy (lf.lfFaceName, L"times new roman");
	      g_free (p);
	    }
	  else if (tries == 1)
	    {
	      gchar *p = g_utf16_to_utf8 (lf.lfFaceName, -1, NULL, NULL, NULL);
	      if (!p)
		; /* Nothing */
	      else if (g_ascii_strcasecmp (p, "courier") == 0)
		{
		  wcscpy (lf.lfFaceName, L"");
		  lf.lfPitchAndFamily |= FF_MODERN;
		}
	      else if (g_ascii_strcasecmp (p, "times new roman") == 0)
		{
		  wcscpy (lf.lfFaceName, L"");
		  lf.lfPitchAndFamily |= FF_ROMAN;
		}
	      else if (g_ascii_strcasecmp (p, "helvetica") == 0
		       || g_ascii_strcasecmp (p, "lucida") == 0)
		{
		  wcscpy (lf.lfFaceName, L"");
		  lf.lfPitchAndFamily |= FF_SWISS;
		}
	      else
		{
		  wcscpy (lf.lfFaceName, L"");
		  lf.lfPitchAndFamily = (lf.lfPitchAndFamily & 0x0F) | FF_DONTCARE;
		}
	      g_free (p);
	    }
	  else
	    break;
	  tries++;
	}

      if (!hfont)
	return NULL;

      entry = g_slice_new (CacheEntry);

      entry->logfontw = lf;
      entry->hfont = hfont;

      entry->ref_count = 1;
      entry->mru = NULL;

      g_hash_table_insert (cache->forward, &entry->logfontw, entry);
      g_hash_table_insert (cache->back, entry->hfont, entry);
    }

  if (entry->mru)
    {
      if (cache->mru_count > 1 && entry->mru->prev)
	{
	  /* Move to the head of the mru list */

	  if (entry->mru == cache->mru_tail)
	    {
	      cache->mru_tail = cache->mru_tail->prev;
	      cache->mru_tail->next = NULL;
	    }
	  else
	    {
	      entry->mru->prev->next = entry->mru->next;
	      entry->mru->next->prev = entry->mru->prev;
	    }

	  entry->mru->next = cache->mru;
	  entry->mru->prev = NULL;
	  cache->mru->prev = entry->mru;
	  cache->mru = entry->mru;
	}
    }
  else
    {
      g_atomic_int_inc (&entry->ref_count);

      /* Insert into the mru list */

      if (cache->mru_count == CACHE_SIZE)
	{
	  CacheEntry *old_entry = cache->mru_tail->data;

	  cache->mru_tail = cache->mru_tail->prev;
	  cache->mru_tail->next = NULL;

	  g_list_free_1 (old_entry->mru);
	  old_entry->mru = NULL;
	  cache_entry_unref (cache, old_entry);
	}
      else
	cache->mru_count++;

      cache->mru = g_list_prepend (cache->mru, entry);
      if (!cache->mru_tail)
	cache->mru_tail = cache->mru;
      entry->mru = cache->mru;
    }

  return entry->hfont;
}
Beispiel #15
0
void ultrasonic_update_fsm(uint8 cmd, uint8 *param)
{
	enum states 
	{ 
		s_waiting_for_ping=0,	//0 
		s_waiting_for_echo,		//1
		s_none=255
	};
	static enum states state=s_waiting_for_ping;
	static enum states last_state=s_none;
	static u32 t_entry=0;
	static u08 initialized=0;
	static u08 newpulse=0;
	static u32 t_ping=0;
	static u32 pulse;
	static u16 distance;
	static u08 sensor=0;
	DEFINE_CFG2(u08,bitmap,4,1);
	DEFINE_CFG2(u32,echo_timeout,4,2);
	DEFINE_CFG2(u32,intra_delay,4,3);
	

	//task_open();

	if(!initialized)
	{
		initialized=1;

		usb_printf("ultrasonic_update_fsm()\n");

		PREPARE_CFG2(bitmap);					
		PREPARE_CFG2(echo_timeout);					
		PREPARE_CFG2(intra_delay);					
	}

	//while(1)
	{
		UPDATE_CFG2(bitmap);					
		UPDATE_CFG2(echo_timeout);					
		UPDATE_CFG2(intra_delay);					


		first_(s_waiting_for_ping)
		{
			enter_(s_waiting_for_ping) 
			{  
				NOP();
			}
			
			if(get_ms() - t_ping >= intra_delay)
			{
				PING(sonar_pin[sensor]);
				newpulse = new_pulse(sensor); //clear the pulse capture state
				t_ping = get_ms();
				state = s_waiting_for_echo;
			}

			exit_(s_waiting_for_ping)  
			{ 
				NOP();
			}
		}

		next_(s_waiting_for_echo)
		{
			enter_(s_waiting_for_echo) 
			{  
				NOP();
			}

			newpulse = new_high_pulse(sensor);
			if(newpulse)
			{
				pulse = pulse_to_microseconds(get_last_high_pulse(sensor));
				distance = ((pulse*10)/148) + 2;
				state = s_waiting_for_ping;
			}
			else if( get_ms()-t_ping >= echo_timeout)
			{
				distance = 4000;
				state = s_waiting_for_ping;
			}

			exit_(s_waiting_for_echo)  
			{ 
				s.inputs.sonar[sensor] = distance;
				s.us_avg[sensor] = (s.us_avg[sensor]*3 + distance)/4;

				sensor=get_next_sensor();
				if(get_ms() - t_ping >= intra_delay)
				{
					PING(sonar_pin[sensor]);
					newpulse = new_pulse(sensor);
					t_ping = get_ms();
					state = s_waiting_for_echo;
				}
			}
		}
	}
}
Beispiel #16
0
 void bar()       { PING(); }
Beispiel #17
0
 void foo() const { PING(); }