오후 5:43 2008-03-27
조경민 bro@shinbiro.com
motif on posix thread or fork
======================================================================


모티프 API는 해당 스레드 에서만 호출되어야 한다.
만일 Motif 스레드 말고 다른 스레드나 fork된 프로세스에서 Motif 함수를 호출하고
싶다면 pipe나 file, socket file descriptor를 Motif의 XtAppAddInput()로 등록해야 한다.


int fd[2];


pipe(fd);
pid = fork();


if( pid == 0 )
{
  // child process
  write( fd[1], "hello", 5 );
}
else
{
  // parent process
  //Motif초기화
  ..
  XtAppAddInput(app, fd[0], XtInputReadMask, OnGetChar, NULL);
  XtAppMainLoop(app);
  MotifMain();
}


// Motif 스레드 채팅창 구현
void OnPutChar( XtPointer client_data, int* fd, XtInputId* id)
{
    char buf[100]
    n = read(*fd, buf, 100 );
   
    XmTextPosition pos;
    pos = XmTextGetLastPosition( hTextArea );
    XmTextSetInsertionPosition ( hTextArea, pos );
    XmTextReplace( hTextArea, pos, pos, buf );
}


 


DEC xmh/command.c
-----------------------------------------------------------------
pipe를 생성하여 이 파이프에 누군가 쓰면 XtAppAddInput()을 이용해서 읽어볼수 있게
하는 소스 제공
http://cvsweb.xfree86.org/cvsweb/xc/programs/xmh/command.c?rev=3.12


Chapter 9. More Input Techniques
-----------------------------------------------------------------
XtAppAddInput() 설명
http://wwweic.eri.u-


tokyo.ac.jp/computer/manual/lx/SGI_Developer/books/XLib_WinSys/sgi_html/ch09.html#EX-


1013-09-7


Motif FAQ (Part 8 of 9) 277) How can an application be informed of signals?
-----------------------------------------------------------------
XtAppAddInput()은 SVR3기반 유닉스에서는 pipe가 (pipe may not be selected on)없어 write


와 함께 사용할 수 없다.
http://209.85.175.104/search?q=cache:YwQxnDzBlk0J:www.faqs.org/faqs/motif-


faq/part8/section-28.html+XtAppAddInput+not+work&hl=ko&ct=clnk&cd=3&gl=kr



Sample DCE/Motif/Threads program
-----------------------------------------------------------------
RPC로 XtAppAddInput() 받기
http://www.opengroup.org/dce/mall/ruddock.htm


Adding External Input Sources to the X Toolkit Event Loop
-----------------------------------------------------------------
먼저 posix signal sigaction()을 발생하고 이를 핸들링하고 다시 XtNoticeSignal()로
X로 이벤트를 다시 X11R6이후에 생긴 함수 XtAppAddSignal()로 보내고; 받는 방식을 소개;;;
 http://www.rahul.net/kenton/txa/dec95.html


/*
 * Kenton Lee:  X11R6 X Toolkit signal handler demo
 * cc signaldemo.c -lXm -lXt -lX11 -o signaldemo
 */
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <signal.h>


/* Xt signal handler ID */
static XtSignalId signalID;


/* Xt signal callback */
static void signalCB(XtPointer clientData, XtSignalId *id)
{
    if (*id == signalID)
        printf("received signal\n");
}


/* POSIX signal handler */
static void handler(int sig)
{
    if (sig == SIGUSR1)
        XtNoticeSignal(signalID);
}


void main(int argc, char **argv)
{
    struct sigaction act, oact;
    XtAppContext app;
    Widget top;


    /* create user interface */
    top = XtAppInitialize(&app, "Signal", 0, 0, &argc, argv,
        0, 0, 0);
    XtCreateManagedWidget("label", xmLabelWidgetClass, top,
        0, 0);
    XtRealizeWidget(top);


    /* Xt signal callback */
    signalID = XtAppAddSignal(app, signalCB, 0);


    /* POSIX signal handler */
    act.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    sigaction(SIGUSR1, &act, &oact);


    /* Xt event loop */
    XtAppMainLoop(app);
}


 


 

'KB > linux' 카테고리의 다른 글

안드로이드 gcc 설치하기  (7) 2012.08.23
grep, 특정 디렉터리에서  (0) 2008.07.11
posix thread  (0) 2008.03.27
유닉스,리눅스 GUI프로그래밍 개요  (0) 2008.02.21
Linux VFS (Virtual File system)  (0) 2007.08.01

+ Recent posts