Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
text_thread.h
Package: videoserver-0.6.2.tar.gz [view]
Upload User: psq1974
Upload Date: 2007-01-06
Package Size: 1195k
Code Size: 3k
Category:
mpeg mp3
Development Platform:
C/C++
- /* Copyright (C) 1998, 1999 State University of New York at Stony Brook
- Author: Andrew V. Shuvalov ( andrew@ecsl.cs.sunysb.edu )
- Software license is located in file "COPYING"
- */
- #ifndef text_thread_h
- #define text_thread_h
- #include "mutex.h"
- /** structure that holds text and associated timestamp
- */
- struct text_data
- {
- std::string text;
- /** time in string form */
- std::string s_timestamp;
- text_data( const std::string &s ) : text( s )
- {
- s_timestamp.resize( 100 );
- # ifdef WIN32
- SYSTEMTIME st;
- GetSystemTime( &st );
- int l = _snprintf( (char *)s_timestamp.c_str(), s_timestamp.capacity(),
- "%04d-%02d-%02d %02d:%02d:%02d", st.wYear, st.wMonth, st.wDay,
- st.wHour, st.wMinute, st.wSecond ) + 1;
- # endif
- s_timestamp.resize( l );
- }
- text_data( const text_data &d ) : text( d.text ),
- s_timestamp( d.s_timestamp )
- {
- }
- const std::string &get_time() const { return s_timestamp; }
- const std::string &get_text() const { return text; }
- };
- /** hide all comport I/O complexity
- */
- class comport
- {
- std::string portname;
- /** open this with CreateFile */
- HANDLE port_h;
- /** mutex to lock shutdown procedure */
- mutex shutdown_mutex;
- /** allows background data loading */
- OVERLAPPED os;
- /** this var just keep the status of previous call of wait_comport_event()
- */
- DWORD dwEvtMask;
- /** internal buffer where get_data function places intermediate data */
- std::string internal_buffer;
- public:
- /** arg is com1 or com2. Do not connect immediately */
- comport( const std::string &comport_name );
- /** init only there */
- void init();
- void shutdown();
- ~comport();
- /** this is a blocking call which does not returns until some activity on
- port happens. We can do that because this thread have nothing to do
- if no data in port. It returns true if new data is awailable. It
- happens that it returns false if new event is coming but this is
- not a data event
- */
- bool wait_comport_event();
- /** fill given structures with data. If it happens that data from comport
- are invalid or end-of-line is not reached yet - return NULL.
- The structure is allocated inside this function and pointer is
- released - you are responsible to clean-up it
- */
- text_data *get_data();
- };
- /** thread class to work with closed captions grabber */
- class text_thread
- {
- comport *com_port;
- bool shutdown_now;
- /** mutex to lock shutdown procedure */
- mutex shutdown_mutex;
- public:
- /** should take the comport number from args. Do nothing else */
- text_thread( int argc, char **argv );
- ~text_thread()
- {
- shutdown();
- }
- static void text_thread_entry_func( void *_instance );
- void init()
- {
- com_port->init();
- }
- void shutdown()
- {
- wait_for_mutex wm( shutdown_mutex, 3 );
- if( com_port == NULL )
- return;
- com_port->shutdown();
- delete com_port;
- com_port = NULL;
- }
- void loop();
- };
- extern text_thread *textThread;
- #endif // text_thread_h