Changeset 34 in libcf


Ignore:
Timestamp:
02/05/13 11:26:59 (11 years ago)
Author:
cheese
Message:

#1 add example code for doxygen

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/cf_debug.h

    r30 r34  
    1111 * 환경에 적합하도록 사용자가 구성한 컨텍스트를 이용하여 사용할 수도 있음 <br />
    1212 * (단, 콜스택의 푸시/팝은 컨텍스트를 이용해야만 사용 가능)
     13 *
     14 * @section 샘플코드
     15 * @code
     16
     17#include "cf_debug.h"
     18
     19CF_Debug_Ctx gDebugCtx;
     20
     21void callee (void) {
     22    CF_Debug_CallStack callstack;
     23   
     24    CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
     25    CF_DEBUG_CALLSTACK_POP (gDebugCtx, &callstack);
     26}
     27
     28int main (void) {
     29    int fd = 0;
     30    gDebugCtx = CF_Debug_CreateCtx ();
     31
     32    CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
     33
     34    CF_DEBUG_TRACE (gDebugCtx, "print trace message with context to stderr\n");
     35
     36    fd = CF_File_Create ("debug.txt");
     37    if (fd < 0) {
     38        CF_DEBUG_PRINT (stderr, "error ...\n");
     39        // error
     40    }
     41    CF_Debug_SetOutputFD (gDebugCtx, fd);
     42
     43    CF_DEBUG_TRACE (gDebugCtx, "print trace message with context to debug.txt\n");
     44
     45    CF_DEBUG_CALLSTACK_POP (gDebugCtx, NULL);
     46
     47    CF_Debug_DestroyCtx (gDebugCtx);
     48
     49    return 0;
     50}
     51
     52 * @endcode
    1353 */
    1454#ifndef __CF_DEBUG_H__
     
    1959#include <stdio.h>
    2060
    21 /** 잘못된 컨텍스트 오류 */
    2261#define CF_ERROR_DEBUG_INVALID_CTX          CF_ERROR_DEBUG - 1
    23 
    24 /** 디버그 메시지 출력을 위한 파일 포인터 설정 오류 */
    2562#define CF_ERROR_DEBUG_SET_OUTPUT_FD        CF_ERROR_DEBUG - 2
    26 
    27 /** 콜스택 푸시 오류 */
    2863#define CF_ERROR_DEBUG_PUSH_CALLSTACK       CF_ERROR_DEBUG - 3
    29 
    30 /** 콜스택 팝 오류 */
    3164#define CF_ERROR_DEBUG_POP_CALLSTACK        CF_ERROR_DEBUG - 4
    3265
  • trunk/include/cf_file.h

    r26 r34  
    33 * @author  myusgun <myusgun@gmail.com>
    44 * @version 0.1
     5 *
     6 * @section 샘플코드
     7 * @code
     8
     9#include "cf_file.h"
     10
     11int main (void) {
     12    int fd = 0;
     13    char *name = "file.txt";
     14    char buffer[128] = {0x00,};
     15
     16    fd = CF_File_Create (name);
     17    if (fd < 0) {
     18        // error
     19    }
     20    if (CF_File_Write (fd, "file test", 9) < 0) {
     21        // error
     22    }
     23    CF_File_Close (fd);
     24
     25    fd = CF_File_Open (name, CF_FILE_RO);
     26    if (fd < 0) {
     27        // error
     28    }
     29    printf ("file size : %d\n", CF_File_GetSize (fd));
     30    if (CF_File_Read (fd, buffer, sizeof (buffer)) < 0) {
     31        // error
     32    }
     33    CF_File_Close (fd);
     34
     35    return 0;
     36}
     37
     38 * @endcode
    539 */
    640#ifndef __CF_FILE_H__
  • trunk/include/cf_log.h

    r26 r34  
    33 * @author  myusgun <myusgun@gmail.com>
    44 * @version 0.1
     5 *
     6 * @section 샘플코드
     7 * @code
     8
     9#include "cf_log.h"
     10
     11CF_Log_Ctx gLogCtx;
     12
     13void main (const char * message)
     14{
     15    int         i, j;
     16    char        logname[16] = {0x00,};
     17
     18    CF_DEBUG_CALLSTACK_PUSH (gDebugCtx);
     19
     20    CF_Log_Initialize (10);
     21
     22    // with context
     23    gLogCtx = CF_Log_CreateCtx (file, CF_LOG_BUFFER_DEFAULT);
     24    if (gLogCtx == NULL)
     25        CF_DEBUG_PRINT (stderr, "create log ctx error\n");
     26
     27    for (i = 0 ; i < 10000 ; i++)
     28        CF_Log_Write (gLogCtx, "LOG_TEST", "turn %d\n", i);
     29
     30    CF_DEBUG_CALLSTACK_POP (gDebugCtx, &gDebugCallstack);
     31
     32    CF_Log_Write (gLogCtx, message,
     33                            "here is the end of function [file:%s line:%d func:%s]\n",
     34                            gDebugCallstack.file,
     35                            gDebugCallstack.line,
     36                            gDebugCallstack.function);
     37
     38    CF_Log_DestroyCtx (gLogCtx);
     39
     40    // with id number
     41    for (i = 0 ; i < 10 ; i++)
     42    {
     43        sprintf (logname, "logid%d.txt", i);
     44        CF_LOG_OPEN (i, logname, CF_LOG_BUFFER_NO);
     45    }
     46
     47    for (i = 0 ; i < 10 ; i++)
     48    {
     49        for (j = 0 ; j < 10000 ; j++)
     50            CF_LOG_WRITE (i, "LOG_ID_TEST", "turn %d\n", j);
     51
     52        CF_LOG_CLOSE (i);
     53    }
     54
     55    CF_Log_Finalize ();
     56}
     57
     58 * @endcode
    559 */
    660#ifndef __CF_LOG_H__
  • trunk/include/cf_socket.h

    r26 r34  
    33 * @author  myusgun <myusgun@gmail.com>
    44 * @version 0.1
    5 
     5 *
    66 * @remark TCP 소켓만 지원됨
     7 *
     8 * @section 샘플코드(서버)
     9 * @code
     10
     11#include "cf_socket.h"
     12
     13int main (void) {
     14    int srvsock = 0;
     15    int clntsock = 0;
     16    short port = 12345;
     17    int recvd = 0;
     18    char buf[1024] = {0x00,};
     19
     20    if (CF_Socket_Initialize () < 0) {
     21        // error
     22    }
     23    srvsock = CF_Socket_Server (port, 5);
     24    if (srvsock < 0) {
     25        // error
     26    }
     27    clntsock = CF_Socket_Accept (srvsock, NULL);
     28    if (clntsock < 0) {
     29        // error
     30    }
     31    if ((recvd = CF_Socket_Recv (clntsock, buf, sizeof (buf))) < 0) {
     32        // error
     33    }
     34    if (CF_Socket_Send (clntsock, buf, recvd) < 0) {
     35        // error
     36    }
     37    CF_Socket_Close (srvsock);
     38    CF_Socket_Finalize ();
     39
     40    return 0;
     41}
     42
     43 * @endcode
     44 *
     45 * @section 샘플코드(클라이언트)
     46 * @code
     47
     48#include "cf_socket.h"
     49
     50int main (void) {
     51    int sock = 0;
     52    int recvd = 0;
     53    char buf[1024] = {0x00,};
     54    short port = 12345;
     55
     56    if (CF_Socket_Initialize () < 0) {
     57        // error
     58    }
     59    sock = CF_Socket_Connect ("localhost", port);
     60    if (sock < 0) {
     61        // error
     62    }
     63    if (CF_Socket_Send (sock, buf, sizeof (buf)) < 0) {
     64        // error
     65    }
     66    if ((recvd = CF_Socket_Recv (sock, buf, sizeof (buf))) < 0) {
     67        // error
     68    }
     69    CF_Socket_Close (sock);
     70    CF_Socket_Finalize ();
     71
     72    return 0;
     73}
     74
     75 * @endcode
    776 */
    877#ifndef __CF_SOCKET_H__
  • trunk/include/cf_thread.h

    r33 r34  
    55 *
    66 * @remark 멀티스레드 및 뮤텍스 지원
     7 *
     8 * @section 샘플코드
     9 * @code
     10
     11#include "cf_thread.h"
     12
     13CF_Mutex globalMutex;
     14
     15CF_THREAD_RETURN CF_THREAD_CALL worker (void * arg) {
     16    if (CF_Mutex_Create (&globalMutex) < 0) {
     17        // error
     18    }
     19
     20    if (CF_Mutex_Lock (&globalMutex) < 0) { // for critical section
     21        // error
     22    }
     23
     24    // critical section
     25
     26    if (CF_Mutex_Unlock (&globalMutex) < 0) { // for critical section
     27        // error
     28    }
     29
     30    if (CF_Mutex_Destory (&globalMutex) < 0) {
     31        // error
     32    }
     33}
     34
     35int main (void) {
     36    CF_Thread tid;
     37    if (CF_Thread_Create (&tid, worker, NULL) < 0) {
     38        // error
     39    }
     40
     41    if (CF_Thread_Join (&tid) < 0) { // block
     42        // error
     43    }
     44
     45    if (CF_Thread_Release (&tid) < 0) {
     46        // error
     47    }
     48    return 0;
     49}
     50
     51 * @endcode
    752 */
    853#ifndef __CF_THREAD_H__
     
    4691 * @param callback  스레드 워커 함수 이름
    4792 * @param arg       스레드 함수로 전달할 인자
    48  *
    49  * @code
    50 
    51 #include "cf_thread.h"
    52 
    53 CF_Mutex globalMutex;
    54 
    55 CF_THREAD_RETURN CF_THREAD_CALL worker (void * arg) {
    56     if (CF_Mutex_Create (&globalMutex) < 0) {
    57         // error
    58     }
    59 
    60     if (CF_Mutex_Lock (&globalMutex) < 0) { // for critical section
    61         // error
    62     }
    63 
    64     // critical section
    65 
    66     if (CF_Mutex_Unlock (&globalMutex) < 0) { // for critical section
    67         // error
    68     }
    69 
    70     if (CF_Mutex_Destory (&globalMutex) < 0) {
    71         // error
    72     }
    73 }
    74 
    75 int main (void) {
    76     CF_Thread tid;
    77     if (CF_Thread_Create (&tid, worker, NULL) < 0) {
    78         // error
    79     }
    80 
    81     if (CF_Thread_Join (&tid) < 0) { // block
    82         // error
    83     }
    84 
    85     if (CF_Thread_Release (&tid) < 0) {
    86         // error
    87     }
    88 }
    89 
    90  * @endcode
    9193 */
    9294CF_EXPORT int
  • trunk/src/cf_debug.c

    r28 r34  
    169169        }
    170170
    171         fp = fdopen (dupfd, "a+");
     171        fp = fdopen (dupfd, "a");
    172172        if (fp == NULL)
    173173        {
  • trunk/src/cf_log.c

    r30 r34  
    3737#define CF_LOG_BUFFER_DEFAULT_SIZE      128 * 1024
    3838
     39#define CF_LOG_DATETIME_LENGTH          sizeof ("0000-00-00 00:00:00.000") - 1
     40
    3941typedef struct __cf_util_datetime__
    4042{
     
    150152    CF_Log_Local_GetTime (&dt);
    151153
    152    
    153 
    154     snprintf (buffer, strlen ("0000-00-00 00:00:00.000"),
     154    snprintf (buffer, CF_LOG_DATETIME_LENGTH,
    155155              "%02d-%02d-%02d %02d:%02d:%02d.%03d",
    156156              dt.year, dt.month, dt.day,
     
    336336    va_list     valist;
    337337    char        buffer[4096] = {0x00,};
     338    char        datetime[CF_LOG_DATETIME_LENGTH + 1] = {0x00,};
    338339    size_t      length = 0;
    339340
     
    344345    va_start (valist, fmt);
    345346
    346     strncat (buffer, "[", 1);
    347     CF_Log_Local_GetTimeString (buffer + strlen (buffer));
    348     sprintf (buffer + strlen (buffer), "][%s] ", prefix);
     347    CF_Log_Local_GetTimeString (datetime);
     348    sprintf (buffer, "[%s][%s] ", datetime, prefix);
    349349    vsprintf (buffer + strlen (buffer), fmt, valist);
    350350
Note: See TracChangeset for help on using the changeset viewer.