コード例 #1
0
IMnetRetCode AIMAuthModule_onRspCheckCode(IMnetHandle hIMnetHandle, EventContent* pEventContent)
{
	IAIM *pIM = (IAIM *)IMnetGetReference(hIMnetHandle);
	AIMAuthModule *pAuthModule = AMNULL;
	ImRspCheckAuthCode *pCheckAuth = (ImRspCheckAuthCode *)pEventContent;
	AIMAuth *pAuthFind = AMNULL;
	AMChar *szImgData = AMNULL, *szSession = 0;
	AMInt32 iImgLen = 0, iRetCode = eAIM_RESULT_OK;
	AIM_RSP_CHECK_CODE rspCheckCode;

	AMAssert(pIM);
	pAuthModule = (AIMAuthModule *)pIM->hAuthModule;

	DPRINT("%s >>>>>> session: %s, retCode %d\n", __FUNCTION__, pCheckAuth->szSession, pCheckAuth->retCode);

	AMThreadMutexLock(&pAuthModule->mtxAuth);

	pAuthFind = _AIMAuthModule_findSession(pAuthModule, pCheckAuth->szSession);
	if(pAuthFind)
	{
		rspCheckCode.iAuthId = pAuthFind->iAuth;
		rspCheckCode.iRetCode = pCheckAuth->retCode;

		_AIMAuth_notify(pIM, OnRspCheckCode, &rspCheckCode);

		if(!pCheckAuth->retCode)
		{
			IMnetSendRawPacket(hIMnetHandle, pAuthFind->szRawPacket, pAuthFind->uiPacketLen);
			set_compare(List, &pAuthModule->lstAuth, _AIMAuth_cmpPtr);
			delete_List(&pAuthModule->lstAuth, pAuthFind, sizeof(AIMAuth));
		}
		else
		{
			AIM_NTF_NEED_AUTH ntfNeedAuth;

			ntfNeedAuth.iAuthId = pAuthFind->iAuth;

			ntfNeedAuth.iRetCode  = _AIMAuth_getAuthImg(&szSession, &ntfNeedAuth.pvData, &ntfNeedAuth.iDataLen);
			_AIMAuth_setSession(pAuthFind, szSession);
			
			_AIMAuth_notify(pIM, OnNtfNeedAuth, &ntfNeedAuth);
		}
	}
	else
	{
		iRetCode = eAIM_RESULT_NOT_READY;
	}

	AMThreadMutexUnlock(&pAuthModule->mtxAuth);

	return eIMnetSkip;
}
コード例 #2
0
ファイル: us_ticker.c プロジェクト: Babody/mbed
// Used by interrupt system
static void tim_oc_irq_handler(void) {
    uint16_t cval = TIM_MST->CNT;
    TimMasterHandle.Instance = TIM_MST;

    // Clear CC1 interrupt flag
    if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
        __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
    }
    if (oc_rem_part > 0) {
        set_compare(oc_rem_part); // Finish the remaining time left
        oc_rem_part = 0;
    } else {
        if (oc_int_part > 0) {
            set_compare(0xFFFF);
            oc_rem_part = cval; // To finish the counter loop the next time
            oc_int_part--;
        } else {
            us_ticker_irq_handler();
        }
    }

}
コード例 #3
0
// Used for mbed timeout (channel 1) and HAL tick (channel 2)
void timer_oc_irq_handler(void)
{
    uint16_t cval = TIM_MST->CNT;
    TimMasterHandle.Instance = TIM_MST;

    // Channel 1 for mbed timeout
    if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
        __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
        if (oc_rem_part > 0) {
            set_compare(oc_rem_part); // Finish the remaining time left
            oc_rem_part = 0;
        } else {
            if (oc_int_part > 0) {
                set_compare(0xFFFF);
                oc_rem_part = cval; // To finish the counter loop the next time
                oc_int_part--;
            } else {
                us_ticker_irq_handler();
            }
        }
    }

    // Channel 2 for HAL tick
    if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) {
        __HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC2);
        uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle);
        if ((val - PreviousVal) >= HAL_TICK_DELAY) {
            // Increment HAL variable
            HAL_IncTick();
            // Prepare next interrupt
            __HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY);
            PreviousVal = val;
#if 0 // For DEBUG only
            HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6);
