[109] | 1 | /**
|
---|
| 2 | * @file cf_queue.c
|
---|
| 3 | * @author myusgun <myusgun@gmail.com>
|
---|
| 4 | */
|
---|
| 5 | #include "cf_queue.h"
|
---|
| 6 | #include "cf_list.h"
|
---|
| 7 | #include "cf_error.h"
|
---|
| 8 |
|
---|
| 9 | #include <stdio.h>
|
---|
| 10 |
|
---|
[111] | 11 | /**
|
---|
| 12 | * 큐 컨텍스트 생성
|
---|
| 13 | *
|
---|
| 14 | * @return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
| 15 | *
|
---|
| 16 | * @param ctx 큐 컨텍스트 포인터
|
---|
| 17 | */
|
---|
[109] | 18 | int
|
---|
| 19 | CF_Queue_CreateCtx (CF_Queue_Ctx * ctx)
|
---|
| 20 | {
|
---|
| 21 | return CF_List_CreateCtx ((CF_List_Ctx *) ctx);
|
---|
| 22 | }
|
---|
| 23 |
|
---|
[111] | 24 | /**
|
---|
| 25 | * 큐 컨텍스트 해제
|
---|
| 26 | *
|
---|
| 27 | * @return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
| 28 | *
|
---|
| 29 | * @param ctx 큐 컨텍스트
|
---|
| 30 | */
|
---|
[109] | 31 | int
|
---|
| 32 | CF_Queue_DestroyCtx (CF_Queue_Ctx ctx)
|
---|
| 33 | {
|
---|
| 34 | return CF_List_DestroyCtx (ctx);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[111] | 37 | /**
|
---|
| 38 | * 큐에 삽입
|
---|
| 39 | *
|
---|
| 40 | * @return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
| 41 | *
|
---|
| 42 | * @param ctx 큐 컨텍스트
|
---|
| 43 | * @param element 데이터 주소
|
---|
| 44 | */
|
---|
[109] | 45 | int
|
---|
| 46 | CF_Queue_Put (CF_Queue_Ctx ctx,
|
---|
| 47 | const void * element)
|
---|
| 48 | {
|
---|
| 49 | int result = 0;
|
---|
| 50 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 51 | CF_Traverser traverser = NULL;
|
---|
| 52 |
|
---|
| 53 | result = CF_List_Rear (list, &traverser);
|
---|
| 54 | if (result < 0)
|
---|
| 55 | return result;
|
---|
| 56 |
|
---|
| 57 | return CF_List_Insert (list, traverser, CF_DIRECTION_AFTER, element);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[111] | 60 | /**
|
---|
| 61 | * 큐에서 꺼내기
|
---|
| 62 | *
|
---|
| 63 | * @return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
| 64 | *
|
---|
| 65 | * @param ctx 큐 컨텍스트
|
---|
| 66 | * @param element 데이터 주소
|
---|
| 67 | */
|
---|
[109] | 68 | int
|
---|
| 69 | CF_Queue_Get (CF_Queue_Ctx ctx,
|
---|
| 70 | void ** element)
|
---|
| 71 | {
|
---|
| 72 | int result = 0;
|
---|
| 73 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 74 | CF_Traverser traverser = NULL;
|
---|
| 75 |
|
---|
| 76 | result = CF_Queue_Front (ctx, element);
|
---|
| 77 | if (result < 0)
|
---|
| 78 | return result;
|
---|
| 79 |
|
---|
| 80 | result = CF_List_Front (list, &traverser);
|
---|
| 81 | if (result < 0)
|
---|
| 82 | return result;
|
---|
| 83 |
|
---|
| 84 | return CF_List_Remove (ctx, &traverser);
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[111] | 87 | /**
|
---|
| 88 | * 큐 처음의 데이터 조회
|
---|
| 89 | *
|
---|
| 90 | * @return 성공 시, CF_OK; 실패 시, 오류 코드
|
---|
| 91 | *
|
---|
| 92 | * @param ctx 큐 컨텍스트
|
---|
| 93 | * @param element 데이터 주소
|
---|
| 94 | */
|
---|
[109] | 95 | int
|
---|
| 96 | CF_Queue_Front (CF_Queue_Ctx ctx,
|
---|
| 97 | void ** element)
|
---|
| 98 | {
|
---|
| 99 | int result = 0;
|
---|
| 100 | CF_List_Ctx list = (CF_List_Ctx) ctx;
|
---|
| 101 | CF_Traverser traverser = NULL;
|
---|
| 102 |
|
---|
| 103 | result = CF_List_Front (list, &traverser);
|
---|
| 104 | if (result < 0)
|
---|
| 105 | return result;
|
---|
| 106 |
|
---|
| 107 | return CF_List_GetElement (traverser, element);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[111] | 110 | /**
|
---|
| 111 | * 큐에 등록된 항목의 수를 가져옴
|
---|
| 112 | *
|
---|
| 113 | * @return 성공 시, 항목 수; 실패 시, 오류 코드
|
---|
| 114 | *
|
---|
| 115 | * @param ctx 큐 컨텍스트
|
---|
| 116 | */
|
---|
[109] | 117 | int
|
---|
| 118 | CF_Queue_GetSize (CF_Queue_Ctx ctx)
|
---|
| 119 | {
|
---|
| 120 | return CF_List_GetSize ((CF_List_Ctx) ctx);
|
---|
| 121 | }
|
---|