RDK Documentation (Open Sourced RDK Components)
server.cpp
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 2016 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 // Part of conditional implementation
20 //#include <pthread.h>
21 
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string>
26 #include <unistd.h>
27 #include "client/linux/crash_generation/client_info.h"
28 #include "client/linux/crash_generation/crash_generation_server.h"
29 #include "servercontainer.h"
30 #include <string.h>
31 
32 using google_breakpad::ClientInfo;
33 using google_breakpad::CrashGenerationServer;
34 
35 using std::string;
36 
37 static string dump_path = "/opt/minidumps";
38 
39 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
40 
41 // Part of conditional implementation
42 //pthread_cond_t condition_var = PTHREAD_COND_INITIALIZER;
43 
44 static unsigned int count = 0;
45 
46 static void OnClientDumpRequest(void* aContext,
47  const ClientInfo* aClientInfo,
48  const string* aFilePath)
49 {
50  static const char msg[] = "Server wrote dump for client: ";
51  write(2, msg, sizeof(msg)-1);
52  static const char* dump_path = aFilePath->c_str();
53  write(2, dump_path, strlen(dump_path));
54  write(2, "\n", 1);
55 
56  // Part of conditional implementation
57  //pthread_mutex_lock(&mutex);
58  //pthread_cond_signal(&condition_var);
59  //pthread_mutex_unlock(&mutex);
60 }
61 
62 int main(int argc, char** argv)
63 {
64  pid_t spid = getpid();
65  printf("Server pid %d: starting\n", spid);
66  const int required_args = 3;
67  if (argc < required_args)
68  {
69  printf("usage: server: <pipe fd> <server fd>\n");
70  return 1;
71  }
72 
73  int pipe_fd = atoi(argv[1]);
74  int server_fd = atoi(argv[2]);
75 
76  // Part of conditional implementation
77  //pthread_mutex_lock(&mutex);
78 
79  ServerContainer pServer(new CrashGenerationServer(server_fd,
80  OnClientDumpRequest,
81  NULL,
82  NULL,
83  NULL,
84  true,
85  &dump_path));
86 
87  if (!pServer.get()->Start())
88  {
89  printf("Server pid %d: Failed to start CrashGenerationServer\n",
90  spid);
91  return 1;
92  }
93 
94  printf("Server pid %d: started server\n", spid);
95 
96  // Signal parent that this process has started the server.
97  uint8_t byte = 1;
98  write(pipe_fd, &byte, sizeof(byte));
99 
100  // Part of conditional implementation
101  /*
102  printf("Server pid %d: waiting for client request\n", spid);
103  pthread_cond_wait(&condition_var, &mutex);
104  */
105 
106  while (1)
107  {
108  // server loop
109  }
110 
111  return 0;
112 }
ServerContainer
Definition: servercontainer.h:24