#endif
        }
    }
}
コード例 #4
0
ファイル: us_ticker.c プロジェクト: 23chrischen/mbed
// Used by interrupt system
static void tim_oc_irq_handler(void) {
    uint16_t cval = TIM_MST->CNT;
  
    // Clear interrupt flag
    if (TIM_GetITStatus(TIM_MST, TIM_IT_CC1) == SET) {
        TIM_ClearITPendingBit(TIM_MST, TIM_IT_CC1);
    }

    if (oc_rem_part > 0) {
        set_compare(oc_rem_part); // Finish the remaining time left
        oc_rem_part = 0;
    }
    else {
        if (oc_int_part > 0) {
            set_compare(0xFFFF);
            oc_rem_part = cval; // To finish the counter loop the next time
            oc_int_part--;
        }
        else {
            us_ticker_irq_handler();
        }
    }
}
コード例 #5
0
AMInt32	AIMAuthModule_updateCode(AMHandle hAuthModule, AMInt32 iAuthId)
{
	AIMAuthModule *pAuthModule = (AIMAuthModule *)hAuthModule;
	AIMAuth tmpAuth, *pAuthFind = AMNULL;
	AMInt32 iRetCode = eAIM_RESULT_OK, iImgLen = 0;
	AMChar *szSessin = AMNULL, *szImgData = AMNULL;
	AIM_NTF_NEED_AUTH ntfNeedAuth;

	AMAssert(pAuthModule && iAuthId);

	iRetCode = _AIMAuth_getAuthImg(&szSessin, &szImgData, &iImgLen);

	DPRINT("%s >>>>>> session: %s, imgLen: %d\n", __FUNCTION__, szSessin, iImgLen);

	if(eAIM_RESULT_OK == iRetCode)
	{
		tmpAuth.iAuth = iAuthId;

		AMThreadMutexLock(&pAuthModule->mtxAuth);

		set_compare(List, &pAuthModule->lstAuth, _AIMAuth_cmpId);

		pAuthFind = _AIMAuthModule_findId(pAuthModule, iAuthId);

		if(pAuthFind)
			_AIMAuth_setSession(pAuthFind, szSessin);
		else
			iRetCode = eAIM_RESULT_NOT_READY;

		AMThreadMutexUnlock(&pAuthModule->mtxAuth);
	}

	AMMemset(&ntfNeedAuth, 0, sizeof(ntfNeedAuth));
	ntfNeedAuth.iAuthId = iAuthId;
	ntfNeedAuth.iRetCode = iRetCode;
	if(eAIM_RESULT_OK == iRetCode)
	{
		ntfNeedAuth.pvData = szImgData;
		ntfNeedAuth.iDataLen = iImgLen;
	}

	if(eAIM_RESULT_NOT_READY != iRetCode)
		_AIMAuth_notify(pAuthModule->pIM, OnNtfNeedAuth, &ntfNeedAuth);

	if(ntfNeedAuth.pvData)
		AMFree(ntfNeedAuth.pvData);

	return eAIM_RESULT_OK;
}
コード例 #6
0
AMInt32	AIMAuthModule_cancelAuth(AMHandle hAuthModule, AMInt32 iAuthId)
{
	AIMAuthModule *pAuthModule = (AIMAuthModule *)hAuthModule;
	AIMAuth tmpAuth;
	AMInt32 iRetCode = eAIM_RESULT_OK;
	
	tmpAuth.iAuth = iAuthId;

	AMAssert(pAuthModule && iAuthId);

	AMThreadMutexLock(&pAuthModule->mtxAuth);

	set_compare(List, &pAuthModule->lstAuth, _AIMAuth_cmpId);
	delete_List(&pAuthModule->lstAuth, &tmpAuth, sizeof(AIMAuth));

	AMThreadMutexUnlock(&pAuthModule->mtxAuth);

	return iRetCode;
}
コード例 #7
0
IAccountModel*	IAccountModel_Create()
{
	if(0 == pSingleAcntModel)
	{
		DPRINT("IAccountModel_Create.................AcntModle Creating\n");

		pSingleAcntModel = (IAccountModel *)AMMalloc(sizeof(IAccountModel));
		AMAssert(0 != pSingleAcntModel);
		AMMemset(pSingleAcntModel, 0, sizeof(IAccountModel));

 		construct(List, &(pSingleAcntModel->listAcnt), sizeof(AIMAccount), FREEOBJ);
 		set_compare(List, &(pSingleAcntModel->listAcnt), IAccount_cmpID);
 		set_dealloc(List, &(pSingleAcntModel->listAcnt), IAccount_Destroy);

		IAccountModel_Restore(pSingleAcntModel);

		DPRINT("IAccountModel_Create.................AcntModle Created\n");
	}
	pSingleAcntModel->iRefCount++;

	DPRINT("IAccountModel_Create.................Add Reference %d\n", pSingleAcntModel->iRefCount);
	return pSingleAcntModel;
}
コード例 #8
0
ファイル: vector_test.c プロジェクト: Nejij/c-generic-library
int
main(void) {
  Vector  object;
  Vector *v_copy = NULL;
  VectorIter *ptr;
  unsigned int x, y;
  unsigned int value;
  memset(&object, 0, sizeof (object));
  x = RUNS;
  construct(Vector, &object,sizeof(x),FREEOBJ);
  set_alloc(Vector,  &object, ckalloc);
  set_dealloc(Vector,  &object, ckfree);
  set_compare(Vector,  &object, intcmp);
  set_print(Vector,  &object, print);
  for (y = 0; y < x; y++) {
    srand((x * y) / (x - y) + (x + y / x));
    switch ((rand() % NUMCASES) + BASE) {
        case 0:
        case 10:
        case 11:
        case 1:
        case 12:
        case 13:
        case 2:
        case 14:
        case 3:
        case 15:
        case 4:
          value = rand() % BOUND;
          push_front(Vector,  &object, &value, DYNAMIC);
          break;
          /*pop_front(Vector,  &object);
          break;*/
        case 5:
        case 6:
        case 16:
          /*pop_back(Vector,  &object);
          break;*/
        case 7:
        case 17:
          back(Vector,  &object);
        case 8:
        case 9:
          front(Vector,  &object);
          value = rand() % BOUND;
          push_back(Vector,  &object, &value, DYNAMIC);
          break;
        default:
          break;
    };
  }
  destruct(Vector,  &object);
  fprintf(stderr, "Now testing the iterators!\n");
  construct_func(Vector,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp,  print,
                 memcpy);
  for (x = 0; x < RUNS; x++) {
	  value = rand() % RUNS;
    push_back(Vector,  &object, &value, STATIC);
  }

  ptr = create(VectorIter,  &object);
  head(VectorIter, ptr);
  /*printf("Head = %d\n",*(unsigned int *)retrieve(VectorIter,ptr));*/
  tail(VectorIter,ptr);
  /*printf("Tail = %d\n",*(unsigned int *)retrieve(VectorIter,ptr));*/
  head(VectorIter,ptr);
  do {
    value = *(unsigned int *) retrieve(VectorIter, ptr);
	/*printf("%d ",value);*/
  }
  while (!next(VectorIter, ptr));
  assign(VectorIter, ptr, &object);
  tail(VectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(VectorIter, ptr);
  } while (!prev(VectorIter, ptr));
  /*printf("\n");*/
  for(x = 0; x < RUNS; x++) {
	  switch(rand() % 2) {
		  case 1:
			  next(VectorIter,ptr);
			  break;
		  case 2:
			  prev(VectorIter,ptr);
			  break;
	  }
  }
  destroy(VectorIter, ptr);
  v_copy = duplicate(Vector,&object);
  ptr = create(VectorIter,v_copy);
  do{
	  value = *(unsigned int *)retrieve(VectorIter,ptr);
	  /*printf("%d ",value);*/
  }while(!next(VectorIter,ptr));
  /*printf("\n");*/
  destroy(VectorIter,ptr);
  destruct(Vector,v_copy);
  destruct(Vector,&object);
  free(v_copy);
  return EXIT_SUCCESS;
}
コード例 #9
0
int
main(void) {
  QueueVector  object;
  QueueVectorIter *ptr;
  unsigned int x, y;
  unsigned int value;
  memset(&object, 0, sizeof (object));
  x = RUNS;
  construct(QueueVector, &object,sizeof(x),FREEOBJ);
  set_alloc(QueueVector,  &object, ckalloc);
  set_dealloc(QueueVector,  &object, ckfree);
  set_compare(QueueVector,  &object, intcmp);
  set_print(QueueVector,  &object, print);
  for (y = 0; y < x; y++) {
    srand((x * y) / (x - y) + (x + y / x));
    switch ((rand() % NUMCASES) + BASE) {
        case 0:
        case 10:
        case 11:
        case 1:
        case 12:
        case 13:
        case 2:
        case 14:
          value = rand() % BOUND;
          push(QueueVector,  &object, &value, DYNAMIC);
          break;
        case 3:
        case 15:
        case 4:
        case 5:
        case 6:
        case 16:
          pop(QueueVector,  &object);
          break;
        case 7:
        case 17:
        case 8:
        case 9:
          front(QueueVector,  &object);
          break;
        default:
          break;
    };
  }
  destruct(QueueVector,  &object);
  fprintf(stderr, "Now testing the iterators!\n");
  construct_func(QueueVector,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp, print,
                 memcpy);
  for (x = 0; x < RUNS; x++) {
	  value = rand();
    push(QueueVector,  &object, &value, STATIC);
  }

  ptr = create(QueueVectorIter,  &object);
  head(QueueVectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(QueueVectorIter, ptr);
  }
  while (!next(QueueVectorIter, ptr));
  assign(QueueVectorIter, ptr, &object);
  tail(QueueVectorIter, ptr);
  do {
    value = *(unsigned int *) retrieve(QueueVectorIter, ptr);
  } while (!prev(QueueVectorIter, ptr));
  for(x = 0; x < RUNS; x++) {
	  switch(rand() % 2) {
		  case 1:
			  next(QueueVectorIter,ptr);
			  break;
		  case 2:
			  prev(QueueVectorIter,ptr);
			  break;
	  }
  }
  destroy(QueueVectorIter, ptr);
  destruct(QueueVector,  &object);
  return EXIT_SUCCESS;
}
コード例 #10
0
int
main(void) {
  BinaryTree  object,*dupe;
  BinaryTreeIter *ptr;
  BinaryTreeDFSIter *dfsptr;
  BinaryTreeBFSIter *bfsptr;
  unsigned int x, y;
  unsigned int value;
  memset(&object, 0, sizeof (object));
  x = RUNS;

  construct(BinaryTree, &object,sizeof(x),FREEOBJ);
  
set_alloc(BinaryTree,  &object, ckalloc);
  set_dealloc(BinaryTree,  &object, ckfree);
  set_compare(BinaryTree,  &object, intcmp);
  set_print(BinaryTree,  &object, print);

	
  for (y = 0; y < x; y++) {
	  if (!(y % (RUNS/10))) fprintf(stderr, ".");
    srand((x * y) / (x - y) + (x + y / x));
    switch ((rand() % NUMCASES) + BASE) {
        case 0:
        case 10:
        case 12:
        case 13:
        case 2:
        case 17:
        case 8:
          value = rand() % BOUND;
          insert(BinaryTree,  &object, &value, STATIC);
          break;
        case 9:
        case 3:
        case 15:
        case 4:
        case 5:
        case 14:
        case 7:
	  value = rand() % BOUND;
          delete(BinaryTree,  &object,&value);
          break;
        case 11:
        case 1:
        case 6:
        case 16:
	  /*value = rand() % BOUND;
	  find(BinaryTree,&object,&value);
          break;*/
        default:
          value = rand() % BOUND;
          insert(BinaryTree,  &object, &value,STATIC);
          break;
    };
    /*dump(BinaryTree,&object);*/
  }
  printf("\n");
  destruct(BinaryTree,  &object);
  fprintf(stderr, "Now testing the iterators!\n");
  construct_func(BinaryTree,&object,sizeof(x),FREEOBJ, ckalloc, ckfree, intcmp,  print,
                 memcpy);
  for (x = 0; x < 15; x++) {
	  if (!(x % (RUNS/10))) fprintf(stderr, ".");
	  value = rand() % 30;
    convert(BinaryTree,  &object, &value, sizeof(value),STATIC);
  }

  ptr = create(BinaryTreeIter,  &object);
  head(BinaryTreeIter, ptr);
  do {
    value = *(unsigned int*)retrieve(BinaryTreeIter, ptr);
/*	printf("%d ",value);*/
  }
  while (!next(BinaryTreeIter, ptr));
  /*printf("\n");*/
  assign(BinaryTreeIter, ptr, &object);
  tail(BinaryTreeIter, ptr);
  do {
    value = *(unsigned int*) retrieve(BinaryTreeIter, ptr);
  } while (!prev(BinaryTreeIter, ptr));
  for(x = 0; x < RUNS; x++) {
	  if (!(x % (RUNS/10))) fprintf(stderr, ".");
	  switch(rand() % 2) {
		  case 1:
			  prev(BinaryTreeIter,ptr);
			  break;
		  case 0:
			  next(BinaryTreeIter,ptr);
			  break;
		  default:
			  break;
	  }
  }
  printf("\n");
  destroy(BinaryTreeIter, ptr);
  dupe = duplicate(BinaryTree,&object);
  ptr = create(BinaryTreeIter,  dupe);
  head(BinaryTreeIter, ptr);
  do {
    value = *(unsigned int*)retrieve(BinaryTreeIter, ptr);
	/*printf("%d ",value);*/
  }
  while (!next(BinaryTreeIter, ptr));
  /*printf("\n");*/
  assign(BinaryTreeIter, ptr, dupe);
  tail(BinaryTreeIter, ptr);
  do {
    value = *(unsigned int*) retrieve(BinaryTreeIter, ptr);
  } while (!prev(BinaryTreeIter, ptr));
  for(x = 0; x < RUNS; x++) {
	  if (!(x % (RUNS/10))) fprintf(stderr, ".");
	  switch(rand() % 2) {
		  case 1:
			  prev(BinaryTreeIter,ptr);
			  break;
		  case 0:
			  next(BinaryTreeIter,ptr);
			  break;
		  default:
			  break;
	  }
  }
  printf("\n");
  destroy(BinaryTreeIter, ptr);

  bfsptr = create(BinaryTreeBFSIter,&object);
  do {
	  value = *(unsigned int *)retrieve(BinaryTreeBFSIter, bfsptr);
	  /*fprintf(stderr,"%d ",value);*/
  }while(!next(BinaryTreeBFSIter,bfsptr));
  /*printf("\n");*/
  dfsptr = create(BinaryTreeDFSIter,&object);
  do {
	  value = *(unsigned int *)retrieve(BinaryTreeDFSIter, dfsptr);
	  /*fprintf(stderr,"%d ",value);*/
  }while(!next(BinaryTreeDFSIter,dfsptr));
  /*printf("\n");*/
  destroy(BinaryTreeDFSIter,dfsptr);
  destroy(BinaryTreeBFSIter,bfsptr);
  destruct(BinaryTree,  &object);
  destruct(BinaryTree,dupe);
  free(dupe);
  printf("\n");
  return EXIT_SUCCESS;
}
コード例 #11
0
//main function
int main() {
	//print out some application instructions
	printf("Enter some numbers that are bigger than 0 and smaller than %u\n", UINT_MAX);
	printf("If you enter the number 0 the applications will print out all given numbers as a sorted list\n\n---- Input --------------\n\n");
	
	
	//declare a c-generic datatype
	List container;
	
	//initialize the list
	memset(&container, 0, sizeof(List));
	construct(List, &container, sizeof(unsigned int), FREEOBJ);
	
	
	
	while(1) {
		//read out an element
		unsigned int* t=malloc(sizeof(unsigned int));
		scanf("%u", t);
		
		//add it to the list
		push_back(List, &container, t, DYNAMIC);
		
		//break if zero is the input
		if(*t==0)
			break;
	}
	
	
	printf("\n\n---- Unsorted --------------\n\n");
	
	//set print functions
	set_print(List, &container, print);
	
	//print all element in our list
	print_all(List, &container);
	
	
	//lets have fun with iterators (instead using print_all)
	printf("\n\n---- Iterators --------------\n\n");
	
	ListIter* i = create(ListIter, &container);
	//check if it is empty - this will never happen
	if(!empty(List, &container)) {
		//place the iterator at the first element
		head(ListIter, i);
		
		do {
			printf("%u\n", *((unsigned int*)retrieve(ListIter, i)));
			
		}while(!next(ListIter, i));
	}
	
	//give the memory free
	destroy(ListIter, i);
	
	
	printf("\n\n---- Sorted ASC --------------\n\n");
	
	//set the sort functions
	set_compare(List, &container, intcmp);
	
	//use the in-place sort
	sort(List, &container);
	
	
	print_all(List, &container);
	
	
	//give the memory free
	destruct(List, &container);
	
	printf("\n\n");
	return 0;
}