ACE_TAO 004
Posted islinyoubiao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ACE_TAO 004相关的知识,希望对你有一定的参考价值。
网络上的确也有一些好方法,但是最重要还是一步一步来。
ACE要用,一一定要初始化ACE,这步非常重要。
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
return run_main (argc, argv);
}
这其实是最基础的,好多库都是要这样的,就像用到的硬件一样,要初始化。
pro文件如下:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
#CONFIG -= UNICODE
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += c:/ace/include
LIBS += -lws2_32 -lmswsock -liphlpapi -lwsock32 -lnetapi32
LIBS += C:/ace/lib/libACE.dll.a \\
C:/ace/lib/libACE_Qt5Reactor.dll.a
#SOURCES += \\
# main.cpp \\
# mainwindow.cpp \\
# qtestapplication.cpp
#HEADERS += \\
# mainwindow.h \\
# qtestapplication.h
#FORMS += \\
# mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
HEADERS += \\
QtReactor_Test.h \\
Test_Output_Export.h \\
test_config.h
SOURCES += \\
Main.cpp \\
QtReactor_Test.cpp \\
Test_Output.cpp
QtReactor_Test.h如下:
/* -*- C++ -*- */
#ifndef QTREACTOR_TEST_H
#define QTREACTOR_TEST_H
#define ACE_HAS_QT5 1
#ifdef ACE_HAS_QT5
#include /**/ <QtWidgets/QApplication>
#else
#include /**/ <QtGui/QApplication>
#endif
#include <QtCore/qtimer.h>
class QTestApplication: public QApplication
{
Q_OBJECT
public:
typedef QApplication inherited;
public:
QTestApplication( int argc, char *argv[] );
virtual void exec( int msec = 0 );
public slots:
virtual void finishTest(); //!< slot to finish the test, connected to finishTimer_
private:
QTimer finishTimer_; //!< timer to finish the test
};
#endif /*QTREACTOR_TEST_H*/
test_config.h
// -*- C++ -*-
// ============================================================================
/**
* @file test_config.h
*
* This file factors out common macros and other utilities used by the
* ACE automated regression tests. It also shows how to redirect ACE_DEBUG/ACE_ERROR
* output to a file.
*
* @author Prashant Jain <pjain@cs.wustl.edu>
* @author Tim Harrison <harrison@cs.wustl.edu>
* @author David Levine <levine@cs.wustl.edu>
*/
// ============================================================================
#ifndef ACE_TEST_CONFIG_H
#define ACE_TEST_CONFIG_H
// This first #undef protects against command-line definitions.
#undef ACE_NDEBUG
#include "ace/config-all.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#if defined (ACE_NLOGGING)
// ACE_NLOGGING must not be set if the tests are to produce any output.
#undef ACE_NLOGGING
#endif /* ACE_NLOGGING */
#include "ace/OS_NS_errno.h"
#include "ace/OS_NS_stdio.h"
#include "ace/Log_Msg.h"
#if defined (ACE_HAS_WINCE)
// Note that Pocket PC 2002 will NOT create a directory if it does not start with a leading '\\'.
// PPC 2002 only accepts '\\log' as a valid directory name, while 'log\\' works under WinCE 3.0.
# define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("\\\\log")
# define ACE_LOG_DIRECTORY ACE_TEXT ("\\\\log\\\\")
# define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\\\\\.\\\\pipe\\\\"#X)
#elif defined (ACE_WIN32)
# define ACE_LOG_DIRECTORY ACE_TEXT ("log\\\\")
# define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("log\\\\")
# define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\\\\\.\\\\pipe\\\\"#X)
#elif defined (ANDROID)
# define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("/sdcard/log/")
# define ACE_LOG_DIRECTORY ACE_TEXT ("/sdcard/log/")
# define MAKE_PIPE_NAME(X) ACE_TEXT (X)
#else
# define ACE_LOG_DIRECTORY_FOR_MKDIR ACE_TEXT ("log/")
# define ACE_LOG_DIRECTORY ACE_TEXT ("log/")
# define MAKE_PIPE_NAME(X) ACE_TEXT (X)
#endif /* ACE_WIN32 */
#if !defined (ACE_DEFAULT_TEST_DIR)
# define ACE_DEFAULT_TEST_DIR ACE_TEXT ("")
#endif
#if !defined (ACE_LOG_FILE_EXT_NAME)
# define ACE_LOG_FILE_EXT_NAME ACE_TEXT (".log")
#endif /* ACE_LOG_FILE_EXT_NAME */
#if defined (ACE_HAS_WINCE) || defined (ACE_HAS_PHARLAP)
size_t const ACE_MAX_CLIENTS = 4;
#else
size_t const ACE_MAX_CLIENTS = 30;
#endif /* ACE_HAS_WINCE */
size_t const ACE_NS_MAX_ENTRIES = 1000;
size_t const ACE_DEFAULT_USECS = 1000;
size_t const ACE_MAX_TIMERS = 4;
size_t const ACE_MAX_DELAY = 10;
size_t const ACE_MAX_INTERVAL = 0;
size_t const ACE_MAX_ITERATIONS = 10;
size_t const ACE_MAX_PROCESSES = 10;
size_t const ACE_MAX_THREADS = 4;
#if defined ACE_HAS_CONSOLE_TEST_OUTPUT
#ifndef ACE_START_TEST
# define ACE_START_TEST(NAME) const ACE_TCHAR *program = NAME; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\\n"), NAME))
#endif /* ACE_START_TEST */
#ifndef ACE_END_TEST
# define ACE_END_TEST ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test %D\\n"), program));
#endif /* ACE_END_TEST */
#endif /* ACE_HAS_CONSOLE_TEST_OUTPUT */
#ifdef ACE_TEST_LOG_TO_STDERR
# define ACE_TEST_LOG_MSG_FLAGS ACE_Log_Msg::STDERR | ACE_Log_Msg::VERBOSE_LITE
# define ACE_TEST_SET_OUTPUT(APPEND)
# define ACE_CLOSE_TEST_LOG
#else
# define ACE_TEST_LOG_MSG_FLAGS ACE_Log_Msg::OSTREAM | ACE_Log_Msg::VERBOSE_LITE
# define ACE_TEST_SET_OUTPUT(APPEND) \\
if (ace_file_stream::instance ()->set_output (program, APPEND) != 0) \\
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\\n"), ACE_TEXT ("set_output failed")), -1);
# define ACE_CLOSE_TEST_LOG ace_file_stream::instance ()->close ()
#endif
#define ACE_START_TEST_TEMPLATE(NAME, APPEND) \\
const ACE_TCHAR *program = NAME; \\
if (ACE_LOG_MSG->open (program, ACE_TEST_LOG_MSG_FLAGS) != 0) \\
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\\n"), ACE_TEXT ("open log_msg failed")), -1); \\
ACE_TEST_SET_OUTPUT (APPEND); \\
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Starting %s test at %D\\n"), program))
#ifndef ACE_START_TEST
# define ACE_START_TEST(NAME) ACE_START_TEST_TEMPLATE (NAME, 0)
#endif /* ACE_START_TEST */
#ifndef ACE_END_TEST
#define ACE_END_TEST \\
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\\n"), program)); \\
ACE_CLOSE_TEST_LOG;
#endif /* ACE_END_TEST */
#ifndef ACE_APPEND_LOG
# define ACE_APPEND_LOG(NAME) ACE_START_TEST_TEMPLATE (NAME, 1)
#endif /* ACE_APPEND_LOG */
#define ACE_END_LOG \\
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Ending %s test at %D\\n\\n"), program)); \\
ACE_LOG_MSG->set_flags(ACE_Log_Msg::SILENT); \\
ACE_CLOSE_TEST_LOG;
#if defined (ACE_VXWORKS)
// This is the only way I could figure out to avoid an error
// about attempting to unlink a non-existent file.
#include "ace/OS_NS_fcntl.h"
#define ACE_INIT_LOG(NAME) \\
ACE_TCHAR temp[MAXPATHLEN]; \\
ACE_OS::sprintf (temp, ACE_TEXT ("%s%s%s"), \\
ACE_LOG_DIRECTORY, \\
ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \\
ACE_LOG_FILE_EXT_NAME); \\
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Deleting old log file %s (if any)\\n\\n"), temp)); \\
int fd_init_log; \\
if ((fd_init_log = ACE_OS::open (temp, \\
O_WRONLY|O_CREAT, \\
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) != ERROR) \\
{ \\
ACE_OS::close (fd_init_log); \\
ACE_OS::unlink (temp); \\
}
#else /* ! VXWORKS */
# if !defined (ACE_WIN32) && defined (ACE_USES_WCHAR)
# define ACE_INIT_LOG_FMT ACE_TEXT ("%ls%ls%ls")
# else
# define ACE_INIT_LOG_FMT ACE_TEXT ("%s%s%s")
# endif /* !ACE_WIN32 && ACE_USES_WCHAR */
#define ACE_INIT_LOG(NAME) \\
ACE_TCHAR temp[MAXPATHLEN]; \\
ACE_OS::sprintf (temp, ACE_INIT_LOG_FMT, \\
ACE_LOG_DIRECTORY, \\
ACE::basename (NAME, ACE_DIRECTORY_SEPARATOR_CHAR), \\
ACE_LOG_FILE_EXT_NAME); \\
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) Deleting old log file %s (if any)\\n\\n"), temp)); \\
ACE_OS::unlink (temp);
#endif /* ! VXWORKS */
#if defined (ACE_LACKS_iosTREAM_TOTALLY)
#define OFSTREAM FILE
#else
#define OFSTREAM ofstream
#endif /* ACE_LACKS_IOSTREAM_TOTALLY */
#include "Test_Output_Export.h"
class Test_Output_Export ACE_Test_Output
{
public:
ACE_Test_Output (void);
~ACE_Test_Output (void);
static ACE_Test_Output *instance (void);
int set_output (const ACE_TCHAR *filename, int append = 0);
OFSTREAM *output_file (void);
void close (void);
const ACE_TCHAR *dll_name (void);
const ACE_TCHAR *name (void);
static void close_singleton (void);
private:
static ACE_Test_Output *instance_;
OFSTREAM *output_file_;
};
typedef ACE_Test_Output ace_file_stream;
#endif /* ACE_TEST_CONFIG_H */
Test_Output_Export.h
// -*- C++ -*-
// Definition for Win32 Export directives.
// This file is generated automatically by generate_export_file.pl Test_Output
// ------------------------------
#ifndef TEST_OUTPUT_EXPORT_H
#define TEST_OUTPUT_EXPORT_H
#include "ace/config-all.h"
#if defined (ACE_AS_STATIC_LIBS) && !defined (TEST_OUTPUT_HAS_DLL)
# define TEST_OUTPUT_HAS_DLL 0
#endif /* ACE_AS_STATIC_LIBS && TEST_OUTPUT_HAS_DLL */
//#if !defined (TEST_OUTPUT_HAS_DLL)
//# define TEST_OUTPUT_HAS_DLL 1
//#endif /* ! TEST_OUTPUT_HAS_DLL */
#if defined (TEST_OUTPUT_HAS_DLL) && (TEST_OUTPUT_HAS_DLL == 1)
# if defined (TEST_OUTPUT_BUILD_DLL)
# define Test_Output_Export ACE_Proper_Export_Flag
# define TEST_OUTPUT_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)
# define TEST_OUTPUT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
# else /* TEST_OUTPUT_BUILD_DLL */
# define Test_Output_Export ACE_Proper_Import_Flag
# define TEST_OUTPUT_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)
# define TEST_OUTPUT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
# endif /* TEST_OUTPUT_BUILD_DLL */
#else /* TEST_OUTPUT_HAS_DLL == 1 */
# define Test_Output_Export
# define TEST_OUTPUT_SINGLETON_DECLARATION(T)
# define TEST_OUTPUT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
#endif /* TEST_OUTPUT_HAS_DLL == 1 */
// Set TEST_OUTPUT_NTRACE = 0 to turn on library specific tracing even if
// tracing is turned off for ACE.
#if !defined (TEST_OUTPUT_NTRACE)
# if (ACE_NTRACE == 1)
# define TEST_OUTPUT_NTRACE 1
# else /* (ACE_NTRACE == 1) */
# define TEST_OUTPUT_NTRACE 0
# endif /* (ACE_NTRACE == 1) */
#endif /* !TEST_OUTPUT_NTRACE */
#if (TEST_OUTPUT_NTRACE == 1)
# define TEST_OUTPUT_TRACE(X)
#else /* (TEST_OUTPUT_NTRACE == 1) */
# define TEST_OUTPUT_TRACE(X) ACE_TRACE_IMPL(X)
#endif /* (TEST_OUTPUT_NTRACE == 1) */
#endif /* TEST_OUTPUT_EXPORT_H */
// End of auto generated file.
运行结果LOG如下:
内容为
2021-07-27 00:52:52.748@LM_DEBUG@(8552|9684) Starting QtReactor_Test test at 2021-07-27 00:52:52.748677
2021-07-27 00:52:52.749@LM_INFO@Testing autotest using native reactor
2021-07-27 00:52:52.752@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:52:52.752@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:52:52.752@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:52:52.752@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:52:52.752@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:52:52.752@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:52:52.752@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:52:52.752@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:53:00.751@LM_INFO@Test seems to work with native reactor.
2021-07-27 00:53:00.754@LM_INFO@Testing QtReactor
2021-07-27 00:53:00.807@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:53:00.808@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:53:00.808@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:53:00.808@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:53:00.808@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:53:00.808@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:53:00.808@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
2021-07-27 00:53:00.808@LM_DEBUG@TCPAcceptorHandler::make_svc_handler new TCP server created
成功了,多谢。亲爱的美美。
以上是关于ACE_TAO 004的主要内容,如果未能解决你的问题,请参考以下文章
ACE_TAO 017 ACE_wrappersexamplesReactor