COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
datalib.h
Go to the documentation of this file.
1 /********************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
30 #ifndef _DATALIB_H
31 #define _DATALIB_H
32 
33 // COSMOS libs
34 #include "support/configCosmos.h"
35 #include "support/cosmos-errno.h"
36 #include "support/jsondef.h"
37 #include "support/jsonlib.h"
38 #include "thirdparty/zlib/zlib.h"
39 #include "support/timelib.h"
40 
41 // C libs
42 #include <sys/stat.h>
43 #include <fstream>
44 
45 #ifdef _MSC_BUILD
46 #include "dirent/dirent.h"
47 #else
48 #include <dirent.h>
49 #endif
50 
55 
107 
108 #define DATA_LOG_TYPE_SOH 0
109 #define DATA_LOG_TYPE_EVENT 1
110 #define DATA_LOG_TYPE_BEACON 2
111 #define DATA_LOG_TYPE_PROGRAM 3 // to log program status information while running
112 
113 typedef struct
114 {
115  string node;
116  string agent;
117  string name;
118  string type;
119  string path;
120  off_t size;
121  uint16_t year;
122  uint16_t jday;
123  uint32_t seconds;
124  double utc;
125 } filestruc;
126 
127 void log_reopen();
128 void log_write(string node, int type, double utc, const char* data, string directory="temp");
129 void log_write(string node, string agent, double utc, string type, const char *data);
130 //void log_write(string node, string agent, double utc, string extra, string type, string record);
131 void log_write(string node, string agent, double utc, string extra, string type, string record, string location="temp");
132 void log_move(string node, string agent, string srclocation, string dstlocation, bool compress);
133 void log_move(string node, string agent);
134 void log_move(string oldpath, string newpath, bool compress);
135 string log_read(gzFile &file, int num);
136 int check_events(eventstruc* events, int max, cosmosstruc* data);
137 int32_t data_get_nodes(vector<cosmosstruc> &data);
138 vector<string> data_list_nodes();
139 int32_t data_list_nodes(vector<string>& nodes);
140 vector<filestruc> data_list_files(string directory);
141 size_t data_list_files(string directory, vector<filestruc>& files);
142 vector<filestruc> data_list_files(string node, string location, string agent);
143 size_t data_list_files(string node, string location, string agent, vector<filestruc>& files);
144 vector<filestruc> data_list_archive(string node, string agent, double utc, string type);
145 vector<filestruc> data_list_archive(string node, string agent, double utc);
146 vector <double> data_list_archive_days(string node, string agent);
147 FILE* data_open(string path, const char *mode);
148 int32_t data_name_date(string node, string filename, uint16_t &year, uint16_t &jday, uint32_t &seconds);
149 int32_t data_name_date(string node, string filename, double &utc);
150 string data_name(string node, double mjd, string extra, string type);
151 string data_name(string node, double mjd, string type);
152 string data_base_path(string node);
153 string data_base_path(string node, string location);
154 string data_base_path(string node, string location, string agent);
155 string data_base_path(string node, string location, string agent, string filename);
156 string data_archive_path(string node, string agent, double mjd);
157 string data_type_path(string node, string location, string agent, double mjd, string type);
158 string data_type_path(string node, string location, string agent, double mjd, string extra, string type);
159 string data_name_path(string node, string location="", string agent="", double mjd=0., string name="");
160 string data_resource_path(string name);
161 bool data_exists(string& path);
162 bool data_isdir(string path);
163 bool data_ischardev(string path);
164 bool data_isfile(string path, off_t size=0);
165 double data_ctime(string path);
166 int32_t data_execute(string cmd, string& result, string shell="");
167 off_t data_size(string path);
168 int32_t set_cosmosroot(string name, bool create_flag=false);
169 int32_t set_cosmosroot(bool create_flag=false);
170 int32_t get_cosmosroot(string &result, bool create_flag=false);
171 string get_cosmosroot(bool create_flag=false);
172 int32_t set_cosmosresources(string name, bool create_flag);
173 int32_t set_cosmosresources(bool create_flag=false);
174 int32_t get_cosmosresources(string &result, bool create_flag=false);
175 string get_cosmosresources(bool create_flag=false);
176 int32_t setEnvCosmosResources(string path);
177 int32_t setEnvCosmosNodes(string path);
178 int32_t setEnv(string var, string path);
179 int32_t setEnvCosmos(string path);
180 int32_t set_cosmosnodes(string name, bool create_flag=false);
181 int32_t set_cosmosnodes(bool create_flag=false);
182 int32_t get_cosmosnodes(string &result, bool create_flag=false);
183 string get_cosmosnodes(bool create_flag=false);
184 string get_nodedir(string node, bool create_flag=false);
185 int32_t data_load_archive(string node, string agent, double utcbegin, double utcend, string type, vector<string> &result);
186 int32_t data_load_archive(string node, string agent, double mjd, string type, vector<string> &result);
187 int32_t data_load_archive(double mjd, vector<string> &telem, vector<string> &event, cosmosstruc* root);
188 double findlastday(string node);
189 double findfirstday(string node);
190 int32_t kml_write(cosmosstruc* cinfo);
191 
193 
194 #endif // DATALIB_H
string name
Definition: datalib.h:117
double findfirstday(string name)
Find first day in archive.
Definition: datalib.cpp:1754
off_t size
Definition: datalib.h:120
uint16_t year
Definition: datalib.h:121
uint32_t seconds
Definition: datalib.h:123
int32_t set_cosmosroot(string name, bool create_flag)
Set Root Directory.
Definition: datalib.cpp:1064
double utcend
Definition: fast_contacts.cpp:65
string data_name(string node, double mjd, string extra, string type)
Create data file name.
Definition: datalib.cpp:685
FILE * data_open(string path, const char *mode)
Open file from path.
Definition: datalib.cpp:1019
string node
Definition: datalib.h:115
int32_t set_cosmosnodes(string name, bool create_flag)
Set Nodes Directory.
Definition: datalib.cpp:1445
int32_t setEnvCosmosNodes(string path)
Set Environment Variable for COSMOS nodes.
Definition: datalib.cpp:1383
void log_move(string oldpath, string newpath, bool compress)
Move log file - path version.
Definition: datalib.cpp:200
int32_t data_load_archive(string node, string agent, double utcbegin, double utcend, string type, vector< string > &result)
Load data from archive.
Definition: datalib.cpp:1616
vector< filestruc > data_list_archive(string node, string agent, double utc, string type)
Get a list of files in a Node archive.
Definition: datalib.cpp:385
string data_name_path(string node, string location, string agent, double mjd, string name)
Create data file path.
Definition: datalib.cpp:954
vector< filestruc > data_list_files(string directory)
Get list of files in a directory, directly.
Definition: datalib.cpp:461
double utc
Definition: datalib.h:124
int32_t data_get_nodes(vector< cosmosstruc > &node)
Get vector of Node structures.
Definition: datalib.cpp:636
int32_t set_cosmosresources(string name, bool create_flag)
Set Resources Directory.
Definition: datalib.cpp:1248
string data_base_path(string node, string location, string agent, string filename)
Create data file path.
Definition: datalib.cpp:767
static vector< eventstruc > events
Definition: propagator_simple.cpp:64
vector< string > data_list_nodes()
Get list of Nodes, directly.
Definition: datalib.cpp:583
off_t data_size(string path)
Definition: datalib.cpp:1932
string get_cosmosnodes(bool create_flag)
Return COSMOS Nodes Directory.
Definition: datalib.cpp:1532
double findlastday(string name)
Find last day in archive.
Definition: datalib.cpp:1679
int32_t data_execute(string cmd, string &result, string shell)
Definition: datalib.cpp:1947
Definition: datalib.h:113
string get_cosmosresources(bool create_flag)
Return COSMOS Resources Directory.
Definition: datalib.cpp:1337
string data_type_path(string node, string location, string agent, double mjd, string type)
Create data file path.
Definition: datalib.cpp:910
int32_t setEnv(string var, string path)
Set Environment Variable for COSMOS.
Definition: datalib.cpp:1393
bool data_isfile(string path, off_t size)
Definition: datalib.cpp:1895
string path
Definition: datalib.h:119
std::vector< cosmosstruc > nodes
Definition: agent_data-2-0.cpp:57
static Agent * agent
ensure the Agent constructor creates only one instance per process
Definition: agent_001.cpp:45
bool data_isdir(string path)
Definition: datalib.cpp:1865
void log_reopen()
JSON Support definitions.
Headers and definitions common to all COSMOS.
string name
Definition: cubesat2obj.cpp:6
Full COSMOS Event structure.
Definition: jsondef.h:1093
COSMOS Error Codes.
double mjd
Definition: udp_send.cpp:41
timelib include file A library providing functions for handling various types of time.
uint16_t jday
Definition: datalib.h:122
double data_ctime(string path)
Definition: datalib.cpp:1910
int32_t kml_write(cosmosstruc *cinfo)
Add to KML path.
Definition: datalib.cpp:1828
void log_write(string node, string agent, double utc, string extra, string type, string record, string location)
Write log entry - full.
Definition: datalib.cpp:75
string get_nodedir(string node, bool create_flag)
Get Current Node Directory.
Definition: datalib.cpp:1572
string data_archive_path(string node, string agent, double mjd)
Definition: datalib.cpp:871
string agent
Definition: datalib.h:116
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
Definition: compress.c:62
string get_cosmosroot(bool create_flag)
Return COSMOS Root Directory.
Definition: datalib.cpp:1209
int32_t setEnvCosmos(string path)
Definition: datalib.cpp:1427
bool data_ischardev(string path)
Definition: datalib.cpp:1880
string log_read(gzFile &file, int num)
log_reads Loop until the newline character is seen. Append it to a string and return the line once th...
Definition: datalib.cpp:357
Definition: zlib.h:1670
int32_t setEnvCosmosResources(string path)
Set Environment Variable for COSMOS resources.
Definition: datalib.cpp:1373
string data_resource_path(string name)
Create resource file path.
Definition: datalib.cpp:983
static string node
Definition: agent_monitor.cpp:126
Definition: jsondef.h:4199
int32_t data_name_date(string node, string filename, uint16_t &year, uint16_t &jday, uint32_t &seconds)
Get date from file name.
Definition: datalib.cpp:722
int check_events(eventstruc *events, int max, cosmosstruc *data)
vector< double > data_list_archive_days(string node, string agent)
Get a list of days in a Node archive.
Definition: datalib.cpp:303
string type
Definition: datalib.h:118
bool data_exists(string &path)
Check existence of path.
Definition: datalib.cpp:1003