[22] | 1 | extern "C"
|
---|
| 2 | {
|
---|
| 3 | #include "TriChannel.h"
|
---|
| 4 | }
|
---|
| 5 | #ifdef WIN32
|
---|
| 6 | #include <Windows.h>
|
---|
| 7 | #endif
|
---|
| 8 | #include <boost/thread/thread.hpp>
|
---|
| 9 | #include <boost/thread/condition.hpp>
|
---|
| 10 | #include "tri-sa.h"
|
---|
| 11 | #include "tri-pa.h"
|
---|
| 12 | #include "Logger/Logger.h"
|
---|
| 13 | #include <iostream>
|
---|
| 14 |
|
---|
| 15 | static boost::mutex exitMutex;
|
---|
| 16 | static boost::condition exitCondition;
|
---|
| 17 |
|
---|
| 18 | void onConnectionClosed()
|
---|
| 19 | {
|
---|
| 20 | boost::mutex::scoped_lock localLock(exitMutex);
|
---|
| 21 | exitCondition.notify_one();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | int main(int argc, char **argv)
|
---|
| 25 | {
|
---|
| 26 | if (argc == 2 && strcmp(argv[1], "-help") == 0)
|
---|
| 27 | {
|
---|
| 28 | std::cout << "Usage: Adapter [-a address][-p port_number]" << std::endl;
|
---|
| 29 | std::cout << "-a address Specifies MessageMagic IP address. 127.0.0.1 is used by" << std::endl;
|
---|
| 30 | std::cout << " default." << std::endl;
|
---|
| 31 | std::cout << "-p port_number Specifies MessageMagic port. 7777 is used by default." << std::endl;
|
---|
| 32 | std::cout << "-L* Sets the log level. Log levels can be combined together." << std::endl;
|
---|
| 33 | std::cout << " The following log levels are available:" << std::endl;
|
---|
| 34 | std::cout << " -Linfo Displays information messages" << std::endl;
|
---|
| 35 | std::cout << " -Lerr Displays errors" << std::endl;
|
---|
| 36 | std::cout << " -Lwarn Displays warnings" << std::endl;
|
---|
| 37 | std::cout << " -Ldebug Displays debugging information" << std::endl;
|
---|
| 38 | std::cout << " -Lall Displays all information" << std::endl;
|
---|
| 39 | std::cout << " -Lnone No messages are displayed" << std::endl;
|
---|
| 40 | return 0;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | int nLogMode = 0;
|
---|
| 44 | bool bLogModeSet = false;
|
---|
| 45 | bool bError = false;
|
---|
| 46 | Logger::Instance().SetLoggingMode(Logger::LOG_ERRORS);
|
---|
| 47 | char * pszAddr = "127.0.0.1";
|
---|
| 48 | int nPort = 7777;
|
---|
| 49 | for (int i = 1; i < argc; ++i)
|
---|
| 50 | {
|
---|
| 51 | bool bLog = false;
|
---|
| 52 | char * pszArg = argv[i];
|
---|
| 53 | if (strcmp(pszArg, "-p") == 0)
|
---|
| 54 | {
|
---|
| 55 | if (bError = i + 1 == argc)
|
---|
| 56 | std::cout << "Port value missing" << std::endl;
|
---|
| 57 | else
|
---|
| 58 | {
|
---|
| 59 | pszArg = argv[++i];
|
---|
| 60 | nPort = atoi(pszArg);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | else if (strcmp(pszArg, "-a") == 0)
|
---|
| 64 | {
|
---|
| 65 | if (bError = i + 1 == argc)
|
---|
| 66 | std::cout << "Address value missing" << std::endl;
|
---|
| 67 | else
|
---|
| 68 | {
|
---|
| 69 | pszArg = argv[++i];
|
---|
| 70 | pszAddr = pszArg;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | else if (bLog = strcmp(pszArg, "-Linfo") == 0)
|
---|
| 74 | nLogMode |= Logger::LOG_INFO;
|
---|
| 75 | else if (bLog = strcmp(pszArg, "-Lerr") == 0)
|
---|
| 76 | nLogMode |= Logger::LOG_ERRORS;
|
---|
| 77 | else if (bLog = strcmp(pszArg, "-Lwarn") == 0)
|
---|
| 78 | nLogMode |= Logger::LOG_WARNINGS;
|
---|
| 79 | else if (bLog = strcmp(pszArg, "-Ldebug") == 0)
|
---|
| 80 | nLogMode |= Logger::LOG_DEBUG | Logger::LOG_INFO;
|
---|
| 81 | else if (bLog = strcmp(pszArg, "-Lall") == 0)
|
---|
| 82 | nLogMode = Logger::LOG_ALL;
|
---|
| 83 | else if (bLog = strcmp(pszArg, "-Lnone") == 0)
|
---|
| 84 | nLogMode = Logger::LOG_NOTHING;
|
---|
| 85 | else
|
---|
| 86 | {
|
---|
| 87 | bError = true;
|
---|
| 88 | std::string s = "Unknown command line parameter \"";
|
---|
| 89 | s += pszArg;
|
---|
| 90 | s += "\"";
|
---|
| 91 | std::cout << s << std::endl;
|
---|
| 92 | }
|
---|
| 93 | if (bLog)
|
---|
| 94 | bLogModeSet = true;
|
---|
| 95 | }
|
---|
| 96 | if (bError)
|
---|
| 97 | return 1;
|
---|
| 98 | if (!bLogModeSet)
|
---|
| 99 | nLogMode = Logger::LOG_INFO | Logger::LOG_ERRORS;
|
---|
| 100 | Logger::Instance().SetLoggingMode(nLogMode);
|
---|
| 101 | Logger::Instance().LogDebug("Command line parameters processed successfully");
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 | #ifdef WIN32
|
---|
| 105 | // Winsock init
|
---|
| 106 | WSADATA w;
|
---|
| 107 | if (WSAStartup(0x0002, &w))
|
---|
| 108 | {
|
---|
| 109 | std::cout << "Error initiating Winsock library" << std::endl;
|
---|
| 110 | return 1;
|
---|
| 111 | }
|
---|
| 112 | #endif
|
---|
| 113 | // Map callbacks
|
---|
| 114 | setTriSAResetCallback (triSAReset);
|
---|
| 115 | setTriExecuteTestCaseCallback (triExecuteTestCase);
|
---|
| 116 | setTriMapCallback (triMap);
|
---|
| 117 | setTriUnmapCallback (triUnmap);
|
---|
| 118 | setTriEndTestCaseCallback (triEndTestcase);
|
---|
| 119 | setTriSendCallback (triSend);
|
---|
| 120 | //setTriSendBCCallback (triSendBC);
|
---|
| 121 | //setTriSendMCCallback (triSendMC);
|
---|
| 122 | setTriCallCallback (triCall);
|
---|
| 123 | //setTriCallBCCallback (triCallBC);
|
---|
| 124 | //setTriCallMCCallback (triCallMC);
|
---|
| 125 | setTriReplyCallback (triReply);
|
---|
| 126 | //setTriReplyBCCallback (triReplyBC);
|
---|
| 127 | //setTriReplyMCCallback (triReplyMC);
|
---|
| 128 | setTriRaiseCallback (triRaise);
|
---|
| 129 | //setTriRaiseBCCallback (triRaiseBC);
|
---|
| 130 | //setTriRaiseMCCallback (triRaiseMC);
|
---|
| 131 | //setTriSUTActionInformalCallback (triSUTActionInformal);
|
---|
| 132 | //setTriPAResetCallback (triPAReset);
|
---|
| 133 | //setTriStartTimerCallback (triStartTimer);
|
---|
| 134 | //setTriStopTimerCallback (triStopTimer);
|
---|
| 135 | //setTriReadTimerCallback (triReadTimer);
|
---|
| 136 | //setTriTimerRunningCallback (triTimerRunning);
|
---|
| 137 | //setTriExternalFunctionCallback (triExternalFunction);
|
---|
| 138 |
|
---|
| 139 | // Callback for monitoring connection termination
|
---|
| 140 | setOnConnectionClosedCallback(onConnectionClosed);
|
---|
| 141 |
|
---|
| 142 | int nRes = 0;
|
---|
| 143 | // Create TCP/IP connection
|
---|
| 144 | if (openTriChannel(pszAddr, nPort, -1, -1, L"Generic T3devkit Adapter"))
|
---|
| 145 | {
|
---|
| 146 | std::cout << "TCP/IP connection with MessageMagic established" << std::endl;
|
---|
| 147 | // Local lock for monitoring exit condition
|
---|
| 148 | boost::mutex::scoped_lock exitLock(exitMutex);
|
---|
| 149 | // Waiting for exit condition
|
---|
| 150 | exitCondition.wait(exitLock);
|
---|
| 151 | closeTriChannel();
|
---|
| 152 | std::cout << "TCP/IP connection with MessageMagic closed" << std::endl;
|
---|
| 153 | }
|
---|
| 154 | else
|
---|
| 155 | {
|
---|
| 156 | std::cout << "Failed to open TRI channel" << std::endl;
|
---|
| 157 | nRes = 2;
|
---|
| 158 | }
|
---|
| 159 | #ifdef WIN32
|
---|
| 160 | // Winsock cleanup
|
---|
| 161 | WSACleanup();
|
---|
| 162 | #endif
|
---|
| 163 | return 2;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 |
|
---|