소스 수정없이 다양한 플랫폼에서 동작하는 프로그램 제작
글쓴이: jundotcom / 작성시간: 수, 2003/11/19 - 10:03오전
검색해보니 이 팁은 안보이는 관계로 하나 올립니다.
저는 지금 파일 백업 솔루션을 개발하고 있습니다.
이 프로젝트의 특징은 ACE라는 common library를 사용하여 windows,linux,solaris,aix,bsd등 다양한 플랫폼에서 소스 수정없이 실행가능한 프로그램을 구현하는 것인데요, 하나의 소스로 여러 플랫폼에서 돌아갈 프로그램을 개발하는데 상당히 유용한것 같습니다.
원리는 함수 (거의 Unix 기준) 하나 하나에 대해 wrapping 형태로 library상으로 구현이 되어 있습니다.
라이브러리 하나를 살펴보면 이런식입니다.
pid_t ACE_OS::fork_exec (ACE_TCHAR *argv[]) { # if defined (ACE_WIN32) ACE_TCHAR *buf; if (ACE_OS::argv_to_string (argv, buf) != -1) { PROCESS_INFORMATION process_info; # if !defined (ACE_HAS_WINCE) ACE_TEXT_STARTUPINFO startup_info; ACE_OS::memset ((void *) &startup_info, 0, sizeof startup_info); startup_info.cb = sizeof startup_info; if (ACE_TEXT_CreateProcess (0, buf, 0, // No process attributes. 0, // No thread attributes. TRUE, // Allow handle inheritance. 0, // Don't create a new console window. 0, // No environment. 0, // No current directory. &startup_info, &process_info)) # else if (ACE_TEXT_CreateProcess (0, buf, 0, // No process attributes. 0, // No thread attributes. FALSE, // Can's inherit handles on CE 0, // Don't create a new console window. 0, // No environment. 0, // No current directory. 0, // Can't use startup info on CE &process_info)) # endif /* ! ACE_HAS_WINCE */ { // Free resources allocated in kernel. ACE_OS::close (process_info.hThread); ACE_OS::close (process_info.hProcess); // Return new process id. delete [] buf; return process_info.dwProcessId; } } // CreateProcess failed. return -1; # elif defined (CHORUS) return ACE_OS::execv (argv[0], argv); # else pid_t result = ACE_OS::fork (); switch (result) { case -1: // Error. return -1; case 0: // Child process. if (ACE_OS::execv (argv[0], argv) == -1) { // The OS layer should not print stuff out // ACE_ERROR ((LM_ERROR, // "%p Exec failed\n")); // If the execv fails, this child needs to exit. ACE_OS::exit (errno); } default: // Server process. The fork succeeded. return result; } # endif /* ACE_WIN32 */ }
Linux에 익숙한 프로그래머도 쉽게 윈도우 프로그램을 할수 있다는 장점이 있습니다.
간단하게 ACE_OS::memcpy 이런 식입니다.
물론 Visual Studio를 사용할줄 알아야겠지요.
사이트는 http://www.cs.wustl.edu/~schmidt/ACE.html 입니다.
그럼..^^;
Forums:
댓글 달기