/[H7]/branches/linux-serial/server/main.cpp
ViewVC logotype

Annotation of /branches/linux-serial/server/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 75 - (hide annotations) (download)
Mon Aug 6 12:39:10 2007 UTC (16 years, 10 months ago) by torben
File size: 1319 byte(s)
Added comments on which external library this program uses

1 torben 75 /* Sample implementation of a H7 server for linux
2     * this application uses boost::thread library (http://boost.org)
3     * and cppsocket (http:://sourceforge.net/projects/cppsocket)
4     */
5    
6 torben 60 #include <iostream>
7     #include <string>
8    
9     #include <boost/thread/thread.hpp>
10     #include <boost/thread/mutex.hpp>
11    
12     #include "../H7Serial.h"
13     #include "serialthread.h"
14 torben 67 #include "serverthread.h"
15 torben 60
16 torben 67 #include "globalstorage.h"
17 torben 60
18     void my_pause()
19     {
20     char d[1];
21     std::cout << "Press enter to continue" << std::endl;
22     std::cin.getline(d,1);
23     }
24    
25     int main(int argc, char* argv[])
26     {
27 torben 67 CH7Serial& serialPort = GlobalStorage::instance()->serialPort;
28    
29     SerialThread& serial = GlobalStorage::instance()->serialThread;
30     ServerThread server;
31     // GlobalStorage::instance()->serialThread = &serial;
32    
33 torben 60 try
34     {
35 torben 67 serialPort.open("/dev/ttyS0", CSerial::Baud9600);
36 torben 60 }
37     catch(std::exception&e )
38     {
39     std::cout << "Error opening serial port : " << e.what() << std::endl;
40 torben 67 exit(1);
41 torben 60 }
42    
43 torben 67 try
44     {
45     GlobalStorage::instance()->server.start(9000); //listen on port 9000
46     }
47     catch(...)
48     {
49     std::cout << "Could not listen on port 9000" << std::endl;
50     serialPort.close();
51     exit(2);
52     }
53 torben 60
54 torben 67
55    
56     boost::thread serialThread(serial);
57     boost::thread serverThread(server);
58    
59 torben 60 my_pause();
60    
61 torben 67 serial.stop();
62     server.stop();
63     while(!serial.stopped() && !server.stopped() )
64 torben 60 usleep(10000);
65     }

  ViewVC Help
Powered by ViewVC 1.1.20