//...................................................................
void QHsm::tranStat(Tran *tran, QState target) {
   REQUIRE(target != &QHsm::top);        // cannot target "top" state
   register QState s;
   for (s = myState; s != mySource; ) {
      ASSERT(s);                     // we are about to dereference s
      QState t = TRIGGER(s, Q_EXIT_SIG);
      if (t) {       // exit action unhandled, t points to superstate
         s = t;
      }
      else {                // exit action handled, elicit superstate
         s = TRIGGER(s, Q_EMPTY_SIG);
      }
   }
   if (tran->myChain[0] == 0) {    // is the tran object initialized?
      tranSetup(tran, target);         // setup the transition object
   }
   else {  // transition object initialized, execute transition chain
      register QState *c = &tran->myChain[0];
      register unsigned short a;
      for (a = tran->myActions; a; a >>= 2, ++c) {
         (this->*(*c))(&pkgStdEvt[a & 3]);
      }
      myState = *c;
   }
}
Ejemplo n.º 2
0
char   *DMrealloc(char *ptr, int size, char *fname, int line)
{
  char   *saveptr;

  saveptr = ptr;
  ptr = DMmemcheck(ptr, fname, line);

  if ((ptr = (char *) realloc(ptr, size + HDRSIZE + 1)) == NULL) {
    fprintf(stderr, "%s[%d]: realloc(0x%x,%d) OUT OF MEMORY\n",
        fname, line,
        saveptr,
        size);
    abort();
  }
  ptr = guardit(ptr, size);
  if (DMverbose || (DMtriggeraddr == ptr) || (DMtriggeraddr == saveptr)) {
    fprintf(stderr, "%s[%d]: realloc(0x%x,%d) = 0x%x\n",
        fname, line, saveptr, size, ptr);
    TRIGGER(saveptr);
    TRIGGER(ptr);
  }
  freed(saveptr, fname, line);
  malloced(ptr);
  return(ptr);
}
Ejemplo n.º 3
0
EnHandleResult CTcpServer::TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj)
{
	EnHandleResult rs = (EnHandleResult)HR_CLOSED;

	if(m_enOnSendSyncPolicy == OSSP_NONE)
		rs = TRIGGER(FireSend(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len));
	else
	{
		ASSERT(m_enOnSendSyncPolicy >= OSSP_CLOSE && m_enOnSendSyncPolicy <= OSSP_RECEIVE);

		if(TSocketObj::IsValid(pSocketObj))
		{
			CCriSecLock locallock(m_enOnSendSyncPolicy == OSSP_CLOSE ? pSocketObj->csSend : pSocketObj->csRecv);

			if(TSocketObj::IsValid(pSocketObj))
			{
				rs = TRIGGER(FireSend(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len));
			}
		}
	}

	if(rs == HR_ERROR)
	{
		TRACE("<S-CNNID: %Iu> OnSend() event should not return 'HR_ERROR' !!\n", pSocketObj->connID);
		ASSERT(FALSE);
	}

	if(pBufferObj->ReleaseSendCounter() == 0)
		AddFreeBufferObj(pBufferObj);

	return rs;
}
Ejemplo n.º 4
0
EnHandleResult CTcpServer::TriggerFireAccept(TSocketObj* pSocketObj)
{
	EnHandleResult rs = TRIGGER(FireAccept(pSocketObj));
	pSocketObj->csRecv.Unlock();

	return rs;
}
Ejemplo n.º 5
0
char   *DMcalloc(int size, int nitems, char *fname, int line)
{
  char   *ptr;
  int     totalsize;
  int    i;
  char   *tempptr;

  DMmemcheck(NULL, fname, line);

  totalsize = size * nitems;
  if ((ptr = (char *) malloc(totalsize + HDRSIZE + 1)) == NULL) {
    fprintf(stderr, "%s[%d]: calloc(%d,%d) OUT OF MEMORY\n",
        fname, line, size, nitems);
    abort();
  }
  ptr = guardit(ptr, totalsize);

  /* initialize to zeros */
  tempptr = ptr;
  for (i = 0; i < totalsize; i++) {
    *tempptr++ = 0;
  }

  if (DMverbose || (ptr == DMtriggeraddr)) {
    fprintf(stderr, "%s[%d]: calloc(%d,%d) = 0x%x\n", fname, line,
        size, nitems, ptr);
    TRIGGER(ptr);
  }
  malloced(ptr);
  return(ptr);
}
Ejemplo n.º 6
0
BOOL CTcpClient::HandleConnect(SHORT events)
{
	ASSERT(events & POLLOUT);

	int code = ::SSO_GetError(m_soClient);

	if(!IS_NO_ERROR(code) || (events & _POLL_ERROR_EVENTS))
	{
		m_ccContext.Reset(TRUE, SO_CONNECT, code);
		return FALSE;
	}

	if(events & _POLL_HUNGUP_EVENTS)
	{
		m_ccContext.Reset(TRUE, SO_CONNECT, NO_ERROR);
		return FALSE;
	}

	SetConnected();

	if(TRIGGER(FireConnect()) == HR_ERROR)
	{
		m_ccContext.Reset(FALSE);
		return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 7
0
/*向hash表中插入一组数据*/
void hash_insert(struct HashTable *table, char *key, void *value)
{
	int index;
	struct HashNode *node;

	if(!table || !key)
		return;

	index = _find(table, key);
	if(index == -1)
	{
		if(TRIGGER(table->capacity, table->number + 1))
			_resize(table);
		index = _get_empty(table, key);
		node = (struct HashNode*)mm_malloc(sizeof(struct HashNode));
		node->key = (char*)mm_malloc(strlen(key) + 1);
		strcpy(node->key, key);
		if(table->copy_value)
			node->value = table->copy_value(value);
		else
			node->value = value;
		table->head[index] = node;
		table->number ++;
	}
	else
	{
		
		if(table->free_value)
			table->free_value(table->head[index]->value);
		if(table->copy_value)
			table->head[index]->value = table->copy_value(value);
		else
			table->head[index]->value = value;
	}
}
Ejemplo n.º 8
0
BOOL CTcpClient::DoSendData(TItem* pItem)
{
	while(!pItem->IsEmpty())
	{
		int rc = (int)write(m_soClient, (char*)pItem->Ptr(), pItem->Size());

		if(rc > 0)
		{
			if(TRIGGER(FireSend(pItem->Ptr(), rc)) == HR_ERROR)
			{
				TRACE("<C-CNNID: %zu> OnSend() event should not return 'HR_ERROR' !!", m_dwConnID);
				ASSERT(FALSE);
			}

			pItem->Reduce(rc);
		}
		else if(rc == SOCKET_ERROR)
		{
			int code = ::WSAGetLastError();

			if(code == ERROR_WOULDBLOCK)
				break;
			else
			{
				m_ccContext.Reset(TRUE, SO_SEND, code);
				return FALSE;
			}
		}
		else
			ASSERT(FALSE);
	}

	return TRUE;
}
//...................................................................
void QHsm::init(QEvent const *e) {
   REQUIRE(myState == &QHsm::top &&        /* HSM not executed yet */
           mySource != 0); /* we are about to dereference mySource */
   register QState s = myState;        // save myState in a temporary
   (this->*(QPseudoState)mySource)(e); // top-most initial transition
                       // initial transition must go *one* level deep
   ASSERT(s == TRIGGER(myState, Q_EMPTY_SIG));
   s = myState;                               // update the temporary
   TRIGGER(s, Q_ENTRY_SIG);                        // enter the state
   while (TRIGGER(s, Q_INIT_SIG) == 0) {             // init handled?
                       // initial transition must go *one* level deep
      ASSERT(s == TRIGGER(myState, Q_EMPTY_SIG));
      s = myState;
      TRIGGER(s, Q_ENTRY_SIG);                  // enter the substate
   }
}
//...................................................................
int QHsm::isIn(QState state) {
   register QState s;
   for (s = myState; s; s = TRIGGER(mySource, Q_EMPTY_SIG)) {
      if (s == state) {                       // do the states match?
         return !0;                       // match found, return true
      }
   }
   return 0;                          // no match found, return false
} 
Ejemplo n.º 11
0
BOOL CTcpServer::CreateListenSocket(LPCTSTR lpszBindAddress, USHORT usPort)
{
	BOOL isOK = FALSE;

	if(!lpszBindAddress || lpszBindAddress[0] == 0)
		lpszBindAddress = DEFAULT_IPV4_BIND_ADDRESS;

	HP_SOCKADDR addr;

	if(::sockaddr_A_2_IN(lpszBindAddress, usPort, addr))
	{
		m_usFamily = addr.family;
		m_soListen = socket(m_usFamily, SOCK_STREAM, IPPROTO_TCP);

		if(m_soListen != INVALID_SOCKET)
		{
			BOOL bOnOff	= (m_dwKeepAliveTime > 0 && m_dwKeepAliveInterval > 0);
			ENSURE(::SSO_KeepAliveVals(m_soListen, bOnOff, m_dwKeepAliveTime, m_dwKeepAliveInterval) == NO_ERROR);
			ENSURE(::SSO_ExclusiveAddressUse(m_soListen, TRUE) == NO_ERROR);
			ENSURE(::SSO_NoBlock(m_soListen) == NO_ERROR);
			
			if(::bind(m_soListen, addr.Addr(), addr.AddrSize()) != SOCKET_ERROR)
			{
				if(TRIGGER(FirePrepareListen(m_soListen)) != HR_ERROR)
				{
					if(::listen(m_soListen, m_dwSocketListenQueue) != SOCKET_ERROR)
					{
						m_pfnAcceptEx				= ::Get_AcceptEx_FuncPtr(m_soListen);
						m_pfnGetAcceptExSockaddrs	= ::Get_GetAcceptExSockaddrs_FuncPtr(m_soListen);
						m_pfnDisconnectEx			= ::Get_DisconnectEx_FuncPtr(m_soListen);

						ASSERT(m_pfnAcceptEx);
						ASSERT(m_pfnGetAcceptExSockaddrs);
						ASSERT(m_pfnDisconnectEx);

						isOK = TRUE;
					}
					else
						SetLastError(SE_SOCKET_LISTEN, __FUNCTION__, ::WSAGetLastError());
				}
				else
					SetLastError(SE_SOCKET_PREPARE, __FUNCTION__, ENSURE_ERROR_CANCELLED);
			}
			else
				SetLastError(SE_SOCKET_BIND, __FUNCTION__, ::WSAGetLastError());
		}
		else
			SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError());
	}
	else
		SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError());

	return isOK;
}
Ejemplo n.º 12
0
EnHandleResult CTcpServer::TriggerFireReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj)
{
	EnHandleResult rs = (EnHandleResult)HR_CLOSED;

	if(TSocketObj::IsValid(pSocketObj))
	{
		CCriSecLock locallock(pSocketObj->csRecv);

		if(TSocketObj::IsValid(pSocketObj))
		{
			rs = TRIGGER(FireReceive(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len));
		}
	}

	return rs;
}
Ejemplo n.º 13
0
BOOL CTcpClient::Start(LPCTSTR lpszRemoteAddress, USHORT usPort, BOOL bAsyncConnect, LPCTSTR lpszBindAddress, USHORT usLocalPort)
{
	if(!CheckParams() || !CheckStarting())
		return FALSE;

	PrepareStart();
	m_ccContext.Reset();

	BOOL isOK = FALSE;

	HP_SOCKADDR addrRemote, addrBind;

	if(CreateClientSocket(lpszRemoteAddress, addrRemote, usPort, lpszBindAddress, addrBind))
	{
		if(BindClientSocket(addrBind, addrRemote, usLocalPort))
		{
			if(TRIGGER(FirePrepareConnect(m_soClient)) != HR_ERROR)
			{
				if(ConnectToServer(addrRemote, bAsyncConnect))
				{
					if(CreateWorkerThread())
						isOK = TRUE;
					else
						SetLastError(SE_WORKER_THREAD_CREATE, __FUNCTION__, ERROR_CREATE_FAILED);
				}
				else
					SetLastError(SE_CONNECT_SERVER, __FUNCTION__, ::WSAGetLastError());
			}
			else
				SetLastError(SE_SOCKET_PREPARE, __FUNCTION__, ENSURE_ERROR_CANCELLED);
		}
		else
			SetLastError(SE_SOCKET_BIND, __FUNCTION__, ::WSAGetLastError());
	}
	else
		SetLastError(SE_SOCKET_CREATE, __FUNCTION__, ::WSAGetLastError());

	if(!isOK)
	{
		m_ccContext.Reset(FALSE);
		EXECUTE_RESTORE_ERROR(Stop());
	}

	return isOK;
}
Ejemplo n.º 14
0
DMfree(char *ptr, char *fname, int line)
{
  unsigned long size;

  if (ptr == NULL)
    return;

  if (DMverbose || (ptr == DMtriggeraddr)) {
    size = ((unsigned long *)ptr)[-2];
    fprintf(stderr, "%s[%d]: free(0x%x) (%ld bytes)\n",
        fname, line, ptr, size);
    TRIGGER(ptr);
  }
  ptr = DMmemcheck(ptr, fname, line);

  /* Negate the last byte of the header guard to signify freed */
  ((unsigned long *)ptr)[1] ^= 0x00ff;

  /* all's well so free it */
  freed(ptr + HDRSIZE, fname, line);
  free(ptr);
}
Ejemplo n.º 15
0
BOOL CTcpClient::ReadData()
{
	while(TRUE)
	{
		int rc = (int)read(m_soClient, (char*)(BYTE*)m_rcBuffer, m_dwSocketBufferSize);

		if(rc > 0)
		{
			if(TRIGGER(FireReceive(m_rcBuffer, rc)) == HR_ERROR)
			{
				TRACE("<C-CNNID: %zu> OnReceive() event return 'HR_ERROR', connection will be closed !", m_dwConnID);

				m_ccContext.Reset(TRUE, SO_RECEIVE, ENSURE_ERROR_CANCELLED);
				return FALSE;
			}
		}
		else if(rc == SOCKET_ERROR)
		{
			int code = ::WSAGetLastError();

			if(code == ERROR_WOULDBLOCK)
				break;
			else
			{
				m_ccContext.Reset(TRUE, SO_RECEIVE, code);
				return FALSE;
			}
		}
		else if(rc == 0)
		{
			m_ccContext.Reset(TRUE, SO_CLOSE, SE_OK);
			return FALSE;
		}
		else
			ASSERT(FALSE);
	}

	return TRUE;
}
Ejemplo n.º 16
0
char   *DMmalloc(int size, char *fname, int line)
{
  char   *ptr;

  DMmemcheck(NULL, fname, line);

  if ((ptr = (char *) malloc(size + HDRSIZE + 1)) == NULL) {
    fprintf(stderr, "%s[%d]: malloc(%d) OUT OF MEMORY\n", fname, line,
        size);
    abort();
  }

  ptr = guardit(ptr, size);


  if (DMverbose || (DMtriggeraddr == ptr)) {
    fprintf(stderr, "%s[%d]: malloc(%d) = 0x%x\n",
        fname, line, size, ptr);
    TRIGGER(ptr);
  }
  malloced(ptr);
  return(ptr);
}
Ejemplo n.º 17
0
BOOL CTcpClient::ConnectToServer(const HP_SOCKADDR& addrRemote, BOOL bAsyncConnect)
{
	BOOL isOK = FALSE;

	if(bAsyncConnect)
	{
		VERIFY(::fcntl_SETFL(m_soClient, O_NOATIME | O_NONBLOCK | O_CLOEXEC));

		int rc = ::connect(m_soClient, addrRemote.Addr(), addrRemote.AddrSize());

		if(IS_NO_ERROR(rc) || IS_IO_PENDING_ERROR())
		{
			m_nEvents	= POLLOUT;
			isOK		= TRUE;
		}
	}
	else
	{
		if(::connect(m_soClient, addrRemote.Addr(), addrRemote.AddrSize()) != SOCKET_ERROR)
		{
			VERIFY(::fcntl_SETFL(m_soClient, O_NOATIME | O_NONBLOCK | O_CLOEXEC));

			SetConnected();

			if(TRIGGER(FireConnect()) == HR_ERROR)
				::WSASetLastError(ENSURE_ERROR_CANCELLED);
			else
			{
				m_nEvents = (SHORT)((m_lsSend.IsEmpty() ? 0 : POLLOUT) | (m_bPaused ? 0 : POLLIN) | POLLRDHUP);				
				isOK	  = TRUE;
			}
		}
	}

	return isOK;
}
//...................................................................
void QHsm::tranSetup(Tran *tran, QState target) {
   QState entry[8], p, q, s, *c, *e, *lca;
   unsigned short a = 0;

   #define RECORD(state_, sig_) \
      if (TRIGGER(state_, sig_) == 0) {\
         a |= ((sig_) << 14);   \
         a >>= 2;               \
         *c++ = (state_);       \
      } else ((void)0)

   c = &tran->myChain[0];
   *(e = &entry[0]) = 0;
   *(++e) = target;                         // assume entry to target

   // (a) check mySource == target (transition to self)
   if (mySource == target) {
      RECORD(mySource, Q_EXIT_SIG);                    // exit source
      goto inLCA;
   }
   // (b) check mySource == target->super
   p = TRIGGER(target, Q_EMPTY_SIG);
   if (mySource == p) {
      goto inLCA;
   }
   // (c) check mySource->super == target->super (most common)
   q = TRIGGER(mySource, Q_EMPTY_SIG);
   if (q == p) {
      RECORD(mySource, Q_EXIT_SIG);                    // exit source
      goto inLCA;
   }
   // (d) check mySource->super == target
   if (q == target) {
      RECORD(mySource, Q_EXIT_SIG);                    // exit source
      --e;                                    // do not enter the LCA
      goto inLCA;
   }
   // (e) check rest of mySource == target->super->super... hierarchy
   *(++e) = p;
   for (s = TRIGGER(p, Q_EMPTY_SIG); s; 
        s = TRIGGER(s, Q_EMPTY_SIG)) 
   {
      if (mySource == s) {
         goto inLCA;
      }
      *(++e) = s;
   }
   RECORD(mySource, Q_EXIT_SIG);                     // exit source
   // (f) check rest of mySource->super == target->super->super...
   for (lca = e; *lca; --lca) {
      if (q == *lca) {
         e = lca - 1;                         // do not enter the LCA
         goto inLCA;
      }
   }
   // (g) check each mySource->super->super..for each target...
   for (s = q; s; s = TRIGGER(s, Q_EMPTY_SIG)) {
      for (lca = e; *lca; --lca) {
         if (s == *lca) {
            e = lca - 1;                      // do not enter the LCA
            goto inLCA;
         }
      }
      RECORD(s, Q_EXIT_SIG);                                // exit s
   }   
   ASSERT(0);                                        // malformed HSM
inLCA:                // now we are in the LCA of mySource and target
   ASSERT(e < &entry[DIM(entry)]);         // new entry e must fit in
   while (s = *e--) {      // retrace the entry path in reverse order
      RECORD(s, Q_ENTRY_SIG);                              // enter s
   }
   myState = target;                          // update current state
   while (TRIGGER(target, Q_INIT_SIG) == 0) {
                       // initial transition must go *one* level deep
      ASSERT(target == TRIGGER(myState, Q_EMPTY_SIG));
      a |= (Q_INIT_SIG << 14);
      a >>= 2;
      *c++ = target;
      target = myState;
      RECORD(target, Q_ENTRY_SIG);                    // enter target
   }
   #undef RECORD
   *c = target;
   tran->myActions = a >> (14 - (c - &tran->myChain[0])*2);
   ENSURE(tran->myChain[0] != 0 &&       /* transition initialized */
          c < &tran->myChain[DIM(tran->myChain)]); /*check overflow*/
}
void QHsmTran_(QHsm *me, QState target) {
   QState entry[8], p, q, s, *e, *lca;
   REQUIRE(target != (QState)QHsm_top); /* cannot target top state */
   for (s = me->state__; s != me->source__; ) {
      QState t;
      ASSERT(s);                  /* we are about to dereference s */
      t = TRIGGER(s, Q_EXIT_SIG);
      if (t) {    /* exit action unhandled, t points to superstate */
         s = t;
      }
      else {             /* exit action handled, elicit superstate */
         s = TRIGGER(s, Q_EMPTY_SIG);
      }
   }

   *(e = &entry[0]) = 0;
   *(++e) = target;                      /* assume entry to target */

   /* (a) check source == target (transition to self) */
   if (me->source__ == target) {
      TRIGGER(me->source__, Q_EXIT_SIG);            /* exit source */
      goto inLCA;
   }
   /* (b) check source == target->super */
   p = TRIGGER(target, Q_EMPTY_SIG);
   if (me->source__ == p) {
      goto inLCA;
   }
   /* (c) check source->super == target->super (most common) */
   q = TRIGGER(me->source__, Q_EMPTY_SIG);
   if (q == p) {
      TRIGGER(me->source__, Q_EXIT_SIG);            /* exit source */
      goto inLCA;
   }
   /* (d) check me->source->super == target */
   if (q == target) {
      TRIGGER(me->source__, Q_EXIT_SIG);            /* exit source */
      --e;                                 /* do not enter the LCA */
      goto inLCA;
   }
   /* (e) check rest of source == target->super->super... hierarchy*/
   *(++e) = p;
   for (s = TRIGGER(p, Q_EMPTY_SIG); s; 
        s = TRIGGER(s, Q_EMPTY_SIG)) 
   {
      if (me->source__ == s) {
         goto inLCA;
      }
      *(++e) = s;
   }
   TRIGGER(me->source__, Q_EXIT_SIG);               /* exit source */
   /* (f) check rest of source->super == target->super->super... */
   for (lca = e; *lca; --lca) {
      if (q == *lca) {
         e = lca - 1;                      /* do not enter the LCA */
         goto inLCA;
      }
   }
   /* (g) check each me->source__->super->super..for each target...*/
   for (s = q; s; s = TRIGGER(s, Q_EMPTY_SIG)) {
      for (lca = e; *lca; --lca) {
         if (s == *lca) {
            e = lca - 1;                   /* do not enter the LCA */
            goto inLCA;
         }
      }
      TRIGGER(s, Q_EXIT_SIG);                            /* exit s */
   }   
   ASSERT(0);                                     /* malformed HSM */
inLCA:         /* now we are in the LCA of me->source__ and target */
   ASSERT(e < &entry[sizeof(entry)/sizeof(*entry)]); /* entry fits */
   while (s = *e--) {   /* retrace the entry path in reverse order */
      TRIGGER(s, Q_ENTRY_SIG);                          /* enter s */
   }
   me->state__ = target;                   /* update current state */
   while (TRIGGER(target, Q_INIT_SIG) == 0) {
                      /* initial transition must go one level deep */
      ASSERT(target == TRIGGER(me->state__, Q_EMPTY_SIG));
      target = me->state__;
      TRIGGER(target, Q_ENTRY_SIG);                /* enter target */
   }
}
Ejemplo n.º 20
0
#include "clk-kona.h"
#include "dt-bindings/clock/bcm281xx.h"

