4 * Created on: Jul 5, 2010
11 using namespace boost
;
13 namespace bp
= ::boost::process
;
14 namespace ba
= ::boost::asio
;
16 #define BUFFER_SIZE 0xFFFFFF
18 int ImportFileList(nSyncBuf_s
& buf
, char * fn
)
23 if(access(fn
, R_OK
) == -1)
25 snprintf(errStr
, 4095, "[%s][%s][%d]: File->%s", __FILE__
, __FUNCTION__
, __LINE__
, fn
);
33 getline(I
, strTmp
, '\n');
36 if(access(strTmp
.c_str(), R_OK
) == -1)
38 snprintf(errStr
, 4095, "[%s][%s][%d]: File->%s", __FILE__
, __FUNCTION__
, __LINE__
, strTmp
.c_str());
42 buf
.fnList
.push_back(strTmp
);
49 int InsertFile(nSyncBuf_s
& buf
, char * fn
)
53 if(access(fn
, R_OK
) == -1)
55 snprintf(errStr
, 4095, "[%s][%s][%d]: File->%s", __FILE__
, __FUNCTION__
, __LINE__
, fn
);
60 buf
.fnList
.push_back(fn
);
64 bp::child
StartChild(nSyncBuf_s
& buf
)
66 string exec
= bp::find_executable_in_path("zcat");
69 args
.push_back(bp::find_executable_in_path("zcat"));
72 for(uint
i(0); i
< buf
.fnList
.size(); ++i
)
74 args
.push_back(buf
.fnList
[i
]);
78 ctx
.stdout_behavior
= bp::capture_stream();
79 ctx
.stderr_behavior
= bp::inherit_stream();
80 ctx
.environment
= bp::self::get_environment();
82 return bp::launch(exec
, args
, ctx
);
85 void endRead(nSyncBuf_s
&, const boost::system::error_code
& ec
, size_t bytes_transferred
);
87 void nSyncRead(nSyncBuf_s
& buf
)
89 buf
.in
.async_read_some(boost::asio::buffer(buf
.buffer
, BUFFER_SIZE
),
90 boost::bind(&endRead
, boost::ref(buf
), ba::placeholders::error
, ba::placeholders::bytes_transferred
));
93 void endRead(nSyncBuf_s
& buf
, const boost::system::error_code
& ec
, size_t bytes_transferred
)
99 buf
.Routine(buf
, bytes_transferred
);
104 void nSync(nSyncBuf_s
& buf
)
106 if(buf
.fnList
.empty())
108 perror("Empty filename vector. Program Terminated");
111 bp::child c
= StartChild(buf
);
113 buf
.in
.assign(c
.get_stdout().handle().release());
117 buf
.io_service
.run();
122 nSyncBuf_s::nSyncBuf_s(_ConsumeBufferRoutine_f func
, bool atomic
) : atomEnabler(atomic
), Routine(func
), in(io_service
)
124 buffer
= new char[BUFFER_SIZE
];
127 perror("[nSyncBuf_s]: Buffer allocation error.");
132 nSyncBuf_s::~nSyncBuf_s()
140 perror("[nSyncBuf_s]: Null ptr of buffer when destruction.");
145 inline void nSyncBuf_s::lock()
150 inline void nSyncBuf_s::unlock()
155 void nSyncBuf_s::release()
160 nSyncBufAry_t
nSyncBuf_s::ptr()
165 nSyncBufAry_t
nSyncBuf_s::operator *()