process.h
Go to the documentation of this file.
1 /* vim: set ts=2 expandtab: */
2 /**
3  * @file process.h
4  * @brief a simple object-oriented process manager
5  * object model inspired by Zed Shaw
6  *
7  * @author Josh King (jheretic), jking@chambana.net
8  *
9  * @internal
10  * Created 03/07/2013
11  * Revision $Id: doxygen.commotion.templates,v 0.1 2013/01/01 09:00:00 jheretic Exp $
12  * Compiler gcc/g++
13  * Company The Open Technology Institute
14  * Copyright Copyright (c) 2013, Josh King
15  *
16  * This file is part of Commotion, Copyright (c) 2013, Josh King
17  *
18  * Commotion is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as
20  * published by the Free Software Foundation, either version 3 of the
21  * License, or (at your option) any later version.
22  *
23  * Commotion is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with Commotion. If not, see <http://www.gnu.org/licenses/>.
30  *
31  * =====================================================================================
32  */
33 
34 #ifndef _PROCESS_H
35 #define _PROCESS_H
36 
37 #include <stdlib.h>
38 #include <stdbool.h>
39 #include "util.h"
40 #include "obj.h"
41 
42 /**
43  * @enum co_process_state_t defines the state of the process
44  */
45 typedef enum {
46  _STOPPING = 0,
47  _STOPPED =1,
48  _STARTING = 2,
49  _STARTED = 3,
50  _FAILED = -1
52 
53 typedef struct co_process_t co_process_t;
54 
55 /**
56  * @struct co_process_t process struct, including process id, run path and state information
57  */
58 struct co_process_t {
59  co_obj_t _header;
60  uint8_t _exttype;
61  uint8_t _len;
62  int pid;
63  bool registered;
64  bool use_watchdog;
65  co_process_state_t state;
66  char *name;
67  char *pid_file;
68  char *exec_path;
69  char *run_path;
70  int input;
71  int output;
72  int (*init)(co_obj_t *self);
73  int (*destroy)(co_obj_t *self);
74  int (*start)(co_obj_t *self, char *argv[]);
75  int (*stop)(co_obj_t *self);
76  int (*restart)(co_obj_t *self);
77 } __attribute__((packed));
78 
79 /**
80  * @brief creates a new commotion process
81  * @param size size of the process
82  * @param co_process_t protocol
83  * @param name name of the process
84  * @param pid_file the lockfile where the process id is stored
85  * @param exec_path the execution path
86  * @param run_path the run path
87  * @return co_process_t to be registered with the daemon
88  */
89 co_obj_t *co_process_create(size_t size, co_process_t proto, const char *name, const char *pid_file, const char *exec_path, const char *run_path);
90 
91 /**
92  * @brief removes a process from commotiond
93  * @param self pointer to the process' struct
94  */
95 int co_process_destroy(co_obj_t *self);
96 
97 /**
98  * @brief starts a selected process
99  * @param self pointer to the process' struct
100  * @param argv[] execution path for the process
101  */
102 int co_process_start(co_obj_t *self, char *argv[]);
103 
104 /**
105  * @brief stops a running process
106  * @param self pointer to the process' struct
107  */
108 int co_process_stop(co_obj_t *self);
109 
110 /**
111  * @brief restarts a process
112  * @param self pointer to the process' struct
113  */
114 int co_process_restart(co_obj_t *self);
115 
116 #endif
int co_process_start(co_obj_t *self, char *argv[])
starts a selected process
Definition: process.c:91
Commotion object model.
int co_process_stop(co_obj_t *self)
stops a running process
Definition: process.c:136
co_process_state_t
Definition: process.h:45
Definition: obj.h:131
co_obj_t * co_process_create(size_t size, co_process_t proto, const char *name, const char *pid_file, const char *exec_path, const char *run_path)
creates a new commotion process
Definition: process.c:44
Definition: process.h:58
utility functions for the Commotion daemon
int co_process_destroy(co_obj_t *self)
removes a process from commotiond
Definition: process.c:78
int co_process_restart(co_obj_t *self)
restarts a process
Definition: process.c:148