Commit | Line | Data |
---|---|---|
970ed795 | 1 | /////////////////////////////////////////////////////////////////////////////// |
3abe9331 | 2 | // Copyright (c) 2000-2015 Ericsson Telecom AB |
970ed795 EL |
3 | // All rights reserved. This program and the accompanying materials |
4 | // are made available under the terms of the Eclipse Public License v1.0 | |
5 | // which accompanies this distribution, and is available at | |
6 | // http://www.eclipse.org/legal/epl-v10.html | |
7 | /////////////////////////////////////////////////////////////////////////////// | |
8 | #ifndef JNIMW_JNIMW_H | |
9 | #define JNIMW_JNIMW_H | |
10 | //---------------------------------------------------------------------------- | |
11 | ||
12 | #include <stdio.h> | |
13 | #include <pthread.h> | |
14 | #include <jni.h> | |
15 | #include "../core/Types.h" | |
16 | #include "../mctr2/mctr/UserInterface.h" | |
17 | #include "../mctr2/mctr/MainController.h" | |
18 | #include "../common/memory.h" | |
19 | #include "../mctr2/mctr/config_data.h" | |
20 | ||
21 | //---------------------------------------------------------------------------- | |
22 | ||
23 | namespace jnimw { | |
24 | ||
25 | //---------------------------------------------------------------------------- | |
26 | ||
27 | /** | |
28 | * User interface jnimw implementation. | |
29 | */ | |
30 | class Jnimw : public mctr::UserInterface | |
31 | { | |
32 | public: | |
33 | static Jnimw *userInterface; | |
34 | int pipe_fd[2]; | |
35 | char *pipe_buffer; | |
36 | fd_set readfds; | |
37 | ||
38 | static bool has_status_message_pending; | |
39 | static int pipe_size; | |
40 | ||
41 | static pthread_mutex_t mutex; | |
42 | ||
43 | /** | |
44 | * Configuration data which is filled by calling set_cfg_file() | |
45 | * Based on Cli::mycfg | |
46 | */ | |
47 | static config_data mycfg; | |
48 | ||
49 | public: | |
50 | /** | |
51 | * Constructor, destructor. | |
52 | */ | |
53 | Jnimw(); | |
54 | ~Jnimw(); | |
55 | ||
56 | virtual int enterLoop(int argc, char* argv[]); | |
57 | ||
58 | /* Callback interface */ | |
59 | /** | |
60 | * Status of MC has changed. | |
61 | */ | |
62 | virtual void status_change(); | |
63 | ||
64 | /** | |
65 | * Error message from MC. | |
66 | */ | |
67 | virtual void error(int severity, const char* msg); | |
68 | ||
69 | /** | |
70 | * General notification from MC. | |
71 | */ | |
72 | virtual void notify(const struct timeval* time, const char* source, | |
73 | int severity, const char* msg); | |
74 | ||
75 | void create_pipe(); | |
76 | void destroy_pipe(); | |
77 | char* read_pipe(); | |
78 | void write_pipe(const char *buf); | |
79 | ||
80 | bool is_pipe_readable(); | |
81 | ||
82 | static void lock(); | |
83 | static void unlock(); | |
84 | static void fatal_error(const char *fmt, ...) | |
85 | __attribute__ ((__format__ (__printf__, 1, 2), __noreturn__)); | |
86 | }; | |
87 | //---------------------------------------------------------------------------- | |
88 | ||
89 | } | |
90 | ||
91 | //---------------------------------------------------------------------------- | |
92 | #endif // JNIMW_JNIMW_H |