RDK Documentation (Open Sourced RDK Components)
PacketSender.hpp
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2020 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #pragma once
21 
22 #include <memory>
23 #include <queue>
24 #include <thread>
25 #include <sys/socket.h>
26 #include <sys/un.h>
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <cstring>
30 #include <mutex>
31 #include <condition_variable>
32 #include <atomic>
33 
34 #ifdef SUBTEC_PACKET_DEBUG
35 #define AAMPLOG_WARN(...) printf
36 #define AAMPLOG_INFO(...) printf
37 #define AAMPLOG_TRACE(...) printf
38 #define AAMPLOG_ERR(...) printf
39 #else
40 #include "priv_aamp.h"
41 #endif
42 
43 #include "SubtecPacket.hpp"
44 
45 #ifdef AAMP_SIMULATOR_BUILD
46 const constexpr char *SOCKET_PATH = "subtecsim";
47 #else
48 const constexpr char *SOCKET_PATH = "/run/subttx/pes_data_main";
49 #endif
50 
51 void runWorkerTask(void *ctx);
52 
54 {
55 public:
56  ~PacketSender();
57 
58  void Close();
59  void Flush();
60  bool Init();
61  bool Init(const char *socket_path);
62  void SendPacket(PacketPtr && packet);
63  void senderTask();
64  bool IsRunning();
65  static PacketSender *Instance();
66 private:
67  void closeSenderTask();
68  void flushPacketQueue();
69  void sendPacket(PacketPtr && pkt);
70  bool initSenderTask();
71  bool initSocket(const char *socket_path);
72 
73  std::thread mSendThread;
74  int mSubtecSocketHandle;
75  std::atomic_bool running;
76  std::queue<PacketPtr> mPacketQueue;
77  std::mutex mPktMutex;
78  std::condition_variable mCv;
79  std::mutex mStartMutex;
80  int mSockBufSize;
81 protected:
82  PacketSender() :
83  mSendThread(),
84  mSubtecSocketHandle(-1),
85  running(false),
86  mPacketQueue(),
87  mPktMutex(),
88  mCv(),
89  mStartMutex(),
90  mSockBufSize(0)
91  {}
92 };
priv_aamp.h
Private functions and types used internally by AAMP.
PacketSender
Definition: PacketSender.hpp:53