TimeManager
common.h
Go to the documentation of this file.
1 
13 #ifndef _COMMON_H_
14 #define _COMMON_H_
15 
16 #include <stdio.h>
17 #include <sys/types.h>
18 
23 #define DEFAULT_SCHED_CAPTION "TimeManager."
24 
29 #define DEFAULT_SEMAPHORE_NAME "/sem_timemanager"
30 
35 #define DEFAULT_SHARED_MEMORY_NAME "/shm_timemanager"
36 
41 #define SHARED_MEMORY_SIZE 65536
42 
47 #define MAX_NUM_DB 5
48 
53 #define ENV_NAME "TM_DB_NUM"
54 
59 #define EXIT_MISUSE 2
60 
65 #define MAX_NUM_SCHEDULES 1024
66 
71 #define MAX_CAPTION_LEN 256
72 
77 #define MAX_SCHEDULE_STRING_LEN 512
78 
84 #define MAX_RECORD_STRING_LEN 510
85 
90 struct schedule {
91  pid_t pgid;
92  int lock;
93  pid_t terminator;
94  time_t start;
95  unsigned int duration;
97 };
98 
99 #ifdef __cplusplus
100 extern "C" {
101 #endif
102 
110  int check_sched_conflict(struct schedule* sched, struct schedule* *scheds, size_t len);
111 
117  void cleanup_schedules(struct schedule* *scheds, size_t len);
118 
133  int create_schedule(pid_t pgid, int lock, pid_t terminator,
134  time_t start, unsigned int duration, const char *caption,
135  struct schedule* *sched);
136 
144  void debug_schedule(const char* comment, struct schedule* *scheds,
145  size_t len);
146 
153  int get_env(char *sem_name, char *shm_name);
154 
164  int find_sched_by_pgid(pid_t pgid, struct schedule* *scheds, size_t len,
165  struct schedule* *sched);
166 
167 
180  size_t generate_unoccupied_scheds_from_scheds(struct schedule** scheds,
181  size_t len,
182  struct schedule** unoccupied_scheds,
183  size_t max_len,
184  time_t range_start,
185  unsigned int range_dur,
186  const char* caption);
187 
198  int load_schedules(const char* shm_path, size_t shm_size,
199  struct schedule** scheds, size_t scheds_len,
200  size_t *loaded_len);
201 
210  int save_schedules(const char* path, const size_t size,
211  struct schedule** scheds, size_t len);
212 
218  void sort_schedules(struct schedule** scheds, size_t len);
219 
228  int string_to_schedule(const char* str, struct schedule* *sched);
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 
234 #endif
int find_sched_by_pgid(pid_t pgid, struct schedule **scheds, size_t len, struct schedule **sched)
与えられたスケジュール群から、指定されたpgid値を持つスケジュールを見つける。
Definition: common.c:181
int string_to_schedule(const char *str, struct schedule **sched)
文字列の内容からスケジュール構造体を作成する。
Definition: common.c:491
int lock
Definition: common.h:92
int check_sched_conflict(struct schedule *sched, struct schedule **scheds, size_t len)
スケジュールが、スケジュール群の中のスケジュールと重複していないか確認する。
Definition: common.c:58
スケジュールに関する情報を保持する構造体
Definition: common.h:90
void cleanup_schedules(struct schedule **scheds, size_t len)
スケジュール構造体群のメモリをそれぞれ解放する。
Definition: common.c:82
int create_schedule(pid_t pgid, int lock, pid_t terminator, time_t start, unsigned int duration, const char *caption, struct schedule **sched)
引数を元にスケジュール構造体を作成する。
Definition: common.c:108
pid_t terminator
Definition: common.h:93
void sort_schedules(struct schedule **scheds, size_t len)
schedule構造体のstart値で昇順ソートする。
Definition: common.c:485
size_t generate_unoccupied_scheds_from_scheds(struct schedule **scheds, size_t len, struct schedule **unoccupied_scheds, size_t max_len, time_t range_start, unsigned int range_dur, const char *caption)
与えられたスケジュール群の中から、空き時間のスケジュール群を作成する。
Definition: common.c:198
#define MAX_CAPTION_LEN
schedule構造体のcaptionの最大文字数(英数時、終端文字列含む。)
Definition: common.h:71
pid_t pgid
Definition: common.h:91
unsigned int duration
Definition: common.h:95
int save_schedules(const char *path, const size_t size, struct schedule **scheds, size_t len)
スケジュール群を決められた書式で共有メモリに書き込む。
Definition: common.c:441
void debug_schedule(const char *comment, struct schedule **scheds, size_t len)
スケジュール群の内容を、コメントとともにstderrに出力する。
Definition: common.c:132
int get_env(char *sem_name, char *shm_name)
環境変数を解析する。
Definition: common.c:159
int load_schedules(const char *shm_path, size_t shm_size, struct schedule **scheds, size_t scheds_len, size_t *loaded_len)
共有メモリからスケジュールを読込、スケジュール構造体を作成する。
Definition: common.c:358
char caption[MAX_CAPTION_LEN]
Definition: common.h:96
time_t start
Definition: common.h:94
int lock(int argc, char *argv[])
スケジュールの書き換えをロックする。
Definition: lock.c:218