Init basesystem source codes.
[staging/basesystem.git] / video_in_hal / systemservice / logger_service / server / include / readerWriter / reader_writer.h
1 /*
2  * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 ///////////////////////////////////////////////////////////////////////////////
18 /// \ingroup  tag_SS_LoggerService
19 /// \brief    TODO
20 ///
21 ///////////////////////////////////////////////////////////////////////////////
22 #ifndef LOGGER_SERVICE_SERVER_INCLUDE_READERWRITER_READER_WRITER_H_
23 #define LOGGER_SERVICE_SERVER_INCLUDE_READERWRITER_READER_WRITER_H_
24
25 #include <pthread.h>
26 #include <native_service/frameworkunified_types.h>
27 #include <string>
28 #include "readerWriter/reader_writer_cfg.h"
29 #include "readerWriter/reader/reader.h"
30 #include "readerWriter/writer/writer.h"
31
32 namespace ReaderWriter {
33
34 class CReaderWriter {
35  public:
36   CReaderWriter();
37   virtual ~CReaderWriter();
38
39   EFrameworkunifiedStatus Initialize(CLoggerCfg* f_pLoggerCfg, EReaderType f_readerType,
40                         std::string f_readerName, UI_32 f_readerMaxSize,
41                         EWriterType f_writerType, std::string f_writer1Name,
42                         UI_32 f_writer1MaxSize);
43   EFrameworkunifiedStatus Initialize(CLoggerCfg* f_pLoggerCfg, EReaderType f_readerType,
44                         std::string f_readerName, UI_32 f_readerMaxSize,
45                         EWriterType f_writerType, std::string f_writer1Name,
46                         UI_32 f_writer1MaxSize, std::string f_writer2Name,
47                         UI_32 f_writer2MaxSize);
48   EFrameworkunifiedStatus Start(std::string f_readerName);
49   EFrameworkunifiedStatus Stop();
50   void ThreadFunction(CReaderWriter* l_pObj);
51   void Cleanup(CReaderWriter* l_pObj);
52   EFrameworkunifiedStatus FlushCache(std::string f_filename);
53   EFrameworkunifiedStatus UpdateLoggingParameters(void);
54
55  private:
56   void Pause(void);
57   void Resume(void);
58   static void* ThreadFunctionWrapper(void* param);
59
60   static void CleanupWrapper(void* param);
61   CLoggerCfg* m_pLoggerCfg;
62   CReader* m_reader;
63   CWriter* m_writer;
64   BOOL m_running;
65   pthread_t m_thread;
66   pthread_barrier_t m_barrier;
67   std::string m_readerName;
68
69   pthread_mutex_t m_writeMutex;
70   pthread_mutex_t m_pauseMutex;
71   pthread_cond_t m_condVariable;
72   BOOL m_paused;
73 };
74
75 }  // namespace ReaderWriter
76
77 #endif  // LOGGER_SERVICE_SERVER_INCLUDE_READERWRITER_READER_WRITER_H_