⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppcfuncs.c

📁 ppciaxclient softphone
💻 C
字号:
/*
 * iaxclient: a cross-platform IAX softphone library
 *
 * Copyrights:
 * Copyright (C) 2003 HorizonLive.com, (c) 2004, Horizon Wimba, Inc.
 *
 * Contributors:
 * Steve Kann <stevek@stevek.com>
 *
 *
 * This program is free software, distributed under the terms of
 * the GNU Lesser (Library) General Public License
 */

#include "iaxclient_lib.h"

#include <windows.h>
#include <winbase.h>

#include <stdio.h>
#include "time.h"
#include "timeb.h"

/* Win-doze doesnt have gettimeofday(). This sux. So, what we did is
provide some gettimeofday-like functionality that works for our purposes. */

/*
	changed 'struct timezone*' to 'void*' since
	timezone is defined as a long in MINGW and caused compile-time warnings.
	this should be okay since we don't use the passed value. 
*/

static time_t elapsed_minutes_cache = 0;
static unsigned __int64 millis_at_system_start = 0;

typedef union {
  unsigned __int64 ft_scalar;
  FILETIME ft_struct;
} FT;


#define EPOCH_BIAS  116444736000000000i64

#define DAYLIGHT_TIME   1
#define STANDARD_TIME   0
#define UNKNOWN_TIME    -1

static int dstflag_cache = UNKNOWN_TIME;

void 
xceftime(struct _timeb *tp)
{
  FT nt_time;
  time_t t;
  SYSTEMTIME sysTime;
  TIME_ZONE_INFORMATION tzinfo;
  DWORD tzstate;
  __int64 current_millis;

  if(millis_at_system_start == 0)
    {
//      __tzset();

	  
	
	GetSystemTime(&sysTime);
	SystemTimeToFileTime(&sysTime,&nt_time.ft_struct);
    //  XCEGetSystemTimeAsFileTime(&(nt_time.ft_struct));

      if((t = (time_t)(nt_time.ft_scalar / 600000000i64))
	 != elapsed_minutes_cache)
	{
	  if((tzstate = GetTimeZoneInformation(&tzinfo)) != 0xFFFFFFFF)
	    {
	      if ( (tzstate == TIME_ZONE_ID_DAYLIGHT) &&
		   (tzinfo.DaylightDate.wMonth != 0) &&
		   (tzinfo.DaylightBias != 0) )
		dstflag_cache = DAYLIGHT_TIME;
	      else
		dstflag_cache = STANDARD_TIME;
	    }
	  else
	    {
	      dstflag_cache = UNKNOWN_TIME;
	    }

	  elapsed_minutes_cache = t;
	}

      // current millisecs
      millis_at_system_start = ((nt_time.ft_scalar - EPOCH_BIAS) / 10000i64);
      // subtract ticks
      millis_at_system_start -= GetTickCount();
    }

  current_millis = millis_at_system_start + GetTickCount();

  tp->time = (time_t)(current_millis / 1000i64);
  tp->millitm = current_millis % 1000i64;
//  tp->timezone = (short)(_timezone / 60);
  tp->dstflag = (short)dstflag_cache;
}


int
xcegettimeofday (struct timeval *tv, void *tz)
{
  struct _timeb tb;

  xceftime (&tb);

  tv->tv_sec = tb.time;
  tv->tv_usec = tb.millitm * 1000;

#if 0
  // why not?
  if(tz) 
    {
      tz->tz_minuteswest = tb.timezone;
      tz->tz_dsttime = tb.dstflag;
    }
#endif

  return 0;
}

/* 
 * functions implementations
 */

void gettimeofday( struct timeval* tv, void* tz )
{
/*	struct _timeb curSysTime;
	_ftime(&curSysTime);
	tv->tv_sec = curSysTime.time;
	tv->tv_usec = curSysTime.millitm * 1000;*/
	xcegettimeofday (tv, tz);
	

	
//	tv->tv_sec = (sysTime.wYear*365*24*60*60)+(sysTime.wMonth*30*24*60*60)+(sysTime.w

	return ;
}

void os_init(void)
{
	WSADATA wsd;

	if(WSAStartup(0x0101,&wsd))
	{   // Error message?
	    exit(1);
	}
}

/* yes, it could have just been a #define, but that makes linking trickier */
EXPORT void iaxc_millisleep(long ms)
{
	Sleep(ms);
}

int post_event_callback(iaxc_event ev) {
  iaxc_event *e;
  e = malloc(sizeof(ev));
  *e = ev;

  /* XXX Test return value? */
  PostMessage(post_event_handle,post_event_id,(WPARAM) NULL, (LPARAM) e);
  return 0;
}

/* Increasing the Thread Priority.  See
 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/scheduling_priorities.asp
 * for discussion on Win32 scheduling priorities.
 */

int iaxc_prioboostbegin() {
      if ( !SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL)  ) {
            fprintf(stderr, "SetThreadPriority failed: %ld.\n", GetLastError());
      }
}

int iaxc_prioboostend() {
    /* TODO */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -