RDK Documentation (Open Sourced RDK Components)
glib_tools.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2017 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 #ifndef GLIB_TOOLS_H
21 #define GLIB_TOOLS_H
22 
23 #include <glib.h>
24 
25 /**
26  * @addtogroup MSE Player
27  * @{
28  */
29 
30 constexpr int eintr_maximum_attempts =100;
31 #define HANDLE_EINTR_EAGAIN(x) ({ \
32  unsigned char _attempts = 0; \
33  \
34  decltype(x) _result; \
35  \
36  do \
37  { \
38  _result = (x); \
39  } \
40  while (_result == -1 \
41  && (errno == EINTR || \
42  errno == EAGAIN || \
43  errno == EWOULDBLOCK) \
44  && _attempts++ < eintr_maximum_attempts); \
45  \
46  _result; \
47 })
48 
49 constexpr int PIPE_LISTEN = 0, PIPE_WRITE = 1;
50 typedef void (*PipeSourceCallback)(void* ctx);
51 
52 /**
53  * @brief This API creates a new event source "rtRemoteSource".
54  *
55  * This API also adds a file descriptor polled for this source, sets whether a source can be called recursively.
56  *
57  * @param[in] pipefd Pipe File descriptor
58  * @param[in] cb Callback Function
59  * @param[in] ctx Context
60  *
61  * @return Returns RT_OK on success, appropriate error code otherwise.
62 */
63 GSource* pipe_source_new(int pipefd[2], PipeSourceCallback cb, void* ctx);
64 
65 #endif // GLIB_TOOLS_H
pipe_source_new
GSource * pipe_source_new(int pipefd[2], PipeSourceCallback cb, void *ctx)
This API creates a new event source "rtRemoteSource".
Definition: glib_tools.cpp:81