/* bcm11351 CCU device tree "compatible" strings */
#define BCM11351_DT_ROOT_CCU_COMPAT	"brcm,bcm11351-root-ccu"
#define BCM11351_DT_AON_CCU_COMPAT	"brcm,bcm11351-aon-ccu"
#define BCM11351_DT_HUB_CCU_COMPAT	"brcm,bcm11351-hub-ccu"
#define BCM11351_DT_MASTER_CCU_COMPAT	"brcm,bcm11351-master-ccu"
#define BCM11351_DT_SLAVE_CCU_COMPAT	"brcm,bcm11351-slave-ccu"

/* Root CCU clocks */

static struct peri_clk_data frac_1m_data = {
	.gate		= HW_SW_GATE(0x214, 16, 0, 1),
	.trig		= TRIGGER(0x0e04, 0),
	.div		= FRAC_DIVIDER(0x0e00, 0, 22, 16),
	.clocks		= CLOCKS("ref_crystal"),
};

/* AON CCU clocks */

static struct peri_clk_data hub_timer_data = {
	.gate		= HW_SW_GATE(0x0414, 16, 0, 1),
	.clocks		= CLOCKS("bbl_32k",
				 "frac_1m",
				 "dft_19_5m"),
	.sel		= SELECTOR(0x0a10, 0, 2),
	.trig		= TRIGGER(0x0a40, 4),
};