Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c462e7adb | ||
|
|
78444a27f8 | ||
|
|
8fdda73c79 | ||
|
|
ac7eb4a56d | ||
|
|
bd18ca0e9e | ||
|
|
34e11538ec | ||
|
|
e0b7a7e83d |
@@ -1,28 +0,0 @@
|
||||
#! /usr/bin/make -f
|
||||
|
||||
DEFAULTS = Makefile.config
|
||||
|
||||
include $(DEFAULTS)
|
||||
|
||||
all:sys_nicmonitor libnic_shm.so
|
||||
|
||||
CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral #-g
|
||||
|
||||
sys_nicmonitor:mnic.o read_netcard.o send_alarm.o
|
||||
$(CC) -lman -ldotconf -lpthread -o $@ $^
|
||||
libnic_shm.so:nicinfo_shm.c
|
||||
$(CC) -fpic -shared -o $@ $^
|
||||
clean:
|
||||
$(RM) *.o
|
||||
$(RM) libnic_shm.so sys_nicmonitor
|
||||
install:
|
||||
$(MKDIR) -p $(LIBDIR)
|
||||
$(MKDIR) -p $(BINDIR)
|
||||
$(MKDIR) -p $(INCDIR)
|
||||
$(CP) libnic_shm.so $(LIBDIR)
|
||||
$(CP) sys_nicmonitor $(BINDIR)
|
||||
$(CP) nicinfo_shm.h $(INCDIR)
|
||||
uninstall:
|
||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,209 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "nicinfo_shm.h"
|
||||
|
||||
#define SHM_PATH "/tmp/sys_netcard_shm_path"
|
||||
#define SEM_PATH "/tmp/sys_netcard_sem_path"
|
||||
#define LOG_PATH "/var/log/netcard/"
|
||||
|
||||
typedef struct net_info{
|
||||
NETCARD_INFO info[MAXNICNUM];
|
||||
}SHM;
|
||||
|
||||
static int semid = 0;
|
||||
static char log_path[1024];
|
||||
static char shm_path[1024];
|
||||
static char sem_path[1024];
|
||||
SHM *ptr = NULL;
|
||||
|
||||
/* write error in logfile */
|
||||
void record_log(char *str)
|
||||
{
|
||||
time_t tamp;
|
||||
char str_tm[4];
|
||||
char log_str[512];
|
||||
FILE *log_fp = NULL;
|
||||
struct tm tmptr;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
if((log_fp = fopen(log_path, "a")) != NULL){
|
||||
tamp = time(NULL);
|
||||
memset(str_tm, 0, sizeof(str_tm));
|
||||
memset(log_str, 0, sizeof(log_str));
|
||||
localtime_r(&tamp, &tmptr);
|
||||
gettimeofday(&tv, &tz);
|
||||
snprintf(str_tm, sizeof(str_tm), "%d", (int)tv.tv_usec/1000);
|
||||
if(str_tm[1] == '\0')str_tm[1] = '0';
|
||||
if(str_tm[2] == '\0')str_tm[2] = '0';
|
||||
strftime(log_str, sizeof(log_str), "%F %T.", &tmptr);
|
||||
strcat(log_str, str_tm);
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, "get_nic_info");
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, str);
|
||||
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
}
|
||||
fclose(log_fp);
|
||||
}
|
||||
}
|
||||
|
||||
void get_sem(int semid)
|
||||
{
|
||||
char err_str[200];
|
||||
struct sembuf lock[2];
|
||||
|
||||
lock[0].sem_num = 0;
|
||||
lock[0].sem_op = 0;
|
||||
lock[0].sem_flg = SEM_UNDO;
|
||||
|
||||
lock[1].sem_num = 0;
|
||||
lock[1].sem_op = 1;
|
||||
lock[1].sem_flg = SEM_UNDO;
|
||||
|
||||
while(semop(semid, lock, 2)){
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void release_sem(int semid)
|
||||
{
|
||||
int ret;
|
||||
char err_str[200];
|
||||
struct sembuf unlock;
|
||||
|
||||
unlock.sem_num = 0;
|
||||
unlock.sem_op = -1;
|
||||
unlock.sem_flg = SEM_UNDO;
|
||||
|
||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int init_nic_info(void)
|
||||
{
|
||||
int fd = -1;
|
||||
int sem_val;
|
||||
char err_str[200];
|
||||
key_t key;
|
||||
|
||||
|
||||
if ((key=ftok(sem_path, SEM_PROJ_ID)) == -1) {
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: ftok():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
if((semid = semget(key, 1, IPC_CREAT|0666)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Create semaphore error: %s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
return -1;
|
||||
}
|
||||
if(!sem_val){
|
||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if((fd = open(shm_path, O_RDONLY)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Error open %s: %s!\n",shm_path, strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
||||
if(ptr == MAP_FAILED){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
{
|
||||
int i,ret;
|
||||
time_t tamp;
|
||||
struct tm tmptr;
|
||||
DIR *dir;
|
||||
char *s;
|
||||
char buf[128];
|
||||
char err_str[200];
|
||||
struct passwd *user;
|
||||
|
||||
tamp = time(NULL);
|
||||
localtime_r(&tamp, &tmptr);
|
||||
|
||||
if((user = getpwnam("d5000"))!= NULL){
|
||||
sprintf(log_path,"%s",user->pw_dir);
|
||||
sprintf(shm_path,"%s",user->pw_dir);
|
||||
sprintf(sem_path,"%s",user->pw_dir);
|
||||
}
|
||||
strcat(log_path,LOG_PATH);
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
|
||||
if((dir = opendir(log_path)) == NULL){
|
||||
if(errno == ENOENT){
|
||||
strcpy(log_path, "/tmp/");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
s = strrchr(log_path, '/');
|
||||
s++;
|
||||
*s = '\0';
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
||||
strcat(buf, "sys_nicmonitor");
|
||||
strcat(buf, ".log");
|
||||
strcat(log_path, buf);
|
||||
if((ret = init_nic_info()) == -1){
|
||||
return -1;
|
||||
}
|
||||
get_sem(semid);
|
||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
||||
// get_sem(semid);
|
||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
||||
release_sem(semid);
|
||||
munmap(ptr, sizeof(SHM));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
release_sem(semid);
|
||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
||||
record_log(err_str);
|
||||
munmap(ptr, sizeof(SHM));
|
||||
return -1;
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
||||
//
|
||||
// FileName : procconf.h
|
||||
//
|
||||
// Function : this class realize some basic functions for process managerment,
|
||||
// such as initiate process, report status of process, check status of process,
|
||||
// update status of process, get information of process
|
||||
//
|
||||
// Author :
|
||||
//
|
||||
// Date :
|
||||
//
|
||||
// Modify by :
|
||||
//
|
||||
// Mod Date :
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _PROCCONF_H
|
||||
#define _PROCCONF_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
//#include <iostream.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "const.h"
|
||||
|
||||
//for alarm ................................
|
||||
typedef struct MESS_BH
|
||||
{
|
||||
unsigned char mtype;
|
||||
int length;
|
||||
};
|
||||
typedef struct PROCESS_ALM
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
unsigned char status;
|
||||
};
|
||||
//for alarm end .............................
|
||||
|
||||
//for mmi....................................
|
||||
const int MAX_BUFFER_LEN = 500;
|
||||
typedef struct MESS_BLOCK
|
||||
{
|
||||
unsigned char num;
|
||||
char buffer[MAX_BUFFER_LEN];
|
||||
};
|
||||
typedef struct MESS_PROC
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
char status;
|
||||
};
|
||||
//for mmi end ................................
|
||||
|
||||
const int DEFAULT_PERIOD = 3;
|
||||
const int COUNT_LIMIT = 2;
|
||||
const int START_DEFAULT_PERIOD = 60;
|
||||
const int START_COUNT_LIMIT = 5;
|
||||
const int APP_COUNT_LIMIT = 1;
|
||||
|
||||
//process critical level
|
||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
||||
//const int GENERAL = 4; // reboot the process
|
||||
const int CRUCIAL = 1; // crucial process
|
||||
const int GENERAL = 0; // general process
|
||||
|
||||
|
||||
extern int srv_init(char *service,int port);
|
||||
extern int Tcp_close(int sockfd);
|
||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
||||
extern int client_tcp_open(char *host,char *service,int port);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
pid_t proc_pid;
|
||||
}PROC_ADM_INFO;
|
||||
|
||||
//***************************************************************
|
||||
// structure name : PROC_INFO
|
||||
// function : store process informatin
|
||||
// author :
|
||||
// date :
|
||||
// modify by :
|
||||
// modification :
|
||||
// mod date :
|
||||
//***************************************************************
|
||||
typedef struct
|
||||
{
|
||||
int position;
|
||||
char node_name[MAX_STRING_LEN];
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
|
||||
unsigned char active_flag;
|
||||
unsigned char master_flag;
|
||||
|
||||
time_t startup_time;
|
||||
time_t refresh_time;
|
||||
short refresh_peri;
|
||||
unsigned char monitor_type;
|
||||
|
||||
pid_t proc_pid;
|
||||
unsigned char auto_start;
|
||||
unsigned char act_timer;
|
||||
unsigned char start_timer;
|
||||
unsigned char critical_level;
|
||||
|
||||
char exefile_path[MAX_EXECMD_LEN];
|
||||
|
||||
}PROC_INFO;
|
||||
|
||||
//***************************************************************
|
||||
// structure name : APP_INFO
|
||||
// function : store application informatin
|
||||
// author :
|
||||
// date :
|
||||
// modify by :
|
||||
// modification :
|
||||
// mod date :
|
||||
//***************************************************************
|
||||
typedef struct
|
||||
{
|
||||
int position;
|
||||
char context_name[MAX_STRING_LEN];
|
||||
int context_id;
|
||||
char app_name[MAX_STRING_LEN];
|
||||
int app_id;
|
||||
unsigned char act_timer;
|
||||
unsigned char active_flag;
|
||||
}APP_INFO;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int no_proc;
|
||||
int semdes_cfg;
|
||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
||||
APP_INFO app[MAX_LOCAL_APP];
|
||||
}PROCCFG;
|
||||
|
||||
class proc_invocation
|
||||
{
|
||||
public:
|
||||
int m_init;
|
||||
PROCCFG *proccfg_p;
|
||||
|
||||
public:
|
||||
proc_invocation();
|
||||
~proc_invocation();
|
||||
|
||||
int conf_create();
|
||||
//int check_proc_status();
|
||||
//int update_rtdb();
|
||||
//int kill_proc(pid_t pid);
|
||||
//int start_proc(char *cmdline);
|
||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
||||
|
||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
||||
int proc_report(int pos, char status, int intertime=3);
|
||||
int proc_exit(int proc_pos);
|
||||
|
||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
||||
int conf_map();
|
||||
|
||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
||||
int get_active_pid(int &num, int *p_pidlist);
|
||||
int is_proc_run(pid_t pid);
|
||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
#include "mnic.h"
|
||||
|
||||
static char *prase_digit(char **s)
|
||||
{
|
||||
char *retp = NULL;
|
||||
char *p = *s;
|
||||
|
||||
if(!p)return NULL;
|
||||
while(!isdigit(*p)){
|
||||
p++;
|
||||
if(*p == '\0')return NULL;
|
||||
}
|
||||
retp = p;
|
||||
while(isdigit(*p)){
|
||||
p++;
|
||||
if(*p == '\0'){
|
||||
*s = NULL;
|
||||
return retp;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
p++;
|
||||
*s = p;
|
||||
return retp;
|
||||
}
|
||||
|
||||
|
||||
char *get_name(char *name, char *p)
|
||||
{
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
while (*p) {
|
||||
if (isspace(*p))
|
||||
break;
|
||||
if (*p == ':') { /* could be an alias */
|
||||
char *dot = p, *dotname = name;
|
||||
*name++ = *p++;
|
||||
while (isdigit(*p))
|
||||
*name++ = *p++;
|
||||
if (*p != ':') { /* it wasn't, backup */
|
||||
p = dot;
|
||||
name = dotname;
|
||||
}
|
||||
if (*p == '\0')
|
||||
return NULL;
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
*name++ = *p++;
|
||||
}
|
||||
*name++ = '\0';
|
||||
return p;
|
||||
}
|
||||
|
||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
||||
{
|
||||
int i = 0;
|
||||
char *retp[16];
|
||||
|
||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
||||
ife->rx_bytes = atoll(retp[0]);
|
||||
ife->rx_packets = atoll(retp[1]);
|
||||
ife->rx_errors = atol(retp[2]);
|
||||
ife->rx_dropped = atol(retp[3]);
|
||||
ife->rx_fifo_errors = atol(retp[4]);
|
||||
ife->rx_multicast = atol(retp[7]);
|
||||
ife->tx_bytes = atoll(retp[8]);
|
||||
ife->tx_packets = atoll(retp[9]);
|
||||
ife->tx_errors = atol(retp[10]);
|
||||
ife->tx_dropped = atol(retp[11]);
|
||||
ife->tx_fifo_errors = atol(retp[12]);
|
||||
ife->collisions = atol(retp[13]);
|
||||
ife->tx_carrier_errors = atol(retp[14]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_fetch(NETCARD_INFO *ife)
|
||||
{
|
||||
int skfd;
|
||||
struct ifreq ifr;
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
|
||||
strcpy(ifr.ifr_name, ife->charname);
|
||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
||||
ife->flags = ifr.ifr_flags;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
||||
ife->hwaddr = ifr.ifr_hwaddr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
||||
ife->mtu = ifr.ifr_mtu;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
||||
ife->tx_queue_len = ifr.ifr_qlen;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
||||
ife->addr = ifr.ifr_addr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
||||
ife->broadaddr = ifr.ifr_broadaddr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
||||
ife->netmask = ifr.ifr_netmask;
|
||||
|
||||
ife->time_stamp = time(NULL);
|
||||
close(skfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int ioc_get_name(NETCARD_INFO *name)
|
||||
{
|
||||
int skfd;
|
||||
int ifrnum;
|
||||
int i = 0;
|
||||
struct ifconf ifc;
|
||||
struct ifreq buf[MAXNICNUM];
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
ifc.ifc_len = sizeof(buf);
|
||||
ifc.ifc_buf = (caddr_t) buf;
|
||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
||||
while(ifrnum-- > 0){
|
||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
||||
i++;
|
||||
}
|
||||
close(skfd);
|
||||
return i;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,28 +0,0 @@
|
||||
#! /usr/bin/make -f
|
||||
|
||||
DEFAULTS = Makefile.config
|
||||
|
||||
include $(DEFAULTS)
|
||||
|
||||
all:sys_nicmonitor libnic_shm.so
|
||||
|
||||
CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral #-g
|
||||
|
||||
sys_nicmonitor:mnic.o read_netcard.o send_alarm.o
|
||||
$(CC) -lman -ldotconf -lpthread -o $@ $^
|
||||
libnic_shm.so:nicinfo_shm.c
|
||||
$(CC) -fpic -shared -o $@ $^
|
||||
clean:
|
||||
$(RM) *.o
|
||||
$(RM) libnic_shm.so sys_nicmonitor
|
||||
install:
|
||||
$(MKDIR) -p $(LIBDIR)
|
||||
$(MKDIR) -p $(BINDIR)
|
||||
$(MKDIR) -p $(INCDIR)
|
||||
$(CP) libnic_shm.so $(LIBDIR)
|
||||
$(CP) sys_nicmonitor $(BINDIR)
|
||||
$(CP) nicinfo_shm.h $(INCDIR)
|
||||
uninstall:
|
||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
PREFIX = $(DESTDIR)
|
||||
|
||||
BINDIR = $(PREFIX)/usr/bin
|
||||
|
||||
LIBDIR = $(PREFIX)/usr/lib64
|
||||
|
||||
INCDIR = $(PREFIX)/usr/include
|
||||
|
||||
INSTALL_SH = ./install.sh
|
||||
|
||||
CP = cp
|
||||
RM = rm
|
||||
#CC = gcc
|
||||
CC = g++
|
||||
MKDIR = mkdir
|
||||
@@ -1,32 +0,0 @@
|
||||
|
||||
lijin:/home/d5000/lijin/sys_nicmonitor # ./sys_nicmonitor
|
||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
||||
udp bond0
|
||||
nic bond0
|
||||
nic eth0
|
||||
nic eth1
|
||||
|
||||
d5000@lijin:~ > cat var/log/netcard/20110110_sys_nicmonitor.log
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor NOTICE: sys_nicmonitor V1.5 is
|
||||
started !
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor udp bond0
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor nic bond0
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor nic eth0
|
||||
2011-01-10 11:10:37.762 sys_nicmonitor nic eth1
|
||||
2011-01-10 11:10:37.762 sys_nicmonitor NOTICE: bond0 is NORMAL!
|
||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth0 is NORMAL!
|
||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth1 is NORMAL!
|
||||
|
||||
与1.4不一样的地方在与增加log文件中的打印语句
|
||||
sys_nicmonitor started! version v1.4
|
||||
shm_path: /home/d5000/tmp
|
||||
log_path: /home/d5000/ var/log/netcard
|
||||
udp bond0
|
||||
nic bond0
|
||||
nic eth0
|
||||
nic eth1
|
||||
@@ -1,51 +0,0 @@
|
||||
#ifndef _RTE_CONST_H
|
||||
#define _RTE_CONST_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
#define MAX_STRING_LEN 24
|
||||
#define MAX_EXECMD_LEN 200
|
||||
#define MAX_FILENAME_LEN 200
|
||||
|
||||
#define MAX_CONTEXT 8
|
||||
#define MAX_HOSTNAME_LEN 24
|
||||
#define MAX_LOCAL_MESPROC 512
|
||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
||||
#define MAX_LOCAL_APP 32
|
||||
#define MAX_LOCAL_NODE 256
|
||||
|
||||
#define MAX_SET 256 //max num of event set
|
||||
#define MAX_EVENT 1300
|
||||
#define MAX_REG_PROC 20
|
||||
|
||||
#define LEN_SHMBLK_BIG 4096
|
||||
#define MAX_MSGBUF_LEN 32767
|
||||
#define FREE_PAGE_SIZE 65536
|
||||
#define MAX_PAGE_NUM 1024
|
||||
|
||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
||||
|
||||
#define DOMAIN_I 1
|
||||
#define DOMAIN_II 2
|
||||
#define DOMAIN_III 3
|
||||
|
||||
//Add 20090225
|
||||
const int PROC_TYPE_RPT =1;
|
||||
const int PROC_TYPE_UNRPT =0;
|
||||
//add end
|
||||
|
||||
|
||||
//status for proc and app
|
||||
const int NON_ACTIVE = 0;
|
||||
const int ACTIVE = 1;
|
||||
const int HANGUP = 2;
|
||||
const int FAILURE = 5;
|
||||
const int START = 6;
|
||||
const int STOP = 7;
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
||||
#ifndef __MNIC_H
|
||||
#define __MNIC_H
|
||||
|
||||
//#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/param.h>
|
||||
#include <linux/types.h>
|
||||
#include <glob.h>
|
||||
#include <linux/sockios.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "sys_netcard.h"
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#define IPSIZE 16
|
||||
|
||||
char *get_name(char *, char *);
|
||||
int if_fetch(NETCARD_INFO *);
|
||||
int ioc_get_name(NETCARD_INFO *);
|
||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
||||
int get_user_home(int , char *);
|
||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
||||
void record_log(char *);
|
||||
|
||||
#endif
|
||||
@@ -1,209 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "nicinfo_shm.h"
|
||||
|
||||
#define SHM_PATH "/tmp/sys_netcard_shm_path"
|
||||
#define SEM_PATH "/tmp/sys_netcard_sem_path"
|
||||
#define LOG_PATH "/var/log/netcard/"
|
||||
|
||||
typedef struct net_info{
|
||||
NETCARD_INFO info[MAXNICNUM];
|
||||
}SHM;
|
||||
|
||||
static int semid = 0;
|
||||
static char log_path[1024];
|
||||
static char shm_path[1024];
|
||||
static char sem_path[1024];
|
||||
SHM *ptr = NULL;
|
||||
|
||||
/* write error in logfile */
|
||||
void record_log(char *str)
|
||||
{
|
||||
time_t tamp;
|
||||
char str_tm[4];
|
||||
char log_str[512];
|
||||
FILE *log_fp = NULL;
|
||||
struct tm tmptr;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
if((log_fp = fopen(log_path, "a")) != NULL){
|
||||
tamp = time(NULL);
|
||||
memset(str_tm, 0, sizeof(str_tm));
|
||||
memset(log_str, 0, sizeof(log_str));
|
||||
localtime_r(&tamp, &tmptr);
|
||||
gettimeofday(&tv, &tz);
|
||||
snprintf(str_tm, sizeof(str_tm), "%d", (int)tv.tv_usec/1000);
|
||||
if(str_tm[1] == '\0')str_tm[1] = '0';
|
||||
if(str_tm[2] == '\0')str_tm[2] = '0';
|
||||
strftime(log_str, sizeof(log_str), "%F %T.", &tmptr);
|
||||
strcat(log_str, str_tm);
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, "get_nic_info");
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, str);
|
||||
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
}
|
||||
fclose(log_fp);
|
||||
}
|
||||
}
|
||||
|
||||
void get_sem(int semid)
|
||||
{
|
||||
char err_str[200];
|
||||
struct sembuf lock[2];
|
||||
|
||||
lock[0].sem_num = 0;
|
||||
lock[0].sem_op = 0;
|
||||
lock[0].sem_flg = SEM_UNDO;
|
||||
|
||||
lock[1].sem_num = 0;
|
||||
lock[1].sem_op = 1;
|
||||
lock[1].sem_flg = SEM_UNDO;
|
||||
|
||||
while(semop(semid, lock, 2)){
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void release_sem(int semid)
|
||||
{
|
||||
int ret;
|
||||
char err_str[200];
|
||||
struct sembuf unlock;
|
||||
|
||||
unlock.sem_num = 0;
|
||||
unlock.sem_op = -1;
|
||||
unlock.sem_flg = SEM_UNDO;
|
||||
|
||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int init_nic_info(void)
|
||||
{
|
||||
int fd = -1;
|
||||
int sem_val;
|
||||
char err_str[200];
|
||||
key_t key;
|
||||
|
||||
|
||||
if ((key=ftok(sem_path, SEM_PROJ_ID)) == -1) {
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: ftok():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
if((semid = semget(key, 1, IPC_CREAT|0666)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Create semaphore error: %s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
return -1;
|
||||
}
|
||||
if(!sem_val){
|
||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if((fd = open(shm_path, O_RDONLY)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Error open %s: %s!\n",shm_path, strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
||||
if(ptr == MAP_FAILED){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
{
|
||||
int i,ret;
|
||||
time_t tamp;
|
||||
struct tm tmptr;
|
||||
DIR *dir;
|
||||
char *s;
|
||||
char buf[128];
|
||||
char err_str[200];
|
||||
struct passwd *user;
|
||||
|
||||
tamp = time(NULL);
|
||||
localtime_r(&tamp, &tmptr);
|
||||
|
||||
if((user = getpwnam("d5000"))!= NULL){
|
||||
sprintf(log_path,"%s",user->pw_dir);
|
||||
sprintf(shm_path,"%s",user->pw_dir);
|
||||
sprintf(sem_path,"%s",user->pw_dir);
|
||||
}
|
||||
strcat(log_path,LOG_PATH);
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
|
||||
if((dir = opendir(log_path)) == NULL){
|
||||
if(errno == ENOENT){
|
||||
strcpy(log_path, "/tmp/");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
s = strrchr(log_path, '/');
|
||||
s++;
|
||||
*s = '\0';
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
||||
strcat(buf, "sys_nicmonitor");
|
||||
strcat(buf, ".log");
|
||||
strcat(log_path, buf);
|
||||
if((ret = init_nic_info()) == -1){
|
||||
return -1;
|
||||
}
|
||||
get_sem(semid);
|
||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
||||
// get_sem(semid);
|
||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
||||
release_sem(semid);
|
||||
munmap(ptr, sizeof(SHM));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
release_sem(semid);
|
||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
||||
record_log(err_str);
|
||||
munmap(ptr, sizeof(SHM));
|
||||
return -1;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#ifndef NIC_SHM_H
|
||||
#define NIC_SHM_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef NIC_NAME_LEN
|
||||
#define NIC_NAME_LEN 64
|
||||
#endif
|
||||
#define SEM_PROJ_ID 's'
|
||||
#define MAXNICNUM 32
|
||||
|
||||
typedef long KEYID;
|
||||
typedef struct _net_info
|
||||
{
|
||||
KEYID ID;
|
||||
char charname[NIC_NAME_LEN];
|
||||
char descr[128];
|
||||
struct sockaddr addr;
|
||||
struct sockaddr broadaddr;
|
||||
struct sockaddr netmask;
|
||||
struct sockaddr hwaddr;
|
||||
int time_stamp;
|
||||
short flags;
|
||||
int mtu;
|
||||
int tx_queue_len;
|
||||
unsigned long long average_flow;
|
||||
unsigned long long rx_packets;
|
||||
unsigned long long tx_packets;
|
||||
unsigned long long rx_bytes;
|
||||
unsigned long long tx_bytes;
|
||||
unsigned long rx_errors;
|
||||
unsigned long tx_errors;
|
||||
unsigned long rx_dropped;
|
||||
unsigned long tx_dropped;
|
||||
unsigned long rx_multicast;
|
||||
unsigned long collisions;
|
||||
unsigned long rx_fifo_errors;
|
||||
unsigned long tx_carrier_errors;
|
||||
unsigned long tx_fifo_errors;
|
||||
}NETCARD_INFO;
|
||||
|
||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,198 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
||||
//
|
||||
// FileName : procconf.h
|
||||
//
|
||||
// Function : this class realize some basic functions for process managerment,
|
||||
// such as initiate process, report status of process, check status of process,
|
||||
// update status of process, get information of process
|
||||
//
|
||||
// Author :
|
||||
//
|
||||
// Date :
|
||||
//
|
||||
// Modify by :
|
||||
//
|
||||
// Mod Date :
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _PROCCONF_H
|
||||
#define _PROCCONF_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
//#include <iostream.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "const.h"
|
||||
|
||||
//for alarm ................................
|
||||
typedef struct MESS_BH
|
||||
{
|
||||
unsigned char mtype;
|
||||
int length;
|
||||
};
|
||||
typedef struct PROCESS_ALM
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
unsigned char status;
|
||||
};
|
||||
//for alarm end .............................
|
||||
|
||||
//for mmi....................................
|
||||
const int MAX_BUFFER_LEN = 500;
|
||||
typedef struct MESS_BLOCK
|
||||
{
|
||||
unsigned char num;
|
||||
char buffer[MAX_BUFFER_LEN];
|
||||
};
|
||||
typedef struct MESS_PROC
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
char status;
|
||||
};
|
||||
//for mmi end ................................
|
||||
|
||||
const int DEFAULT_PERIOD = 3;
|
||||
const int COUNT_LIMIT = 2;
|
||||
const int START_DEFAULT_PERIOD = 60;
|
||||
const int START_COUNT_LIMIT = 5;
|
||||
const int APP_COUNT_LIMIT = 1;
|
||||
|
||||
//process critical level
|
||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
||||
//const int GENERAL = 4; // reboot the process
|
||||
const int CRUCIAL = 1; // crucial process
|
||||
const int GENERAL = 0; // general process
|
||||
|
||||
|
||||
extern int srv_init(char *service,int port);
|
||||
extern int Tcp_close(int sockfd);
|
||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
||||
extern int client_tcp_open(char *host,char *service,int port);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
pid_t proc_pid;
|
||||
}PROC_ADM_INFO;
|
||||
|
||||
//***************************************************************
|
||||
// structure name : PROC_INFO
|
||||
// function : store process informatin
|
||||
// author :
|
||||
// date :
|
||||
// modify by :
|
||||
// modification :
|
||||
// mod date :
|
||||
//***************************************************************
|
||||
typedef struct
|
||||
{
|
||||
int position;
|
||||
char node_name[MAX_STRING_LEN];
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
|
||||
unsigned char active_flag;
|
||||
unsigned char master_flag;
|
||||
|
||||
time_t startup_time;
|
||||
time_t refresh_time;
|
||||
short refresh_peri;
|
||||
unsigned char monitor_type;
|
||||
|
||||
pid_t proc_pid;
|
||||
unsigned char auto_start;
|
||||
unsigned char act_timer;
|
||||
unsigned char start_timer;
|
||||
unsigned char critical_level;
|
||||
|
||||
char exefile_path[MAX_EXECMD_LEN];
|
||||
|
||||
}PROC_INFO;
|
||||
|
||||
//***************************************************************
|
||||
// structure name : APP_INFO
|
||||
// function : store application informatin
|
||||
// author :
|
||||
// date :
|
||||
// modify by :
|
||||
// modification :
|
||||
// mod date :
|
||||
//***************************************************************
|
||||
typedef struct
|
||||
{
|
||||
int position;
|
||||
char context_name[MAX_STRING_LEN];
|
||||
int context_id;
|
||||
char app_name[MAX_STRING_LEN];
|
||||
int app_id;
|
||||
unsigned char act_timer;
|
||||
unsigned char active_flag;
|
||||
}APP_INFO;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int no_proc;
|
||||
int semdes_cfg;
|
||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
||||
APP_INFO app[MAX_LOCAL_APP];
|
||||
}PROCCFG;
|
||||
|
||||
class proc_invocation
|
||||
{
|
||||
public:
|
||||
int m_init;
|
||||
PROCCFG *proccfg_p;
|
||||
|
||||
public:
|
||||
proc_invocation();
|
||||
~proc_invocation();
|
||||
|
||||
int conf_create();
|
||||
//int check_proc_status();
|
||||
//int update_rtdb();
|
||||
//int kill_proc(pid_t pid);
|
||||
//int start_proc(char *cmdline);
|
||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
||||
|
||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
||||
int proc_report(int pos, char status, int intertime=3);
|
||||
int proc_exit(int proc_pos);
|
||||
|
||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
||||
int conf_map();
|
||||
|
||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
||||
int get_active_pid(int &num, int *p_pidlist);
|
||||
int is_proc_run(pid_t pid);
|
||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
#include "mnic.h"
|
||||
|
||||
static char *prase_digit(char **s)
|
||||
{
|
||||
char *retp = NULL;
|
||||
char *p = *s;
|
||||
|
||||
if(!p)return NULL;
|
||||
while(!isdigit(*p)){
|
||||
p++;
|
||||
if(*p == '\0')return NULL;
|
||||
}
|
||||
retp = p;
|
||||
while(isdigit(*p)){
|
||||
p++;
|
||||
if(*p == '\0'){
|
||||
*s = NULL;
|
||||
return retp;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
p++;
|
||||
*s = p;
|
||||
return retp;
|
||||
}
|
||||
|
||||
|
||||
char *get_name(char *name, char *p)
|
||||
{
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
while (*p) {
|
||||
if (isspace(*p))
|
||||
break;
|
||||
if (*p == ':') { /* could be an alias */
|
||||
char *dot = p, *dotname = name;
|
||||
*name++ = *p++;
|
||||
while (isdigit(*p))
|
||||
*name++ = *p++;
|
||||
if (*p != ':') { /* it wasn't, backup */
|
||||
p = dot;
|
||||
name = dotname;
|
||||
}
|
||||
if (*p == '\0')
|
||||
return NULL;
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
*name++ = *p++;
|
||||
}
|
||||
*name++ = '\0';
|
||||
return p;
|
||||
}
|
||||
|
||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
||||
{
|
||||
int i = 0;
|
||||
char *retp[16];
|
||||
|
||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
||||
ife->rx_bytes = atoll(retp[0]);
|
||||
ife->rx_packets = atoll(retp[1]);
|
||||
ife->rx_errors = atol(retp[2]);
|
||||
ife->rx_dropped = atol(retp[3]);
|
||||
ife->rx_fifo_errors = atol(retp[4]);
|
||||
ife->rx_multicast = atol(retp[7]);
|
||||
ife->tx_bytes = atoll(retp[8]);
|
||||
ife->tx_packets = atoll(retp[9]);
|
||||
ife->tx_errors = atol(retp[10]);
|
||||
ife->tx_dropped = atol(retp[11]);
|
||||
ife->tx_fifo_errors = atol(retp[12]);
|
||||
ife->collisions = atol(retp[13]);
|
||||
ife->tx_carrier_errors = atol(retp[14]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_fetch(NETCARD_INFO *ife)
|
||||
{
|
||||
int skfd;
|
||||
struct ifreq ifr;
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
|
||||
strcpy(ifr.ifr_name, ife->charname);
|
||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
||||
ife->flags = ifr.ifr_flags;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
||||
ife->hwaddr = ifr.ifr_hwaddr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
||||
ife->mtu = ifr.ifr_mtu;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
||||
ife->tx_queue_len = ifr.ifr_qlen;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
||||
ife->addr = ifr.ifr_addr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
||||
ife->broadaddr = ifr.ifr_broadaddr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
||||
ife->netmask = ifr.ifr_netmask;
|
||||
|
||||
ife->time_stamp = time(NULL);
|
||||
close(skfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int ioc_get_name(NETCARD_INFO *name)
|
||||
{
|
||||
int skfd;
|
||||
int ifrnum;
|
||||
int i = 0;
|
||||
struct ifconf ifc;
|
||||
struct ifreq buf[MAXNICNUM];
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
ifc.ifc_len = sizeof(buf);
|
||||
ifc.ifc_buf = (caddr_t) buf;
|
||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
||||
while(ifrnum-- > 0){
|
||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
||||
i++;
|
||||
}
|
||||
close(skfd);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#include "mnic.h"
|
||||
|
||||
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
||||
{
|
||||
int bytes;
|
||||
int sock_sd;
|
||||
int val;
|
||||
char error_str[200];
|
||||
struct sockaddr_in recever;
|
||||
socklen_t sock_len;
|
||||
|
||||
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
val=1;
|
||||
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
/* init socket*/
|
||||
recever.sin_family = AF_INET;
|
||||
recever.sin_port = htons(socket_port);
|
||||
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
||||
sock_len = sizeof(recever);
|
||||
/* send alarm*/
|
||||
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
||||
//record_log(error_str);
|
||||
close(sock_sd);
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
#ifndef _SYS_NETCARD_H
|
||||
#define _SYS_NETCARD_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef NIC_NAME_LEN
|
||||
#define NIC_NAME_LEN 64
|
||||
#endif
|
||||
|
||||
#define SEM_PROJ_ID 's'
|
||||
#define MAXNICNUM 32
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
typedef long KEYID;
|
||||
|
||||
typedef struct _msg_frame // message frame
|
||||
{
|
||||
short len; // message length
|
||||
short seqno; // send sequence
|
||||
short serv; // services ID
|
||||
short event; // event ID
|
||||
unsigned char domain; // domain ID
|
||||
unsigned char ctxt; // Context ID
|
||||
short stid; // SOURCE task id
|
||||
short dtid; // DESTINATION task ID
|
||||
unsigned char ver_coding; // 版本号 + 编码
|
||||
unsigned char mes_type; // 帧类型
|
||||
}MSG_FRAME, *LPMSG_FRAME;
|
||||
|
||||
typedef struct _net_info
|
||||
{
|
||||
KEYID ID;
|
||||
char charname[NIC_NAME_LEN];
|
||||
char descr[128];
|
||||
struct sockaddr addr;
|
||||
struct sockaddr broadaddr;
|
||||
struct sockaddr netmask;
|
||||
struct sockaddr hwaddr;
|
||||
int time_stamp;
|
||||
short flags;
|
||||
int mtu;
|
||||
int tx_queue_len;
|
||||
unsigned long long average_flow;
|
||||
unsigned long long rx_packets;
|
||||
unsigned long long tx_packets;
|
||||
unsigned long long rx_bytes;
|
||||
unsigned long long tx_bytes;
|
||||
unsigned long rx_errors;
|
||||
unsigned long tx_errors;
|
||||
unsigned long rx_dropped;
|
||||
unsigned long tx_dropped;
|
||||
unsigned long rx_multicast;
|
||||
unsigned long collisions;
|
||||
unsigned long rx_fifo_errors;
|
||||
unsigned long tx_carrier_errors;
|
||||
unsigned long tx_fifo_errors;
|
||||
}NETCARD_INFO, *LPNETCARD_INFO;
|
||||
|
||||
#define NETCARD_ALARM_FAULT 1
|
||||
#define NETCARD_ALARM_RESUME 2
|
||||
#define NETCARD_ALARM_SWITCH 3
|
||||
#define NETCARD_ALARM_ABNORMAL 4
|
||||
#define NETCARD_ALARM_NORMAL 5
|
||||
typedef struct _sys_netcard_alarm
|
||||
{
|
||||
char fault_devname[NIC_NAME_LEN]; /*故障设备名称 */
|
||||
char switch_devname[NIC_NAME_LEN]; /*切换设备名称 */
|
||||
short flags; /* 状态标记 : 1:网卡故障。2:网卡恢复。3:网卡切换。4:流量异常。*/
|
||||
short retrytimes; //0,1,2 重发次数
|
||||
}SYS_NETCARD_ALARM, *LPSYS_NETCARD_ALARM;
|
||||
|
||||
|
||||
typedef struct _d5000_nic_alarm
|
||||
{
|
||||
MSG_FRAME tMsgFrame ;
|
||||
SYS_NETCARD_ALARM tSysNetcardAlarm ;
|
||||
}D5000_NIC_ALARM, *LPD5000_NIC_ALARM;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Binary file not shown.
@@ -1,28 +0,0 @@
|
||||
#! /usr/bin/make -f
|
||||
|
||||
DEFAULTS = Makefile.config
|
||||
|
||||
include $(DEFAULTS)
|
||||
|
||||
all:sys_nicmonitor libnic_shm.so
|
||||
|
||||
CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral #-g
|
||||
|
||||
sys_nicmonitor:mnic.o read_netcard.o send_alarm.o
|
||||
$(CC) -lman -ldotconf -lpthread -o $@ $^
|
||||
libnic_shm.so:nicinfo_shm.c
|
||||
$(CC) -fpic -shared -o $@ $^
|
||||
clean:
|
||||
$(RM) *.o
|
||||
$(RM) libnic_shm.so sys_nicmonitor
|
||||
install:
|
||||
$(MKDIR) -p $(LIBDIR)
|
||||
$(MKDIR) -p $(BINDIR)
|
||||
$(MKDIR) -p $(INCDIR)
|
||||
$(CP) libnic_shm.so $(LIBDIR)
|
||||
$(CP) sys_nicmonitor $(BINDIR)
|
||||
$(CP) nicinfo_shm.h $(INCDIR)
|
||||
uninstall:
|
||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
PREFIX = $(DESTDIR)
|
||||
|
||||
BINDIR = $(PREFIX)/usr/bin
|
||||
|
||||
LIBDIR = $(PREFIX)/usr/lib64
|
||||
|
||||
INCDIR = $(PREFIX)/usr/include
|
||||
|
||||
INSTALL_SH = ./install.sh
|
||||
|
||||
CP = cp
|
||||
RM = rm
|
||||
#CC = gcc
|
||||
CC = g++
|
||||
MKDIR = mkdir
|
||||
@@ -1,32 +0,0 @@
|
||||
|
||||
lijin:/home/d5000/lijin/sys_nicmonitor # ./sys_nicmonitor
|
||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
||||
udp bond0
|
||||
nic bond0
|
||||
nic eth0
|
||||
nic eth1
|
||||
|
||||
d5000@lijin:~ > cat var/log/netcard/20110110_sys_nicmonitor.log
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor NOTICE: sys_nicmonitor V1.5 is
|
||||
started !
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
||||
shm_path:/home/d5000/tmp/sys_netcard_shm_path
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor
|
||||
log_path:/home/d5000/var/log/netcard/20110110_sys_nicmonitor.log
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor udp bond0
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor nic bond0
|
||||
2011-01-10 11:10:37.761 sys_nicmonitor nic eth0
|
||||
2011-01-10 11:10:37.762 sys_nicmonitor nic eth1
|
||||
2011-01-10 11:10:37.762 sys_nicmonitor NOTICE: bond0 is NORMAL!
|
||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth0 is NORMAL!
|
||||
2011-01-10 11:10:37.763 sys_nicmonitor NOTICE: eth1 is NORMAL!
|
||||
|
||||
与1.4不一样的地方在与增加log文件中的打印语句
|
||||
sys_nicmonitor started! version v1.4
|
||||
shm_path: /home/d5000/tmp
|
||||
log_path: /home/d5000/ var/log/netcard
|
||||
udp bond0
|
||||
nic bond0
|
||||
nic eth0
|
||||
nic eth1
|
||||
@@ -1,2 +0,0 @@
|
||||
V1.5与V1.6差异
|
||||
将ping_gw中的system调用改为popen减少系统误报
|
||||
@@ -1,51 +0,0 @@
|
||||
#ifndef _RTE_CONST_H
|
||||
#define _RTE_CONST_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
#define MAX_STRING_LEN 24
|
||||
#define MAX_EXECMD_LEN 200
|
||||
#define MAX_FILENAME_LEN 200
|
||||
|
||||
#define MAX_CONTEXT 8
|
||||
#define MAX_HOSTNAME_LEN 24
|
||||
#define MAX_LOCAL_MESPROC 512
|
||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
||||
#define MAX_LOCAL_APP 32
|
||||
#define MAX_LOCAL_NODE 256
|
||||
|
||||
#define MAX_SET 256 //max num of event set
|
||||
#define MAX_EVENT 1300
|
||||
#define MAX_REG_PROC 20
|
||||
|
||||
#define LEN_SHMBLK_BIG 4096
|
||||
#define MAX_MSGBUF_LEN 32767
|
||||
#define FREE_PAGE_SIZE 65536
|
||||
#define MAX_PAGE_NUM 1024
|
||||
|
||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
||||
|
||||
#define DOMAIN_I 1
|
||||
#define DOMAIN_II 2
|
||||
#define DOMAIN_III 3
|
||||
|
||||
//Add 20090225
|
||||
const int PROC_TYPE_RPT =1;
|
||||
const int PROC_TYPE_UNRPT =0;
|
||||
//add end
|
||||
|
||||
|
||||
//status for proc and app
|
||||
const int NON_ACTIVE = 0;
|
||||
const int ACTIVE = 1;
|
||||
const int HANGUP = 2;
|
||||
const int FAILURE = 5;
|
||||
const int START = 6;
|
||||
const int STOP = 7;
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
||||
#ifndef __MNIC_H
|
||||
#define __MNIC_H
|
||||
|
||||
//#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/param.h>
|
||||
#include <linux/types.h>
|
||||
#include <glob.h>
|
||||
#include <linux/sockios.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "sys_netcard.h"
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#define IPSIZE 16
|
||||
|
||||
char *get_name(char *, char *);
|
||||
int if_fetch(NETCARD_INFO *);
|
||||
int ioc_get_name(NETCARD_INFO *);
|
||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
||||
int get_user_home(int , char *);
|
||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
||||
void record_log(char *);
|
||||
|
||||
#endif
|
||||
@@ -1,209 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include "nicinfo_shm.h"
|
||||
|
||||
#define SHM_PATH "/tmp/sys_netcard_shm_path"
|
||||
#define SEM_PATH "/tmp/sys_netcard_sem_path"
|
||||
#define LOG_PATH "/var/log/netcard/"
|
||||
|
||||
typedef struct net_info{
|
||||
NETCARD_INFO info[MAXNICNUM];
|
||||
}SHM;
|
||||
|
||||
static int semid = 0;
|
||||
static char log_path[1024];
|
||||
static char shm_path[1024];
|
||||
static char sem_path[1024];
|
||||
SHM *ptr = NULL;
|
||||
|
||||
/* write error in logfile */
|
||||
void record_log(char *str)
|
||||
{
|
||||
time_t tamp;
|
||||
char str_tm[4];
|
||||
char log_str[512];
|
||||
FILE *log_fp = NULL;
|
||||
struct tm tmptr;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
if((log_fp = fopen(log_path, "a")) != NULL){
|
||||
tamp = time(NULL);
|
||||
memset(str_tm, 0, sizeof(str_tm));
|
||||
memset(log_str, 0, sizeof(log_str));
|
||||
localtime_r(&tamp, &tmptr);
|
||||
gettimeofday(&tv, &tz);
|
||||
snprintf(str_tm, sizeof(str_tm), "%d", (int)tv.tv_usec/1000);
|
||||
if(str_tm[1] == '\0')str_tm[1] = '0';
|
||||
if(str_tm[2] == '\0')str_tm[2] = '0';
|
||||
strftime(log_str, sizeof(log_str), "%F %T.", &tmptr);
|
||||
strcat(log_str, str_tm);
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, "get_nic_info");
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, str);
|
||||
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
}
|
||||
fclose(log_fp);
|
||||
}
|
||||
}
|
||||
|
||||
void get_sem(int semid)
|
||||
{
|
||||
char err_str[200];
|
||||
struct sembuf lock[2];
|
||||
|
||||
lock[0].sem_num = 0;
|
||||
lock[0].sem_op = 0;
|
||||
lock[0].sem_flg = SEM_UNDO;
|
||||
|
||||
lock[1].sem_num = 0;
|
||||
lock[1].sem_op = 1;
|
||||
lock[1].sem_flg = SEM_UNDO;
|
||||
|
||||
while(semop(semid, lock, 2)){
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void release_sem(int semid)
|
||||
{
|
||||
int ret;
|
||||
char err_str[200];
|
||||
struct sembuf unlock;
|
||||
|
||||
unlock.sem_num = 0;
|
||||
unlock.sem_op = -1;
|
||||
unlock.sem_flg = SEM_UNDO;
|
||||
|
||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int init_nic_info(void)
|
||||
{
|
||||
int fd = -1;
|
||||
int sem_val;
|
||||
char err_str[200];
|
||||
key_t key;
|
||||
|
||||
|
||||
if ((key=ftok(sem_path, SEM_PROJ_ID)) == -1) {
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: ftok():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
if((semid = semget(key, 1, IPC_CREAT|0666)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Create semaphore error: %s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
return -1;
|
||||
}
|
||||
if(!sem_val){
|
||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
if((fd = open(shm_path, O_RDONLY)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Error open %s: %s!\n",shm_path, strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
||||
if(ptr == MAP_FAILED){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
{
|
||||
int i,ret;
|
||||
time_t tamp;
|
||||
struct tm tmptr;
|
||||
DIR *dir;
|
||||
char *s;
|
||||
char buf[128];
|
||||
char err_str[200];
|
||||
struct passwd *user;
|
||||
|
||||
tamp = time(NULL);
|
||||
localtime_r(&tamp, &tmptr);
|
||||
|
||||
if((user = getpwnam("d5000"))!= NULL){
|
||||
sprintf(log_path,"%s",user->pw_dir);
|
||||
sprintf(shm_path,"%s",user->pw_dir);
|
||||
sprintf(sem_path,"%s",user->pw_dir);
|
||||
}
|
||||
strcat(log_path,LOG_PATH);
|
||||
strcat(shm_path,SHM_PATH);
|
||||
strcat(sem_path,SEM_PATH);
|
||||
|
||||
if((dir = opendir(log_path)) == NULL){
|
||||
if(errno == ENOENT){
|
||||
strcpy(log_path, "/tmp/");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
s = strrchr(log_path, '/');
|
||||
s++;
|
||||
*s = '\0';
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
||||
strcat(buf, "sys_nicmonitor");
|
||||
strcat(buf, ".log");
|
||||
strcat(log_path, buf);
|
||||
if((ret = init_nic_info()) == -1){
|
||||
return -1;
|
||||
}
|
||||
get_sem(semid);
|
||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
||||
// get_sem(semid);
|
||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
||||
release_sem(semid);
|
||||
munmap(ptr, sizeof(SHM));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
release_sem(semid);
|
||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
||||
record_log(err_str);
|
||||
munmap(ptr, sizeof(SHM));
|
||||
return -1;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#ifndef NIC_SHM_H
|
||||
#define NIC_SHM_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef NIC_NAME_LEN
|
||||
#define NIC_NAME_LEN 64
|
||||
#endif
|
||||
#define SEM_PROJ_ID 's'
|
||||
#define MAXNICNUM 32
|
||||
|
||||
typedef long KEYID;
|
||||
typedef struct _net_info
|
||||
{
|
||||
KEYID ID;
|
||||
char charname[NIC_NAME_LEN];
|
||||
char descr[128];
|
||||
struct sockaddr addr;
|
||||
struct sockaddr broadaddr;
|
||||
struct sockaddr netmask;
|
||||
struct sockaddr hwaddr;
|
||||
int time_stamp;
|
||||
short flags;
|
||||
int mtu;
|
||||
int tx_queue_len;
|
||||
unsigned long long average_flow;
|
||||
unsigned long long rx_packets;
|
||||
unsigned long long tx_packets;
|
||||
unsigned long long rx_bytes;
|
||||
unsigned long long tx_bytes;
|
||||
unsigned long rx_errors;
|
||||
unsigned long tx_errors;
|
||||
unsigned long rx_dropped;
|
||||
unsigned long tx_dropped;
|
||||
unsigned long rx_multicast;
|
||||
unsigned long collisions;
|
||||
unsigned long rx_fifo_errors;
|
||||
unsigned long tx_carrier_errors;
|
||||
unsigned long tx_fifo_errors;
|
||||
}NETCARD_INFO;
|
||||
|
||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,198 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
||||
//
|
||||
// FileName : procconf.h
|
||||
//
|
||||
// Function : this class realize some basic functions for process managerment,
|
||||
// such as initiate process, report status of process, check status of process,
|
||||
// update status of process, get information of process
|
||||
//
|
||||
// Author :
|
||||
//
|
||||
// Date :
|
||||
//
|
||||
// Modify by :
|
||||
//
|
||||
// Mod Date :
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _PROCCONF_H
|
||||
#define _PROCCONF_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
//#include <iostream.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "const.h"
|
||||
|
||||
//for alarm ................................
|
||||
typedef struct MESS_BH
|
||||
{
|
||||
unsigned char mtype;
|
||||
int length;
|
||||
};
|
||||
typedef struct PROCESS_ALM
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
unsigned char status;
|
||||
};
|
||||
//for alarm end .............................
|
||||
|
||||
//for mmi....................................
|
||||
const int MAX_BUFFER_LEN = 500;
|
||||
typedef struct MESS_BLOCK
|
||||
{
|
||||
unsigned char num;
|
||||
char buffer[MAX_BUFFER_LEN];
|
||||
};
|
||||
typedef struct MESS_PROC
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
char status;
|
||||
};
|
||||
//for mmi end ................................
|
||||
|
||||
const int DEFAULT_PERIOD = 3;
|
||||
const int COUNT_LIMIT = 2;
|
||||
const int START_DEFAULT_PERIOD = 60;
|
||||
const int START_COUNT_LIMIT = 5;
|
||||
const int APP_COUNT_LIMIT = 1;
|
||||
|
||||
//process critical level
|
||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
||||
//const int GENERAL = 4; // reboot the process
|
||||
const int CRUCIAL = 1; // crucial process
|
||||
const int GENERAL = 0; // general process
|
||||
|
||||
|
||||
extern int srv_init(char *service,int port);
|
||||
extern int Tcp_close(int sockfd);
|
||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
||||
extern int client_tcp_open(char *host,char *service,int port);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
pid_t proc_pid;
|
||||
}PROC_ADM_INFO;
|
||||
|
||||
//***************************************************************
|
||||
// structure name : PROC_INFO
|
||||
// function : store process informatin
|
||||
// author :
|
||||
// date :
|
||||
// modify by :
|
||||
// modification :
|
||||
// mod date :
|
||||
//***************************************************************
|
||||
typedef struct
|
||||
{
|
||||
int position;
|
||||
char node_name[MAX_STRING_LEN];
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
|
||||
unsigned char active_flag;
|
||||
unsigned char master_flag;
|
||||
|
||||
time_t startup_time;
|
||||
time_t refresh_time;
|
||||
short refresh_peri;
|
||||
unsigned char monitor_type;
|
||||
|
||||
pid_t proc_pid;
|
||||
unsigned char auto_start;
|
||||
unsigned char act_timer;
|
||||
unsigned char start_timer;
|
||||
unsigned char critical_level;
|
||||
|
||||
char exefile_path[MAX_EXECMD_LEN];
|
||||
|
||||
}PROC_INFO;
|
||||
|
||||
//***************************************************************
|
||||
// structure name : APP_INFO
|
||||
// function : store application informatin
|
||||
// author :
|
||||
// date :
|
||||
// modify by :
|
||||
// modification :
|
||||
// mod date :
|
||||
//***************************************************************
|
||||
typedef struct
|
||||
{
|
||||
int position;
|
||||
char context_name[MAX_STRING_LEN];
|
||||
int context_id;
|
||||
char app_name[MAX_STRING_LEN];
|
||||
int app_id;
|
||||
unsigned char act_timer;
|
||||
unsigned char active_flag;
|
||||
}APP_INFO;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int no_proc;
|
||||
int semdes_cfg;
|
||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
||||
APP_INFO app[MAX_LOCAL_APP];
|
||||
}PROCCFG;
|
||||
|
||||
class proc_invocation
|
||||
{
|
||||
public:
|
||||
int m_init;
|
||||
PROCCFG *proccfg_p;
|
||||
|
||||
public:
|
||||
proc_invocation();
|
||||
~proc_invocation();
|
||||
|
||||
int conf_create();
|
||||
//int check_proc_status();
|
||||
//int update_rtdb();
|
||||
//int kill_proc(pid_t pid);
|
||||
//int start_proc(char *cmdline);
|
||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
||||
|
||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
||||
int proc_report(int pos, char status, int intertime=3);
|
||||
int proc_exit(int proc_pos);
|
||||
|
||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
||||
int conf_map();
|
||||
|
||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
||||
int get_active_pid(int &num, int *p_pidlist);
|
||||
int is_proc_run(pid_t pid);
|
||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
#include "mnic.h"
|
||||
|
||||
static char *prase_digit(char **s)
|
||||
{
|
||||
char *retp = NULL;
|
||||
char *p = *s;
|
||||
|
||||
if(!p)return NULL;
|
||||
while(!isdigit(*p)){
|
||||
p++;
|
||||
if(*p == '\0')return NULL;
|
||||
}
|
||||
retp = p;
|
||||
while(isdigit(*p)){
|
||||
p++;
|
||||
if(*p == '\0'){
|
||||
*s = NULL;
|
||||
return retp;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
p++;
|
||||
*s = p;
|
||||
return retp;
|
||||
}
|
||||
|
||||
|
||||
char *get_name(char *name, char *p)
|
||||
{
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
while (*p) {
|
||||
if (isspace(*p))
|
||||
break;
|
||||
if (*p == ':') { /* could be an alias */
|
||||
char *dot = p, *dotname = name;
|
||||
*name++ = *p++;
|
||||
while (isdigit(*p))
|
||||
*name++ = *p++;
|
||||
if (*p != ':') { /* it wasn't, backup */
|
||||
p = dot;
|
||||
name = dotname;
|
||||
}
|
||||
if (*p == '\0')
|
||||
return NULL;
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
*name++ = *p++;
|
||||
}
|
||||
*name++ = '\0';
|
||||
return p;
|
||||
}
|
||||
|
||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
||||
{
|
||||
int i = 0;
|
||||
char *retp[16];
|
||||
|
||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
||||
ife->rx_bytes = atoll(retp[0]);
|
||||
ife->rx_packets = atoll(retp[1]);
|
||||
ife->rx_errors = atol(retp[2]);
|
||||
ife->rx_dropped = atol(retp[3]);
|
||||
ife->rx_fifo_errors = atol(retp[4]);
|
||||
ife->rx_multicast = atol(retp[7]);
|
||||
ife->tx_bytes = atoll(retp[8]);
|
||||
ife->tx_packets = atoll(retp[9]);
|
||||
ife->tx_errors = atol(retp[10]);
|
||||
ife->tx_dropped = atol(retp[11]);
|
||||
ife->tx_fifo_errors = atol(retp[12]);
|
||||
ife->collisions = atol(retp[13]);
|
||||
ife->tx_carrier_errors = atol(retp[14]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_fetch(NETCARD_INFO *ife)
|
||||
{
|
||||
int skfd;
|
||||
struct ifreq ifr;
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
|
||||
strcpy(ifr.ifr_name, ife->charname);
|
||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
||||
ife->flags = ifr.ifr_flags;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
||||
ife->hwaddr = ifr.ifr_hwaddr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
||||
ife->mtu = ifr.ifr_mtu;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
||||
ife->tx_queue_len = ifr.ifr_qlen;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
||||
ife->addr = ifr.ifr_addr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
||||
ife->broadaddr = ifr.ifr_broadaddr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
||||
ife->netmask = ifr.ifr_netmask;
|
||||
|
||||
ife->time_stamp = time(NULL);
|
||||
close(skfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int ioc_get_name(NETCARD_INFO *name)
|
||||
{
|
||||
int skfd;
|
||||
int ifrnum;
|
||||
int i = 0;
|
||||
struct ifconf ifc;
|
||||
struct ifreq buf[MAXNICNUM];
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
ifc.ifc_len = sizeof(buf);
|
||||
ifc.ifc_buf = (caddr_t) buf;
|
||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
||||
while(ifrnum-- > 0){
|
||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
||||
i++;
|
||||
}
|
||||
close(skfd);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#include "mnic.h"
|
||||
|
||||
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
||||
{
|
||||
int bytes;
|
||||
int sock_sd;
|
||||
int val;
|
||||
char error_str[200];
|
||||
struct sockaddr_in recever;
|
||||
socklen_t sock_len;
|
||||
|
||||
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
val=1;
|
||||
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
/* init socket*/
|
||||
recever.sin_family = AF_INET;
|
||||
recever.sin_port = htons(socket_port);
|
||||
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
||||
sock_len = sizeof(recever);
|
||||
/* send alarm*/
|
||||
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
||||
//record_log(error_str);
|
||||
close(sock_sd);
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
#ifndef _SYS_NETCARD_H
|
||||
#define _SYS_NETCARD_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef NIC_NAME_LEN
|
||||
#define NIC_NAME_LEN 64
|
||||
#endif
|
||||
|
||||
#define SEM_PROJ_ID 's'
|
||||
#define MAXNICNUM 32
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
typedef long KEYID;
|
||||
|
||||
typedef struct _msg_frame // message frame
|
||||
{
|
||||
short len; // message length
|
||||
short seqno; // send sequence
|
||||
short serv; // services ID
|
||||
short event; // event ID
|
||||
unsigned char domain; // domain ID
|
||||
unsigned char ctxt; // Context ID
|
||||
short stid; // SOURCE task id
|
||||
short dtid; // DESTINATION task ID
|
||||
unsigned char ver_coding; // 版本号 + 编码
|
||||
unsigned char mes_type; // 帧类型
|
||||
}MSG_FRAME, *LPMSG_FRAME;
|
||||
|
||||
typedef struct _net_info
|
||||
{
|
||||
KEYID ID;
|
||||
char charname[NIC_NAME_LEN];
|
||||
char descr[128];
|
||||
struct sockaddr addr;
|
||||
struct sockaddr broadaddr;
|
||||
struct sockaddr netmask;
|
||||
struct sockaddr hwaddr;
|
||||
int time_stamp;
|
||||
short flags;
|
||||
int mtu;
|
||||
int tx_queue_len;
|
||||
unsigned long long average_flow;
|
||||
unsigned long long rx_packets;
|
||||
unsigned long long tx_packets;
|
||||
unsigned long long rx_bytes;
|
||||
unsigned long long tx_bytes;
|
||||
unsigned long rx_errors;
|
||||
unsigned long tx_errors;
|
||||
unsigned long rx_dropped;
|
||||
unsigned long tx_dropped;
|
||||
unsigned long rx_multicast;
|
||||
unsigned long collisions;
|
||||
unsigned long rx_fifo_errors;
|
||||
unsigned long tx_carrier_errors;
|
||||
unsigned long tx_fifo_errors;
|
||||
}NETCARD_INFO, *LPNETCARD_INFO;
|
||||
|
||||
#define NETCARD_ALARM_FAULT 1
|
||||
#define NETCARD_ALARM_RESUME 2
|
||||
#define NETCARD_ALARM_SWITCH 3
|
||||
#define NETCARD_ALARM_ABNORMAL 4
|
||||
#define NETCARD_ALARM_NORMAL 5
|
||||
typedef struct _sys_netcard_alarm
|
||||
{
|
||||
char fault_devname[NIC_NAME_LEN]; /*故障设备名称 */
|
||||
char switch_devname[NIC_NAME_LEN]; /*切换设备名称 */
|
||||
short flags; /* 状态标记 : 1:网卡故障。2:网卡恢复。3:网卡切换。4:流量异常。*/
|
||||
short retrytimes; //0,1,2 重发次数
|
||||
}SYS_NETCARD_ALARM, *LPSYS_NETCARD_ALARM;
|
||||
|
||||
|
||||
typedef struct _d5000_nic_alarm
|
||||
{
|
||||
MSG_FRAME tMsgFrame ;
|
||||
SYS_NETCARD_ALARM tSysNetcardAlarm ;
|
||||
}D5000_NIC_ALARM, *LPD5000_NIC_ALARM;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Binary file not shown.
51
code/README
Normal file
51
code/README
Normal file
@@ -0,0 +1,51 @@
|
||||
=========
|
||||
编译前准备:
|
||||
* 安装dotconf相关软件包。
|
||||
* 拷贝libproc_common.so库文件到动态库中
|
||||
|
||||
编译说明:
|
||||
在Rocky 4.2上编译
|
||||
1. 执行 sh 42/run.sh
|
||||
2 执行: sh build.sh
|
||||
将在当前的目录下生成安装包:
|
||||
sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
在Linx 90上编译
|
||||
1. 执行 sh 90/run.sh
|
||||
2. 进入到sys_nicmonitor中执行make
|
||||
将在sys_nicmonitor中生成libnic_shm.so和sys_nicmonitor
|
||||
|
||||
========
|
||||
安装说明:
|
||||
1)安装,以root的用户执行安装命令:
|
||||
pkgadd sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
如果之前已经安装,则可先卸载旧的然后再安装,或者通过更新方式安装
|
||||
卸载命令: pkgrm sys_nicmonitor
|
||||
更新方式安装命令:
|
||||
pkgadd -u sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
2)查看安装是否成功
|
||||
pkginfo -i|grep sys_nicmonitor
|
||||
或者
|
||||
查看d5000用户的目录下lib/libnic_shm.so和bin/sys_nicmonitor的日期是否匹配
|
||||
|
||||
========
|
||||
|
||||
版本说明:
|
||||
详见sys_nicmonitor目录中的README
|
||||
|
||||
|
||||
=-======update 2015-11-17
|
||||
编译前,进入dep目录运行sh run.sh,安装编译依赖文件.
|
||||
|
||||
然后sh build.sh编译1.9版本的sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
调试模式下:
|
||||
cd sys_nicmonitor-1.9
|
||||
make clean
|
||||
make
|
||||
make test
|
||||
make runtest
|
||||
|
||||
版本号变更方法,更新sys_nicmonitor/version.h文件,需要同时修改//后面的和define中的,前者用于pkg包,后者用于sys_nicmonitor程序.
|
||||
制作pkg包方法: sh build.sh
|
||||
@@ -1,28 +0,0 @@
|
||||
#! /usr/bin/make -f
|
||||
|
||||
DEFAULTS = Makefile.config
|
||||
|
||||
include $(DEFAULTS)
|
||||
|
||||
all:sys_nicmonitor libnic_shm.so
|
||||
|
||||
CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral #-g
|
||||
|
||||
sys_nicmonitor:mnic.o read_netcard.o send_alarm.o
|
||||
$(CC) -lman -ldotconf -lpthread -o $@ $^
|
||||
libnic_shm.so:nicinfo_shm.c
|
||||
$(CC) -fpic -shared -o $@ $^
|
||||
clean:
|
||||
$(RM) *.o
|
||||
$(RM) libnic_shm.so sys_nicmonitor
|
||||
install:
|
||||
$(MKDIR) -p $(LIBDIR)
|
||||
$(MKDIR) -p $(BINDIR)
|
||||
$(MKDIR) -p $(INCDIR)
|
||||
$(CP) libnic_shm.so $(LIBDIR)
|
||||
$(CP) sys_nicmonitor $(BINDIR)
|
||||
$(CP) nicinfo_shm.h $(INCDIR)
|
||||
uninstall:
|
||||
$(RM) -f $(LIBDIR)/libnic_shm.so
|
||||
$(RM) -f $(BINDIR)/sys_nicmonitor
|
||||
$(RM) -f $(INCDIR)/nicinfo_shm.h
|
||||
@@ -1,16 +0,0 @@
|
||||
|
||||
PREFIX = $(DESTDIR)
|
||||
|
||||
BINDIR = $(PREFIX)/usr/bin
|
||||
|
||||
LIBDIR = $(PREFIX)/usr/lib64
|
||||
|
||||
INCDIR = $(PREFIX)/usr/include
|
||||
|
||||
INSTALL_SH = ./install.sh
|
||||
|
||||
CP = cp
|
||||
RM = rm
|
||||
#CC = gcc
|
||||
CC = g++
|
||||
MKDIR = mkdir
|
||||
@@ -1,51 +0,0 @@
|
||||
#ifndef _RTE_CONST_H
|
||||
#define _RTE_CONST_H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
|
||||
#define MAX_STRING_LEN 24
|
||||
#define MAX_EXECMD_LEN 200
|
||||
#define MAX_FILENAME_LEN 200
|
||||
|
||||
#define MAX_CONTEXT 8
|
||||
#define MAX_HOSTNAME_LEN 24
|
||||
#define MAX_LOCAL_MESPROC 512
|
||||
#define MAX_LOCAL_PROCESS MAX_LOCAL_MESPROC
|
||||
#define MAX_LOCAL_APP 32
|
||||
#define MAX_LOCAL_NODE 256
|
||||
|
||||
#define MAX_SET 256 //max num of event set
|
||||
#define MAX_EVENT 1300
|
||||
#define MAX_REG_PROC 20
|
||||
|
||||
#define LEN_SHMBLK_BIG 4096
|
||||
#define MAX_MSGBUF_LEN 32767
|
||||
#define FREE_PAGE_SIZE 65536
|
||||
#define MAX_PAGE_NUM 1024
|
||||
|
||||
#define MAX_QUE MAX_LOCAL_MESPROC
|
||||
#define MAX_SEMPHORE_SET MAX_LOCAL_MESPROC*2
|
||||
#define RTE_HAN 0 // queue number for event handeler0(RTE)
|
||||
#define EX_EVENT_HAN RTE_HAN // queue number for extrnal event handeler
|
||||
|
||||
#define DOMAIN_I 1
|
||||
#define DOMAIN_II 2
|
||||
#define DOMAIN_III 3
|
||||
|
||||
//Add 20090225
|
||||
const int PROC_TYPE_RPT =1;
|
||||
const int PROC_TYPE_UNRPT =0;
|
||||
//add end
|
||||
|
||||
|
||||
//status for proc and app
|
||||
const int NON_ACTIVE = 0;
|
||||
const int ACTIVE = 1;
|
||||
const int HANGUP = 2;
|
||||
const int FAILURE = 5;
|
||||
const int START = 6;
|
||||
const int STOP = 7;
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,44 +0,0 @@
|
||||
#ifndef __MNIC_H
|
||||
#define __MNIC_H
|
||||
|
||||
//#define _GNU_SOURCE
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
#include <time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/param.h>
|
||||
#include <linux/types.h>
|
||||
#include <glob.h>
|
||||
#include <linux/sockios.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "sys_netcard.h"
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#define IPSIZE 16
|
||||
|
||||
char *get_name(char *, char *);
|
||||
int if_fetch(NETCARD_INFO *);
|
||||
int ioc_get_name(NETCARD_INFO *);
|
||||
int get_dev_fields(char *p, NETCARD_INFO *);
|
||||
int get_user_home(int , char *);
|
||||
void send_alarm(D5000_NIC_ALARM *, int , char *);
|
||||
void record_log(char *);
|
||||
|
||||
#endif
|
||||
@@ -1,188 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "nicinfo_shm.h"
|
||||
|
||||
#define SHM_PATH "/tmp/sys_netcard_shm_path"
|
||||
#define SEM_PATH "/tmp/sys_netcard_sem_path"
|
||||
#define LOG_PATH "/var/log/netcard/"
|
||||
|
||||
typedef struct net_info{
|
||||
NETCARD_INFO info[MAXNICNUM];
|
||||
}SHM;
|
||||
|
||||
static int semid = 0;
|
||||
static char log_path[1024];
|
||||
SHM *ptr = NULL;
|
||||
|
||||
/* write error in logfile */
|
||||
void record_log(char *str)
|
||||
{
|
||||
time_t tamp;
|
||||
char str_tm[4];
|
||||
char log_str[512];
|
||||
FILE *log_fp = NULL;
|
||||
struct tm tmptr;
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
|
||||
if((log_fp = fopen(log_path, "a")) != NULL){
|
||||
tamp = time(NULL);
|
||||
memset(str_tm, 0, sizeof(str_tm));
|
||||
memset(log_str, 0, sizeof(log_str));
|
||||
localtime_r(&tamp, &tmptr);
|
||||
gettimeofday(&tv, &tz);
|
||||
snprintf(str_tm, sizeof(str_tm), "%d", (int)tv.tv_usec/1000);
|
||||
if(str_tm[1] == '\0')str_tm[1] = '0';
|
||||
if(str_tm[2] == '\0')str_tm[2] = '0';
|
||||
strftime(log_str, sizeof(log_str), "%F %T.", &tmptr);
|
||||
strcat(log_str, str_tm);
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, "get_nic_info");
|
||||
strcat(log_str, " ");
|
||||
strcat(log_str, str);
|
||||
if(fwrite(log_str, 1, strlen(log_str), log_fp) < 1){
|
||||
}
|
||||
fclose(log_fp);
|
||||
}
|
||||
}
|
||||
|
||||
void get_sem(int semid)
|
||||
{
|
||||
char err_str[200];
|
||||
struct sembuf lock;
|
||||
|
||||
lock.sem_num = 0;
|
||||
lock.sem_op = -1;
|
||||
lock.sem_flg = SEM_UNDO;
|
||||
|
||||
while(semop(semid, &lock, 1)){
|
||||
if (errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void release_sem(int semid)
|
||||
{
|
||||
int ret;
|
||||
char err_str[200];
|
||||
struct sembuf unlock;
|
||||
|
||||
unlock.sem_num = 0;
|
||||
unlock.sem_op = 1;
|
||||
unlock.sem_flg = SEM_UNDO;
|
||||
|
||||
if((ret = semop(semid, &unlock, 1)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semop():\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int init_nic_info(void)
|
||||
{
|
||||
int fd = -1;
|
||||
int sem_val;
|
||||
char err_str[200];
|
||||
key_t key;
|
||||
|
||||
|
||||
if ((key=ftok(SEM_PATH, SEM_PROJ_ID)) == -1) {
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: ftok():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
if((semid = semget(key, 1, IPC_CREAT|0666)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Create semaphore error: %s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
if((sem_val = semctl(semid, 0, GETVAL, 0)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
return -1;
|
||||
}
|
||||
if(!sem_val){
|
||||
if(semctl(semid, 0, SETVAL, 1) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: semctl: %s !\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
semctl(semid, 0, IPC_RMID);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if((fd = open(SHM_PATH, O_RDONLY)) == -1){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: Error open %s: %s!\n", SHM_PATH, strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
ptr = (SHM*)mmap(NULL, sizeof(SHM), PROT_READ, MAP_SHARED, fd, 0);
|
||||
if(ptr == MAP_FAILED){
|
||||
snprintf(err_str, sizeof(err_str), "EMERG: mmap():%s\n", strerror(errno));
|
||||
record_log(err_str);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info)
|
||||
{
|
||||
int i,ret;
|
||||
time_t tamp;
|
||||
struct tm tmptr;
|
||||
DIR *dir;
|
||||
char *s;
|
||||
char buf[128];
|
||||
char err_str[200];
|
||||
|
||||
tamp = time(NULL);
|
||||
localtime_r(&tamp, &tmptr);
|
||||
strcpy(log_path, LOG_PATH);
|
||||
if((dir = opendir(log_path)) == NULL){
|
||||
if(errno == ENOENT){
|
||||
strcpy(log_path, "/tmp/");
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
s = strrchr(log_path, '/');
|
||||
s++;
|
||||
*s = '\0';
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strftime(buf, sizeof(buf), "%Y%m%d_", &tmptr);
|
||||
strcat(buf, "sys_nicmonitor");
|
||||
strcat(buf, ".log");
|
||||
strcat(log_path, buf);
|
||||
if((ret = init_nic_info()) == -1){
|
||||
return -1;
|
||||
}
|
||||
for(i = 0; ptr->info[i].charname[0] != 0; i++){
|
||||
if(!strcmp(ptr->info[i].charname, nic_name)){
|
||||
get_sem(semid);
|
||||
memcpy(net_info, &ptr->info[i], sizeof(NETCARD_INFO));
|
||||
release_sem(semid);
|
||||
munmap(ptr, sizeof(SHM));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
snprintf(err_str, sizeof(err_str), "NOTICE: No information of %s !\n", nic_name);
|
||||
record_log(err_str);
|
||||
munmap(ptr, sizeof(SHM));
|
||||
return -1;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#ifndef NIC_SHM_H
|
||||
#define NIC_SHM_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef NIC_NAME_LEN
|
||||
#define NIC_NAME_LEN 64
|
||||
#endif
|
||||
#define SEM_PROJ_ID 's'
|
||||
#define MAXNICNUM 32
|
||||
|
||||
typedef long KEYID;
|
||||
typedef struct _net_info
|
||||
{
|
||||
KEYID ID;
|
||||
char charname[NIC_NAME_LEN];
|
||||
char descr[128];
|
||||
struct sockaddr addr;
|
||||
struct sockaddr broadaddr;
|
||||
struct sockaddr netmask;
|
||||
struct sockaddr hwaddr;
|
||||
int time_stamp;
|
||||
short flags;
|
||||
int mtu;
|
||||
int tx_queue_len;
|
||||
unsigned long long average_flow;
|
||||
unsigned long long rx_packets;
|
||||
unsigned long long tx_packets;
|
||||
unsigned long long rx_bytes;
|
||||
unsigned long long tx_bytes;
|
||||
unsigned long rx_errors;
|
||||
unsigned long tx_errors;
|
||||
unsigned long rx_dropped;
|
||||
unsigned long tx_dropped;
|
||||
unsigned long rx_multicast;
|
||||
unsigned long collisions;
|
||||
unsigned long rx_fifo_errors;
|
||||
unsigned long tx_carrier_errors;
|
||||
unsigned long tx_fifo_errors;
|
||||
}NETCARD_INFO;
|
||||
|
||||
int get_nic_info(char *nic_name, NETCARD_INFO *net_info);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,198 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) Comets' Grp. of Kedong Corp 2008. All Rights Reserved.
|
||||
//
|
||||
// FileName : procconf.h
|
||||
//
|
||||
// Function : this class realize some basic functions for process managerment,
|
||||
// such as initiate process, report status of process, check status of process,
|
||||
// update status of process, get information of process
|
||||
//
|
||||
// Author :
|
||||
//
|
||||
// Date :
|
||||
//
|
||||
// Modify by :
|
||||
//
|
||||
// Mod Date :
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _PROCCONF_H
|
||||
#define _PROCCONF_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
//#include <iostream.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "const.h"
|
||||
|
||||
//for alarm ................................
|
||||
typedef struct MESS_BH
|
||||
{
|
||||
unsigned char mtype;
|
||||
int length;
|
||||
};
|
||||
typedef struct PROCESS_ALM
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
unsigned char status;
|
||||
};
|
||||
//for alarm end .............................
|
||||
|
||||
//for mmi....................................
|
||||
const int MAX_BUFFER_LEN = 500;
|
||||
typedef struct MESS_BLOCK
|
||||
{
|
||||
unsigned char num;
|
||||
char buffer[MAX_BUFFER_LEN];
|
||||
};
|
||||
typedef struct MESS_PROC
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
char status;
|
||||
};
|
||||
//for mmi end ................................
|
||||
|
||||
const int DEFAULT_PERIOD = 3;
|
||||
const int COUNT_LIMIT = 2;
|
||||
const int START_DEFAULT_PERIOD = 60;
|
||||
const int START_COUNT_LIMIT = 5;
|
||||
const int APP_COUNT_LIMIT = 1;
|
||||
|
||||
//process critical level
|
||||
//const int WST_CRITICAL = 1; // Shutdown and reboot workstation when failed
|
||||
//const int SYS_CRITICAL = 2; // Shutdown and reboot the system on the wst when failed
|
||||
//const int USER_CRITICAL = 3; // Shutdown and reboot the subsystem when failed
|
||||
//const int GENERAL = 4; // reboot the process
|
||||
const int CRUCIAL = 1; // crucial process
|
||||
const int GENERAL = 0; // general process
|
||||
|
||||
|
||||
extern int srv_init(char *service,int port);
|
||||
extern int Tcp_close(int sockfd);
|
||||
extern int Tcp_read(int fd,char *ptr,int nbytes);
|
||||
extern int Tcp_write(int fd,char *ptr,int nbytes);
|
||||
extern int srv_accept(int fd,struct sockaddr *cli_addr,int *clilen);
|
||||
extern int client_tcp_open(char *host,char *service,int port);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
pid_t proc_pid;
|
||||
}PROC_ADM_INFO;
|
||||
|
||||
//***************************************************************
|
||||
// structure name : PROC_INFO
|
||||
// function : store process informatin
|
||||
// author :
|
||||
// date :
|
||||
// modify by :
|
||||
// modification :
|
||||
// mod date :
|
||||
//***************************************************************
|
||||
typedef struct
|
||||
{
|
||||
int position;
|
||||
char node_name[MAX_STRING_LEN];
|
||||
char context_name[MAX_STRING_LEN];
|
||||
char app_name[MAX_STRING_LEN];
|
||||
char proc_name[MAX_STRING_LEN];
|
||||
|
||||
unsigned char active_flag;
|
||||
unsigned char master_flag;
|
||||
|
||||
time_t startup_time;
|
||||
time_t refresh_time;
|
||||
short refresh_peri;
|
||||
unsigned char monitor_type;
|
||||
|
||||
pid_t proc_pid;
|
||||
unsigned char auto_start;
|
||||
unsigned char act_timer;
|
||||
unsigned char start_timer;
|
||||
unsigned char critical_level;
|
||||
|
||||
char exefile_path[MAX_EXECMD_LEN];
|
||||
|
||||
}PROC_INFO;
|
||||
|
||||
//***************************************************************
|
||||
// structure name : APP_INFO
|
||||
// function : store application informatin
|
||||
// author :
|
||||
// date :
|
||||
// modify by :
|
||||
// modification :
|
||||
// mod date :
|
||||
//***************************************************************
|
||||
typedef struct
|
||||
{
|
||||
int position;
|
||||
char context_name[MAX_STRING_LEN];
|
||||
int context_id;
|
||||
char app_name[MAX_STRING_LEN];
|
||||
int app_id;
|
||||
unsigned char act_timer;
|
||||
unsigned char active_flag;
|
||||
}APP_INFO;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int no_proc;
|
||||
int semdes_cfg;
|
||||
PROC_INFO proc[MAX_LOCAL_PROCESS];
|
||||
APP_INFO app[MAX_LOCAL_APP];
|
||||
}PROCCFG;
|
||||
|
||||
class proc_invocation
|
||||
{
|
||||
public:
|
||||
int m_init;
|
||||
PROCCFG *proccfg_p;
|
||||
|
||||
public:
|
||||
proc_invocation();
|
||||
~proc_invocation();
|
||||
|
||||
int conf_create();
|
||||
//int check_proc_status();
|
||||
//int update_rtdb();
|
||||
//int kill_proc(pid_t pid);
|
||||
//int start_proc(char *cmdline);
|
||||
//int send_alarm(char *context_name, char *app_name, char *proc_name, unsigned char status);
|
||||
//int update_proc_status(char *context_name, char *app_name, char *proc_name, char status);
|
||||
|
||||
//int proc_init(char *context_name, char *app_name, char *proc_name, int critical_level);//exefile_path,auto_start
|
||||
int proc_init(char *context_name, char *app_name, char *proc_name);
|
||||
int proc_report(int pos, char status, int intertime=3);
|
||||
int proc_exit(int proc_pos);
|
||||
|
||||
int get_pos(char *context_name, char *app_name, char *proc_name);
|
||||
int is_proc_exist(char *context_name, char *app_name, char *proc_name);
|
||||
int conf_map();
|
||||
|
||||
int get_procinfo(int position, PROC_ADM_INFO *p_info);
|
||||
int get_active_pid(int &num, int *p_pidlist);
|
||||
int is_proc_run(pid_t pid);
|
||||
int is_proc_run(char *context_name, char *app_name, char *proc_name);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
#include "mnic.h"
|
||||
|
||||
static char *prase_digit(char **s)
|
||||
{
|
||||
char *retp = NULL;
|
||||
char *p = *s;
|
||||
|
||||
if(!p)return NULL;
|
||||
while(!isdigit(*p)){
|
||||
p++;
|
||||
if(*p == '\0')return NULL;
|
||||
}
|
||||
retp = p;
|
||||
while(isdigit(*p)){
|
||||
p++;
|
||||
if(*p == '\0'){
|
||||
*s = NULL;
|
||||
return retp;
|
||||
}
|
||||
}
|
||||
*p = '\0';
|
||||
p++;
|
||||
*s = p;
|
||||
return retp;
|
||||
}
|
||||
|
||||
|
||||
char *get_name(char *name, char *p)
|
||||
{
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
while (*p) {
|
||||
if (isspace(*p))
|
||||
break;
|
||||
if (*p == ':') { /* could be an alias */
|
||||
char *dot = p, *dotname = name;
|
||||
*name++ = *p++;
|
||||
while (isdigit(*p))
|
||||
*name++ = *p++;
|
||||
if (*p != ':') { /* it wasn't, backup */
|
||||
p = dot;
|
||||
name = dotname;
|
||||
}
|
||||
if (*p == '\0')
|
||||
return NULL;
|
||||
p++;
|
||||
break;
|
||||
}
|
||||
*name++ = *p++;
|
||||
}
|
||||
*name++ = '\0';
|
||||
return p;
|
||||
}
|
||||
|
||||
int get_dev_fields(char *str, NETCARD_INFO *ife)
|
||||
{
|
||||
int i = 0;
|
||||
char *retp[16];
|
||||
|
||||
while((retp[i] = prase_digit(&str)) != NULL){i++;if(i > 15)break;}
|
||||
ife->rx_bytes = atoll(retp[0]);
|
||||
ife->rx_packets = atoll(retp[1]);
|
||||
ife->rx_errors = atol(retp[2]);
|
||||
ife->rx_dropped = atol(retp[3]);
|
||||
ife->rx_fifo_errors = atol(retp[4]);
|
||||
ife->rx_multicast = atol(retp[7]);
|
||||
ife->tx_bytes = atoll(retp[8]);
|
||||
ife->tx_packets = atoll(retp[9]);
|
||||
ife->tx_errors = atol(retp[10]);
|
||||
ife->tx_dropped = atol(retp[11]);
|
||||
ife->tx_fifo_errors = atol(retp[12]);
|
||||
ife->collisions = atol(retp[13]);
|
||||
ife->tx_carrier_errors = atol(retp[14]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_fetch(NETCARD_INFO *ife)
|
||||
{
|
||||
int skfd;
|
||||
struct ifreq ifr;
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
|
||||
strcpy(ifr.ifr_name, ife->charname);
|
||||
if (!ioctl(skfd, SIOCGIFFLAGS, &ifr))
|
||||
ife->flags = ifr.ifr_flags;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFHWADDR, &ifr))
|
||||
ife->hwaddr = ifr.ifr_hwaddr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFMTU, &ifr))
|
||||
ife->mtu = ifr.ifr_mtu;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFTXQLEN, &ifr))
|
||||
ife->tx_queue_len = ifr.ifr_qlen;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFADDR, &ifr))
|
||||
ife->addr = ifr.ifr_addr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFBRDADDR, &ifr))
|
||||
ife->broadaddr = ifr.ifr_broadaddr;
|
||||
|
||||
if (!ioctl(skfd, SIOCGIFNETMASK, &ifr))
|
||||
ife->netmask = ifr.ifr_netmask;
|
||||
|
||||
ife->time_stamp = time(NULL);
|
||||
close(skfd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int ioc_get_name(NETCARD_INFO *name)
|
||||
{
|
||||
int skfd;
|
||||
int ifrnum;
|
||||
int i = 0;
|
||||
struct ifconf ifc;
|
||||
struct ifreq buf[MAXNICNUM];
|
||||
|
||||
if((skfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)return -1;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
ifc.ifc_len = sizeof(buf);
|
||||
ifc.ifc_buf = (caddr_t) buf;
|
||||
ioctl(skfd, SIOCGIFCONF, &ifc);
|
||||
ifrnum = ifc.ifc_len / sizeof(struct ifreq);
|
||||
while(ifrnum-- > 0){
|
||||
strcpy(name[i].charname, buf[ifrnum].ifr_name);
|
||||
i++;
|
||||
}
|
||||
close(skfd);
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#include "mnic.h"
|
||||
|
||||
void send_alarm(D5000_NIC_ALARM *mesg, int socket_port, char *ipv4)
|
||||
{
|
||||
int bytes;
|
||||
int sock_sd;
|
||||
int val;
|
||||
char error_str[200];
|
||||
struct sockaddr_in recever;
|
||||
socklen_t sock_len;
|
||||
|
||||
if((sock_sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: socket(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
val=1;
|
||||
if ((setsockopt(sock_sd, SOL_SOCKET, SO_BROADCAST, &val, sizeof(val))) == -1) {
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: setsockopt(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
/* init socket*/
|
||||
recever.sin_family = AF_INET;
|
||||
recever.sin_port = htons(socket_port);
|
||||
inet_pton(AF_INET, ipv4, &recever.sin_addr);
|
||||
sock_len = sizeof(recever);
|
||||
/* send alarm*/
|
||||
if((bytes = sendto(sock_sd, mesg, sizeof(D5000_NIC_ALARM), 0, (const struct sockaddr *)&recever, sock_len)) < 1){
|
||||
snprintf(error_str, sizeof(error_str), "EMERG: sendto(): %s\n", strerror(errno));
|
||||
record_log(error_str);
|
||||
return;
|
||||
}
|
||||
//snprintf(error_str, sizeof(error_str), "NOTICE: Alarm information has already send!\n");
|
||||
//record_log(error_str);
|
||||
close(sock_sd);
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
#ifndef _SYS_NETCARD_H
|
||||
#define _SYS_NETCARD_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
|
||||
#ifndef NIC_NAME_LEN
|
||||
#define NIC_NAME_LEN 64
|
||||
#endif
|
||||
|
||||
#define SEM_PROJ_ID 's'
|
||||
#define MAXNICNUM 32
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
typedef long KEYID;
|
||||
|
||||
typedef struct _msg_frame // message frame
|
||||
{
|
||||
short len; // message length
|
||||
short seqno; // send sequence
|
||||
short serv; // services ID
|
||||
short event; // event ID
|
||||
unsigned char domain; // domain ID
|
||||
unsigned char ctxt; // Context ID
|
||||
short stid; // SOURCE task id
|
||||
short dtid; // DESTINATION task ID
|
||||
unsigned char ver_coding; // 版本号 + 编码
|
||||
unsigned char mes_type; // 帧类型
|
||||
}MSG_FRAME, *LPMSG_FRAME;
|
||||
|
||||
typedef struct _net_info
|
||||
{
|
||||
KEYID ID;
|
||||
char charname[NIC_NAME_LEN];
|
||||
char descr[128];
|
||||
struct sockaddr addr;
|
||||
struct sockaddr broadaddr;
|
||||
struct sockaddr netmask;
|
||||
struct sockaddr hwaddr;
|
||||
int time_stamp;
|
||||
short flags;
|
||||
int mtu;
|
||||
int tx_queue_len;
|
||||
unsigned long long average_flow;
|
||||
unsigned long long rx_packets;
|
||||
unsigned long long tx_packets;
|
||||
unsigned long long rx_bytes;
|
||||
unsigned long long tx_bytes;
|
||||
unsigned long rx_errors;
|
||||
unsigned long tx_errors;
|
||||
unsigned long rx_dropped;
|
||||
unsigned long tx_dropped;
|
||||
unsigned long rx_multicast;
|
||||
unsigned long collisions;
|
||||
unsigned long rx_fifo_errors;
|
||||
unsigned long tx_carrier_errors;
|
||||
unsigned long tx_fifo_errors;
|
||||
}NETCARD_INFO, *LPNETCARD_INFO;
|
||||
|
||||
#define NETCARD_ALARM_FAULT 1
|
||||
#define NETCARD_ALARM_RESUME 2
|
||||
#define NETCARD_ALARM_SWITCH 3
|
||||
#define NETCARD_ALARM_ABNORMAL 4
|
||||
#define NETCARD_ALARM_NORMAL 5
|
||||
typedef struct _sys_netcard_alarm
|
||||
{
|
||||
char fault_devname[NIC_NAME_LEN]; /*故障设备名称 */
|
||||
char switch_devname[NIC_NAME_LEN]; /*切换设备名称 */
|
||||
short flags; /* 状态标记 : 1:网卡故障。2:网卡恢复。3:网卡切换。4:流量异常。*/
|
||||
short retrytimes; //0,1,2 重发次数
|
||||
}SYS_NETCARD_ALARM, *LPSYS_NETCARD_ALARM;
|
||||
|
||||
|
||||
typedef struct _d5000_nic_alarm
|
||||
{
|
||||
MSG_FRAME tMsgFrame ;
|
||||
SYS_NETCARD_ALARM tSysNetcardAlarm ;
|
||||
}D5000_NIC_ALARM, *LPD5000_NIC_ALARM;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
2
code/dep/42/run.sh
Normal file
2
code/dep/42/run.sh
Normal file
@@ -0,0 +1,2 @@
|
||||
pkgadd dotconf#1.0.13-1.pkg.tar.gz
|
||||
cp ../libproc_common.so /usr/lib64/
|
||||
BIN
code/dep/90/libdotconf-dev_1.3-0.2_amd64.deb
Normal file
BIN
code/dep/90/libdotconf-dev_1.3-0.2_amd64.deb
Normal file
Binary file not shown.
BIN
code/dep/90/libdotconf-dev_1.3-0.2_arm64.deb
Normal file
BIN
code/dep/90/libdotconf-dev_1.3-0.2_arm64.deb
Normal file
Binary file not shown.
BIN
code/dep/90/libdotconf0_1.3-0.2_amd64.deb
Normal file
BIN
code/dep/90/libdotconf0_1.3-0.2_amd64.deb
Normal file
Binary file not shown.
BIN
code/dep/90/libdotconf0_1.3-0.2_arm64.deb
Normal file
BIN
code/dep/90/libdotconf0_1.3-0.2_arm64.deb
Normal file
Binary file not shown.
12
code/dep/90/run.sh
Normal file
12
code/dep/90/run.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
arch=`uname -m`
|
||||
if [ "x$arch" == "x86_64" ]; then
|
||||
dpkg -i libdotconf0_1.3-0.2_amd64.deb
|
||||
dpkg -i libdotconf-dev_1.3-0.2_amd64.deb
|
||||
elif [ "x$arch" == "aarch64" ]; then
|
||||
dpkg -i libdotconf0_1.3-0.2_arm64.deb
|
||||
dpkg -i libdotconf-dev_1.3-0.2_arm64.deb
|
||||
fi
|
||||
|
||||
cp ../libproc_common.so /usr/lib/
|
||||
BIN
code/dep/dotconf#1.0.13-1.pkg.tar.gz
Normal file
BIN
code/dep/dotconf#1.0.13-1.pkg.tar.gz
Normal file
Binary file not shown.
BIN
code/dep/libproc_common.so
Executable file
BIN
code/dep/libproc_common.so
Executable file
Binary file not shown.
19
code/dep/proc_common.cpp
Normal file
19
code/dep/proc_common.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include "proc_common.h"
|
||||
|
||||
|
||||
NS_SYSADMIN::CProcCommon::CProcCommon(int rw)
|
||||
{
|
||||
printf("NS_SYSADMIN::CProcCommon::CProcCommon\n");
|
||||
}
|
||||
|
||||
NS_SYSADMIN::CProcCommon::~CProcCommon()
|
||||
{
|
||||
printf("NS_SYSADMIN::CProcCommon::~CProcCommon\n");
|
||||
}
|
||||
|
||||
int NS_SYSADMIN::CProcCommon::proc_init(const char* scn_name, const char* subscn_name,char* process_name, const char* label = NULL, const char* subscn_lable = NULL)
|
||||
{
|
||||
printf("NS_SYSADMIN::CProcCommon::proc_init\n");
|
||||
return 0;
|
||||
}
|
||||
BIN
code/sys_nicmonitor-code.tar.gz
Normal file
BIN
code/sys_nicmonitor-code.tar.gz
Normal file
Binary file not shown.
@@ -6,14 +6,18 @@ include $(DEFAULTS)
|
||||
|
||||
all:sys_nicmonitor libnic_shm.so test
|
||||
|
||||
CFLAGS += -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral #-g
|
||||
#CFLAGS += -D TESTINTERVAL -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral -O0 -g
|
||||
CFLAGS += -I ./include -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral -O0
|
||||
#CFLAGS += -I ./include -D USER_NUSP -Wall -Wformat=2 -Wno-format-extra-args -Wformat-security -Wformat-nonliteral -O0
|
||||
|
||||
sys_nicmonitor:mnic.o read_netcard.o send_alarm.o
|
||||
$(CC) -lman -ldotconf -lpthread -o $@ $^
|
||||
libnic_shm.so:nicinfo_shm.c
|
||||
$(CC) $(CFLAGS) -lproc_common -ldotconf -lpthread -o $@ $^
|
||||
libnic_shm.so:nicinfo_shm.o
|
||||
$(CC) -fpic -shared -o $@ $^
|
||||
test:test.c
|
||||
gcc -o test test.c -lnic_shm -L=./ -lpthread
|
||||
nicinfo_shm.o:nicinfo_shm.c
|
||||
$(CC) $(CFLAGS) -fPIC -c $^
|
||||
test:test.c
|
||||
gcc -o test test.c -lnic_shm -L./ -lpthread
|
||||
runtest:
|
||||
LD_LIBRARY_PATH=./ ./test bond0 5000 &
|
||||
clean:
|
||||
@@ -1,3 +1,78 @@
|
||||
========
|
||||
版本说明:
|
||||
--V1.22 --
|
||||
2020-07-09
|
||||
1)根本南瑞郭海龙要求进行接口的修改
|
||||
取消之前libman.so动态库和proc_inv.h头文件,改为新的libproc_common.so动态库,同时增加include头文件目录
|
||||
2020-10-22
|
||||
1) 修复sys_nicmonitor进程重启后,再调用get_nic_info接口时出现的大量告警日志问题
|
||||
问题描述:sys_nicmonitor进程重新启动时,调用接口程序会输出告警日志,日志的增长量和调用接口频率成正比增长
|
||||
解决办法:接口程序增加sys_nicmonitor进程状态检测,当sys_nicmonitor进程重启时,接口程序重新获取新信号量的id
|
||||
|
||||
--V1.21 --
|
||||
2019-09-05
|
||||
1)修复问题:monitor_interval参数溢出导致cpu 100%
|
||||
问题描述:当monitor_interval参数配置为1000时,出现进程cpu占用100%的问题
|
||||
解决办法:增加对monitor_interval配置的检测和限制
|
||||
|
||||
--V1.9 --
|
||||
2013-08-12
|
||||
1)修复问题:占用内存快速累加,导致内存占用很大
|
||||
问题描述:日志线程资源退出时未回收,导致占用内存快速累加
|
||||
解决办法:修改为一个日志线程,并且线程退出时设置为自动回收。
|
||||
将日志写文件的地方放到common.c中,以便动态库和daemon程序使用一个。
|
||||
|
||||
2)修复问题:日志文件名在家目录或者var目录下,未在规定位置
|
||||
问题描述:日志文件命名在一个单独的线程进行,导致日志线程和该线程对log_path存在同时访问的情况。
|
||||
导致在换天或者换月时,日志文件名变更一半时,日志写线程此时写日志,用未更新完成的
|
||||
log_path创建日志,导致日志文件不再规定的位置。
|
||||
解决办法:增加线程互斥锁pthread_mutex对log_path进行保护,修复该问题。
|
||||
|
||||
--V1.8.1 --
|
||||
2013-06-05
|
||||
1)修改BUG:ping_gw函数当PING失败时没有尝试对余下的GW进行PING操作
|
||||
2)增加环境变量SYS_NIC_DEBUG用于调试流量抖动问题。
|
||||
|
||||
--V1.8 --
|
||||
2013-05-27
|
||||
对系统高磁盘IO情况下,应用如果进行IO将可能会被阻塞。本版本为此作出调整。
|
||||
cs-fes1上编译测试OK。
|
||||
|
||||
1) 去掉shm和sem的实体文件
|
||||
#define SHM_PATH "$D5000_HOME/share/sys_netcard_shm_path"
|
||||
#define SEM_PATH "$D5000_HOME/share/sys_netcard_sem_path"
|
||||
|
||||
用key=0x1d5200 代替 sem
|
||||
用key=0x1d5010 代替 shm
|
||||
|
||||
|
||||
2)去掉动态库中get_nic_info接口中,判断路径的opendir调用,采用实际路径
|
||||
上层应用每秒可能调用3次这个接口,每判断一个网卡都调用一次,判断都个网卡的状态时就调用多次。
|
||||
|
||||
可改进:一次调用get_nic_info接口,可输入多个网卡,一次返回所有网卡状态信息。
|
||||
|
||||
3) record_log函数为日志函数,每次写一次,都重新打开一次文件。
|
||||
修改为线程模式,当记录日志时,不会被磁盘IO阻塞。
|
||||
|
||||
4) 安装目录为d5000用户的HOME目录下的lib和bin目录
|
||||
|
||||
--V1.7 --
|
||||
|
||||
V1.6与V1.7差异
|
||||
共享内存路径修改:
|
||||
由/home/d5000/someone/tmp/sys_netcard_shm_path 改为 /home/d5000/someone/share/sys_netcard_shm_path
|
||||
信号量路径修改:
|
||||
由/home/d5000/someone/tmp/sys_netcard_sem_path 改为 /home/d5000/someone/share/sys_netcard_sem_path
|
||||
|
||||
注意:在编译过程中,需要动态看libman.so,它存放在目录 tags/下面 ,在进行编译的时候需要将其拷贝到
|
||||
/lib64/目录下,编译的基础环境是 Rocky 4.2 系统。
|
||||
|
||||
pkgmk命令的使用:
|
||||
将源代码打包成name-version.tar.gz样式,编写Pkgfile文件。
|
||||
使用命令:
|
||||
pkgmk -um #更新软件包的md5值
|
||||
pkgmk -kw #制作pkg安装包
|
||||
|
||||
--V1.14 --
|
||||
2015-12-29
|
||||
修正了common.c中对日志消息队列的操作,其中包括:交换log_prepare与log_writing>队列指针的bug;以及在写入log_prepare队列时未检查已写入消息是否大于队列长度的b
|
||||
@@ -26,112 +101,3 @@ ug。修正了log_path(即日志文件名)不会随时间改变的bug。
|
||||
2)信号量应由网卡监控程序sys_nicmonitor创建,而不应由用户程序创建,对其进行了相应的修改(在创建信号量时在flag中添加IPC_EXCL,并将用户程序引用信号量时的flag中去除IPC_CREATE)。
|
||||
|
||||
3)在对获取网卡信息函数get_nic_info中添加获取时间的操作后得知,其中对getpwdnam的调用会减慢函数的工作(该函数并非每次都减慢函数很多,多数在30~40ms左右,但在测试中曾达到2s左右)。对其修改为在sys_nicmonitor程序启动时,调用getpwdnam函数,并将得到的用户主目录名写入到一块共享内存中。当用户程序要获得该目录名时,则从该值从共享内存中读取出来,而不需要每次都通过getpwdnam来获取,故可以提高该函数的速度。
|
||||
|
||||
|
||||
=-======update 2015-11-17
|
||||
编译前,进入dep目录运行sh run.sh,安装编译依赖文件.
|
||||
|
||||
然后sh build.sh编译1.9版本的sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
调试模式下:
|
||||
cd sys_nicmonitor-1.9
|
||||
make clean
|
||||
make
|
||||
make test
|
||||
make runtest
|
||||
|
||||
版本号变更方法,更新sys_nicmonitor/version.h文件,需要同时修改//后面的和define中的,前者用于pkg包,后者用于sys_nicmonitor程序.
|
||||
制作pkg包方法: sh build.sh
|
||||
|
||||
|
||||
|
||||
=========
|
||||
编译前准备:
|
||||
编译前先安装dotconf软件包。
|
||||
libman.so拷贝到/usr/lib64/下
|
||||
pkgadd dotconf#1.0.13-1.pkg.tar.gz
|
||||
|
||||
编译说明:
|
||||
在Rocky 4.2上编译
|
||||
|
||||
执行: sh build.sh
|
||||
将在当前的目录下生成安装包:
|
||||
sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
========
|
||||
安装说明:
|
||||
1)安装,以root的用户执行安装命令:
|
||||
pkgadd sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
如果之前已经安装,则可先卸载旧的然后再安装,或者通过更新方式安装
|
||||
卸载命令: pkgrm sys_nicmonitor
|
||||
更新方式安装命令:
|
||||
pkgadd -u sys_nicmonitor#1.9-x86_64-Linx-Rocky4.2.pkg.tar.gz
|
||||
|
||||
2)查看安装是否成功
|
||||
pkginfo -i|grep sys_nicmonitor
|
||||
或者
|
||||
查看d5000用户的目录下lib/libnic_shm.so和bin/sys_nicmonitor的日期是否匹配
|
||||
|
||||
========
|
||||
|
||||
版本说明:
|
||||
--V1.9 --
|
||||
2013-08-12
|
||||
1)修复问题:占用内存快速累加,导致内存占用很大
|
||||
问题描述:日志线程资源退出时未回收,导致占用内存快速累加
|
||||
解决办法:修改为一个日志线程,并且线程退出时设置为自动回收。
|
||||
将日志写文件的地方放到common.c中,以便动态库和daemon程序使用一个。
|
||||
|
||||
2)修复问题:日志文件名在家目录或者var目录下,未在规定位置
|
||||
问题描述:日志文件命名在一个单独的线程进行,导致日志线程和该线程对log_path存在同时访问的情况。
|
||||
导致在换天或者换月时,日志文件名变更一半时,日志写线程此时写日志,用未更新完成的
|
||||
log_path创建日志,导致日志文件不再规定的位置。
|
||||
解决办法:增加线程互斥锁pthread_mutex对log_path进行保护,修复该问题。
|
||||
|
||||
|
||||
--V1.8.1--
|
||||
2013-06-05
|
||||
1)修改BUG:ping_gw函数当PING失败时没有尝试对余下的GW进行PING操作
|
||||
2)增加环境变量SYS_NIC_DEBUG用于调试流量抖动问题。
|
||||
|
||||
--V1.8 --
|
||||
2013-05-27
|
||||
对系统高磁盘IO情况下,应用如果进行IO将可能会被阻塞。本版本为此作出调整。
|
||||
cs-fes1上编译测试OK。
|
||||
|
||||
1) 去掉shm和sem的实体文件
|
||||
#define SHM_PATH "$D5000_HOME/share/sys_netcard_shm_path"
|
||||
#define SEM_PATH "$D5000_HOME/share/sys_netcard_sem_path"
|
||||
|
||||
用key=0x1d5200 代替 sem
|
||||
用key=0x1d5010 代替 shm
|
||||
|
||||
|
||||
2)去掉动态库中get_nic_info接口中,判断路径的opendir调用,采用实际路径
|
||||
上层应用每秒可能调用3次这个接口,每判断一个网卡都调用一次,判断都个网卡的状态时就调用多次。
|
||||
|
||||
可改进:一次调用get_nic_info接口,可输入多个网卡,一次返回所有网卡状态信息。
|
||||
|
||||
3) record_log函数为日志函数,每次写一次,都重新打开一次文件。
|
||||
修改为线程模式,当记录日志时,不会被磁盘IO阻塞。
|
||||
|
||||
4) 安装目录为d5000用户的HOME目录下的lib和bin目录
|
||||
|
||||
----
|
||||
|
||||
|
||||
V1.6与V1.7差异
|
||||
共享内存路径修改:
|
||||
由/home/d5000/someone/tmp/sys_netcard_shm_path 改为 /home/d5000/someone/share/sys_netcard_shm_path
|
||||
信号量路径修改:
|
||||
由/home/d5000/someone/tmp/sys_netcard_sem_path 改为 /home/d5000/someone/share/sys_netcard_sem_path
|
||||
|
||||
注意:在编译过程中,需要动态看libman.so,它存放在目录 tags/下面 ,在进行编译的时候需要将其拷贝到
|
||||
/lib64/目录下,编译的基础环境是 Rocky 4.2 系统。
|
||||
|
||||
pkgmk命令的使用:
|
||||
将源代码打包成name-version.tar.gz样式,编写Pkgfile文件。
|
||||
使用命令:
|
||||
pkgmk -um #更新软件包的md5值
|
||||
pkgmk -kw #制作pkg安装包
|
||||
|
||||
@@ -117,7 +117,7 @@ static void *record_log_thread( void *arg )
|
||||
//free self thread resources
|
||||
pthread_detach(pthread_self());
|
||||
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* write error in logfile */
|
||||
@@ -177,6 +177,6 @@ void record_log(char *str)
|
||||
log_idx++;
|
||||
}
|
||||
}
|
||||
LOG_UNLOCK;
|
||||
LOG_UNLOCK;
|
||||
}
|
||||
|
||||
95
code/sys_nicmonitor/include/common_types.h
Normal file
95
code/sys_nicmonitor/include/common_types.h
Normal file
@@ -0,0 +1,95 @@
|
||||
#ifndef _COMMON_TYPES_H
|
||||
#define _COMMON_TYPES_H
|
||||
|
||||
#ifdef _LINUX
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
//support ILP32/LLP64/LP64
|
||||
//8bit
|
||||
typedef signed char cmnInt8;
|
||||
typedef unsigned char cmnUint8;
|
||||
typedef cmnUint8 cmnByte;
|
||||
|
||||
//16bit
|
||||
typedef signed short cmnInt16;
|
||||
typedef unsigned short cmnUint16;
|
||||
typedef cmnUint16 cmnWord;
|
||||
|
||||
//32bit
|
||||
typedef int cmnInt32;
|
||||
typedef unsigned int cmnUint32;
|
||||
#define CMN_PRdINT32 "d"
|
||||
#define CMN_PRuUINT32 "u"
|
||||
#define CMN_PRxUINT32 "x"
|
||||
#define CMN_PRXUINT32 "X"
|
||||
|
||||
#ifdef _WINDOWS_
|
||||
#if _MSC_VER >= 1400
|
||||
typedef long long cmnInt64;
|
||||
typedef unsigned long long cmnUint64;
|
||||
#define CMN_PRdINT64 "lld"
|
||||
#define CMN_PRuUINT64 "llu"
|
||||
#define CMN_PRxUINT64 "llx"
|
||||
#define CMN_PRXUINT64 "llX"
|
||||
#else
|
||||
typedef __int64 cmnInt64;
|
||||
typedef unsigned __int64 cmnUint64;
|
||||
#define CMN_PRdINT64 "I64d"
|
||||
#define CMN_PRuUINT64 "I64u"
|
||||
#define CMN_PRxUINT64 "I64x"
|
||||
#define CMN_PRXUINT64 "I64X"
|
||||
#endif
|
||||
#ifdef _WIN64
|
||||
typedef cmnInt64 cmnPtInt;
|
||||
typedef cmnUint64 cmnPtUint;
|
||||
#define CMN_PRdPTINT CMN_PRdINT64
|
||||
#define CMN_PRuPTUINT CMN_PRuUINT64
|
||||
#define CMN_PRxPTUINT CMN_PRxUINT64
|
||||
#define CMN_PRXPTUINT CMN_PRXUINT64
|
||||
#else
|
||||
typedef cmnInt32 cmnPtInt;
|
||||
typedef cmnUint32 cmnPtUint;
|
||||
#define CMN_PRdPTINT CMN_PRdINT32
|
||||
#define CMN_PRuPTUINT CMN_PRuUINT32
|
||||
#define CMN_PRxPTUINT CMN_PRxUINT32
|
||||
#define CMN_PRXPTUINT CMN_PRXUINT32
|
||||
#endif
|
||||
#else
|
||||
#if defined (__LP64__) || defined (__64BIT__) || defined (_LP64) || (__WORDSIZE == 64)
|
||||
typedef long cmnInt64;
|
||||
typedef unsigned long cmnUint64;
|
||||
typedef cmnInt64 cmnPtInt;
|
||||
typedef cmnUint64 cmnPtUint;
|
||||
#define CMN_PRdINT64 "ld"
|
||||
#define CMN_PRuUINT64 "lu"
|
||||
#define CMN_PRxUINT64 "lx"
|
||||
#define CMN_PRXUINT64 "lX"
|
||||
#define CMN_PRdPTINT CMN_PRdINT64
|
||||
#define CMN_PRuPTUINT CMN_PRuUINT64
|
||||
#define CMN_PRxPTUINT CMN_PRxUINT64
|
||||
#define CMN_PRXPTUINT CMN_PRXUINT64
|
||||
#else
|
||||
typedef long long cmnInt64;
|
||||
typedef unsigned long long cmnUint64;
|
||||
typedef cmnInt32 cmnPtInt;
|
||||
typedef cmnUint32 cmnPtUint;
|
||||
#define CMN_PRdINT64 "lld"
|
||||
#define CMN_PRuUINT64 "llu"
|
||||
#define CMN_PRxUINT64 "llx"
|
||||
#define CMN_PRXUINT64 "llX"
|
||||
#define CMN_PRdPTINT CMN_PRdINT32
|
||||
#define CMN_PRuPTUINT CMN_PRuUINT32
|
||||
#define CMN_PRxPTUINT CMN_PRxUINT32
|
||||
#define CMN_PRXPTUINT CMN_PRXUINT32
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
130
code/sys_nicmonitor/include/d5000_err.h
Normal file
130
code/sys_nicmonitor/include/d5000_err.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/*3.ʵʱ¿â´íÎóÂë*/
|
||||
/*ERR_RTDB_ errno of rtdb --- wj added on 20090218 */
|
||||
|
||||
#define ERR_RTDB_ERROR -1 /* error */
|
||||
#define ERR_RTDB_PARA -2 /* bad para_parameter */
|
||||
#define ERR_RTDB_CHAOS -3 /* innner error */
|
||||
|
||||
//access
|
||||
#define ERR_RTDB_ACCESSMETH -3001 /* access_meth is error */
|
||||
#define ERR_RTDB_EXIST -3002 /* Db name is exist, cannot creat */
|
||||
#define ERR_RTDB_NODB -3003 /* Db name not founded */
|
||||
#define ERR_RTDB_INVDBNO -3004 /* Db no is wrong */
|
||||
#define ERR_RTDB_INVFNAME -3005 /* Field name not founded */
|
||||
#define ERR_RTDB_HASOPENED -3006 /* The db has been opened */
|
||||
#define ERR_RTDB_FILE_NOPEN -3007 /* The file cannot open */
|
||||
#define ERR_RTDB_READ_FILE -3008 /* The file cannot read */
|
||||
#define ERR_RTDB_APP_NO_DB -3009 /* This table isn't in current application */
|
||||
#define ERR_RTDB_DB_NONE -3010 /* The table is deleted or hasn't been created*/
|
||||
|
||||
//lock
|
||||
#define ERR_RTDB_LOCK -3111 /* The db is locked */
|
||||
#define ERR_RTDB_UNLOCK -3112 /* The db isnot locked */
|
||||
#define ERR_RTDB_INVUNLOCK -3113 /* locker is not me */
|
||||
#define ERR_RTDB_NOINDEX -3114 /* havenot index */
|
||||
|
||||
#define ERR_RTDB_DIFFSIZE -3121 /* size is different */
|
||||
#define ERR_RTDB_NOTCHKEY -3122 /* ?? */
|
||||
#define ERR_RTDB_NOCACHE -3123 /* no cache block */
|
||||
#define ERR_RTDB_NOTE_NEND -3124 /* NOTE must be last field */
|
||||
|
||||
#define ERR_RTDB_CTRLFULL -3131 /* The db ctrl table is full */
|
||||
#define ERR_RTDB_DBFULL -3132 /* The db is full */
|
||||
#define ERR_RTDB_EODB -3133 /* End of Database */
|
||||
#define ERR_RTDB_INVSIZE -3134 /* The size is invalid */
|
||||
#define ERR_RTDB_DBBEGIN -3135 /* Have reach the begin of db */
|
||||
#define ERR_RTDB_DBEND -3136 /* Have reach the end of db */
|
||||
|
||||
#define ERR_RTDB_INVCCOMM -3137 /* Invalid comparition command */
|
||||
#define ERR_RTDB_TMOPEN -3138 /* Too many open */
|
||||
#define ERR_RTDB_EMPTY -3139 /* table is empty */
|
||||
|
||||
////key
|
||||
#define ERR_RTDB_KEYNOTFIND -3241 /* keyword not founded */
|
||||
#define ERR_RTDB_MULTIKEY -3242 /* Multi-keywords */
|
||||
#define ERR_RTDB_INVKEY -3243 /* The keyword is invalid */
|
||||
#define ERR_RTDB_MKEYFIELD -3244 /* The keyword field can be only one */
|
||||
#define ERR_RTDB_KEYFLEN -3245 /* The keyword length must be 4 times*/
|
||||
#define ERR_RTDB_DBTYPE -3246 /* Invalid db type */
|
||||
#define ERR_RTDB_KEYTYPE -3247 /* Invalid keyword type */
|
||||
#define ERR_RTDB_PASSWD -3248 /* Invalid passwd */
|
||||
|
||||
////table
|
||||
#define ERR_RTDB_TABLE_NO -3300 /* no match table or no*/
|
||||
#define ERR_RTDB_TABLE_STA -3301 /* table status is abnormal */
|
||||
|
||||
////record
|
||||
#define ERR_RTDB_EXISTREC -3451 /* Record existed, cannot write */
|
||||
#define ERR_RTDB_NEXISTREC -3452 /* Record not existed, cannot modify */
|
||||
#define ERR_RTDB_SUPMAX -3453 /* record value too bigger */
|
||||
#define ERR_RTDB_BELMIN -3454 /* record value too smaller */
|
||||
#define ERR_RTDB_RECSIZE -3455 /* record size wrong */
|
||||
#define ERR_RTDB_NOTERASE -3456 /* record not erased */
|
||||
#define ERR_RTDB_RECERASE -3457 /* The record is erased */
|
||||
#define ERR_RTDB_POINTER -3458 /* record_pointer error */
|
||||
#define ERR_RTDB_CONT_ERR -3459 /* condition express error */
|
||||
#define ERR_RTDB_NEED_CHK -3460 /* something wrong, need to check record state*/
|
||||
|
||||
////field
|
||||
#define ERR_RTDB_DATATYPE -3561 /* field data type is wrong */
|
||||
#define ERR_RTDB_DIFFTYPE -3562 /* type is different */
|
||||
#define ERR_RTDB_KEYFIELD -3563 /* The field is keyword */
|
||||
#define ERR_RTDB_BIGFIELDNO -3564 /* The field no is too big */
|
||||
#define ERR_RTDB_DLT_WRITE -3565 /* The direct link hash cannot write */
|
||||
#define ERR_RTDB_INVFIELDNO -3566 /* field_no is wrong */
|
||||
#define ERR_RTDB_NOTFIND -3567 /* Not find the value */
|
||||
#define ERR_RTDB_FIELD_NO -3568 /* no match field name or no */
|
||||
#define ERR_RTDB_FIELD_SIZE -3569 /* field length wrong */
|
||||
#define ERR_RTDB_NONE_FIELD -3570 /* this table has no field */
|
||||
|
||||
|
||||
//operation
|
||||
#define ERR_RTDB_INVCOMM -3601 /* Invalid db operater command */
|
||||
#define ERR_RTDB_NPERMIT -3602 /* The OP is not permit */
|
||||
|
||||
#define ERR_RTDB_CONTEXT -3620 /* no context or application */
|
||||
#define ERR_RTDB_APP_UNLOAD -3621 /* application isn't loaded */
|
||||
|
||||
|
||||
#define ERR_RTDB_SQL_COMMAND -3631 /*select error*/
|
||||
#define ERR_RTDB_SQL_FORM -3632 /*form error*/
|
||||
#define ERR_RTDB_SQL_WHERE -3633 /*where condition error*/
|
||||
#define ERR_RTDB_SQL_ORDER -3634 /*order by error*/
|
||||
|
||||
//memory
|
||||
#define ERR_RTDB_MEMORY -3700 /* Cannot malloc or calloc memory */
|
||||
#define ERR_RTDB_BUFFFULL -3701 /* Buffer is full */
|
||||
#define ERR_RTDB_MEM_NOALLOC -3702 /* The memory cannot allocation */
|
||||
|
||||
#define ERR_RTDB_MAP -3710 /* map file error */
|
||||
#define ERR_RTDB_SHM -3711 /* get shm error */
|
||||
|
||||
#define ERR_RTDB_OFLOW_MALLOC -3712 /* malloc error in overflow area */
|
||||
#define ERR_RTDB_OFLOW_FREE -3713 /* free error in overflow area */
|
||||
#define ERR_RTDB_STG_HASH_SAME_HASH_NUM -3715 /*error when INDEX_STORAGE_HASH_REC_HEAD::same_hash_num<0 */
|
||||
#define ERR_RTDB_WRONG_MEM -3716 /* shmget or mmap a wrong memory */
|
||||
#define ERR_RTDB_INDEX_MEM_ALLOC_TYPE -3717 /*wrong index memory allocation type */
|
||||
//#define ERR_RTDB_PTABFULL -10 /* process tab is full */
|
||||
|
||||
//sql
|
||||
#define ERR_RTDB_SQL -3720 /* sql syntax error */
|
||||
|
||||
#define ERR_RTDB_DBNAMENOTF -3800 /* db_name not founded */
|
||||
#define ERR_RTDB_FACNAMENOTF -3801 /* fac_name not founded */
|
||||
#define ERR_RTDB_VALNAMENOTF -3802 /* val_name not founded */
|
||||
#define ERR_RTDB_FIELDNAMENOTF -3803 /* field_name not founded */
|
||||
#define ERR_RTDB_VIEWFIELD -3901 /* view get fieldnum over error */
|
||||
#define ERR_RTDB_SYBASE -3902 /* modify sybase error */
|
||||
#define ERR_RTDB_INDEXERR -3903 /* index number error */
|
||||
#define ERR_RTDB_MODIFYSIZE -3904 /* modify bufsize error */
|
||||
#define ERR_RTDB_API_INVCOMM -3905 /* Invalid db operater command */
|
||||
#define ERR_RTDB_API_NOAPP -3906 /* App name not founded */
|
||||
#define ERR_RTDB_API_NODB -3907 /* Db name not founded */
|
||||
#define ERR_RTDB_API_INVDBNO -3908 /* Db no is wrong */
|
||||
#define ERR_RTDB_API_NODEOFF -3909 /* node is offline */
|
||||
#define ERR_RTDB_API_ERRINIT -3910 /* odbms init error */
|
||||
#define ERR_RTDB_API_NEWERR -3911 /* new space error */
|
||||
#define ERR_RTDB_API_DATAERR -3912 /* data tye error */
|
||||
#define ERR_RTDB_NOSPACE -3915 /* no space left in disk */
|
||||
|
||||
/* end of ERR_RTDB_ */
|
||||
102
code/sys_nicmonitor/include/db_api/DeleteRecorder.h
Normal file
102
code/sys_nicmonitor/include/db_api/DeleteRecorder.h
Normal file
@@ -0,0 +1,102 @@
|
||||
// insert into the odb_table.cpp
|
||||
#include "common_types.h"
|
||||
#ifndef _WINDOWS64
|
||||
#ifndef _HPUX
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <sys/pthread.h>
|
||||
#endif
|
||||
|
||||
#include <sys/sem.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#else
|
||||
#include <WinSock2.h>
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#include <process.h>
|
||||
#include <time.h>
|
||||
#include <sys/timeb.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "ThreadKit/ThreadKit.h"
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#define LOGLOCK 0x10999
|
||||
#define FILEMAXSIZE 30000000
|
||||
#define BIGSIZE 90000000
|
||||
#define FRESH (int)'6'
|
||||
#define NOTFRESH (int)'A'
|
||||
|
||||
|
||||
|
||||
|
||||
class ODB_API_LIB_API DeleteRecorder
|
||||
{
|
||||
private:
|
||||
FILE* _m_file_handle;
|
||||
int _m_file_size;
|
||||
int _m_status;
|
||||
|
||||
char processName[256];
|
||||
char fileName[256];
|
||||
|
||||
cmnUint64 processID;
|
||||
int lockID;
|
||||
time_t fileTag;
|
||||
|
||||
static DeleteRecorder * _m_instance;
|
||||
#ifndef _WINDOWS64
|
||||
static pthread_mutex_t _m_lock;
|
||||
#else
|
||||
// static CRITICAL_SECTION _m_lock;
|
||||
static THREADKIT::Mutex _m_lock;
|
||||
#endif
|
||||
|
||||
|
||||
DeleteRecorder(const DeleteRecorder &);
|
||||
void operator = (const DeleteRecorder &);
|
||||
|
||||
int initLock();
|
||||
int lockLog();
|
||||
int unlockLog();
|
||||
|
||||
int initLog();
|
||||
int checkAndRenameLog();
|
||||
int getNameFromPid();
|
||||
|
||||
public:
|
||||
static DeleteRecorder * getInstance();
|
||||
|
||||
DeleteRecorder();
|
||||
~DeleteRecorder();
|
||||
|
||||
int openLog();
|
||||
int writeLog(int app, int tab, cmnInt64 logContent);
|
||||
// int renameLog();
|
||||
int isValid();
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
void WriteLog(int,int,cmnInt64);
|
||||
175
code/sys_nicmonitor/include/db_api/codb_net.h
Normal file
175
code/sys_nicmonitor/include/db_api/codb_net.h
Normal file
@@ -0,0 +1,175 @@
|
||||
#ifndef __CODB_NET_H__
|
||||
#define __CODB_NET_H__
|
||||
|
||||
#include "db_api/odb_net_m.h"
|
||||
#include "db_api/odb_define.h"
|
||||
|
||||
#ifndef _WINDOWS64
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include "servicemanage.h"
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
namespace RTDB_SERVER
|
||||
{
|
||||
|
||||
template<class T>
|
||||
bool serializeProto(const T & message, char * &pret, int & retlen)
|
||||
{
|
||||
std::string output;
|
||||
if (!message.SerializeToString(&output)) {
|
||||
return false;
|
||||
}
|
||||
retlen = output.size();
|
||||
pret = new char[retlen];
|
||||
memcpy(pret, output.c_str(), retlen);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool parseProto(T & ret_message, const char * buf, int len)
|
||||
{
|
||||
if (!ret_message.ParseFromArray(buf, len)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
class ODB_API_LIB_API CODB_NET
|
||||
{
|
||||
public:
|
||||
CODB_NET();
|
||||
~CODB_NET();
|
||||
|
||||
public:
|
||||
int TableCreate(RTDB_PROTO::REQ_STDB_CREATE& req_create);//1
|
||||
int TableDelete(RTDB_PROTO::REQ_STDB_DELETE& req_delete);//2
|
||||
|
||||
int TableGet(RTDB_PROTO::REQ_READ& read_req, RTDB_PROTO::RSP_READ& read_rsp);//3
|
||||
int TableGet(RTDB_PROTO::REQ_READ_OLD& read_req, RTDB_PROTO::RSP_READ& read_rsp);//3 for remote
|
||||
int TableGet(RTDB_PROTO::REQ_READ& read_req, RTDB_PROTO::RSP_READ& read_rsp, DB_BYTE_T& remote_byte);//3
|
||||
int TableGet(RTDB_PROTO::REQ_READ_OLD& read_req, RTDB_PROTO::RSP_READ& read_rsp, DB_BYTE_T& remote_byte);//3 for remote
|
||||
int TableGetASync(RTDB_PROTO::REQ_READ& read_req);
|
||||
int TableGet_OPT(RTDB_PROTO::REQ_READ& read_req, char** buf_ptr, int& data_size);//40
|
||||
int TableGet_OPT(RTDB_PROTO::REQ_READ_OLD& read_req, char** buf_ptr, int& data_size);//40 for remote
|
||||
int TableGet_OPT(RTDB_PROTO::REQ_READ& read_req, char** buf_ptr, int& data_size, DB_BYTE_T& remote_byte);//40
|
||||
int TableGet_OPT(RTDB_PROTO::REQ_READ_OLD& read_req, char** buf_ptr, int& data_size, DB_BYTE_T& remote_byte);//40 for remote
|
||||
int TableGet_OPTASync(RTDB_PROTO::REQ_READ& read_req);//40
|
||||
int TableGetByName(RTDB_PROTO::REQ_READ& read_req, RTDB_PROTO::RSP_READ& read_rsp);//4
|
||||
int TableGetByName(RTDB_PROTO::REQ_READ_OLD& read_req, RTDB_PROTO::RSP_READ& read_rsp);//4 for remote
|
||||
int TableGetByNameASync(RTDB_PROTO::REQ_READ& read_req);//4
|
||||
int TableGetByName_OPT(RTDB_PROTO::REQ_READ& read_req, char** buf_ptr, int& data_size, DB_BYTE_T& remote_byte);//41
|
||||
int TableGetByName_OPT(RTDB_PROTO::REQ_READ_OLD& read_req, char** buf_ptr, int& data_size, DB_BYTE_T& remote_byte);//41
|
||||
int TableGetByName_OPTASync(RTDB_PROTO::REQ_READ& read_req);//41
|
||||
int TableGetByFieldValue(RTDB_PROTO::REQ_CON& read_req, RTDB_PROTO::RSP_CON& read_rsp);//5
|
||||
int TableGetByFieldValueASync(RTDB_PROTO::REQ_CON& read_req);//5
|
||||
int TableWrite(RTDB_PROTO::REQ_KEY_WRITE& write_req);//6
|
||||
int TableWriteASync(RTDB_PROTO::REQ_KEY_WRITE& write_req);//6
|
||||
int TableModify(RTDB_PROTO::REQ_MODIFY& modify_req);//7
|
||||
int TableModifyASync(RTDB_PROTO::REQ_MODIFY& modify_req);//7
|
||||
int TableUpdate(RTDB_PROTO::REQ_UPDATE& update_req);//8
|
||||
int TableUpdateASync(RTDB_PROTO::REQ_UPDATE& update_req);//8
|
||||
int DeleteRecord(RTDB_PROTO::REQ_KEY_ERASE& delete_req);//9
|
||||
int DeleteRecordASync(RTDB_PROTO::REQ_KEY_ERASE& delete_req);//9
|
||||
int TableClear(RTDB_PROTO::REQ_TABLE_CLEAR& clear_req);//10
|
||||
int TableClearASync(RTDB_PROTO::REQ_TABLE_CLEAR& clear_req);//10
|
||||
|
||||
int GetTablePara(RTDB_PROTO::REQ_PARAMETER& para_req, RTDB_PROTO::RSP_PARAMETER& para_rsp);//11
|
||||
int GetTableParaASync(RTDB_PROTO::REQ_PARAMETER& para_req);//11
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
int GetTableParaAll(RTDB_PROTO::REQ_PARAMETER& para_req, RTDB_PROTO::RSP_PARAMETER& para_rsp);//35
|
||||
int TableGetAll(RTDB_PROTO::REQ_READ& read_req, RTDB_PROTO::RSP_READ& read_rsp);//36
|
||||
int GetTableParaVir(RTDB_PROTO::REQ_VIR_FIELD& para_req, RTDB_PROTO::RSP_VIR_FIELD& para_rsp);//37
|
||||
#endif
|
||||
int GetTableParameter(RTDB_PROTO::REQ_PARAMETER& para_req, RTDB_PROTO::RSP_READ& para_rsp);//12
|
||||
int GetAppTableParameter(RTDB_PROTO::REQ_APP_PARAMETER& para_req, RTDB_PROTO::RSP_APP_PARAMETER& para_rsp);//13
|
||||
int GetFieldPara(RTDB_PROTO::REQ_FIELD_BASE_INFO& para_req , RTDB_PROTO::RSP_FIELD_BASE_INFO& para_rsp);//14
|
||||
|
||||
int GetKeyInfo(RTDB_PROTO::RSP_KEYINFO& key_rsp);//15
|
||||
int GetKeyInfoSlice(RTDB_PROTO::RSP_KEYINFO_SLICE& key_rsp);//15
|
||||
int TableGetBySql(RTDB_PROTO::REQ_SQL& select_req, RTDB_PROTO::RSP_READ& select_rsp);//16
|
||||
int TableGetBySqlASync(RTDB_PROTO::REQ_SQL& select_req);//16
|
||||
int MenuRead(RTDB_PROTO::REQ_MENU& menu_req, RTDB_PROTO::RSP_MENU& menu_rsp);//17
|
||||
int TableReleMenuRead(RTDB_PROTO::REQ_RELE_MENU& rele_req, RTDB_PROTO::RSP_RELE_MENU& rele_rsp);//18
|
||||
int GetNameStringByKeyID(RTDB_PROTO::REQ_NAME_STRING& name_req, RTDB_PROTO::RSP_NAME_STRING& name_rsp);//19
|
||||
int GetNameStringByKeyIDASync(RTDB_PROTO::REQ_NAME_STRING& name_req);//19
|
||||
int GetRefMenuString(RTDB_PROTO::REQ_REF_MENU& ref_req, RTDB_PROTO::RSP_REF_MENU& ref_rsp);//20
|
||||
int GetRefMenuStringAsync(RTDB_PROTO::REQ_REF_MENU& ref_req);//20
|
||||
int GetNameStringByMultiKeyID(RTDB_PROTO::REQ_MULTI_NAME_STRING& name_req, RTDB_PROTO::RSP_MULTI_NAME_STRING& name_rsp);//21
|
||||
int GetNameStringByMultiKeyIDASync(RTDB_PROTO::REQ_MULTI_NAME_STRING& name_req);//21
|
||||
|
||||
int GraphGetData(RTDB_PROTO::GRAPH_REAL_ODB_REQ& real_req, RTDB_PROTO::GRAPH_REAL_RSP& real_rsp);//22
|
||||
int GraphGetData(RTDB_PROTO::GRAPH_REAL_ODB_REQ_OLD& real_req, RTDB_PROTO::GRAPH_REAL_RSP& real_rsp);//22
|
||||
int GraphGetDataASync(RTDB_PROTO::GRAPH_REAL_ODB_REQ& real_req);
|
||||
int GraphGetAppInfo(RTDB_PROTO::GRAPH_ORDER_KEY_REQ& app_req, RTDB_PROTO::GRAPH_ORDER_KEY_RSP& app_rsp);//23
|
||||
int GraphGetAppInfoASync(RTDB_PROTO::GRAPH_ORDER_KEY_REQ& app_req);//23
|
||||
|
||||
int ExchangeNameNo(RTDB_PROTO::REQ_ENTITY& object_req, RTDB_PROTO::RSP_ENTITY& object_rsp);//24
|
||||
|
||||
int GetFacNameByKeyNo(RTDB_PROTO::REQ_FAC& fac_req, RTDB_PROTO::RSP_FAC& fac_rsp);//25
|
||||
int GetFacNameByFacID(RTDB_PROTO::REQ_FAC& fac_req, RTDB_PROTO::RSP_FAC& fac_rsp);//26
|
||||
int GetFacNameByFacNo(RTDB_PROTO::REQ_FAC& fac_req, RTDB_PROTO::RSP_FAC& fac_rsp);//27
|
||||
|
||||
int GetFacIDByFacName(RTDB_PROTO::REQ_FAC& fac_req, RTDB_PROTO::RSP_FAC& fac_rsp);//28
|
||||
int GetFacNoByFacName(RTDB_PROTO::REQ_FAC& fac_req, RTDB_PROTO::RSP_FAC& fac_rsp);//29
|
||||
|
||||
int GetFacIDByFacNo(RTDB_PROTO::REQ_FAC& fac_req, RTDB_PROTO::RSP_FAC& fac_rsp);//30
|
||||
int GetFacNoByFacID(RTDB_PROTO::REQ_FAC& fac_req, RTDB_PROTO::RSP_FAC& fac_rsp);//31
|
||||
|
||||
int GetValueAndStatus(RTDB_PROTO::REQ_VAL_STA& req_key_id, RTDB_PROTO::RSP_INT_VAL_STA* rsp_int_val, RTDB_PROTO::RSP_FLOAT_VAL_STA* rsp_float_val, RTDB_PROTO::RSP_CHAR_VAL_STA* rsp_char_val, RTDB_PROTO::RSP_LONG_VAL_STA* rsp_long_val, RTDB_PROTO::RSP_UNION_VAL_STA* rsp_union_val);//32
|
||||
int GetValueAndStatus(RTDB_PROTO::REQ_VAL_STA_OLD& req_key_id, RTDB_PROTO::RSP_INT_VAL_STA* rsp_int_val, RTDB_PROTO::RSP_FLOAT_VAL_STA* rsp_float_val, RTDB_PROTO::RSP_CHAR_VAL_STA* rsp_char_val, RTDB_PROTO::RSP_LONG_VAL_STA* rsp_long_val, RTDB_PROTO::RSP_UNION_VAL_STA* rsp_union_val);//32
|
||||
int GetValueAndStatusASync(RTDB_PROTO::REQ_VAL_STA& req_key_id);//32
|
||||
int GetValueAndStatus_YCOPT (RTDB_PROTO::REQ_VAL_STA& req_key_id,
|
||||
std::vector<float> & vec_val, std::vector<int> & vec_status);//42
|
||||
int GetValueAndStatus_YXOPT (RTDB_PROTO::REQ_VAL_STA& req_key_id,
|
||||
std::vector<unsigned char> & vec_val, std::vector<int> & vec_status);//43
|
||||
|
||||
int PingRtdbServer(int req_data , int& rsp_data);//33
|
||||
int GraphDataSend(RTDB_PROTO::GRAPH_REAL_ODB_REQ &real_req,Handle &hdl) ;//22
|
||||
int GraphDataRecv(RTDB_PROTO::GRAPH_REAL_RSP &real_rsp,Handle &hdl,int &ret);
|
||||
|
||||
int DeleteRecords(RTDB_PROTO::DEL_REQ& delete_req);//34
|
||||
int DeleteRecordsASync(RTDB_PROTO::DEL_REQ& delete_req);//34
|
||||
int ReadAsyncRsp(char** rsp_buffer, int* rsp_len, int& ret_code, DB_BYTE_T& remote_byte);
|
||||
int ReadAsyncRsp(char** rsp_buffer, int* rsp_len, int& ret_code);
|
||||
int ReadAsyncRsp(int& ret_code);
|
||||
int ReadAsyncRsp(RTDB_PROTO::RSP_INT_VAL_STA* rsp_int_val, RTDB_PROTO::RSP_FLOAT_VAL_STA* rsp_float_val, RTDB_PROTO::RSP_CHAR_VAL_STA* rsp_char_val, RTDB_PROTO::RSP_LONG_VAL_STA* rsp_long_val, RTDB_PROTO::RSP_UNION_VAL_STA* rsp_union_val);//32
|
||||
int ReadAsyncRespGraphGetData(RTDB_PROTO::GRAPH_REAL_RSP& real_rsp, int& ret_code);
|
||||
void FreeAsyncHandle();
|
||||
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
////add for xdb wuqx ----- 2012-07-11
|
||||
int XdbAccess(RTDB_PROTO::REQ_XDB& req, RTDB_PROTO::RSP_XDB& rsp);
|
||||
#endif
|
||||
public:
|
||||
int SetServiceInfo(ServiceInfo& service_info);
|
||||
int SetDomainInfo(const DomainInfo* p_domain_info);
|
||||
void SetHandle(const Handle handle);
|
||||
void ClearHandle(const Handle handle);
|
||||
static CODB_NET* _narrow(ServiceInfo& serv_info, DomainInfo* p_domain_info = NULL);
|
||||
|
||||
private:
|
||||
ServiceInfo m_Serviceinfo;
|
||||
DomainInfo* m_pDomaininfo;
|
||||
char m_IpAddress[64];
|
||||
int m_Port;
|
||||
public:
|
||||
Handle m_Handle;
|
||||
Handle m_Handle_Async;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
61
code/sys_nicmonitor/include/db_api/mc_rtdb_m.h
Normal file
61
code/sys_nicmonitor/include/db_api/mc_rtdb_m.h
Normal file
@@ -0,0 +1,61 @@
|
||||
//**************************************
|
||||
// Generated by mcpp translator
|
||||
// Version 1.3
|
||||
//**************************************
|
||||
|
||||
#ifndef __MC_RTDB_M_H__
|
||||
#define __MC_RTDB_M_H__
|
||||
|
||||
#include"mcode/mvector.h"
|
||||
#include"mcode/mstring.h"
|
||||
#include"mcode/mstream.h"
|
||||
#include"mcode/mclient.h"
|
||||
|
||||
|
||||
typedef MLang::VECTOR<char> MC_SEQ_CHAR;
|
||||
typedef MLang::VECTOR<int> MC_SEQ_INT;
|
||||
struct MC_SYNC_RT_DATA
|
||||
{
|
||||
int ctx_no;
|
||||
int byte_tag;
|
||||
MLang::STRING scn_name;
|
||||
int scn_inst;
|
||||
MLang::STRING subscn_name;
|
||||
int subscn_inst;
|
||||
int table_no;
|
||||
int op_type;
|
||||
int all_field_num;
|
||||
int one_record_size;
|
||||
int record_num;
|
||||
int stage;
|
||||
int stageall;
|
||||
MLang::STRING stage_message;
|
||||
MLang::STRING description;
|
||||
int map_no;
|
||||
int run_status;
|
||||
int zipped;
|
||||
int unzipped_length;
|
||||
int zipped_length;
|
||||
int reserve_para_1;
|
||||
int reserve_para_2;
|
||||
int reserve_para_3;
|
||||
MC_SEQ_INT op_field;
|
||||
MC_SEQ_CHAR key_buf;
|
||||
MC_SEQ_CHAR op_buf;
|
||||
MC_SYNC_RT_DATA();
|
||||
MC_SYNC_RT_DATA(const MC_SYNC_RT_DATA&);
|
||||
MC_SYNC_RT_DATA&operator=(const MC_SYNC_RT_DATA&);
|
||||
void __write(MLang::OutputStream&__os)const;
|
||||
void __read(MLang::InputStream&__is);
|
||||
};
|
||||
typedef MLang::VECTOR<MC_SYNC_RT_DATA> MC_SEQ_SYNC_RT_DATA;
|
||||
struct MC_SYNC_RT_DATA_VEC
|
||||
{
|
||||
MC_SEQ_SYNC_RT_DATA sync_rt_data_vec;
|
||||
MC_SYNC_RT_DATA_VEC();
|
||||
MC_SYNC_RT_DATA_VEC(const MC_SYNC_RT_DATA_VEC&);
|
||||
MC_SYNC_RT_DATA_VEC&operator=(const MC_SYNC_RT_DATA_VEC&);
|
||||
void __write(MLang::OutputStream&__os)const;
|
||||
void __read(MLang::InputStream&__is);
|
||||
};
|
||||
#endif
|
||||
125
code/sys_nicmonitor/include/db_api/mc_rtdb_mng.h
Normal file
125
code/sys_nicmonitor/include/db_api/mc_rtdb_mng.h
Normal file
@@ -0,0 +1,125 @@
|
||||
#ifndef _MC_RTDB_MNG_H_
|
||||
#define _MC_RTDB_MNG_H_
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef MC_RTDB_MNG_EXPORTS
|
||||
#define MC_RTDB_MNG_API __declspec(dllexport)
|
||||
#else
|
||||
#define MC_RTDB_MNG_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define MC_RTDB_MNG_API
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "pub_buf.h"
|
||||
#include "db_api/mc_rtdb_m.h"
|
||||
|
||||
struct McScnInfo
|
||||
{
|
||||
std::string scn_name;
|
||||
int scn_inst;
|
||||
std::string subscn_name;
|
||||
int subscn_inst;
|
||||
};
|
||||
|
||||
struct TableColumnKey
|
||||
{
|
||||
//int app_no;
|
||||
std::string scn_name;
|
||||
int scn_inst;
|
||||
std::string subscn_name;
|
||||
int subscn_inst;
|
||||
|
||||
int table_no;
|
||||
std::string column_name;
|
||||
std::vector<struct RTDB_KEY_STRU> keys;
|
||||
};
|
||||
|
||||
struct StageStruct
|
||||
{
|
||||
int stage;
|
||||
char stage_message[512];
|
||||
char description[1024];
|
||||
int map_no;
|
||||
int run_status;
|
||||
};
|
||||
|
||||
class MC_RTDB_MNG_API McRtdbMng
|
||||
{
|
||||
public:
|
||||
|
||||
McRtdbMng();
|
||||
~McRtdbMng();
|
||||
|
||||
//实时同步数据更新信息
|
||||
//int SyncSnapShot(const int app_no, std::vector<struct TableColumnKey>& tck, const struct StageStruct stage_stru);
|
||||
int SyncSnapShot(const struct McScnInfo& scninfo, std::vector<struct TableColumnKey>& tck, const struct StageStruct stage_stru);
|
||||
|
||||
//保存应用数据更新信息,数据文件存放在~/conf/mc_scn下({app_name}.dat)
|
||||
//int SaveSnapShot(const std::string app_name, int stage, const std::string description);
|
||||
int SaveSnapShot(const struct McScnInfo& scninfo, int stage, const std::string& description);
|
||||
|
||||
//从数据文件恢复应用数据更新信息
|
||||
//int RecoverSnapShot(const std::string app_name, int stage);
|
||||
int RecoverSnapShot(const struct McScnInfo& scninfo, int stage);
|
||||
|
||||
//设置计算阶段状态信息
|
||||
int SetStage(const struct McScnInfo& scninfo, const struct StageStruct stage_stru);
|
||||
|
||||
//读取计算阶段状态信息 (domain = NULL时读取本机,否则读取指定机器)
|
||||
//int ReadStage(int app_no, std::string& stage_message, std::string& description, int& map_no, int& run_status, char* domain = NULL);
|
||||
int ReadStage(const struct McScnInfo& scninfo, std::string& stage_message, std::string& description, int& map_no, int& run_status, char* domain = NULL);
|
||||
|
||||
//读取计算的总阶段数作为返回值
|
||||
//int ReadTotalStage(int app_no);
|
||||
int ReadTotalStage(const struct McScnInfo& scninfo);
|
||||
|
||||
//设置计算的总阶段数
|
||||
//int SetTotalStage(int app_no, int stageall);
|
||||
int SetTotalStage(const struct McScnInfo& scninfo, int stageall);
|
||||
|
||||
//修改本机的RunStatus
|
||||
//int SetRunStatus (int app_no, int run_status); //run_status值为0或1
|
||||
int SetRunStatus(const struct McScnInfo& scninfo, int run_status); //run_status值为0或1
|
||||
|
||||
//仅在主机状态下使用,修改本机的RunStatus,并将其他中心的RunStatus值设为0
|
||||
//int SetRunStatusSync(int app_no, int run_status);
|
||||
int SetRunStatusSync(const struct McScnInfo& scninfo, int run_status);
|
||||
|
||||
int WriteSnapShotToStandBy (const char* recive_buf, const int buf_len);
|
||||
|
||||
private:
|
||||
|
||||
int read_tck_config(const struct McScnInfo& scninfo, std::vector<struct TableColumnKey>& tck);
|
||||
|
||||
int read_destination(const std::vector<struct MC_CLUSTER>& vec_cluster);
|
||||
|
||||
int read_data(const std::vector<struct TableColumnKey>& tck, CBuffer& buf, \
|
||||
int stage = 0, char* stage_message = NULL, char* description = NULL, \
|
||||
int map_no = 0, int run_status = 0, int stageall = 0);
|
||||
|
||||
//int SetStage(const struct McScnInfo& scninfo, const struct StageStruct stage_stru);
|
||||
|
||||
int SetTotalStageToStandBy(const struct McScnInfo& scninfo, int stageall);
|
||||
|
||||
int SetStageToStandBy(const struct McScnInfo& scninfo, const struct StageStruct stage_stru);
|
||||
|
||||
int get_local_name(char* local_name);
|
||||
|
||||
int SetStageSync(const struct McScnInfo& scninfo, int stage);
|
||||
|
||||
int SetMessageSync(const struct McScnInfo& scninfo, const std::string description);
|
||||
|
||||
|
||||
//TEST
|
||||
int ReadTotalStage_Conf(int app_no);
|
||||
|
||||
//TEST
|
||||
int SetTotalStage_Conf(int app_no, int stageall);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
269
code/sys_nicmonitor/include/db_api/odb_apinet.h
Normal file
269
code/sys_nicmonitor/include/db_api/odb_apinet.h
Normal file
@@ -0,0 +1,269 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_apinet.h
|
||||
DESCRIPTION: for class CTableNet of net access
|
||||
FUNCTION LIST:
|
||||
COMMENT: for net access
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2004-06-25 1.1 add context_no parameter
|
||||
2003-01-09 1.0 modify
|
||||
================================================================================
|
||||
2003-01-09 1.0 created
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ODB_APINET_h__
|
||||
#define __ODB_APINET_h__
|
||||
|
||||
#ifndef __ODB_COMMON_H__
|
||||
#include "db_api/odb_common.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ODB_TABLEBASE_H__
|
||||
#include "db_api/odb_tablebase.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ODB_NETFACTORY_h__
|
||||
#include "db_api/odb_netfactory.h"
|
||||
#endif
|
||||
|
||||
#include "task_service.h"
|
||||
#include "db_api/odb_net_m.h"
|
||||
#include "db_api/codb_net.h"
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
//using namespace RTDB_SERVER;
|
||||
using namespace ODB;
|
||||
|
||||
namespace NET_ODB
|
||||
{
|
||||
//lmj add for GraphGetDataEx
|
||||
typedef struct
|
||||
{
|
||||
cmnInt64 graph_id;
|
||||
cmnInt64 cal_type;
|
||||
cmnInt64 req_status; //-1,0<><30>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>,1(<28><><EFBFBD><EFBFBD>)
|
||||
Handle hdl;
|
||||
|
||||
} TGraphReq;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
std::string scn_name;
|
||||
std::string subscn_name;
|
||||
int type;
|
||||
} TApiNetPriv;
|
||||
|
||||
class ODB_API_LIB_API CApiNet: public CTableBase
|
||||
{
|
||||
public:
|
||||
CApiNet();
|
||||
CApiNet(const int app_no, const short context_no = 0 );
|
||||
CApiNet(const int app_no, const int table_no, const short context_no=0);
|
||||
//CApiNet(const char *hostname);
|
||||
~CApiNet();
|
||||
|
||||
public:
|
||||
int SetAppNo(const int app_no, const short context_no = 0);
|
||||
int SetScenario(const std::string& scenario_name,
|
||||
int scenario_inst_no,
|
||||
const std::string& sub_scenario_name,
|
||||
int sub_scenario_inst_no);
|
||||
int SetScenario(const int scenario_no,
|
||||
const int scenario_inst_no,
|
||||
const int sub_scenario_no,
|
||||
const int sub_scenario_inst_no);
|
||||
int SetAppNo(const std::string& scenario_name,
|
||||
int scenario_inst_no,
|
||||
const std::string& sub_scenario_name,
|
||||
int sub_scenario_inst_no);
|
||||
int Open(const std::string& scenario_name,
|
||||
int scenario_inst_no,
|
||||
const std::string& sub_scenario_name,
|
||||
int sub_scenario_inst_no, int table_no);
|
||||
int SetHostMode(const char* host_name);
|
||||
|
||||
int Open(const int table_no );
|
||||
int Open(const int app_no, const int table_no, const short context_no=0);
|
||||
//int Open(const char* hostname);
|
||||
|
||||
public:
|
||||
int MenuRead(const char* menu_name, std::vector<struct MENU_INFO>& vec_menu, const int menu_status=MENU_ON);
|
||||
|
||||
int TableReleMenuRead(const int table_no, std::vector<struct MENU_RELEVANT>& vec_menu);
|
||||
|
||||
//int GetNameStringByKeyID(const KEY_ID_STRU& keyid_stru, string& ref_string);
|
||||
//int GetNameStringByKeyIDSplit(const KEY_ID_STRU& keyid_stru, string& ref_string);
|
||||
//int GetNameStringByKeyID(const std::vector<KEY_ID_STRU>& vec_keyid, std::vector<string>& vec_ref_string);
|
||||
//int GetNameStringByKeyIDSplit(const std::vector<KEY_ID_STRU>& vec_keyid, std::vector<string>& vec_ref_string);
|
||||
|
||||
int GetRefMenuString(const int table_no, std::vector<struct MENU_STRING>& vec_menu);
|
||||
int GetRefMenuStringSplit(const int table_no, std::vector<struct MENU_STRING>& vec_menu);
|
||||
|
||||
//jinjing 2017-01-17
|
||||
int GetRefMenuStringMultiKeys(const int table_no, std::vector<RTDB_KEY_STRU>& vec_rtdbkeyid,
|
||||
std::vector<struct MENU_STRING>& vec_menu);
|
||||
|
||||
//int GetNameStringByID(const cmnInt64 reference_id, string& ref_string);
|
||||
//int GetNameStringByIDSplit(const long reference_id, string& ref_string);
|
||||
//int GetNameStringByID(const std::vector<cmnInt64>& vec_refid, std::vector<std::string>& vec_ref_string);
|
||||
//int GetNameStringByIDSplit(const std::vector<long>& vec_refid, std::vector<std::string>& vec_ref_string);
|
||||
int GetNameStringBykey(const char* key_ptr, string& ref_string);
|
||||
int GetNameStringBykeySplit(const char* key_ptr, string& ref_string);
|
||||
|
||||
int GetNameStringByAppKeyID( const std::vector<struct APP_KEY_STRU>& vec_appkeyid, std::vector<string>& vec_name_string);
|
||||
int GetNameStringByAppID( const std::vector<APP_ID_STRU>& vec_appid, std::vector<string>& vec_name_string);
|
||||
|
||||
int GetNameStringByRtdbKeyID(const RTDB_KEY_STRU& rtdb_keyid_stru, string& ref_string);
|
||||
int GetNameStringByRtdbKeyIDSplit(const RTDB_KEY_STRU& rtdb_keyid_stru, string& ref_string);
|
||||
int GetNameStringByRtdbKeyID(const std::vector<RTDB_KEY_STRU>& vec_rtdbkeyid, std::vector<string>& vec_ref_string);
|
||||
int GetNameStringByRtdbKeyIDSplit(const std::vector<RTDB_KEY_STRU>& vec_rtdbkeyid, std::vector<string>& vec_ref_string);
|
||||
|
||||
int GraphGetAppInfo(const struct ODB::GRAPH_ORDER_KEY_REQ& graph_req, struct ODB::GRAPH_ORDER_KEY_RSP& graph_rsp);
|
||||
int GraphGetAppInfoSplit(const struct ODB::GRAPH_ORDER_KEY_REQ& graph_req, struct ODB::GRAPH_ORDER_KEY_RSP& graph_rsp);
|
||||
int GraphGetData(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP& real_rsp);
|
||||
int GraphGetDataSplit(const struct RTDB_PROTO::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP& real_rsp);
|
||||
int GraphGetDataSplitSimple(const struct RTDB_PROTO::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP& real_rsp);
|
||||
private:
|
||||
int GraphGetData(const RTDB_PROTO::GRAPH_REAL_REQ& real_req, RTDB_SERVER::GRAPH_REAL_RSP& real_rsp);
|
||||
void GraphRealReqConv(const RTDB_SERVER::GRAPH_REAL_REQ &real_req, RTDB_PROTO::GRAPH_REAL_REQ &real_req_inner);
|
||||
void GraphRealRspConv(const RTDB_PROTO::GRAPH_REAL_RSP &real_rsp_inner, RTDB_SERVER::GRAPH_REAL_RSP &real_rsp);
|
||||
//int GraphGetDataEx(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP_out real_rsp, bool is_req=true);
|
||||
//int GraphDataRecv(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP_out real_rsp );
|
||||
|
||||
//int SqlGet(const char* str_sql, char** buf_ptr, int& buf_size);
|
||||
|
||||
public:
|
||||
int GetFacNameByKeyNo(const int table_no, const char* key_ptr, string& ref_string);
|
||||
int GetFacNameByFacID(char* fac_name, const RTDB_KEY_STRU fac_id);
|
||||
int GetFacNameByFacNo(char* fac_name, const int fac_no);
|
||||
|
||||
int GetFacIDByFacName(RTDB_KEY_STRU& fac_id, const char* fac_name);
|
||||
int GetFacNoByFacName(int& fac_no, const char* fac_name);
|
||||
|
||||
int GetFacIDByFacNo(RTDB_KEY_STRU& fac_id, const int fac_no);
|
||||
int GetFacNoByFacID( int& fac_no, const RTDB_KEY_STRU fac_id);
|
||||
|
||||
int ColMeasType( const std::vector<RTDB_KEY_STRU> vec_keyid , std::vector<int>& vec_col_prop );
|
||||
|
||||
public:
|
||||
int GetAppNameByNo(char* app_name, const int app_no) { return 0;}
|
||||
int GetAppNoByName(int& app_no, const char* app_name) { return 0;}
|
||||
|
||||
int GetTableNameByNo(char* table_name, const int table_no, const bool is_eng=true) { return 0;}
|
||||
int GetTableNoByName(int& table_no, const char* table_name, const bool is_eng=true) { return 0;}
|
||||
|
||||
int GetFieldNameByNo(char* field_name, const int field_no, const bool is_eng=true) { return 0;}
|
||||
int GetFieldNoByName(int& field_no, const char* field_name, const bool is_eng=true) { return 0;}
|
||||
|
||||
public:
|
||||
/*int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
int GetValueAndStatusSplit(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
int GetValueAndStatusSplit(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatusSplit(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
int GetValueAndStatusSplit(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec );//union type
|
||||
*/
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct INT_VALUE_STATUS> & KeyIdValVec);//ym
|
||||
int GetValueAndStatusSplit(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct INT_VALUE_STATUS> & KeyIdValVec);//ym
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec);//yc
|
||||
int GetValueAndStatusSplit(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec);//yc
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatusSplit(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
int GetValueAndStatusSplit(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec );//union type
|
||||
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
int GetValueAndStatusSplit(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
int GetValueAndStatusSplit(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatusSplit(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
int GetValueAndStatusSplit(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
|
||||
int GetRefMenuString (int table_no, std::vector<struct MENU_STRING>& vec_menu, short area_no);
|
||||
int GetRefMenuStringWithAreaSplit(int table_no, std::vector<struct MENU_STRING>& vec_menu, short area_no);
|
||||
int GetRefMenuString(const vector<int> vec_table, std::vector<struct MENU_STRING>& vec_menu);
|
||||
public:
|
||||
int PingRtdbServer(int req_data , int & rep_data);
|
||||
int GraphDataSend(const struct RTDB_PROTO::GRAPH_REAL_REQ& real_req );
|
||||
int GraphDataRecv(RTDB_PROTO::GRAPH_REAL_RSP& real_rsp );
|
||||
|
||||
public:
|
||||
int SetDomainName(const char* domain_name);
|
||||
int SetSecLabel(tSecLabel& sec_label);
|
||||
void ClearDomainName();
|
||||
int SetSliceNo(cmnUint32 slice_no);
|
||||
|
||||
private:
|
||||
int Start();
|
||||
int Refresh();
|
||||
int Refresh(int app_no);
|
||||
int GetSliceByKey(const char* key, cmnUint32& slice_no);
|
||||
int GetAllSlice(vector<int>& slice_no);
|
||||
int GetKeyInfo();
|
||||
int GetKeyInfoSlice();
|
||||
|
||||
inline int slice_app_to_no(int slice_app_no){return slice_app_no % 1000;}
|
||||
inline int slice_no_to_app(int slice_no){return slice_no+AP_SCADA_AREA;}
|
||||
|
||||
private:
|
||||
CApiNet(const CApiNet&);
|
||||
CApiNet& operator=(const CApiNet&);
|
||||
|
||||
private:
|
||||
RTDB_SERVER::CODB_NET* m_OdbNet;
|
||||
CNetFactory* m_Factory;
|
||||
//Handle m_Handle; //for service_bus
|
||||
|
||||
std::vector<int> m_VecKey;
|
||||
std::vector<int> m_IsSliced;
|
||||
//
|
||||
short m_ContextNo;
|
||||
int m_AppNo;
|
||||
int m_TableNo;
|
||||
DB_BYTE_T m_ByteTag;
|
||||
string m_ScenarioName ;
|
||||
int m_ScenarioInstance ;
|
||||
string m_SubScenarioName ;
|
||||
int m_SubScenarioInstance ;
|
||||
|
||||
char m_DomainName[40];
|
||||
tSecLabel m_SecLabel;
|
||||
bool m_IsRemote;
|
||||
int m_SliceNo;
|
||||
TaskService* task_service;
|
||||
|
||||
bool m_IsSysAdmHost;
|
||||
char m_HostName[MAX_NAME_STRING_LEN];
|
||||
|
||||
TGraphReq *m_pGraphReq; //lmj add for GraphGetDataEx
|
||||
TApiNetPriv *m_pPrvStru; //lmj add for reserver
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
236
code/sys_nicmonitor/include/db_api/odb_apinet_rtdb_key.h
Normal file
236
code/sys_nicmonitor/include/db_api/odb_apinet_rtdb_key.h
Normal file
@@ -0,0 +1,236 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_apinet.h
|
||||
DESCRIPTION: for class CTableNet of net access
|
||||
FUNCTION LIST:
|
||||
COMMENT: for net access
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2004-06-25 1.1 add context_no parameter
|
||||
2003-01-09 1.0 modify
|
||||
================================================================================
|
||||
2003-01-09 1.0 created
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ODB_APINET_h__
|
||||
#define __ODB_APINET_h__
|
||||
|
||||
#ifndef __ODB_COMMON_H__
|
||||
#include "db_api/odb_common.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ODB_TABLEBASE_H__
|
||||
#include "db_api/odb_tablebase.h"
|
||||
#endif
|
||||
|
||||
#ifndef __ODB_NETFACTORY_h__
|
||||
#include "db_api/odb_netfactory.h"
|
||||
#endif
|
||||
|
||||
#include "task_service.h"
|
||||
#include "db_api/odb_net_m.h"
|
||||
#include "db_api/codb_net.h"
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
//using namespace RTDB_SERVER;
|
||||
using namespace ODB;
|
||||
|
||||
namespace NET_ODB
|
||||
{
|
||||
//lmj add for GraphGetDataEx
|
||||
typedef struct
|
||||
{
|
||||
cmnInt64 graph_id;
|
||||
cmnInt64 cal_type;
|
||||
cmnInt64 req_status; //-1,0£¨È¡Êý£©,1(ÇëÇó)
|
||||
Handle hdl;
|
||||
|
||||
} TGraphReq;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int type;
|
||||
} TApiNetPriv;
|
||||
|
||||
class ODB_API_LIB_API CApiNet: public CTableBase
|
||||
{
|
||||
public:
|
||||
CApiNet();
|
||||
CApiNet(const int app_no, const short context_no = 0 );
|
||||
CApiNet(const int app_no, const int table_no, const short context_no=0);
|
||||
//CApiNet(const char *hostname);
|
||||
~CApiNet();
|
||||
|
||||
public:
|
||||
int SetAppNo(const int app_no, const short context_no = 0);
|
||||
int SetHostMode(const char* host_name);
|
||||
|
||||
int Open(const int table_no );
|
||||
int Open(const int app_no, const int table_no, const short context_no=0);
|
||||
//int Open(const char* hostname);
|
||||
|
||||
public:
|
||||
int MenuRead(const char* menu_name, std::vector<struct MENU_INFO>& vec_menu, const int menu_status=MENU_ON);
|
||||
|
||||
int TableReleMenuRead(const int table_no, std::vector<struct MENU_RELEVANT>& vec_menu);
|
||||
|
||||
int GetNameStringByKeyID(const KEY_ID_STRU& keyid_stru, string& ref_string);
|
||||
int GetNameStringByKeyIDSplit(const KEY_ID_STRU& keyid_stru, string& ref_string);
|
||||
int GetNameStringByKeyID(const std::vector<KEY_ID_STRU>& vec_keyid, std::vector<string>& vec_ref_string);
|
||||
int GetNameStringByKeyIDSplit(const std::vector<KEY_ID_STRU>& vec_keyid, std::vector<string>& vec_ref_string);
|
||||
|
||||
int GetRefMenuString(const int table_no, std::vector<struct MENU_STRING>& vec_menu);
|
||||
int GetRefMenuStringSplit(const int table_no, std::vector<struct MENU_STRING>& vec_menu);
|
||||
|
||||
//jinjing 2017-01-17
|
||||
int GetRefMenuStringMultiKeys(const int table_no, std::vector<KEY_ID_STRU>& vec_keyid,
|
||||
std::vector<struct MENU_STRING>& vec_menu);
|
||||
|
||||
int GetNameStringByID(const cmnInt64 reference_id, string& ref_string);
|
||||
int GetNameStringByIDSplit(const long reference_id, string& ref_string);
|
||||
int GetNameStringByID(const std::vector<cmnInt64>& vec_refid, std::vector<std::string>& vec_ref_string);
|
||||
int GetNameStringByIDSplit(const std::vector<long>& vec_refid, std::vector<std::string>& vec_ref_string);
|
||||
int GetNameStringBykey(const char* key_ptr, string& ref_string);
|
||||
int GetNameStringBykeySplit(const char* key_ptr, string& ref_string);
|
||||
|
||||
int GetNameStringByAppKeyID( const std::vector<struct APP_KEY_STRU>& vec_appkeyid, std::vector<string>& vec_name_string);
|
||||
int GetNameStringByAppID( const std::vector<APP_ID_STRU>& vec_appid, std::vector<string>& vec_name_string);
|
||||
|
||||
int GetNameStringByRtdbKeyID(const RTDB_KEY_STRU& rtdb_keyid_stru, string& ref_string);
|
||||
int GetNameStringByRtdbKeyID(const std::vector<RTDB_KEY_STRU>& vec_rtdbkeyid, std::vector<string>& vec_ref_string);
|
||||
|
||||
int GraphGetAppInfo(const struct ODB::GRAPH_ORDER_KEY_REQ& graph_req, struct ODB::GRAPH_ORDER_KEY_RSP& graph_rsp);
|
||||
int GraphGetAppInfoSplit(const struct ODB::GRAPH_ORDER_KEY_REQ& graph_req, struct ODB::GRAPH_ORDER_KEY_RSP& graph_rsp);
|
||||
int GraphGetData(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req, RTDB_SERVER::GRAPH_REAL_RSP& real_rsp);
|
||||
int GraphGetDataSplit(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP& real_rsp);
|
||||
int GraphGetDataSplitSimple(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP& real_rsp);
|
||||
//int GraphGetDataEx(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP_out real_rsp, bool is_req=true);
|
||||
//int GraphDataRecv(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req , RTDB_SERVER::GRAPH_REAL_RSP_out real_rsp );
|
||||
|
||||
//int SqlGet(const char* str_sql, char** buf_ptr, int& buf_size);
|
||||
|
||||
public:
|
||||
int GetFacNameByKeyNo(const int table_no, const char* key_ptr, string& ref_string);
|
||||
int GetFacNameByFacID(char* fac_name, const cmnInt64 fac_id);
|
||||
int GetFacNameByFacNo(char* fac_name, const int fac_no);
|
||||
|
||||
int GetFacIDByFacName(cmnInt64& fac_id, const char* fac_name);
|
||||
int GetFacNoByFacName(int& fac_no, const char* fac_name);
|
||||
|
||||
int GetFacIDByFacNo(cmnInt64& fac_id, const int fac_no);
|
||||
int GetFacNoByFacID( int& fac_no, const cmnInt64 fac_id);
|
||||
|
||||
int ColMeasType( const std::vector<KEY_ID_STRU> vec_keyid , std::vector<int>& vec_col_prop );
|
||||
|
||||
public:
|
||||
int GetAppNameByNo(char* app_name, const int app_no) { return 0;}
|
||||
int GetAppNoByName(int& app_no, const char* app_name) { return 0;}
|
||||
|
||||
int GetTableNameByNo(char* table_name, const int table_no, const bool is_eng=true) { return 0;}
|
||||
int GetTableNoByName(int& table_no, const char* table_name, const bool is_eng=true) { return 0;}
|
||||
|
||||
int GetFieldNameByNo(char* field_name, const int field_no, const bool is_eng=true) { return 0;}
|
||||
int GetFieldNoByName(int& field_no, const char* field_name, const bool is_eng=true) { return 0;}
|
||||
|
||||
public:
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
int GetValueAndStatusSplit(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
int GetValueAndStatusSplit(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatusSplit(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
int GetValueAndStatusSplit(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
|
||||
int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec );//union type
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct INT_VALUE_STATUS> & KeyIdValVec);//ym
|
||||
int GetValueAndStatusSplit(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct INT_VALUE_STATUS> & KeyIdValVec);//ym
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec);//yc
|
||||
int GetValueAndStatusSplit(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec);//yc
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatusSplit(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
int GetValueAndStatusSplit(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec );//union type
|
||||
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
|
||||
int GetRefMenuString (int table_no, std::vector<struct MENU_STRING>& vec_menu, short area_no);
|
||||
int GetRefMenuStringWithAreaSplit(int table_no, std::vector<struct MENU_STRING>& vec_menu, short area_no);
|
||||
|
||||
public:
|
||||
int PingRtdbServer(int req_data , int & rep_data);
|
||||
int GraphDataSend(const struct RTDB_SERVER::GRAPH_REAL_REQ& real_req );
|
||||
int GraphDataRecv(RTDB_SERVER::GRAPH_REAL_RSP& real_rsp );
|
||||
|
||||
public:
|
||||
int SetDomainName(const char* domain_name);
|
||||
int SetSecLabel(tSecLabel& sec_label);
|
||||
void ClearDomainName();
|
||||
|
||||
private:
|
||||
int Start();
|
||||
int Refresh();
|
||||
int Refresh(int app_no);
|
||||
int GetSliceByKey(const char* key, cmnUint32& slice_no);
|
||||
int GetAllSlice(vector<int>& slice_no);
|
||||
int GetKeyInfo();
|
||||
int GetKeyInfoSlice();
|
||||
|
||||
inline int slice_app_to_no(int slice_app_no){return slice_app_no % 1000;}
|
||||
inline int slice_no_to_app(int slice_no){return slice_no+AP_SCADA_AREA;}
|
||||
|
||||
private:
|
||||
CApiNet(const CApiNet&);
|
||||
CApiNet& operator=(const CApiNet&);
|
||||
|
||||
private:
|
||||
RTDB_SERVER::CODB_NET* m_OdbNet;
|
||||
CNetFactory* m_Factory;
|
||||
//Handle m_Handle; //for service_bus
|
||||
|
||||
std::vector<int> m_VecKey;
|
||||
std::vector<int> m_IsSliced;
|
||||
//
|
||||
short m_ContextNo;
|
||||
int m_AppNo;
|
||||
int m_TableNo;
|
||||
DB_BYTE_T m_ByteTag;
|
||||
|
||||
char m_DomainName[40];
|
||||
tSecLabel m_SecLabel;
|
||||
bool m_IsRemote;
|
||||
int m_SliceNo;
|
||||
TaskService* task_service;
|
||||
|
||||
bool m_IsSysAdmHost;
|
||||
char m_HostName[MAX_NAME_STRING_LEN];
|
||||
|
||||
TGraphReq *m_pGraphReq; //lmj add for GraphGetDataEx
|
||||
TApiNetPriv *m_pPrvStru; //lmj add for reserver
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
233
code/sys_nicmonitor/include/db_api/odb_apiop.h
Normal file
233
code/sys_nicmonitor/include/db_api/odb_apiop.h
Normal file
@@ -0,0 +1,233 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_api.h
|
||||
DESCRIPTION: general function declaration
|
||||
FUNCTION LIST:
|
||||
COMMENT: public application
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2004-06-25 1.1 add context_no parameter
|
||||
2003-05-28 1.0 modify
|
||||
================================================================================
|
||||
2003-05-28 1.0 created
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ODB_APIOP_H__
|
||||
#define __ODB_APIOP_H__
|
||||
|
||||
#ifndef __ODB_TABLEOP_H__
|
||||
#include "db_api/odb_tableop.h"
|
||||
#endif
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
typedef vector<int> IntVec;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int slice_no;
|
||||
int type;
|
||||
CTableOp *m_pColOp;
|
||||
CTableOp *m_pMenuOp;
|
||||
|
||||
string m_ScenarioName ;
|
||||
int m_ScenarioInstance ;
|
||||
string m_SubScenarioName ;
|
||||
int m_SubScenarioInstance ;
|
||||
|
||||
} TApiOpPriv;
|
||||
|
||||
class ODB_API_LIB_API CApiOp: public CTableBase
|
||||
{
|
||||
public:
|
||||
CApiOp();
|
||||
CApiOp ( const int app_no , const short context_no = 0);
|
||||
CApiOp ( const int app_no, const int table_no , const short context_no = 0);
|
||||
~CApiOp();
|
||||
|
||||
int Open (const int app_no, const int table_no, const short context_no = 0);
|
||||
int Open (const int table_no);
|
||||
int SetAppNo (const int app_no, const short context_no = 0);
|
||||
int SetScenario(const std::string& scenario_name,
|
||||
const int scenario_inst_name,
|
||||
const std::string& sub_scenario_name,
|
||||
const int sub_scenario_inst_name);
|
||||
int SetScenario(const int scenario_no,
|
||||
const int scenario_inst_no,
|
||||
const int sub_scenario_no,
|
||||
const int sub_scenario_inst_no);
|
||||
int SetAppNo(const std::string& scenario_name,
|
||||
const int scenario_inst_name,
|
||||
const std::string& sub_scenario_name,
|
||||
const int sub_scenario_inst_name);
|
||||
int SetSliceNo(int slice_no);
|
||||
|
||||
public:
|
||||
int MenuRead(const char* menu_name, std::vector<struct MENU_INFO>& vec_menu, const int menu_status=MENU_ON);
|
||||
int MenuRead(const char* menu_name, char** buf_ptr, int& buf_size, const int menu_status=MENU_ON);//obsolete
|
||||
|
||||
//
|
||||
int TableReleMenuRead (const int table_no, const int field_no );
|
||||
int TableReleMenuRead(const int table_no, const int field_no, std::vector<struct MENU_RELEVANT>& vec_menu);
|
||||
int TableReleMenuRead(const int table_no, std::vector<struct MENU_RELEVANT>& vec_menu);
|
||||
|
||||
int TableReleMenuRead(const int table_no, const int field_no, char** buf_ptr, int& buf_size);//obsolete
|
||||
int TableReleMenuRead(const int table_no, char** buf_ptr, int& buf_size);//obsolete
|
||||
|
||||
//
|
||||
int GetRefMenuString(const int table_no, std::vector<struct MENU_STRING>& vec_menu);
|
||||
int GetRefMenuString(const vector<int> vec_table, std::vector<struct MENU_STRING>& vec_menu);
|
||||
int GetRefMenuString(const int table_no, char*& menu_buf_ptr, int& menu_buf_size);//obsolete
|
||||
|
||||
//
|
||||
int GetNameStringByID(const cmnInt64 reference_id, std::string& ref_string);
|
||||
int GetNameStringByID(const cmnInt64 reference_id, char*& referenced_namebuf, int& namebuf_size);
|
||||
|
||||
//
|
||||
int GetNameStringByID(const std::vector<cmnInt64>& vec_refid, std::vector<std::string>& vec_ref_string);
|
||||
|
||||
/*
|
||||
int GetNameStringByKeyID(const KEY_ID_STRU& keyid_stru, std::string& ref_string);
|
||||
int GetNameStringByKeyID(const std::vector<KEY_ID_STRU>& vec_keyid, std::vector<string>& vec_ref_string);
|
||||
|
||||
int GetNameStringByKeyID( const KEY_ID_STRU& keyid_stru, char*& referenced_namebuf, int& namebuf_size);
|
||||
*/
|
||||
//
|
||||
int GetNameStringBykey (const char* key_ptr, std::string& ref_string);
|
||||
int GetNameStringBykey(const char* key_ptr, char*& referenced_namebuf, int& namebuf_size );
|
||||
|
||||
//
|
||||
int GetNameStringByAppKeyID( const std::vector<struct APP_KEY_STRU>& vec_appkeyid, std::vector<string>& vec_name_string);
|
||||
int GetNameStringByAppID( const std::vector<APP_ID_STRU>& vec_appid, std::vector<string>& vec_name_string);
|
||||
|
||||
int GetNameStringByRtdbKeyID( const std::vector<struct RTDB_KEY_STRU>& vec_rtdbkeyid, std::vector<string>& vec_name_string);
|
||||
int GetNameStringByRtdbKeyID( const RTDB_KEY_STRU& rtdbkeyid_stru, char*& referenced_namebuf, int& namebuf_size);
|
||||
int GetNameStringByRtdbKeyID(const RTDB_KEY_STRU rtdbkeyid_stru, std::string& ref_string);
|
||||
|
||||
//
|
||||
int GetRefFlag (const int table_no, const short field_no); //obsolete
|
||||
int GetRefFlag (const short field_no);
|
||||
|
||||
public:
|
||||
int GetFacNameByKeyNo(const int table_no, const char* key_ptr, std::string& ref_string);
|
||||
int GetFacNameByFacID(char* fac_name, const RTDB_KEY_STRU fac_id);
|
||||
int GetFacNameByFacNo (char* fac_name, const int fac_no);
|
||||
|
||||
int GetFacIDByFacName(RTDB_KEY_STRU& fac_id, const char* fac_name);
|
||||
int GetFacNoByFacName (int& fac_no, const char* fac_name);
|
||||
|
||||
int GetFacIDByFacNo(RTDB_KEY_STRU& fac_id, const int fac_no);
|
||||
int GetFacNoByFacID(int& fac_no, const RTDB_KEY_STRU fac_id);
|
||||
public:
|
||||
//int ColMeasType ( const KEY_ID_STRU keyid , int& col_prop );
|
||||
int ColMeasType ( const int table_no, const int col_id , int& col_prop );
|
||||
|
||||
//int ColMeasType( const std::vector<KEY_ID_STRU> vec_keyid , std::vector<int>& vec_col_prop );
|
||||
|
||||
public:
|
||||
//
|
||||
int GraphGetAppInfo(const struct GRAPH_ORDER_KEY_REQ& graph_req, struct GRAPH_ORDER_KEY_RSP& graph_rsp);
|
||||
int GraphGetValue();
|
||||
|
||||
public:
|
||||
int GetAppNameByNo(char* app_name, const int app_no) { return 0;}
|
||||
int GetAppNoByName(int& app_no, const char* app_name) { return 0;}
|
||||
|
||||
int GetTableNameByNo(char* table_name, const int table_no, const bool is_eng=true) { return 0;}
|
||||
int GetTableNoByName(int& table_no, const char* table_name, const bool is_eng=true) { return 0;}
|
||||
|
||||
int GetFieldNameByNo(char* field_name, const int field_no, const bool is_eng=true) { return 0;}
|
||||
int GetFieldNoByName(int& field_no, const char* field_name, const bool is_eng=true) { return 0;}
|
||||
|
||||
public:
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec );//union type
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec, bool order); //ym
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec, bool order); //yc
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec, bool order); //yx
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec, bool order); //long
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec, bool order);//union type
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct INT_VALUE_STATUS> & KeyIdValVec);//ym
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec);//yc
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec );//union type
|
||||
//int GetFieldNoFromKeyId(const std::vector<KEY_ID_STRU> &struVec , std::vector<int> &FieldNoVec);
|
||||
|
||||
int ColMeasType( const RTDB_KEY_STRU rtdbkeyid , int& col_prop );
|
||||
int ColMeasType( const std::vector<RTDB_KEY_STRU> vec_rtdbkeyid , std::vector<int>& vec_col_prop );
|
||||
int GetFieldNoFromRtdbKeyId(const std::vector<RTDB_KEY_STRU> &struVec , std::vector<int> &FieldNoVec);
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
private:
|
||||
|
||||
int GetFieldValueByNo(char** field_value_ptr, int& field_length, const char* record_ptr, const int field_no);
|
||||
int GetFieldValueByName(char** field_value_ptr, int& field_length, const char* record_ptr, const char* field_name);
|
||||
|
||||
int GetRecordInfo(char** buf_ptr, short& field_num, int& record_num, int& record_size);
|
||||
int GetRecordInfoByKey(char** buf_ptr, short& field_num, int& record_num, int& record_size, const char* key_ptr);
|
||||
|
||||
int GetMenuStringByValue(const char* menu_name, const int menu_val, const int menu_type, char*& menu_string, int& string_len);
|
||||
|
||||
int get_string(char* total_namestring, const char* read_record_ptr, const struct STDB_FIELD_TAB* mov_field_ptr);
|
||||
int GetNameString(std::string& total_namestring, const char* read_record_ptr, const struct STDB_FIELD_TAB* mov_field_ptr);
|
||||
|
||||
int Start();
|
||||
int SetContext (const short context_no);
|
||||
|
||||
//int GetPosFromKeyIdStru(const std::vector<KEY_ID_STRU> &struVec , vector<int> &errPosVec , vector<IntVec> &posVec);
|
||||
|
||||
private:
|
||||
CApiOp (const CApiOp&);
|
||||
CApiOp& operator= (const CApiOp&);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
TABLE_COLUMN_INFO = 100002,
|
||||
TABLE_MENU_INFO = 100005,
|
||||
TABLE_RELEVANT_MENU = 6,
|
||||
TABLE_FAC_INFO = 405,
|
||||
};
|
||||
|
||||
short m_ContextNo;
|
||||
int m_AppNo;
|
||||
int m_TableNo;
|
||||
|
||||
CTableOp* m_TableOp;
|
||||
//CTableOp* m_ColOp;
|
||||
|
||||
TApiOpPriv *m_pPrvStru;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
227
code/sys_nicmonitor/include/db_api/odb_apiop.h.old
Normal file
227
code/sys_nicmonitor/include/db_api/odb_apiop.h.old
Normal file
@@ -0,0 +1,227 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_api.h
|
||||
DESCRIPTION: general function declaration
|
||||
FUNCTION LIST:
|
||||
COMMENT: public application
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2004-06-25 1.1 add context_no parameter
|
||||
2003-05-28 1.0 modify
|
||||
================================================================================
|
||||
2003-05-28 1.0 created
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ODB_APIOP_H__
|
||||
#define __ODB_APIOP_H__
|
||||
|
||||
#ifndef __ODB_TABLEOP_H__
|
||||
#include "db_api/odb_tableop.h"
|
||||
#endif
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
typedef vector<int> IntVec;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int slice_no;
|
||||
int type;
|
||||
CTableOp *m_pColOp;
|
||||
CTableOp *m_pMenuOp;
|
||||
} TApiOpPriv;
|
||||
|
||||
class ODB_API_LIB_API CApiOp: public CTableBase
|
||||
{
|
||||
public:
|
||||
CApiOp();
|
||||
CApiOp ( const int app_no , const short context_no = 0);
|
||||
CApiOp ( const int app_no, const int table_no , const short context_no = 0);
|
||||
~CApiOp();
|
||||
|
||||
int Open (const int app_no, const int table_no, const short context_no = 0);
|
||||
int Open (const int table_no);
|
||||
int SetAppNo (const int app_no, const short context_no = 0);
|
||||
int SetScenario(const std::string& scenario_name,
|
||||
const int scenario_inst_name,
|
||||
const std::string& sub_scenario_name,
|
||||
const int sub_scenario_inst_name);
|
||||
int SetScenario(const int scenario_no,
|
||||
const int scenario_inst_no,
|
||||
const int sub_scenario_no,
|
||||
const int sub_scenario_inst_no);
|
||||
int SetAppNo(const std::string& scenario_name,
|
||||
const int scenario_inst_name,
|
||||
const std::string& sub_scenario_name,
|
||||
const int sub_scenario_inst_name);
|
||||
int SetSliceNo(int slice_no);
|
||||
|
||||
public:
|
||||
int MenuRead(const char* menu_name, std::vector<struct MENU_INFO>& vec_menu, const int menu_status=MENU_ON);
|
||||
int MenuRead(const char* menu_name, char** buf_ptr, int& buf_size, const int menu_status=MENU_ON);//obsolete
|
||||
|
||||
//
|
||||
int TableReleMenuRead (const int table_no, const int field_no );
|
||||
int TableReleMenuRead(const int table_no, const int field_no, std::vector<struct MENU_RELEVANT>& vec_menu);
|
||||
int TableReleMenuRead(const int table_no, std::vector<struct MENU_RELEVANT>& vec_menu);
|
||||
|
||||
int TableReleMenuRead(const int table_no, const int field_no, char** buf_ptr, int& buf_size);//obsolete
|
||||
int TableReleMenuRead(const int table_no, char** buf_ptr, int& buf_size);//obsolete
|
||||
|
||||
//
|
||||
int GetRefMenuString(const int table_no, std::vector<struct MENU_STRING>& vec_menu);
|
||||
int GetRefMenuString(const vector<int> vec_table, std::vector<struct MENU_STRING>& vec_menu);
|
||||
int GetRefMenuString(const int table_no, char*& menu_buf_ptr, int& menu_buf_size);//obsolete
|
||||
|
||||
//
|
||||
int GetNameStringByID(const cmnInt64 reference_id, std::string& ref_string);
|
||||
int GetNameStringByID(const cmnInt64 reference_id, char*& referenced_namebuf, int& namebuf_size);
|
||||
|
||||
//
|
||||
int GetNameStringByID(const std::vector<cmnInt64>& vec_refid, std::vector<std::string>& vec_ref_string);
|
||||
|
||||
/*
|
||||
int GetNameStringByKeyID(const KEY_ID_STRU& keyid_stru, std::string& ref_string);
|
||||
int GetNameStringByKeyID(const std::vector<KEY_ID_STRU>& vec_keyid, std::vector<string>& vec_ref_string);
|
||||
|
||||
int GetNameStringByKeyID( const KEY_ID_STRU& keyid_stru, char*& referenced_namebuf, int& namebuf_size);
|
||||
*/
|
||||
//
|
||||
int GetNameStringBykey (const char* key_ptr, std::string& ref_string);
|
||||
int GetNameStringBykey(const char* key_ptr, char*& referenced_namebuf, int& namebuf_size );
|
||||
|
||||
//
|
||||
int GetNameStringByAppKeyID( const std::vector<struct APP_KEY_STRU>& vec_appkeyid, std::vector<string>& vec_name_string);
|
||||
int GetNameStringByAppID( const std::vector<APP_ID_STRU>& vec_appid, std::vector<string>& vec_name_string);
|
||||
|
||||
int GetNameStringByRtdbKeyID( const std::vector<struct RTDB_KEY_STRU>& vec_rtdbkeyid, std::vector<string>& vec_name_string);
|
||||
int GetNameStringByRtdbKeyID( const RTDB_KEY_STRU& rtdbkeyid_stru, char*& referenced_namebuf, int& namebuf_size);
|
||||
int GetNameStringByRtdbKeyID(const RTDB_KEY_STRU rtdbkeyid_stru, std::string& ref_string);
|
||||
|
||||
//
|
||||
int GetRefFlag (const int table_no, const short field_no); //obsolete
|
||||
int GetRefFlag (const short field_no);
|
||||
|
||||
public:
|
||||
int GetFacNameByKeyNo(const int table_no, const char* key_ptr, std::string& ref_string);
|
||||
int GetFacNameByFacID(char* fac_name, const RTDB_KEY_STRU fac_id);
|
||||
int GetFacNameByFacNo (char* fac_name, const int fac_no);
|
||||
|
||||
int GetFacIDByFacName(RTDB_KEY_STRU& fac_id, const char* fac_name);
|
||||
int GetFacNoByFacName (int& fac_no, const char* fac_name);
|
||||
|
||||
int GetFacIDByFacNo(RTDB_KEY_STRU& fac_id, const int fac_no);
|
||||
int GetFacNoByFacID(int& fac_no, const RTDB_KEY_STRU fac_id);
|
||||
public:
|
||||
//int ColMeasType ( const KEY_ID_STRU keyid , int& col_prop );
|
||||
int ColMeasType ( const int table_no, const int col_id , int& col_prop );
|
||||
|
||||
//int ColMeasType( const std::vector<KEY_ID_STRU> vec_keyid , std::vector<int>& vec_col_prop );
|
||||
|
||||
public:
|
||||
//
|
||||
int GraphGetAppInfo(const struct GRAPH_ORDER_KEY_REQ& graph_req, struct GRAPH_ORDER_KEY_RSP& graph_rsp);
|
||||
int GraphGetValue();
|
||||
|
||||
public:
|
||||
int GetAppNameByNo(char* app_name, const int app_no) { return 0;}
|
||||
int GetAppNoByName(int& app_no, const char* app_name) { return 0;}
|
||||
|
||||
int GetTableNameByNo(char* table_name, const int table_no, const bool is_eng=true) { return 0;}
|
||||
int GetTableNoByName(int& table_no, const char* table_name, const bool is_eng=true) { return 0;}
|
||||
|
||||
int GetFieldNameByNo(char* field_name, const int field_no, const bool is_eng=true) { return 0;}
|
||||
int GetFieldNoByName(int& field_no, const char* field_name, const bool is_eng=true) { return 0;}
|
||||
|
||||
public:
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec );//union type
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec, bool order); //ym
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec, bool order); //yc
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec, bool order); //yx
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec, bool order); //long
|
||||
|
||||
//int GetValueAndStatus(const std::vector<KEY_ID_STRU> &struVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec, bool order);//union type
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct INT_VALUE_STATUS> & KeyIdValVec);//ym
|
||||
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU > &staStruVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec);//yc
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
int GetValueAndStatus(const std::vector<struct KEY_ID_STA_STRU> &staStruVec , std::vector< struct UNION_VALUE_STATUS> & KeyIdValVec );//union type
|
||||
//int GetFieldNoFromKeyId(const std::vector<KEY_ID_STRU> &struVec , std::vector<int> &FieldNoVec);
|
||||
|
||||
int ColMeasType( const RTDB_KEY_STRU rtdbkeyid , int& col_prop );
|
||||
int ColMeasType( const std::vector<RTDB_KEY_STRU> vec_rtdbkeyid , std::vector<int>& vec_col_prop );
|
||||
int GetFieldNoFromRtdbKeyId(const std::vector<RTDB_KEY_STRU> &struVec , std::vector<int> &FieldNoVec);
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct INT_VALUE_STATUS > &KeyIdValVec); //ym
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec); //yc
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct CHAR_VALUE_STATUS > & KeyIdValVec); //yx
|
||||
int GetValueAndStatus(const std::vector<RTDB_KEY_STRU> &struVec , std::vector< struct LONG_VALUE_STATUS > & KeyIdValVec); //long
|
||||
private:
|
||||
|
||||
int GetFieldValueByNo(char** field_value_ptr, int& field_length, const char* record_ptr, const int field_no);
|
||||
int GetFieldValueByName(char** field_value_ptr, int& field_length, const char* record_ptr, const char* field_name);
|
||||
|
||||
int GetRecordInfo(char** buf_ptr, short& field_num, int& record_num, int& record_size);
|
||||
int GetRecordInfoByKey(char** buf_ptr, short& field_num, int& record_num, int& record_size, const char* key_ptr);
|
||||
|
||||
int GetMenuStringByValue(const char* menu_name, const int menu_val, const int menu_type, char*& menu_string, int& string_len);
|
||||
|
||||
int get_string(char* total_namestring, const char* read_record_ptr, const struct STDB_FIELD_TAB* mov_field_ptr);
|
||||
int GetNameString(std::string& total_namestring, const char* read_record_ptr, const struct STDB_FIELD_TAB* mov_field_ptr);
|
||||
|
||||
int Start();
|
||||
int SetContext (const short context_no);
|
||||
|
||||
//int GetPosFromKeyIdStru(const std::vector<KEY_ID_STRU> &struVec , vector<int> &errPosVec , vector<IntVec> &posVec);
|
||||
|
||||
private:
|
||||
CApiOp (const CApiOp&);
|
||||
CApiOp& operator= (const CApiOp&);
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
TABLE_COLUMN_INFO = 100002,
|
||||
TABLE_MENU_INFO = 100005,
|
||||
TABLE_RELEVANT_MENU = 6,
|
||||
TABLE_FAC_INFO = 405,
|
||||
};
|
||||
|
||||
short m_ContextNo;
|
||||
int m_AppNo;
|
||||
int m_TableNo;
|
||||
|
||||
CTableOp* m_TableOp;
|
||||
//CTableOp* m_ColOp;
|
||||
|
||||
TApiOpPriv *m_pPrvStru;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
80
code/sys_nicmonitor/include/db_api/odb_app2id.h
Normal file
80
code/sys_nicmonitor/include/db_api/odb_app2id.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#ifndef _APPNAME2ID_
|
||||
#define _APPNAME2ID_
|
||||
#include "common_types.h"
|
||||
#ifndef _WINDOWS64
|
||||
#ifndef _HPUX
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <sys/pthread.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define MAXSIZE 8092
|
||||
|
||||
struct ID2NameNode
|
||||
{
|
||||
int app_id;
|
||||
char app_name[32];
|
||||
|
||||
struct ID2NameNode * next_pointer;
|
||||
};
|
||||
|
||||
class ODB_API_LIB_API CAppNameIDTrans
|
||||
{
|
||||
public :
|
||||
CAppNameIDTrans();
|
||||
|
||||
CAppNameIDTrans(const CAppNameIDTrans&);
|
||||
|
||||
~CAppNameIDTrans();
|
||||
|
||||
//void operator= (const CAppNameIDTrans&);
|
||||
|
||||
private:
|
||||
|
||||
#ifndef _WINDOWS64
|
||||
static pthread_mutex_t s_guard;
|
||||
#else
|
||||
static CRITICAL_SECTION s_guard;
|
||||
#endif
|
||||
static CAppNameIDTrans * s_instance ;
|
||||
|
||||
ID2NameNode * m_hashTable;
|
||||
ID2NameNode * second;
|
||||
char* m_InitPtr;
|
||||
|
||||
cmnInt64 * freePos;
|
||||
cmnInt64 freePointer;
|
||||
|
||||
public:
|
||||
static CAppNameIDTrans * getInstance();
|
||||
|
||||
char * getAppNameByID(const int app_id);
|
||||
|
||||
|
||||
int createHashTable();
|
||||
|
||||
int putData2Table();
|
||||
|
||||
|
||||
};
|
||||
#endif
|
||||
138
code/sys_nicmonitor/include/db_api/odb_autolock.h
Normal file
138
code/sys_nicmonitor/include/db_api/odb_autolock.h
Normal file
@@ -0,0 +1,138 @@
|
||||
#ifndef _PVLOCK
|
||||
#define _PVLOCK
|
||||
#include "db_api/odb_common.h"
|
||||
#include "db_api/odb_define.h"
|
||||
|
||||
#include "ThreadKit/ThreadKit.h"
|
||||
#ifndef _WINDOWS64
|
||||
#ifndef _HPUX
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <sys/pthread.h>
|
||||
#endif
|
||||
#else
|
||||
#include <process.h>
|
||||
#endif
|
||||
|
||||
#include "db_api/odb_lock.h"
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
typedef int key_t;
|
||||
#endif
|
||||
|
||||
class PVLock
|
||||
{
|
||||
private:
|
||||
PVLock(const PVLock&);
|
||||
PVLock& operator=(const PVLock&);
|
||||
int m_semid;
|
||||
int m_semno;
|
||||
public:
|
||||
|
||||
PVLock(key_t key , int no);
|
||||
~PVLock();
|
||||
};
|
||||
|
||||
|
||||
class PMutexLock
|
||||
{
|
||||
private:
|
||||
PMutexLock(const PMutexLock&);
|
||||
PMutexLock& operator=(const PMutexLock&);
|
||||
#ifndef _WINDOWS64
|
||||
pthread_mutex_t * m_mutex;
|
||||
|
||||
public:
|
||||
PMutexLock(pthread_mutex_t * out_mutex):m_mutex(out_mutex)
|
||||
{
|
||||
if( 0 != pthread_mutex_lock(m_mutex ))
|
||||
{
|
||||
printf("Error in pthread mutex lock ...,errno === %d \n" , errno);
|
||||
}
|
||||
}
|
||||
~PMutexLock()
|
||||
{
|
||||
if(0 != pthread_mutex_unlock(m_mutex))
|
||||
{
|
||||
printf("Error in pthread mutex unlock ... errno === %d \n" , errno);
|
||||
}
|
||||
}
|
||||
#else
|
||||
/*
|
||||
CRITICAL_SECTION* m_mutex;
|
||||
public:
|
||||
PMutexLock(CRITICAL_SECTION* out_mutex):m_mutex(out_mutex)
|
||||
{
|
||||
EnterCriticalSection(m_mutex);
|
||||
}
|
||||
~PMutexLock()
|
||||
{
|
||||
LeaveCriticalSection(m_mutex);
|
||||
}
|
||||
*/
|
||||
|
||||
THREADKIT::Mutex* m_mutex;
|
||||
public:
|
||||
PMutexLock(THREADKIT::Mutex* out_mutex):m_mutex(out_mutex)
|
||||
{
|
||||
m_mutex->lock();
|
||||
}
|
||||
~PMutexLock()
|
||||
{
|
||||
m_mutex->unlock();
|
||||
};
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
class CRWLock
|
||||
{
|
||||
private:
|
||||
struct ODB::LOCK_STRU *m_LockPtr;
|
||||
DB_LOCK_T m_RWType;
|
||||
int* m_SemId;
|
||||
CRWLock();
|
||||
CRWLock(const CRWLock& theLock);
|
||||
CRWLock& operator=(const CRWLock& theLock);
|
||||
public:
|
||||
|
||||
//jinjing 20120429
|
||||
CRWLock(struct ODB::LOCK_STRU *lock_ptr,const DB_LOCK_T lock_type, int& table_semid);
|
||||
~CRWLock();
|
||||
int ChangeLockType(const DB_LOCK_T lock_type);
|
||||
// CRWLock(struct ODB::LOCK_STRU *lock_ptr,const DB_LOCK_T lock_type, int& table_semid)
|
||||
// {
|
||||
// //jinjing 20120428
|
||||
//// ODB::COdbLock::Lock(*lock_ptr, lock_type, table_semid);
|
||||
//// m_LockPtr = lock_ptr;
|
||||
//// m_RWType = lock_type;
|
||||
//// m_SemId = table_semid;
|
||||
// m_SemId = table_semid;
|
||||
// TRACE("m_SemId1 = %d\n lock_type = %d", m_SemId, lock_type);
|
||||
// TRACE("!!!!!Addr_AutoLock.m_SemId = %d\n", &m_SemId);
|
||||
// ODB::COdbLock::Lock(*lock_ptr, lock_type, m_SemId);
|
||||
// TRACE("!!!!!Addr_AutoLock.m_SemId2 = %d\n", &m_SemId);
|
||||
// TRACE("m_SemId2 = %d\n", m_SemId);
|
||||
// m_LockPtr = lock_ptr;
|
||||
// m_RWType = lock_type;
|
||||
// table_semid = m_SemId;
|
||||
// TRACE("table_semid = %d\n", table_semid);
|
||||
// }
|
||||
// ~CRWLock()
|
||||
// {
|
||||
// ODB::COdbLock::UnLock(*m_LockPtr, m_RWType, m_SemId);
|
||||
// }
|
||||
//
|
||||
// int ChangeLockType(const DB_LOCK_T lock_type)
|
||||
// {
|
||||
// if(lock_type != m_RWType)
|
||||
// {
|
||||
// ODB::COdbLock::UnLock(*m_LockPtr,m_RWType, m_SemId);
|
||||
// ODB::COdbLock::Lock(*m_LockPtr,lock_type, m_SemId);
|
||||
// m_RWType = lock_type;
|
||||
// }
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
};
|
||||
#endif
|
||||
54
code/sys_nicmonitor/include/db_api/odb_baseindex.h
Normal file
54
code/sys_nicmonitor/include/db_api/odb_baseindex.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: Real Time Database management system
|
||||
FileName: rtdb_api.cpp
|
||||
DESCRIPTION: rtdb api interfaces implementation
|
||||
FUNCTION LIST:
|
||||
COMMENT:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2009-01-10 1.1 add net interfaces
|
||||
================================================================================
|
||||
2008-10-30 1.0 created
|
||||
*******************************************************************************/
|
||||
//#include <vector>
|
||||
#include "db_api/odb_prv_struct.h"
|
||||
#ifndef _CBASEINDEX
|
||||
#define _CBASEINDEX
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
class ODB_API_LIB_API CBaseIndex
|
||||
{
|
||||
public:
|
||||
virtual int need_rebuilt(char *existed_table_ptr,struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id) =0;
|
||||
virtual int CreateIndex(struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id,int &shm_size) =0;
|
||||
virtual int Open(char *index_file_name,int table_id,int index_id)=0; //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int Open(int index_shmid,int table_id,int index_id) = 0; //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int SetIndexPtr(char *index_ptr)= 0; //把缓存的指针赋值给索引类,这样就不用使用前面的Open函数。
|
||||
virtual int GetKeyByIndex(char *index_ptr,std::vector<char *> &index_array)=0;//考虑多个关键字可能索引的值相同的情况。
|
||||
virtual int GetKeyPointerByIndex(char *index_ptr, int& pointer)=0;//只对主键索引有效,根据index得到记录的物理位置
|
||||
virtual int IndexInsert(char *index_ptr,char *key_ptr)=0;
|
||||
virtual int BulkIndexInsert(char *bulk_index_key_ptr)=0;//下装的时候,对于顺序索引肯定是有用的。相当于在索引外部排好序,然后一把把所有的索引全部插入进去。
|
||||
virtual int Indexdelete(char *index_ptr,char *key_ptr)=0;
|
||||
virtual int IndexClear()=0;
|
||||
virtual int GetIdxMthd()=0;
|
||||
virtual int FreeResource()=0;//譬如unmap或者shmdt掉指针。
|
||||
virtual int DebugDisp(int type)=0;//方便调试用,不同的type,显示不同或者详细程度不同的信息。
|
||||
virtual int GetIndexRecNum() = 0;//返回索引记录总的个数,包括索引区、溢出区、主溢出区有效记录个数的总和。但是无溢出HASH索引只是返回0。
|
||||
virtual DB_STATUS_T GetIndexStatus()=0;//返回索引的状态
|
||||
virtual void SetIndexStatus(DB_STATUS_T idx_status)=0;//设置索引头上的索引状态
|
||||
virtual ~CBaseIndex(){};
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
64
code/sys_nicmonitor/include/db_api/odb_ckeymanager.h
Normal file
64
code/sys_nicmonitor/include/db_api/odb_ckeymanager.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef _CKEYMAN
|
||||
#define _CKEYMAN
|
||||
#include "db_api/odb_define.h"
|
||||
#include "db_api/odb_prv_struct.h"
|
||||
#ifndef _WINDOWS64
|
||||
#include "sys/time.h"
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
#include "db_api/odb_autolock.h"
|
||||
|
||||
|
||||
#define MAGICLEN 16
|
||||
|
||||
#define MAX_FIX_INDEX_NUM 100
|
||||
struct FIX_INDEX_DEF
|
||||
{
|
||||
short ctx_no;
|
||||
int app_no;
|
||||
int table_no;
|
||||
int idx_seq_no;
|
||||
};
|
||||
|
||||
struct KEY_MANAGE_TAB
|
||||
{
|
||||
char magic[MAGICLEN];
|
||||
int valid ;// = INVALID;
|
||||
int shmKey;
|
||||
int semKey;
|
||||
time_t createTime;
|
||||
|
||||
int fix_index_num;
|
||||
struct FIX_INDEX_DEF fix_index_def_array[MAX_FIX_INDEX_NUM];
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CKeyManager
|
||||
{
|
||||
private:
|
||||
static struct KEY_MANAGE_TAB* m_ShmManTabPtr;
|
||||
static CKeyManager * m_KeyManPtr;
|
||||
static int m_SemId;
|
||||
|
||||
CKeyManager();
|
||||
|
||||
CKeyManager(const CKeyManager&);
|
||||
CKeyManager& operator =(const CKeyManager&);
|
||||
int Init();
|
||||
|
||||
|
||||
public:
|
||||
int GetShmKey();
|
||||
int GetSemKey();
|
||||
time_t GetCreateTime();
|
||||
|
||||
int GetFixIdxDef(struct FIX_INDEX_DEF **fix_idx_array_ptr);
|
||||
int InsertFixIdxDef(struct FIX_INDEX_DEF &fix_idx_def);
|
||||
int DeleteFixIdxDef(struct FIX_INDEX_DEF &fix_idx_def);
|
||||
|
||||
static CKeyManager * GetInstance();
|
||||
};
|
||||
|
||||
#endif
|
||||
202
code/sys_nicmonitor/include/db_api/odb_common.h
Normal file
202
code/sys_nicmonitor/include/db_api/odb_common.h
Normal file
@@ -0,0 +1,202 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_common.h
|
||||
DESCRIPTION: common data struct define
|
||||
FUNCTION LIST:
|
||||
COMMENT: public application
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2002-09-01 1.0 modify
|
||||
================================================================================
|
||||
2002-09-01 1.0 created
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ODB_COMMON_H__
|
||||
#define __ODB_COMMON_H__
|
||||
#include "common_types.h"
|
||||
#include "db_api/odb_public.h"
|
||||
//#include "odb_struct.h"
|
||||
#include "db_api/odb_prv_struct.h"
|
||||
#include "db_api/odb_app2id.h"
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
typedef int key_t;
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
|
||||
//系统表管理类
|
||||
class ODB_API_LIB_API CCommon
|
||||
{
|
||||
public:
|
||||
CCommon(){};
|
||||
~CCommon(){};
|
||||
|
||||
//map file // 2002-10-01
|
||||
static char* MapFile(const char* file_name, const int stab_total_size, const bool read_only = false);
|
||||
static char* MapFile(const char* file_name, MAP_FILE_KEY map_id, const int stab_total_size, const bool read_only = false);
|
||||
#ifdef _WINDOWS64
|
||||
static char* MapFile(const char* file_name, const int stab_total_size, const char* uniq_flag, bool read_only = false);
|
||||
static char* MapFile(const char* file_name, MAP_FILE_KEY map_id, const int stab_total_size, const char* uniq_flag, bool read_only = false);
|
||||
#endif
|
||||
static int UmapFile(char* addr_t, const int size);
|
||||
static int UmapFile(char* addr_t, MAP_FILE_KEY map_id, const int size);
|
||||
|
||||
//sort // 2002-11-20
|
||||
//static void QkSort(std::vector<RCD_TYPE>& r, int base, int top);
|
||||
static void QkSort(std::vector<RCD_TYPE>& r, const int base, const int top);
|
||||
static void StlSort(std::vector<RCD_TYPE>& r);
|
||||
|
||||
//char
|
||||
static char* itoa(const int value);
|
||||
static int str_lwr(char* str_dst, const char* str_src);
|
||||
static int str_upr(char* str_dst, const char* str_src);
|
||||
|
||||
static bool strip_blank1(char* ptr);
|
||||
static int strip_blank2(char* str_src);
|
||||
static bool StripBlank(char* str_src);
|
||||
//static void str_up(char* str);
|
||||
//static void str_lower(char* str);
|
||||
//inline static char* dwcase(char* str);
|
||||
|
||||
//sem 2002-12-28
|
||||
#ifndef _WINDOWS64
|
||||
static int InitSem(const key_t key, const int nsems=1);
|
||||
static int p(const int sem_id, const int sem_num=0);
|
||||
static int v(const int sem_id, const int sem_num=0);
|
||||
static int GetValue(const int sem_id, const int sem_num=0);
|
||||
#else
|
||||
static int p(const char* sem_name, const int sem_num);
|
||||
static int v(const char* sem_name, const int sem_num = 1, const int release_num=1);
|
||||
#endif
|
||||
|
||||
//shm
|
||||
static char* GetShmPtr(const key_t key, const int size);
|
||||
static int GetShmID(const key_t key, const int size);
|
||||
static char* GetShmPtrByID(const int shm_id);
|
||||
static int GetShmSizeByID(const int shm_id);
|
||||
|
||||
//time
|
||||
static void TimevalSub(struct timeval* end, struct timeval* start);
|
||||
|
||||
static bool IsApplication(const char* app_name);
|
||||
static bool IsApplication(const int app_no);
|
||||
|
||||
static void* Malloc(const int buf_size);
|
||||
static void Free(void* pointer);
|
||||
|
||||
static int GetOdbId(const char* odb_id_sysfile);
|
||||
|
||||
static int TransTime(time_t cur_time, char* time_str);
|
||||
|
||||
public:
|
||||
static int ExchangeData(char* buf_ptr, const int buf_size, const std::vector<MEMBER_DEFINITION>& vec_offset, const DB_BYTE_T& remote_byte);
|
||||
static int ExchangeByteOrder(char* buf_ptr, const int len);
|
||||
static DB_BYTE_T GetByteTag();
|
||||
|
||||
static int GetSize(std::vector<MEMBER_DEFINITION>& vec_member);
|
||||
|
||||
public:
|
||||
static int PrintCtrlTab(const struct DB_CTRL_TAB* ctrl_tab_ptr);
|
||||
static int PrintStdbTab(const struct STDB_TAB* stdb_tab_ptr);
|
||||
static int PrintStabField(const struct STDB_FIELD_TAB* stdb_field_tab_ptr);
|
||||
static int PrintField(const int data_type, const char* field_data_ptr);
|
||||
|
||||
private:
|
||||
//static void QkPass(std::vector<RCD_TYPE>& r, int start, int tend, int& i);
|
||||
static void QkPass(std::vector<RCD_TYPE>& r, const int start, const int tend, int& i);
|
||||
|
||||
static int CheckSize(std::vector<MEMBER_DEFINITION>& m_vecMember);
|
||||
static int MakeOffset(std::vector<MEMBER_DEFINITION>& m_vecMember);
|
||||
static int AssignOffset(int& index_pos, const int assign_val);
|
||||
|
||||
public:
|
||||
static void keyid_to_long(struct KEY_STRU *key_stru_ptr,cmnUint64* key_id_ptr);
|
||||
static void long_to_keyid(cmnUint64 key_id,struct KEY_STRU *key_stru_ptr);
|
||||
|
||||
static void long_to_tableNo(cmnUint64 key_id,short *table_no_ptr);
|
||||
static void long_to_field_id(cmnUint64 key_id,short *field_id_ptr);
|
||||
static void long_to_key(cmnUint64 key_id,int *key_ptr);
|
||||
|
||||
static void key_id_to_long(int key,short field_id,short table_id,cmnUint64*key_id_ptr);
|
||||
static void long_to_key_id(cmnUint64 key_id,int *key_ptr,short *field_id_ptr,short *table_id_ptr);
|
||||
|
||||
static int long_to_area_no(const cmnInt64 key_id);
|
||||
static void long_to_key_in_area(const cmnInt64 key_id, int& key_inarea);
|
||||
static void area_key_id_to_long(int area_no, int key, short field_id, short table_id, cmnInt64& key_id);
|
||||
static void long_to_long_without_area(const cmnInt64 id_with_area, cmnInt64& id_without_area);
|
||||
|
||||
/*
|
||||
static unsigned int rtdb_keyid_to_area_id(struct RTDB_KEY_STRU rtdb_key_id);
|
||||
static unsigned int rtdb_keyid_to_table_id(struct RTDB_KEY_STRU rtdb_key_id);
|
||||
static unsigned int rtdb_keyid_to_serial_no(struct RTDB_KEY_STRU rtdb_key_id);
|
||||
static unsigned int rtdb_keyid_to_column_id(struct RTDB_KEY_STRU rtdb_key_id);
|
||||
static void set_rtdb_keyid_area_id(struct RTDB_KEY_STRU& rtdb_key_id, unsigned int area_id);
|
||||
static void set_rtdb_keyid_table_id(struct RTDB_KEY_STRU& rtdb_key_id, unsigned int table_id);
|
||||
static void set_rtdb_keyid_serial_no(struct RTDB_KEY_STRU& rtdb_key_id, unsigned int serial_no);
|
||||
static void set_rtdb_keyid_column_id(struct RTDB_KEY_STRU& rtdb_key_id, unsigned int column_id);
|
||||
static void rtdb_keyid_to_long(unsigned int area_id, unsigned int table_id, unsigned int serial_no, unsigned int column_id, struct RTDB_KEY_STRU& rtdb_key_id);
|
||||
static void rtdb_keyid_to_sgid(string& sgid, const struct RTDB_KEY_STRU& rtdb_key_id);
|
||||
*/
|
||||
static int find_max_prime(int value);
|
||||
|
||||
static int hash33(char * code , int len , int max);
|
||||
static int hash37(char * code , int len , int max);
|
||||
static int hash_string(char * code , int len , int max);
|
||||
static int hash_int(char * code , int len , int max);
|
||||
static int hash_long(char * code , int len , int max);
|
||||
static int ShmDetach(char *& shm_ptr , int size);
|
||||
static int ShmRemove(int shm_id,int type);
|
||||
static int Equal(char *,char *,int length);
|
||||
static int MemCpy(char *dst,char *src,int length);
|
||||
static void FormatAppKeyStru(char* app_key_stru_ptr);
|
||||
static int FieldCompare(char *src_ptr,char *dst_ptr,int type,int length); //return val : 0 means equal , others means not equal
|
||||
//static int NeedFixIndex(int ctx_no,int app_no,int table_no,int index_seq_no);//这儿的index_seq_no是索引在表头里面的顺序号0、1、2....,而不是索引定义表中定义的索引ID。
|
||||
//int RCDCmp(const void *ee1,const void *ee2);
|
||||
|
||||
// //nothing
|
||||
// static void do_nothing1(int nn);
|
||||
// static void do_nothing2(int nn);
|
||||
static int compare_keyword(const char* keyword1_ptr, const char* keyword2_ptr, const ODB::KEYWORD_STRU& key);
|
||||
|
||||
#ifndef _WINDOWS64
|
||||
static int addItem(struct CMmapList& m_list, char* file_ptr, unsigned int map_size, const char* file_name, MAP_FILE_KEY map_id);
|
||||
static char* getMapPtr(struct CMmapList& m_list, const char* file_name, MAP_FILE_KEY map_id);
|
||||
static int shrinkList(struct CMmapList& m_list);
|
||||
static int reduceCounter(struct CMmapList& m_list, char* file_ptr, const int size, MAP_FILE_KEY map_id);
|
||||
static int recoveryList(struct CMmapList& m_list);
|
||||
static void PrintList(struct CMmapList& m_list);
|
||||
|
||||
static CAppNameIDTrans* getAppNameIdTransPtr();
|
||||
////////////////////// using map for file mapping cache ///////////////////////////
|
||||
static int addMapItem(MMapInfoList& m_list, char* file_ptr, unsigned int map_size, const char* file_name, MAP_FILE_KEY map_id);
|
||||
static char* getMapPtr(MMapInfoList& m_list, const char* file_name, MAP_FILE_KEY map_id);
|
||||
static int shrinkMapList(MMapInfoList& m_list);
|
||||
static int reduceMapCounter(MMapInfoList& m_list, char* file_ptr, const int size, MAP_FILE_KEY map_id);
|
||||
static void PrintMapList(MMapInfoList& m_list);
|
||||
|
||||
|
||||
#endif
|
||||
static void setMapFlag(int m_flag);
|
||||
static void setMapID(MAP_FILE_KEY& map_id, int ctx_no, int app_no, short tab_no, int area_no);
|
||||
static int parseAppNameFromFileName(char* app_name, const char* app_file_name);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
563
code/sys_nicmonitor/include/db_api/odb_define.h
Normal file
563
code/sys_nicmonitor/include/db_api/odb_define.h
Normal file
@@ -0,0 +1,563 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_define.h
|
||||
DESCRIPTION: macro define and error no
|
||||
FUNCTION LIST:
|
||||
COMMENT:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2002-09-01 1.0 modify
|
||||
================================================================================
|
||||
2002-09-01 1.0 created
|
||||
*******************************************************************************/
|
||||
#include "system.h"
|
||||
#include "d5000_err.h"
|
||||
#include "common_types.h"
|
||||
#include "logclient.h"
|
||||
#ifdef _WINDOWS64
|
||||
#pragma warning(disable: 4996)
|
||||
#pragma warning(disable: 4267)
|
||||
#endif
|
||||
|
||||
#ifndef __ODB_DEFINE_H__
|
||||
#define __ODB_DEFINE_H__
|
||||
|
||||
#ifndef _SHARE_MEMORY
|
||||
#define DEF_SHMMEM 0
|
||||
#else
|
||||
#define DEF_SHMMEM 1
|
||||
#endif
|
||||
|
||||
//const struct LogInfo ODBLOG = {2, "***", "***", "***", "odb_lib"};
|
||||
|
||||
//const long COLUMN_NO_FACTOR = 100000000; //wqx 2018-08-01
|
||||
//const long SERILA_NO_FACTOR = 100000000; //wqx 2018-08-01
|
||||
//const long AREA_NO_FACTOR = 1000000; //wqx 2018-09-10
|
||||
//const long COLUMN_NO_FACTOR = AREA_NO_FACTOR * SERILA_NO_FACTOR;//wqx 2018-09-10
|
||||
const long COLUMN_NO_FACTOR = 10000;//2018-10-08
|
||||
const int MAX_DB_NUMBER = 999999;//16000;
|
||||
const int MAX_AREA_NUM = 256;
|
||||
// 2002-10-17
|
||||
const int MAX_APP_TABLE = 256; //for each application
|
||||
const int MAX_CONTEXT_NUM = 64;
|
||||
const int MAX_APP_NUM = 256;
|
||||
const int MAX_TABLE_FIELD = 512; //512
|
||||
const short MAX_CONTEXT_NO = 16384;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
const int MAX_SUBKEY_NUMBER = 10;
|
||||
|
||||
const unsigned int MAX_KEY_LEN = 40;
|
||||
const unsigned int MAX_FILE_PATH_LEN = 40;
|
||||
const unsigned int MAX_NAME_STRING_LEN = 40;
|
||||
const unsigned int MAX_DATAFIELD_LEN = 16;
|
||||
const unsigned int MAX_PASSWD_LEN = 8;
|
||||
|
||||
const unsigned int MAX_SUB_SCENARIO_INST_PER_ALLOC = 99;
|
||||
const unsigned int MAX_SUB_SCENARIO_PER_ALLOC = 99;
|
||||
const unsigned int MAX_SCENARIO_INST_ALLOC = 99;
|
||||
|
||||
const unsigned int ENG_NAME_LEN = 32;
|
||||
const unsigned int CHN_NAME_LEN = 64;
|
||||
|
||||
const unsigned int ORIGIN_MENU_NAME_LEN = 40;
|
||||
const unsigned int MENU_NAME_LEN = 64;
|
||||
const unsigned int MENU_DISPLAY_LEN = 40;
|
||||
const unsigned int DEFAULT_VALUE_LEN = 20;
|
||||
const unsigned int ARRAY_NAME_LEN = 32;
|
||||
const unsigned int DESCRIPTION_LEN = 100;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
const unsigned int RECORD_HEAD_LEN = 4;
|
||||
const unsigned int MV_SIZE = 1024;
|
||||
const unsigned int INT_ADDRESS_ASSIGN = 4;
|
||||
|
||||
const unsigned int MAX_PHY_RECORD_LEN = 15000;
|
||||
|
||||
const int RTDB_APP_MOD = AF_AP_MOD; //change from 100 at 2004-07-14
|
||||
const int ORB_TRY_TIMES = 3 ; //initial 20
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
const int RTDB_SYSTEM_SEM_KEY = 0x20000;
|
||||
const int RTDB_APP_SEM_KEY = 0x20010;
|
||||
//const int RTDB_TABLE_SEM_KEY = 0x3200;
|
||||
const int RTDB_TABLE_SEM_KEY = 0x201;
|
||||
|
||||
/***************for CKeyManager SHMKEY and SEMKEY Begin******************************/
|
||||
const int RTDB_TABLE_SHM_KEY = 0x8000;
|
||||
const int RTDB_TABLE_SHAREMEMORY_SHM_KEY = 0x90000;
|
||||
const int RTDB_KEY_MANAGE_SHM_KEY = 0x7999;
|
||||
const int RTDB_KEY_MANAGE_SEM_KEY = 0x20001;
|
||||
/***************for CKeyManager SHMKEY and SEMKEY End *******************************/
|
||||
|
||||
const int MAX_SEM_NUM = 25;
|
||||
const int RTDB_SEM_NUM = 12;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
const short ENTITY_APP = 1;
|
||||
const short ENTITY_TABLE = 2;
|
||||
const short ENTITY_FIELD = 3;
|
||||
|
||||
const unsigned char MODE_CHN = 0;
|
||||
const unsigned char MODE_ENG = 1;
|
||||
|
||||
const unsigned char MODE_NAME_BY_NO = 0;
|
||||
const unsigned char MODE_NO_BY_NAME = 1;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
const char PATH_VIRGULE = '/';
|
||||
|
||||
//#else
|
||||
//
|
||||
//const char PATH_VIRGULE = '\';
|
||||
//
|
||||
//#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
const int MODE_API = 1;
|
||||
|
||||
|
||||
// CONDITION_TYPE: condition_type
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
const short SIMPLE_CON = 0;
|
||||
const short MULTI_CON = 1;
|
||||
const short HIS_SIMPLE_CON = 2;
|
||||
const short HIS_MULTI_CON = 3;
|
||||
const short XY_CURVE_CON = 4;
|
||||
const short TABLE_CON = 5;
|
||||
const short STATISTIC_CON = 6;
|
||||
|
||||
/* ---------------------------------------------------------------------------*/
|
||||
/* Db data type */
|
||||
typedef unsigned char DATA_TYPES_T; //可以考虑为enum
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
DB_OBJECT_T: 2002-10-22
|
||||
---------------------------------------------------------- */
|
||||
enum DB_OBJECT_T
|
||||
{
|
||||
OBJECT_NONE = 0,
|
||||
OBJECT_SYSTEM = 1,
|
||||
OBJECT_APP = 2,
|
||||
OBJECT_TABLE = 3
|
||||
};
|
||||
/* -----------------------------------------------------------
|
||||
DB_LOCK_T: 2002-10-22
|
||||
---------------------------------------------------------- */
|
||||
enum DB_LOCK_T
|
||||
{
|
||||
DB_LOCK_NONE = 0,
|
||||
DB_LOCK_READ = 1,
|
||||
DB_LOCK_WRITE = 2,
|
||||
DB_LOCK_INTEND = 3
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
DB_BYTE_T: 2002-10-22
|
||||
---------------------------------------------------------- */
|
||||
enum DB_BYTE_T
|
||||
{
|
||||
BYTE_LITTLE_ENDIAN = 0,
|
||||
BYTE_BIG_ENDIAN,
|
||||
BYTE_OTHER
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
DB_CONTEXT_T: 2002-10-18
|
||||
---------------------------------------------------------- */
|
||||
enum DB_CONTEXT_T
|
||||
{
|
||||
CONTEXT_REAL_TIME = 0,
|
||||
CONTEXT_RESEARCH,
|
||||
CONTEXT_INSTRUCT,
|
||||
CONTEXT_HISTORY = 3,
|
||||
CONTEXT_NONE = 4
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
DB_STATUS_T: 2002-10-16
|
||||
---------------------------------------------------------- */
|
||||
enum DB_STATUS_T
|
||||
{
|
||||
TABLE_INIT = 0, //系统初始化,表未创建
|
||||
TABLE_NORMAL = 1, //已经创建
|
||||
TABLE_DELETED = 2, //创建后删除
|
||||
TABLE_ERROR =3 ,//表或者索引出现错误,需要修复。
|
||||
TABLE_DOWNLOADING = 4 //表正在下装,下装结束后,状态置成TABLE_NORMAL
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
DB_CLASS_T: db_class
|
||||
---------------------------------------------------------- */
|
||||
enum DB_CLASS_T
|
||||
{
|
||||
STDB = 0,
|
||||
VIEW = 1
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
DB_TYPES_T: db_type
|
||||
---------------------------------------------------------- */
|
||||
enum DB_TYPES_T
|
||||
{
|
||||
DATA = 0,
|
||||
INDEX = 1
|
||||
};
|
||||
/* -----------------------------------------------------------
|
||||
DB_MEDIA_T: db_media
|
||||
---------------------------------------------------------- */
|
||||
enum DB_MEDIA_T
|
||||
{
|
||||
MEMORY = 0,
|
||||
DISK = 1
|
||||
};
|
||||
/* -----------------------------------------------------------
|
||||
INDEX_TYPE_T: index_type
|
||||
---------------------------------------------------------- */
|
||||
enum INDEX_TYPE_T
|
||||
{
|
||||
KEYWORD = 0,
|
||||
RECORD_POINTER = 1
|
||||
};
|
||||
|
||||
const int RTDB_NOT_USED = 0;
|
||||
const int RTDB_USED = 1;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------
|
||||
DATA_TYPES_T: db data type
|
||||
--------------------------------------------------------- */
|
||||
|
||||
const int C_STRING_TYPE = 1;
|
||||
const int C_UCHAR_TYPE = 2;
|
||||
const int C_SHORT_TYPE = 3;
|
||||
const int C_INT_TYPE = 4;
|
||||
const int C_DATETIME_TYPE = 5;
|
||||
const int C_FLOAT_TYPE = 6;
|
||||
const int C_DOUBLE_TYPE = 7;
|
||||
const int C_KEYID_TYPE = 8;
|
||||
const int C_BINARY_TYPE = 9;
|
||||
const int C_TEXT_TYPE = 10;
|
||||
const int C_IMAGE_TYPE = 11;
|
||||
const int C_APPKEY_TYPE = 12;
|
||||
const int C_APPID_TYPE = 13;
|
||||
const int C_UINT_TYPE = 14;
|
||||
const int C_LONG_TYPE = 15;
|
||||
const int C_RTDBKEY_TYPE = 16;
|
||||
const int C_MEASRTDBKEY_TYPE = 17;
|
||||
const int C_APPRTDBKEY_TYPE = 18;
|
||||
const int C_SCNRTDBKEY_TYPE = 19;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------
|
||||
DATA_TYPES_DISPLAY: db data type
|
||||
--------------------------------------------------------- */
|
||||
enum DATA_DISPLAY_T
|
||||
{
|
||||
D_CHAR_TYPE = 1,
|
||||
D_UCHAR_TYPE = 2,
|
||||
D_SHORT_TYPE = 3,
|
||||
D_INT_TYPE = 4,
|
||||
D_LONG_TYPE = 5,
|
||||
D_FLOAT_TYPE = 6,
|
||||
D_DOUBLE_TYPE = 7,
|
||||
D_SINGLEMENU_TYPE = 8,
|
||||
D_MUTIMENU_TYPE = 9,
|
||||
D_STRING_TYPE = 10,
|
||||
D_DATE_TYPE = 11,
|
||||
D_TIME_TYPE = 12,
|
||||
D_DATETIME_TYPE = 13,
|
||||
D_MULTISTRING_TYPE = 14,
|
||||
D_KEYID_TYPE = 15,
|
||||
D_BINARY_TYPE = 16,
|
||||
D_PASSWORD_TYPE = 17,
|
||||
D_TEXT_TYPE = 18,
|
||||
D_IMAGE_TYPE = 19,
|
||||
D_FORMULASTRING_TYPE = 20,
|
||||
D_FIELD_NAME_STRING_TYPE = 21
|
||||
};
|
||||
|
||||
const int MENU_ALL = 2;
|
||||
const int MENU_OFF = 1;
|
||||
const int MENU_ON = 0;
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
ACCESS_METHODS_T: db storage methods
|
||||
------------------------------------------------------------- */
|
||||
enum ACCESS_METHODS_T
|
||||
{
|
||||
ACCESS_SEQUENT = 0,
|
||||
ACCESS_DIRECT = 1,
|
||||
ACCESS_HASH = 2,
|
||||
ACCESS_DIRECT_HASH = 3,
|
||||
ACCESS_HASH_INDEX = 4,
|
||||
ACCESS_DIRECTINDEX_HASH = 5,
|
||||
ACCESS_FLOW = 6,
|
||||
ACCESS_NAMEID_HASH = 7,
|
||||
ACCESS_DIRECTINDEX_FLOW = 8,
|
||||
ACCESS_FIELD_SEQUENT_HASH = 9
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
PHY_ACCESS_METHODS_T: db physical storage methods
|
||||
------------------------------------------------------------- */
|
||||
enum PHY_ACCESS_METHODS_T
|
||||
{
|
||||
PHY_SEQUENT_ACCESS = 0,
|
||||
PHY_LINK_ACCESS = 1,
|
||||
PHY_BLOCKLINK_ACCESS = 2
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
sequent order
|
||||
------------------------------------------------------------- */
|
||||
|
||||
#define ASC 0
|
||||
//#define DEC 1
|
||||
#define ODB_DEC 1
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
db open mode
|
||||
------------------------------------------------------------ */
|
||||
|
||||
#define READ_OPEN 0
|
||||
#define WRITE_OPEN 1
|
||||
#define RDWR_OPEN 2
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
db record head status
|
||||
------------------------------------------------------------ */
|
||||
|
||||
#define RECORD_EMPTY 0
|
||||
#define RECORD_EXIST 1
|
||||
#define RECORD_ERASED 3
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
db lock type
|
||||
------------------------------------------------------------ */
|
||||
|
||||
#define RECORD_LOCK 0x01
|
||||
#define FIELD_LOCK 0x02
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
db lock status
|
||||
------------------------------------------------------------ */
|
||||
|
||||
#define UNLOCK 0
|
||||
#define LOCK 1
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
keyword type
|
||||
------------------------------------------------------------------------------*/
|
||||
const int INT_KEY = 1;
|
||||
const int STRING_KEY = 2;
|
||||
const int INT_STRING_KEY = 3;
|
||||
const int KEYID_KEY = 4;
|
||||
const int APPKEY_KEY = 5;
|
||||
const int APPID_KEY = 6;
|
||||
const int LONG_KEY = 7;
|
||||
const int RTDBKEY_KEY = 8;
|
||||
const int MEASRTDBKEY_KEY = 9;
|
||||
|
||||
|
||||
|
||||
/* -------------------------------------------------------------
|
||||
------------------------------------------------------------- */
|
||||
#define ALL_FIELD -1
|
||||
#define ALL_RECORD -1
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
real time dbms error retcode 2002-10-14
|
||||
------------------------------------------------------------------------------*/
|
||||
const int DB_OK = 0; /* success */
|
||||
const int DB_ERROR = ERR_RTDB_ERROR; /* error */
|
||||
const int DBE_PARA = ERR_RTDB_PARA; /* bad para_parameter */
|
||||
const int DBE_CHAOS = ERR_RTDB_CHAOS; /* inner error */
|
||||
const int DBE_BLOCK = -7;
|
||||
|
||||
//access
|
||||
const int DBE_ACCESSMETH = ERR_RTDB_ACCESSMETH; /* access_meth is error */
|
||||
const int DBE_EXIST = ERR_RTDB_EXIST; /* Db name is exist, cannot creat */
|
||||
const int DBE_NODB = ERR_RTDB_NODB; /* Db name not founded */
|
||||
const int DBE_INVDBNO = ERR_RTDB_INVDBNO; /* Db no is wrong */
|
||||
const int DBE_INVFNAME = ERR_RTDB_INVFNAME; /* Field name not founded */
|
||||
const int DBE_HASOPENED = ERR_RTDB_HASOPENED; /* The db has been opened */
|
||||
const int DBE_FILE_NOPEN = ERR_RTDB_FILE_NOPEN; /* The file cannot open */
|
||||
const int DBE_READ_FILE = ERR_RTDB_READ_FILE; /* The file cannot read */
|
||||
const int DBE_APP_NO_DB = ERR_RTDB_APP_NO_DB; /* This table isn't in current application */
|
||||
const int DBE_DB_NONE = ERR_RTDB_DB_NONE; /* The table is deleted or hasn't been created*/
|
||||
|
||||
//lock
|
||||
const int DBE_LOCK = ERR_RTDB_LOCK; /* The db is locked */
|
||||
const int DBE_UNLOCK = ERR_RTDB_UNLOCK; /* The db isnot locked */
|
||||
const int DBE_INVUNLOCK = ERR_RTDB_INVUNLOCK; /* locker is not me */
|
||||
const int DBE_NOINDEX = ERR_RTDB_NOINDEX; /* havenot index */
|
||||
|
||||
const int DBE_DIFFSIZE = ERR_RTDB_DIFFSIZE; /* size is different */
|
||||
const int DBE_NOTCHKEY = ERR_RTDB_NOTCHKEY; /* ?? */
|
||||
const int DBE_NOCACHE = ERR_RTDB_NOCACHE; /* no cache block */
|
||||
const int DBE_NOTE_NEND = ERR_RTDB_NOTE_NEND; /* NOTE must be last field */
|
||||
|
||||
const int DBE_CTRLFULL = ERR_RTDB_CTRLFULL; /* The db ctrl table is full */
|
||||
const int DBE_DBFULL = ERR_RTDB_DBFULL; /* The db is full */
|
||||
const int DBE_EODB = ERR_RTDB_EODB; /* End of Database */
|
||||
const int DBE_INVSIZE = ERR_RTDB_INVSIZE; /* The size is invalid */
|
||||
const int DBE_DBBEGIN = ERR_RTDB_DBBEGIN; /* Have reach the begin of db */
|
||||
const int DBE_DBEND = ERR_RTDB_DBEND; /* Have reach the end of db */
|
||||
|
||||
const int DBE_INVCCOMM = ERR_RTDB_INVCCOMM; /* Invalid comparition command */
|
||||
const int DBE_TMOPEN = ERR_RTDB_TMOPEN; /* Too many open */
|
||||
|
||||
////key
|
||||
const int DBE_KEYNOTFIND = ERR_RTDB_KEYNOTFIND; /* keyword not founded */
|
||||
const int DBE_MULTIKEY = ERR_RTDB_MULTIKEY; /* Multi-keywords */
|
||||
const int DBE_INVKEY = ERR_RTDB_INVKEY; /* The keyword is invalid */
|
||||
const int DBE_MKEYFIELD = ERR_RTDB_MKEYFIELD; /* The keyword field can be only one */
|
||||
const int DBE_KEYFLEN = ERR_RTDB_KEYFLEN; /* The keyword length must be 4 times*/
|
||||
const int DBE_DBTYPE = ERR_RTDB_DBTYPE; /* Invalid db type */
|
||||
const int DBE_KEYTYPE = ERR_RTDB_KEYTYPE; /* Invalid keyword type */
|
||||
const int DBE_PASSWD = ERR_RTDB_PASSWD; /* Invalid passwd */
|
||||
|
||||
////table
|
||||
const int DBE_TABLE_NO = ERR_RTDB_TABLE_NO; /* no match table or no*/
|
||||
const int DBE_TABLE_STA = ERR_RTDB_TABLE_STA; /* table status is abnormal */
|
||||
|
||||
////record
|
||||
const int DBE_EXISTREC = ERR_RTDB_EXISTREC; /* Record existed, cannot write */
|
||||
const int DBE_NEXISTREC = ERR_RTDB_NEXISTREC; /* Record not existed, cannot modify */
|
||||
const int DBE_SUPMAX = ERR_RTDB_SUPMAX; /* record value too bigger */
|
||||
const int DBE_BELMIN = ERR_RTDB_BELMIN; /* record value too smaller */
|
||||
const int DBE_RECSIZE = ERR_RTDB_RECSIZE; /* record size wrong */
|
||||
const int DBE_NOTERASE = ERR_RTDB_NOTERASE; /* record not erased */
|
||||
const int DBE_RECERASE = ERR_RTDB_RECERASE; /* The record is erased */
|
||||
const int DBE_POINTER = ERR_RTDB_POINTER; /* record_pointer error */
|
||||
const int DBE_CONT_ERR = ERR_RTDB_CONT_ERR; /* condition express error */
|
||||
const int DBE_NEED_CHK = ERR_RTDB_NEED_CHK; /* something wrong, need to check record state*/
|
||||
|
||||
////field
|
||||
const int DBE_DATATYPE = ERR_RTDB_DATATYPE; /* field data type is wrong */
|
||||
const int DBE_DIFFTYPE = ERR_RTDB_DIFFTYPE; /* type is different */
|
||||
const int DBE_KEYFIELD = ERR_RTDB_KEYFIELD; /* The field is keyword */
|
||||
const int DBE_BIGFIELDNO = ERR_RTDB_BIGFIELDNO; /* The field no is too big */
|
||||
const int DBE_DLT_WRITE = ERR_RTDB_DLT_WRITE; /* The direct link hash cannot write */
|
||||
const int DBE_INVFIELDNO = ERR_RTDB_INVFIELDNO; /* field_no is wrong */
|
||||
const int DBE_NOTFIND = ERR_RTDB_NOTFIND; /* Not find the value */
|
||||
const int DBE_FIELD_NO = ERR_RTDB_FIELD_NO; /* no match field name or no */
|
||||
const int DBE_FIELD_SIZE = ERR_RTDB_FIELD_SIZE; /* field length wrong */
|
||||
const int DBE_NONE_FIELD = ERR_RTDB_NONE_FIELD; /* this table has no field */
|
||||
|
||||
|
||||
//operation
|
||||
const int DBE_INVCOMM = ERR_RTDB_INVCOMM; /* Invalid db operater command */
|
||||
const int DBE_NPERMIT = ERR_RTDB_NPERMIT; /* The OP is not permit */
|
||||
|
||||
const int DBE_CONTEXT = ERR_RTDB_CONTEXT; /* no context or application */
|
||||
const int DBE_APP_UNLOAD = ERR_RTDB_APP_UNLOAD; /* application isn't loaded */
|
||||
|
||||
|
||||
const int DBE_SQL_COMMAND = ERR_RTDB_SQL_COMMAND; /*select error*/
|
||||
const int DBE_SQL_FORM = ERR_RTDB_SQL_FORM; /*form error*/
|
||||
const int DBE_SQL_WHERE = ERR_RTDB_SQL_WHERE; /*where condition error*/
|
||||
const int DBE_SQL_ORDER = ERR_RTDB_SQL_ORDER; /*order by error*/
|
||||
|
||||
|
||||
|
||||
//memory
|
||||
const int DBE_MEMORY = ERR_RTDB_MEMORY; /* Cannot malloc or calloc memory */
|
||||
const int DBE_BUFFFULL = ERR_RTDB_BUFFFULL; /* Buffer is full */
|
||||
const int DBE_MEM_NOALLOC = ERR_RTDB_MEM_NOALLOC; /* The memory cannot allocation */
|
||||
|
||||
const int DBE_MAP = ERR_RTDB_MAP; /* map file error */
|
||||
|
||||
//const int DBE_PTABFULL = -10; /* process tab is full */
|
||||
|
||||
//sql
|
||||
const int DBE_SQL = ERR_RTDB_SQL; /* sql syntax error */
|
||||
|
||||
|
||||
|
||||
//
|
||||
const int DBE_DBNAMENOTF = ERR_RTDB_DBNAMENOTF; /* db_name not founded */
|
||||
const int DBE_FACNAMENOTF = ERR_RTDB_FACNAMENOTF; /* fac_name not founded */
|
||||
const int DBE_VALNAMENOTF = ERR_RTDB_VALNAMENOTF; /* val_name not founded */
|
||||
const int DBE_FIELDNAMENOTF = ERR_RTDB_FIELDNAMENOTF; /* field_name not founded */
|
||||
|
||||
//
|
||||
const int DBE_VIEWFIELD = ERR_RTDB_VIEWFIELD; /* view get fieldnum over error */
|
||||
const int DBE_SYBASE = ERR_RTDB_SYBASE; /* modify sybase error */
|
||||
const int DBE_INDEXERR = ERR_RTDB_INDEXERR; /* index number error */
|
||||
const int DBE_MODIFYSIZE = ERR_RTDB_MODIFYSIZE; /* modify bufsize error */
|
||||
|
||||
const int API_INVCOMM = ERR_RTDB_API_INVCOMM; /* Invalid db operater command */
|
||||
const int API_NOAPP = ERR_RTDB_API_NOAPP; /* App name not founded */
|
||||
const int API_NODB = ERR_RTDB_API_NODB; /* Db name not founded */
|
||||
const int API_INVDBNO = ERR_RTDB_API_INVDBNO; /* Db no is wrong */
|
||||
|
||||
const int API_NODEOFF = ERR_RTDB_API_NODEOFF; /* node is offline */
|
||||
const int API_ERRINIT = ERR_RTDB_API_ERRINIT; /* odbms init error */
|
||||
const int API_NEWERR = ERR_RTDB_API_NEWERR; /* new space error */
|
||||
const int API_DATAERR = ERR_RTDB_API_DATAERR; /* data tye error */
|
||||
const int DBE_NOSPACE = ERR_RTDB_NOSPACE; /* no space left in disk */
|
||||
|
||||
|
||||
|
||||
/* -----------------------------------------------------------
|
||||
for sql query: 2002-10-31
|
||||
---------------------------------------------------------- */
|
||||
enum CONDITION_OPERATOR_T
|
||||
{
|
||||
SQL_COND_LSC = 10, /* < */
|
||||
SQL_COND_LEC = 11, /* <= */
|
||||
SQL_COND_EQC = 12, /* == */
|
||||
SQL_COND_GEC = 13, /* >= */
|
||||
SQL_COND_GTC = 14, /* > */
|
||||
SQL_COND_NEQ = 15 /* != */
|
||||
};
|
||||
|
||||
enum LOGICAL_OPERATOR_T
|
||||
{
|
||||
SQL_LOG_AND = 16, /* && */
|
||||
SQL_LOG_OR = 17, /* || */
|
||||
SQL_LOG_NOT = 18, /* ~ */
|
||||
SQL_LOG_NONE= 20
|
||||
};
|
||||
|
||||
|
||||
enum SQL_METHOD_T
|
||||
{
|
||||
METHOD_SELECT = 1,
|
||||
METHOD_UPDATE = 2,
|
||||
METHOD_DELETE = 3,
|
||||
METHOD_CREATE = 4
|
||||
};
|
||||
|
||||
#define DEF_SHMMEM 0
|
||||
|
||||
//SLICED_DB
|
||||
const int TBL_SLICED = 1;
|
||||
const int TBL_UNSLICED = 0;
|
||||
|
||||
//for DSCADA & SCADA
|
||||
//app_area_no
|
||||
#define DRTDB_APP_AREA AP_DSCADA_AREA
|
||||
//app_area_no
|
||||
//#define DRTDB_APP_NO AP_DMS_SCADA
|
||||
#define DRTDB_APP_NO AP_SCADA
|
||||
//dscada 1, scada 0
|
||||
#define DRTDB_DMS 1
|
||||
|
||||
/******************************************************************************
|
||||
* debug display option *
|
||||
******************************************************************************/
|
||||
#define DBG_INDEX_STDB_TAB 1
|
||||
#define DBG_INDEX_STDB_FIELD_TAB 2
|
||||
#define DBG_STDB_INDEX_HASH 3
|
||||
#define DBG_FREE_POINTER 4
|
||||
#define DBG_INDEX_STG 5
|
||||
#define DBG_INDEX_OVERFLOW 6
|
||||
#define DBG_ALL 7
|
||||
#endif
|
||||
@@ -0,0 +1,84 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: Real Time Database management system
|
||||
FileName: rtdb_api.cpp
|
||||
DESCRIPTION: rtdb api interfaces implementation
|
||||
FUNCTION LIST:
|
||||
COMMENT:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2009-01-10 1.1 add net interfaces
|
||||
================================================================================
|
||||
2008-10-30 1.0 created
|
||||
*******************************************************************************/
|
||||
#include "db_api/odb_baseindex.h"
|
||||
#ifndef _CDOUBLEOVERFLOWHASHINDEX
|
||||
#define _CDOUBLEOVERFLOWHASHINDEX
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
class CDoubleOverFlowHashIndex:public CBaseIndex
|
||||
{
|
||||
public:
|
||||
virtual int need_rebuilt(char *existed_table_ptr,struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id);
|
||||
virtual int CreateIndex(struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id,int &shm_size);
|
||||
virtual int Open(char *index_file_name,int table_id,int index_id); //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int Open(int index_shmid,int table_id,int index_id); //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int SetIndexPtr(char *index_ptr); //把缓存的指针赋值给索引类,这样就不用使用前面的Open函数。
|
||||
virtual int GetKeyByIndex(char *index_ptr,std::vector<char *> &index_array);
|
||||
virtual int GetKeyPointerByIndex(char *index_ptr, int& pointer);//只对主键索引有效,根据index得到记录的物理位置
|
||||
virtual int IndexInsert(char *index_ptr,char *key_ptr);
|
||||
virtual int BulkIndexInsert(char *bulk_index_key_ptr);//下装的时候
|
||||
virtual int Indexdelete(char *index_ptr,char *key_ptr);
|
||||
virtual int IndexClear();
|
||||
virtual int GetIdxMthd();
|
||||
virtual int FreeResource();//譬如unmap或者shmdt掉指针。
|
||||
virtual int DebugDisp(int type);//方便调试用,不同的type,显示不同或者详细程度不同的信息。
|
||||
virtual int GetIndexRecNum();//返回索引记录总的个数,包括索引区、溢出区、主溢出区有效记录个数的总和。但是无溢出HASH索引只是返回0。
|
||||
virtual DB_STATUS_T GetIndexStatus()//返回索引的状态
|
||||
{
|
||||
return m_IndexStdbPtr->index_status;
|
||||
}
|
||||
virtual void SetIndexStatus(DB_STATUS_T idx_status)//设置索引头上的索引状态
|
||||
{
|
||||
m_IndexStdbPtr->index_status = idx_status;
|
||||
}
|
||||
|
||||
~CDoubleOverFlowHashIndex();//考虑在析构函数里面调用FreeResource()
|
||||
|
||||
private:
|
||||
int malloc_chunk(int &new_record_pointer);
|
||||
int pri_malloc_chunk(int &new_record_pointer);
|
||||
int free_chunk(struct INDEX_STORAGE_HASH_DOVERFLOW_REC_HEAD* root_index_stg_head_ptr, int unused_record_pointer);
|
||||
int free_chunk(struct INDEX_STORAGE_HASH_DOVERFLOW_REC_HEAD* root_index_stg_head_ptr, struct PRIMARY_OVERFLOW_STORAGE_HASH_REC_HEAD* pri_ofl_stg_head_ptr, int unused_record_pointer);
|
||||
int pri_free_chunk(struct INDEX_STORAGE_HASH_DOVERFLOW_REC_HEAD* root_index_stg_head_ptr, int unused_record_pointer);
|
||||
int index_equal(char *outer_index_ptr,char *inner_index_ptr);
|
||||
|
||||
private:
|
||||
int disp_index_stdb_tab();
|
||||
int disp_index_stdb_field_tab();
|
||||
int disp_stdb_index_hash_doverflow();
|
||||
int disp_free_pointer();
|
||||
int disp_index_stg();
|
||||
int disp_index_overflow();
|
||||
int disp_index_pri_overflow();
|
||||
int disp_all();
|
||||
int disp_index_contents(char *index_ptr);
|
||||
int disp_key_contents(char *key_ptr);
|
||||
|
||||
//int test_insert();
|
||||
|
||||
private:
|
||||
struct INDEX_STDB_TAB *m_IndexStdbPtr;
|
||||
struct INDEX_STDB_FIELD_TAB *m_IndexStdbFieldPtr;
|
||||
struct STDB_INDEX_HASH_DOVERFLOW *m_StdbIndexHashPtr;
|
||||
int *m_FreePointer;//溢出区malloc_chunk和free_chunk使用。
|
||||
int *m_PriFreePointer;// 给主溢出区pri_malloc_chunk和pri_free_chunk使用。
|
||||
char *m_IndexStgHashPtr;
|
||||
char *m_PriOverflowStgHashPtr;
|
||||
char *m_OverflowStgHashPtr;
|
||||
int (*hash_func_ptr)(char *index,int length,int hash_prime);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
85
code/sys_nicmonitor/include/db_api/odb_field.h
Normal file
85
code/sys_nicmonitor/include/db_api/odb_field.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_field.h
|
||||
DESCRIPTION: class table struct define
|
||||
FUNCTION LIST:
|
||||
COMMENT: field struct define
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2002-10-10 1.0 modify
|
||||
================================================================================
|
||||
2002-10-10 1.0 created
|
||||
*******************************************************************************/
|
||||
#ifndef __ODB_FIELD_H__
|
||||
#define __ODB_FIELD_H__
|
||||
|
||||
#include "db_api/odb_public.h"
|
||||
//#include "odb_struct.h"
|
||||
#include "db_api/odb_prv_struct.h"
|
||||
#include "db_api/odb_common.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
|
||||
//字段访问类
|
||||
class COdbField
|
||||
{
|
||||
public:
|
||||
COdbField();
|
||||
COdbField(const char* db_area_ptr); //表头位置
|
||||
COdbField(const char* db_area_ptr, int r_field_no); //表头位置 + 商用字段号
|
||||
COdbField(const char* db_area_ptr, char* field_name);
|
||||
~COdbField();
|
||||
|
||||
int SetFieldTabPtr(const char* db_area_ptr);//设置本字段控制区信息
|
||||
|
||||
int SetRecordPtr(char* record_ptr); //设置表的当前记录位置
|
||||
|
||||
//移动到指定字段位置
|
||||
int MoveTo(const int r_field_no); //根据field_no定位到当前app,table的STDB_FIELD_TAB
|
||||
int MoveTo(const char* field_name);
|
||||
int MoveToByChn(const char* field_name);
|
||||
|
||||
//查询
|
||||
char* GetFieldName(); //return a pointer
|
||||
int GetFieldName(char* field_name); //get_fieldname_by_fieldno()//copy to a array
|
||||
int GetFieldChnName(char* field_name);
|
||||
int SetFieldName(const char* field_name); //set chinese field name
|
||||
int GetFieldNo(bool is_real = false); //get_fieldno_by_fieldname()
|
||||
|
||||
int GetFieldPara(int& data_type, int& offset, int& field_length, int& is_keyword); //get_field_para_byno()
|
||||
int GetFieldLength(int& field_length);
|
||||
|
||||
int GetLimitValue(char* field_value_ptr, const int buf_size); //limited data length
|
||||
int GetFieldValue(char** field_value_ptr);
|
||||
int GetFieldValue(char** field_value_ptr, int& field_length);
|
||||
int GetFieldValue(char** field_value_ptr, int& field_length, const int r_field_no);
|
||||
int SetFieldValue(const char* modify_field_ptr, const int modify_field_length);
|
||||
|
||||
private:
|
||||
COdbField(const COdbField& odb_field);
|
||||
COdbField& operator=(const COdbField& odb_field);
|
||||
|
||||
private:
|
||||
// struct STDB_TAB* stdb_tab_ptr; //表首指针
|
||||
// struct STDB_FIELD_TAB* stdb_field_tab_ptr; //字段首控制区信息,从OdbTable得到
|
||||
// struct STDB_FIELD_TAB* cur_field_tab_ptr; //当前字段控制区信息
|
||||
// char* cur_record_ptr; //当前记录数据
|
||||
|
||||
struct STDB_TAB* m_StdbTabPtr; //表首指针
|
||||
struct STDB_FIELD_TAB* m_StdbFieldTabPtr; //字段首控制区信息,从OdbTable得到
|
||||
struct STDB_FIELD_TAB* m_CurFieldTabPtr; //当前字段控制区信息
|
||||
char* m_CurRecordPtr; //当前记录数据
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
struct STDB_VIR_FIELD_TAB* m_StdbVirFieldTabPtr; //虚拟字段首控制区信息,从OdbTable得到
|
||||
struct STDB_VIR_FIELD_TAB* m_CurVirFieldTabPtr; //当前虚拟字段首控制区信息
|
||||
bool m_CurIsVirtual; //当前域号对应的是虚拟域号,要取虚拟域值
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
72
code/sys_nicmonitor/include/db_api/odb_hashindex.h
Normal file
72
code/sys_nicmonitor/include/db_api/odb_hashindex.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: Real Time Database management system
|
||||
FileName: rtdb_api.cpp
|
||||
DESCRIPTION: rtdb api interfaces implementation
|
||||
FUNCTION LIST:
|
||||
COMMENT:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2009-01-10 1.1 add net interfaces
|
||||
================================================================================
|
||||
2008-10-30 1.0 created
|
||||
*******************************************************************************/
|
||||
#include "db_api/odb_baseindex.h"
|
||||
#include "db_api/odb_ckeymanager.h"
|
||||
#ifndef _CHASHINDEX
|
||||
#define _CHASHINDEX
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
class CHashIndex:public CBaseIndex
|
||||
{
|
||||
public:
|
||||
virtual int need_rebuilt(char *existed_table_ptr,struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id);
|
||||
virtual int CreateIndex(struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id,int &shm_size);
|
||||
virtual int Open(char *index_file_name,int table_id,int index_id); //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int Open(int index_shmid,int table_id,int index_id); //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int SetIndexPtr(char *index_ptr); //把缓存的指针赋值给索引类,这样就不用使用前面的Open函数。
|
||||
virtual int GetKeyByIndex(char *index_ptr,std::vector<char *> &index_array);
|
||||
virtual int GetKeyPointerByIndex(char *index_ptr, int& pointer);//只对主键索引有效,根据index得到记录的物理位置
|
||||
virtual int IndexInsert(char *index_ptr,char *key_ptr);
|
||||
virtual int BulkIndexInsert(char *bulk_index_key_ptr);//下装的时候
|
||||
virtual int Indexdelete(char *index_ptr, char* key);
|
||||
virtual int IndexClear();
|
||||
virtual int GetIdxMthd();
|
||||
virtual int FreeResource();//譬如unmap或者shmdt掉指针。
|
||||
virtual int DebugDisp(int type);//方便调试用,不同的type,显示不同或者详细程度不同的信息。
|
||||
virtual int GetIndexRecNum();//返回索引记录总的个数,包括索引区、溢出区、主溢出区有效记录个数的总和。但是无溢出HASH索引只是返回0。
|
||||
virtual DB_STATUS_T GetIndexStatus()//返回索引的状态
|
||||
{
|
||||
return m_IndexStdbPtr->index_status;
|
||||
}
|
||||
virtual void SetIndexStatus(DB_STATUS_T idx_status)//设置索引头上的索引状态
|
||||
{
|
||||
m_IndexStdbPtr->index_status = idx_status;
|
||||
}
|
||||
|
||||
~CHashIndex();//考虑在析构函数里面调用FreeResource()
|
||||
|
||||
char * next2Ptr(int next);
|
||||
int freeChunk(int pointer);
|
||||
char* mallocChunk(int & pos);
|
||||
|
||||
int keycmp(char * key1 , char * key2);//{return 0;}
|
||||
|
||||
int index_equal(char * outer , char * innter);
|
||||
|
||||
int DebugDisp(int type , char * ptr);
|
||||
|
||||
private:
|
||||
struct INDEX_STDB_TAB *m_IndexStdbPtr;
|
||||
struct INDEX_STDB_FIELD_TAB *m_IndexStdbFieldPtr;
|
||||
struct STDB_INDEX_HASH *m_StdbIndexHashPtr;
|
||||
int *m_FreePointer;//溢出区malloc_chunk和free_chunk使用。
|
||||
char *m_IndexStgHashPtr;
|
||||
char *m_OverflowStgHashPtr;
|
||||
int (*hash_func_ptr)(char *index,int length,int hash_prime);
|
||||
|
||||
int idxLenFlag ;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
73
code/sys_nicmonitor/include/db_api/odb_hashpk.h
Normal file
73
code/sys_nicmonitor/include/db_api/odb_hashpk.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: Real Time Database management system
|
||||
FileName: rtdb_api.cpp
|
||||
DESCRIPTION: rtdb api interfaces implementation
|
||||
FUNCTION LIST:
|
||||
COMMENT:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2009-01-10 1.1 add net interfaces
|
||||
================================================================================
|
||||
2008-10-30 1.0 created
|
||||
*******************************************************************************/
|
||||
#include "db_api/odb_baseindex.h"
|
||||
#ifndef _CHASHPK
|
||||
#define _CHASHPK
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
class CHashPK:public CBaseIndex
|
||||
{
|
||||
public:
|
||||
virtual int need_rebuilt(char *existed_table_ptr,struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id);
|
||||
virtual int CreateIndex(struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id,int &shm_size);
|
||||
virtual int Open(char *index_file_name,int table_id,int index_id); //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int Open(int index_shmid,int table_id,int index_id); //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int SetIndexPtr(char *index_ptr); //把缓存的指针赋值给索引类,这样就不用使用前面的Open函数。
|
||||
virtual int GetKeyByIndex(char *index_ptr,std::vector<char *> &index_array);
|
||||
virtual int GetKeyPointerByIndex(char *index_ptr, int& pointer);//只对主键索引有效,根据index得到记录的物理位置
|
||||
virtual int IndexInsert(char *index_ptr,char *key_ptr);
|
||||
virtual int BulkIndexInsert(char *bulk_index_key_ptr);//下装的时候
|
||||
virtual int Indexdelete(char *index_ptr,char *key_ptr);
|
||||
virtual int IndexClear();
|
||||
virtual int GetIdxMthd();
|
||||
virtual int FreeResource();//譬如unmap或者shmdt掉指针。
|
||||
virtual int DebugDisp(int type);//方便调试用,不同的type,显示不同或者详细程度不同的信息。
|
||||
virtual int GetIndexRecNum();//返回索引记录总的个数,包括索引区、溢出区、主溢出区有效记录个数的总和。但是无溢出HASH索引只是返回0。
|
||||
virtual DB_STATUS_T GetIndexStatus()//返回索引的状态
|
||||
{
|
||||
return m_IndexStdbPtr->index_status;
|
||||
}
|
||||
|
||||
virtual void SetIndexStatus(DB_STATUS_T idx_status)//设置索引头上的索引状态
|
||||
{
|
||||
m_IndexStdbPtr->index_status = idx_status;
|
||||
}
|
||||
|
||||
//virtual int ModifyIndex(char *pk_ptr, int pos);
|
||||
~CHashPK();//考虑在析构函数里面调用FreeResource()
|
||||
private:
|
||||
struct INDEX_STDB_TAB *m_IndexStdbPtr;
|
||||
struct INDEX_STDB_FIELD_TAB *m_IndexStdbFieldPtr;
|
||||
struct STDB_INDEX_HASH *m_StdbIndexHashPtr;
|
||||
int *m_FreePointer;//溢出区malloc_chunk和free_chunk使用。
|
||||
char *m_IndexStgHashPtr;
|
||||
char *m_OverflowStgHashPtr;
|
||||
int (*hash_func_ptr)(char *index,int length,int hash_prime);
|
||||
int index_equal(char *outer_index_ptr,char *inner_index_ptr);
|
||||
int malloc_chunk(int &new_record_pointer);
|
||||
int free_chunk(struct INDEX_STORAGE_HASH_REC_HEAD *root_index_stg_head_ptr,int unused_record_pointer);
|
||||
int assign_index(char *dest_index_ptr,char *sour_index_ptr);
|
||||
int disp_index_stdb_tab();
|
||||
int disp_index_stdb_field_tab();
|
||||
int disp_stdb_index_hash();
|
||||
int disp_free_pointer();
|
||||
int disp_index_stg();
|
||||
int disp_index_overflow();
|
||||
int disp_all();
|
||||
int disp_index_contents(char *index_ptr);
|
||||
int disp_key_contents(char *key_ptr);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
66
code/sys_nicmonitor/include/db_api/odb_intel_ptr.h
Normal file
66
code/sys_nicmonitor/include/db_api/odb_intel_ptr.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef _ODB_INTEL_PTR
|
||||
#define _ODB_INTEL_PTR
|
||||
|
||||
#include <vector>
|
||||
|
||||
template <class T> class CIntelPtr
|
||||
{
|
||||
private:
|
||||
T *m_Ptr;
|
||||
CIntelPtr(const CIntelPtr &);
|
||||
CIntelPtr& operator=(const CIntelPtr &);
|
||||
public:
|
||||
CIntelPtr(){m_Ptr = NULL;}
|
||||
void SetPtr(T* t_ptr)
|
||||
{
|
||||
if(m_Ptr !=NULL)
|
||||
{
|
||||
delete m_Ptr;
|
||||
}
|
||||
m_Ptr = t_ptr;
|
||||
}
|
||||
~CIntelPtr()
|
||||
{
|
||||
delete m_Ptr;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T> class CIntelPtrArray
|
||||
{
|
||||
private:
|
||||
std::vector<T *>m_PtrArray;
|
||||
CIntelPtrArray(const CIntelPtrArray &);
|
||||
CIntelPtrArray& operator =(const CIntelPtrArray&);
|
||||
public:
|
||||
CIntelPtrArray(){}
|
||||
void push_back(T* t_ptr)
|
||||
{
|
||||
m_PtrArray.push_back(t_ptr);
|
||||
return;
|
||||
}
|
||||
~CIntelPtrArray()
|
||||
{
|
||||
int i;
|
||||
int vec_size = m_PtrArray.size();
|
||||
|
||||
for(i=0;i<vec_size;i++)
|
||||
{
|
||||
delete m_PtrArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
T* operator[](int pos)
|
||||
{
|
||||
if(pos>=0 && pos<(int)(m_PtrArray.size()))
|
||||
return m_PtrArray[pos];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int GetSize()
|
||||
{
|
||||
return m_PtrArray.size();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
67
code/sys_nicmonitor/include/db_api/odb_lock.h
Normal file
67
code/sys_nicmonitor/include/db_api/odb_lock.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB
|
||||
FileName: odb_lock.h
|
||||
DESCRIPTION:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2002-10-22 1.0 modify
|
||||
================================================================================
|
||||
2002-10-22 1.0 created
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ODB_LOCK_H__
|
||||
#define __ODB_LOCK_H__
|
||||
|
||||
//#include "odb_struct.h"
|
||||
#include "db_api/odb_prv_struct.h"
|
||||
#include "db_api/odb_public.h"
|
||||
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
class COdbLock
|
||||
{
|
||||
public:
|
||||
COdbLock(){};
|
||||
~COdbLock(){};
|
||||
|
||||
static int InitLock(struct LOCK_STRU& lock);
|
||||
static int ClnLock(struct LOCK_STRU& lock);
|
||||
|
||||
static bool CtlLock(const struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
static bool CtlUnLock(const struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
|
||||
//static bool DtLock(const struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
//static bool DtUnLock(const struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
|
||||
//static bool NpLock(struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
//static bool NpUnLock(struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
|
||||
static bool Lock(struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
static bool UnLock(struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
|
||||
static bool Lock(struct LOCK_STRU& lock, const DB_LOCK_T& lock_type, int& table_semid); //for OPTLOCK
|
||||
static bool UnLock(struct LOCK_STRU& lock, const DB_LOCK_T& lock_type, int& table_semid); //for OPTLOCK
|
||||
|
||||
private:
|
||||
|
||||
static bool CtlLock(const struct LOCK_STRU& lock);
|
||||
static bool CtlUnLock(const struct LOCK_STRU& lock);
|
||||
|
||||
static bool CtlLock(const struct LOCK_STRU& lock, int& table_semid); //for OPTLOCK
|
||||
static bool CtlUnLock(const struct LOCK_STRU& lock, int& table_semid); //for OPTLOCK
|
||||
|
||||
//static bool DtLock(const struct LOCK_STRU& lock);
|
||||
//static bool DtUnLock(const struct LOCK_STRU& lock);
|
||||
|
||||
static bool TryLock(struct LOCK_STRU& lock, const DB_LOCK_T& lock_type);
|
||||
static bool TryLock(struct LOCK_STRU& lock, const DB_LOCK_T& lock_type, int& table_semid); //for OPTLOCK
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
static bool WinLock(const char* sem_name, const int sem_num=1);
|
||||
static bool WinUnLock(const char* sem_name);
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
993
code/sys_nicmonitor/include/db_api/odb_net.h
Normal file
993
code/sys_nicmonitor/include/db_api/odb_net.h
Normal file
@@ -0,0 +1,993 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_tablenet.h
|
||||
DESCRIPTION: RTDBMS NET ACCESS INTERFACE
|
||||
FUNCTION LIST:
|
||||
COMMENT:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
================================================================================
|
||||
2009-06-09 1.0 wj created
|
||||
*******************************************************************************/
|
||||
|
||||
const short C_DATATYPE_STRING = 1;
|
||||
const short C_DATATYPE_UCHAR = 2;
|
||||
const short C_DATATYPE_SHORT = 3;
|
||||
const short C_DATATYPE_INT = 4;
|
||||
const short C_DATATYPE_DATETIME = 5;
|
||||
const short C_DATATYPE_FLOAT = 6;
|
||||
const short C_DATATYPE_DOUBLE = 7;
|
||||
const short C_DATATYPE_KEYID = 8;
|
||||
const short C_DATATYPE_BINARY = 9;
|
||||
const short C_DATATYPE_TEXT = 10;
|
||||
const short C_DATATYPE_IMAGE = 11;
|
||||
|
||||
const short C_DATATYPE_APPKEYID = 12;
|
||||
const short C_DATATYPE_APPID = 13;
|
||||
const short C_DATATYPE_UINT = 14;
|
||||
const short C_DATATYPE_LONG = 15;
|
||||
const short C_RTDBKEY_TYPE = 16;
|
||||
|
||||
typedef vector<varchar> SEQ_STRING;
|
||||
typedef binary SEQ_CHAR;
|
||||
typedef vector<float> SEQ_FLOAT;
|
||||
typedef vector<int> SEQ_LONG;
|
||||
typedef vector<long> SEQ_LONGLONG;
|
||||
/*------------------------------------------------------------------------------
|
||||
1. RTDBMS NET ACCESS for create and delete a table
|
||||
but only used by down load until now 2003-02-28
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
create a table
|
||||
----------------------------------------------------------------------*/
|
||||
|
||||
typedef cmnInt64 KEYID_STRUCT;
|
||||
typedef cmnUint64 unsigned long;
|
||||
|
||||
struct RTDB_KEY_STRU
|
||||
{
|
||||
cmnUint64 key_id1; //indicate table_id && column_id
|
||||
cmnUint64 key_id2; //indicate area_id && serial_no/
|
||||
};
|
||||
|
||||
struct APPKEY_STRUCT
|
||||
{
|
||||
int app_id;
|
||||
KEYID_STRUCT key_id;
|
||||
};
|
||||
|
||||
typedef APPKEY_STRUCT APPID_STRUCT;
|
||||
|
||||
struct KEYID_STATUS_STRUCT
|
||||
{
|
||||
KEYID_STRUCT key_id;
|
||||
short status;
|
||||
};
|
||||
|
||||
typedef vector<KEYID_STRUCT> SEQ_KEY_ID;
|
||||
typedef vector<APPKEY_STRUCT> SEQ_APPKEY_ID;
|
||||
typedef vector<APPID_STRUCT> SEQ_APP_ID;
|
||||
typedef vector<KEYID_STATUS_STRUCT> SEQ_KEY_ID_STA;
|
||||
|
||||
struct union_data_type
|
||||
{
|
||||
int type;
|
||||
union
|
||||
{
|
||||
varchar c_char; //C_DATATYPE_STRING
|
||||
unsigned char c_uchar; //C_DATATYPE_UCHAR
|
||||
short c_short; //C_DATATYPE_SHORT
|
||||
int c_int; //C_DATATYPE_INT
|
||||
cmnInt64 c_time; //C_DATATYPE_DATETIME
|
||||
float c_float; //C_DATATYPE_FLOAT
|
||||
double c_double; //C_DATATYPE_DOUBLE
|
||||
KEYID_STRUCT c_keyid; //C_DATATYPE_KEYID
|
||||
SEQ_CHAR c_binary; //C_DATATYPE_BINARY
|
||||
SEQ_CHAR c_text; //C_DATATYPE_TEXT
|
||||
SEQ_CHAR c_image; //C_DATATYPE_IMAGE
|
||||
APPKEY_STRUCT c_appkeyid; //C_DATATYPE_APPKEYID
|
||||
APPID_STRUCT c_appid; //C_DATATYPE_APPID
|
||||
unsigned int c_uint; //C_DATATYPE_UINT
|
||||
cmnInt64 c_long; //C_DATATYPE_LONG
|
||||
struct RTDB_KEY_STRU c_rtdb_key; //C_C_RTDBKEY_TYPE
|
||||
}val;
|
||||
};
|
||||
|
||||
typedef vector<union_data_type> SEQ_COMMON_DATA;
|
||||
|
||||
struct TABLE_STRU
|
||||
{
|
||||
int table_no; //表号 RDBMS
|
||||
short app_no;
|
||||
short column_num;
|
||||
varchar table_name_eng;
|
||||
varchar table_name_chn;
|
||||
short record_length;
|
||||
int record_num;
|
||||
int max_record_num;
|
||||
unsigned char is_auto_generate;
|
||||
unsigned char is_record_app;
|
||||
};
|
||||
|
||||
struct COLUMN_STRU
|
||||
{
|
||||
short field_no; //域号 RDBMS
|
||||
varchar field_name_eng;
|
||||
varchar field_name_chn;
|
||||
short data_length;
|
||||
unsigned char data_type;
|
||||
|
||||
unsigned char allow_null;
|
||||
unsigned char is_display;
|
||||
unsigned char display_type;
|
||||
short display_length;
|
||||
unsigned char display_precision;
|
||||
|
||||
varchar menu_name;
|
||||
unsigned char reference_flag;
|
||||
unsigned char is_key;
|
||||
unsigned char is_index;
|
||||
unsigned char sort_order_no;
|
||||
|
||||
unsigned char reference_display;
|
||||
unsigned char is_input;
|
||||
unsigned char is_fix;
|
||||
|
||||
varchar init_value;
|
||||
varchar min_value;
|
||||
varchar max_value;
|
||||
|
||||
int reference_table;
|
||||
short reference_column;
|
||||
int column_special;
|
||||
};
|
||||
|
||||
typedef vector<COLUMN_STRU> SEQ_COLUMN_INFO;
|
||||
|
||||
|
||||
//from download idl //OutStruct
|
||||
struct REQ_STDB_CREATE
|
||||
{
|
||||
//short app_no; //应用号
|
||||
//int table_no; //表号 RDBMS
|
||||
//int record_num; //记录 个数
|
||||
//int field_num; //域个数
|
||||
|
||||
TABLE_STRU table_info; //表信息
|
||||
SEQ_COLUMN_INFO column_info; //域信息
|
||||
SEQ_COMMON_DATA data_value; //值
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
delete a table
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_STDB_DELETE
|
||||
{
|
||||
short app_no;
|
||||
int table_no;
|
||||
varchar passwd;
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
2. RTDBMS NET ACCESS for get table and field parameter
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
table parameter
|
||||
----------------------------------------------------------------------*/
|
||||
struct TABLE_PARAMETER
|
||||
{
|
||||
varchar table_name_eng;
|
||||
varchar table_name_chn;
|
||||
int table_no; //RDBMS
|
||||
int key_len;
|
||||
int subkey_num;
|
||||
|
||||
short field_sum;
|
||||
int record_number;
|
||||
int record_size;
|
||||
|
||||
unsigned char is_auto_generated;
|
||||
|
||||
// int table_type; //for graph, etc
|
||||
// unsigned char is_system_table; //Added 2003-09-01
|
||||
// unsigned char is_record_app;
|
||||
// unsigned char is_record_lock;
|
||||
// unsigned char is_record_resp;
|
||||
//
|
||||
// int reserved_1;
|
||||
// int reserved_2;
|
||||
// int reserved_3;
|
||||
// int reserved_4;
|
||||
// int reserved_5;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
field parameter, more 3 elements than struct COLUMN_STRU
|
||||
----------------------------------------------------------------------*/
|
||||
struct FIELD_PARAMETER
|
||||
{
|
||||
short field_no;
|
||||
short r_field_no; //
|
||||
short field_id; //////
|
||||
short column_id; //////
|
||||
|
||||
varchar field_name_eng;
|
||||
varchar field_name_chn;
|
||||
short field_length;
|
||||
unsigned char data_type;
|
||||
|
||||
unsigned char allow_null;
|
||||
//unsigned char is_display; ////
|
||||
unsigned char display_type;
|
||||
//short display_length; ////
|
||||
//unsigned char display_precision; ////
|
||||
|
||||
varchar menu_name;
|
||||
unsigned char reference_flag;
|
||||
unsigned char is_keyword;
|
||||
unsigned char is_index;
|
||||
int offset; //
|
||||
int check_tag; //
|
||||
unsigned char sort_order_no;
|
||||
|
||||
unsigned char reference_mode; //////
|
||||
unsigned char reference_display;
|
||||
//unsigned char is_input; ////
|
||||
//unsigned char is_fix; ////
|
||||
|
||||
unsigned char is_app_syn; //////
|
||||
unsigned char auto_meas_type; //////
|
||||
|
||||
varchar default_asciival;
|
||||
varchar min_asciival;
|
||||
varchar max_asciival;
|
||||
|
||||
int ref_tableno;
|
||||
short ref_fieldno;
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
short is_bit_field;
|
||||
#endif
|
||||
//unsigned char column_special;
|
||||
int column_special;
|
||||
|
||||
int search_attribute; //Added 2003-09-01
|
||||
int statics_attribute;
|
||||
int reserved_1;
|
||||
int reserved_2;
|
||||
int reserved_3;
|
||||
int reserved_4;
|
||||
int reserved_5;
|
||||
};
|
||||
|
||||
struct R_FIELD_BASE_INFO
|
||||
{
|
||||
int offset;
|
||||
int field_length;
|
||||
short field_no;
|
||||
unsigned char data_type;
|
||||
unsigned char is_keyword;
|
||||
};
|
||||
|
||||
typedef vector<R_FIELD_BASE_INFO> SEQ_FIELD_BASE_INFO;
|
||||
/*------------------------------------------------------------------------------
|
||||
3. RTDBMS NET DATA ACCESS structure for get, write, delete, modify, update
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
one or many records; one or many fields;
|
||||
the common structure used by others followed
|
||||
----------------------------------------------------------------------*/
|
||||
struct FIELD_STRU
|
||||
{
|
||||
short field_no;
|
||||
short field_type; //data type for get; byte len for write
|
||||
short field_length; // 2003-07-31 //reserved for later
|
||||
|
||||
};
|
||||
|
||||
typedef vector<FIELD_STRU> SEQ_FIELD_STRU;
|
||||
|
||||
struct REQ_BASE
|
||||
{
|
||||
short context_no; //long
|
||||
int app_no; //short
|
||||
int table_no;
|
||||
char byte_tag; //DB_BYTE_T byte_tag;
|
||||
SEQ_FIELD_STRU seq_field;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
get one or many fields of one or many records;
|
||||
maybe by key_word; if no keyword, default is current record
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_READ
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
|
||||
SEQ_CHAR seq_keyword; //usually only one key word
|
||||
int keybuf_size; //0--no key_word, else key word data size
|
||||
|
||||
varchar str_fname_list;
|
||||
|
||||
//short get_mode; // 0 -- by field no
|
||||
// 1 -- by field name
|
||||
// 2 -- by key word
|
||||
};
|
||||
|
||||
struct RSP_READ
|
||||
{
|
||||
int record_num; //记录 个数
|
||||
int record_size;
|
||||
short field_num; //域个数
|
||||
SEQ_FIELD_STRU seq_field; //field信息
|
||||
|
||||
SEQ_CHAR seq_data; //return data value
|
||||
int data_size; //return data size; 总长度
|
||||
};
|
||||
/* ---------------------------------------------------------------------
|
||||
write one record, include key_word
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_KEY_WRITE
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
|
||||
SEQ_CHAR record_value; //record data value
|
||||
int buf_size; //record data size
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
modify one or many fields of one or many records,
|
||||
maybe by key_word; if no keyword, default is current record
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_MODIFY
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
short is_field_name; //是否按域名修改 是 1 否 0
|
||||
varchar field_name_str; //需要修改的域名
|
||||
|
||||
SEQ_CHAR seq_keyword; //key word data value
|
||||
int keybuf_size; //key word data size
|
||||
|
||||
SEQ_CHAR field_value; //field data buffer
|
||||
int buf_size; //field data size
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
update f one or many records by key_word
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_UPDATE
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
|
||||
SEQ_CHAR field_value; //data buffer
|
||||
int buf_size; //data size
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
delete a record by key_word
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_KEY_ERASE
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
|
||||
SEQ_CHAR seq_keyword; //str_keyword;//2003-02-26
|
||||
int keybuf_size; //redundant
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
delete many records by key
|
||||
----------------------------------------------------------------------*/
|
||||
struct DEL_REQ
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
int del_direction;
|
||||
int del_num;
|
||||
SEQ_CHAR seq_keyword;
|
||||
int keybuf_size;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
clear one table
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_TABLE_CLEAR
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
};
|
||||
|
||||
struct REQ_FIELD_BASE_INFO
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
SEQ_LONG seq_field_no;
|
||||
};
|
||||
|
||||
struct RSP_FIELD_BASE_INFO
|
||||
{
|
||||
SEQ_FIELD_BASE_INFO lseq_field_base_info;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
get table and fields parameter (one)
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_PARAMETER
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
//short para_type; //1--table parameter, 10--fields parameter
|
||||
|
||||
varchar str_field_list; //field's attribute that wanted to be query
|
||||
};
|
||||
|
||||
typedef vector<FIELD_PARAMETER> SEQ_FIELD_PARAMETER;
|
||||
|
||||
struct RSP_PARAMETER
|
||||
{
|
||||
TABLE_PARAMETER table_para;
|
||||
SEQ_FIELD_PARAMETER seq_field_para;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
get table and fields parameter (two)
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_APP_PARAMETER
|
||||
{
|
||||
int app_no;
|
||||
varchar app_name; //all_name
|
||||
};
|
||||
|
||||
//this is rsp
|
||||
typedef vector<TABLE_PARAMETER> SEQ_TABLE_PARAMETER;
|
||||
|
||||
struct RSP_APP_PARAMETER
|
||||
{
|
||||
int app_no;
|
||||
varchar app_name; //all_name
|
||||
|
||||
SEQ_TABLE_PARAMETER seq_table_para;
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
4. RTDBMS key word length of all table
|
||||
|
||||
2003-03-10
|
||||
------------------------------------------------------------------------------*/
|
||||
struct TABLE_KEYINFO
|
||||
{
|
||||
//int table_no; //RDBMS table no
|
||||
short keyword_len; //total key word length
|
||||
};
|
||||
|
||||
typedef vector<TABLE_KEYINFO> SEQ_TABLE_KEYINFO;
|
||||
|
||||
struct RSP_KEYINFO
|
||||
{
|
||||
SEQ_TABLE_KEYINFO seq_keyinfo;
|
||||
};
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
5. SQL INTERFACE
|
||||
|
||||
2003-03-26
|
||||
------------------------------------------------------------------------------*/
|
||||
struct REQ_SQL
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
varchar str_select;
|
||||
//SEQ_CHAR seq_select;
|
||||
};
|
||||
/*------------------------------------------------------------------------------
|
||||
6. some function for gui
|
||||
|
||||
2003-06-05
|
||||
------------------------------------------------------------------------------*/
|
||||
/* ---------------------------------------------------------------------
|
||||
menu read
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_MENU
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
//SEQ_CHAR seq_menu_name;
|
||||
varchar str_menu_name;
|
||||
unsigned char menu_status;
|
||||
};
|
||||
|
||||
struct MENU_INFO_STRU
|
||||
{
|
||||
varchar menu_name; /* 菜单名*/
|
||||
unsigned char menu_no; /* 序号*/
|
||||
int actual_value; /* 实际值*/
|
||||
varchar display_value; /* 显示值*/
|
||||
unsigned char menu_status; /* 菜单状态 */
|
||||
varchar menu_macro_name;
|
||||
};
|
||||
|
||||
typedef vector<MENU_INFO_STRU> SEQ_MENU_INFO;
|
||||
|
||||
struct RSP_MENU
|
||||
{
|
||||
int menu_num;
|
||||
//int record_size;
|
||||
SEQ_MENU_INFO seq_menu;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
relevant menu read
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_RELE_MENU
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
};
|
||||
|
||||
struct MENU_RELEVANT_STRU
|
||||
{
|
||||
int table_id; /* 表ID号 */
|
||||
short column_id; /* 域ID号 */
|
||||
int column_value; /* 域值 */
|
||||
short r_column_id; /* 对应域ID号 */
|
||||
varchar r_menu_name; /* 对应菜单名 */
|
||||
int default_value; /* 默认值 */
|
||||
};
|
||||
|
||||
typedef vector<MENU_RELEVANT_STRU> SEQ_MENU_RELEVANT;
|
||||
|
||||
struct RSP_RELE_MENU
|
||||
{
|
||||
int menu_num;
|
||||
//int record_size;
|
||||
SEQ_MENU_RELEVANT seq_menu;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
get name varchar by key id
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_NAME_STRING
|
||||
{
|
||||
short req_type;
|
||||
|
||||
REQ_BASE base_info;
|
||||
KEYID_STRUCT keyid_stru; //by key id -- 1
|
||||
cmnInt64 reference_id; //by id -- 2
|
||||
SEQ_CHAR seq_keyword; //usually only one key word
|
||||
int keybuf_size; //0--no key_word, else key word data size
|
||||
};
|
||||
|
||||
struct RSP_NAME_STRING
|
||||
{
|
||||
int name_len;
|
||||
varchar ref_string;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
get name varchar by many key ids
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_MULTI_NAME_STRING
|
||||
{
|
||||
short req_type;
|
||||
|
||||
REQ_BASE base_info;
|
||||
SEQ_KEY_ID seq_keyid_stru; // -- 1
|
||||
|
||||
SEQ_APPKEY_ID seq_appkeyid_stru; // -- 2
|
||||
|
||||
SEQ_APP_ID seq_appid_stru; // -- 3
|
||||
|
||||
SEQ_LONGLONG seq_id; // -- 4
|
||||
};
|
||||
|
||||
typedef vector<RSP_NAME_STRING> SEQ_RSP_NAME_STRING;
|
||||
|
||||
struct RSP_MULTI_NAME_STRING
|
||||
{
|
||||
SEQ_RSP_NAME_STRING seq_name_string;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
reference menu read
|
||||
----------------------------------------------------------------------*/
|
||||
struct REQ_REF_MENU
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
};
|
||||
|
||||
struct REF_MENU_STRING
|
||||
{
|
||||
cmnInt64 order_no;
|
||||
varchar menu_name;
|
||||
};
|
||||
|
||||
typedef vector<REF_MENU_STRING> SEQ_REF_MENU;
|
||||
|
||||
struct RSP_REF_MENU
|
||||
{
|
||||
SEQ_REF_MENU seq_menu;
|
||||
};
|
||||
/*------------------------------------------------------------------------------
|
||||
7. some function for graph
|
||||
|
||||
2003-06-16
|
||||
------------------------------------------------------------------------------*/
|
||||
/* ---------------------------------------------------------------------
|
||||
get real time data from rtdbms server
|
||||
----------------------------------------------------------------------*/
|
||||
struct GRAPH_SIMPLE_REQ
|
||||
{
|
||||
int order_no;
|
||||
cmnInt64 keyword_id;
|
||||
short table_no;
|
||||
short field_no;
|
||||
};
|
||||
|
||||
struct GRAPH_XY_REQ
|
||||
{
|
||||
int order_no;
|
||||
cmnInt64 keyword_id;
|
||||
short table_no;
|
||||
short field_no;
|
||||
unsigned char mode; //
|
||||
short data_num;
|
||||
};
|
||||
|
||||
//
|
||||
struct GRAPH_FIELD_STRU
|
||||
{
|
||||
int order_no;
|
||||
short field_no;
|
||||
varchar field_alias; //lmj add for graph list query by sql where
|
||||
|
||||
short rele1_table_no;
|
||||
short rele1_field_no;
|
||||
|
||||
short rele2_table_no; //lmj add for graph list query by 2 index
|
||||
short rele2_field_no; //lmj add for graph list query by 2 index
|
||||
};
|
||||
|
||||
typedef vector<GRAPH_FIELD_STRU> SEQ_GRAPH_FIELD;
|
||||
struct GRAPH_LIST_REQ
|
||||
{
|
||||
short table_no;
|
||||
varchar condition;
|
||||
SEQ_STRING where_field_seq; //lmj add for graph list query by sql where
|
||||
SEQ_GRAPH_FIELD seq_field;
|
||||
};
|
||||
|
||||
typedef vector<GRAPH_SIMPLE_REQ> SEQ_SIMPLE_REQ;
|
||||
typedef vector<GRAPH_XY_REQ> SEQ_XY_REQ;
|
||||
typedef vector<GRAPH_LIST_REQ> SEQ_LIST_REQ;
|
||||
|
||||
struct GRAPH_REAL_REQ
|
||||
{
|
||||
cmnInt64 graph_id; //lmj add for GraphGetDataEx
|
||||
int cal_type; //lmj add for before calculate
|
||||
SEQ_SIMPLE_REQ simple_req;
|
||||
SEQ_XY_REQ xy_req;
|
||||
SEQ_LIST_REQ list_req;
|
||||
};
|
||||
|
||||
struct GRAPH_REAL_ODB_REQ
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
cmnInt64 graph_id; //lmj add for GraphGetDataEx
|
||||
int cal_type; //lmj add for before calculate
|
||||
SEQ_SIMPLE_REQ simple_req;
|
||||
SEQ_XY_REQ xy_req;
|
||||
SEQ_LIST_REQ list_req;
|
||||
};
|
||||
|
||||
/*--------------------------------------------------------------------*/
|
||||
struct GRAPH_SIMPLE_RSP
|
||||
{
|
||||
int order_no;
|
||||
union_data_type data_value;
|
||||
};
|
||||
|
||||
struct GRAPH_XY_RSP
|
||||
{
|
||||
int order_no;
|
||||
SEQ_FLOAT seq_data_value;
|
||||
};
|
||||
|
||||
struct ORDER_VALUE
|
||||
{
|
||||
int order_no;
|
||||
SEQ_COMMON_DATA seq_data_value;
|
||||
};
|
||||
|
||||
typedef vector<ORDER_VALUE> SEQ_ORDER_VALUE;
|
||||
|
||||
struct GRAPH_LIST_RSP
|
||||
{
|
||||
SEQ_ORDER_VALUE seq_list;
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
typedef vector<GRAPH_SIMPLE_RSP> SEQ_SIMPLE_RSP;
|
||||
typedef vector<GRAPH_XY_RSP> SEQ_XY_RSP;
|
||||
typedef vector<GRAPH_LIST_RSP> SEQ_LIST_RSP;
|
||||
|
||||
struct GRAPH_REAL_RSP
|
||||
{
|
||||
cmnInt64 graph_id; //lmj add for GraphGetDataEx
|
||||
int cal_type; //lmj add for before calculate
|
||||
SEQ_SIMPLE_RSP simple_rsp;
|
||||
SEQ_XY_RSP xy_rsp;
|
||||
SEQ_LIST_RSP list_rsp;
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------------
|
||||
get app info from rtdbms server
|
||||
----------------------------------------------------------------------*/
|
||||
struct ORDER_KEY_REQ
|
||||
{
|
||||
int order_no;
|
||||
cmnInt64 key_id;
|
||||
};
|
||||
|
||||
typedef vector<ORDER_KEY_REQ> SEQ_ORDER_KEY_REQ;
|
||||
struct GRAPH_ORDER_KEY_REQ
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
int app_no;
|
||||
cmnInt64 graph_id;
|
||||
SEQ_ORDER_KEY_REQ seq_order_key;
|
||||
};
|
||||
|
||||
struct ORDER_KEY_RSP
|
||||
{
|
||||
int order_no;
|
||||
unsigned char is_in_app;
|
||||
};
|
||||
|
||||
typedef vector<ORDER_KEY_RSP> SEQ_ORDER_KEY_RSP;
|
||||
struct GRAPH_ORDER_KEY_RSP
|
||||
{
|
||||
cmnInt64 graph_id;
|
||||
SEQ_ORDER_KEY_RSP seq_app;
|
||||
};
|
||||
/*------------------------------------------------------------------------------
|
||||
8. some function for exchange name & no (app/table/field, include chn/eng)
|
||||
|
||||
2003-12-16
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
struct REQ_ENTITY
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
|
||||
varchar object_name;
|
||||
short object_id; //app/table/field
|
||||
unsigned char object_mode; // name ---> no // no --->name
|
||||
unsigned char object_eng;
|
||||
};
|
||||
|
||||
struct RSP_ENTITY
|
||||
{
|
||||
int object_no;
|
||||
varchar object_name;
|
||||
};
|
||||
/*------------------------------------------------------------------------------
|
||||
9. some function for factory name & no & id
|
||||
|
||||
2004-01-06
|
||||
------------------------------------------------------------------------------*/
|
||||
struct REQ_FAC
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
|
||||
int table_no;
|
||||
SEQ_CHAR seq_keyword; //usually only one key word
|
||||
int keybuf_size; //0--no key_word, else key word data size
|
||||
|
||||
cmnInt64 fac_no; // hcr: fac_no & fac_id both use this member, so reserve as cmnInt64 but not short
|
||||
varchar fac_name;
|
||||
};
|
||||
|
||||
struct RSP_FAC
|
||||
{
|
||||
cmnInt64 fac_no;
|
||||
varchar fac_name;
|
||||
};
|
||||
|
||||
|
||||
struct REQ_VAL_STA
|
||||
{
|
||||
short req_type; // 1 yc , 2 yx , 3 ym , 4 union type 5 yc , 6 yx , 7 ym , 8 union type
|
||||
REQ_BASE base_info;
|
||||
SEQ_KEY_ID keyid_stru_seq;
|
||||
SEQ_KEY_ID_STA keyid_sta_stru_seq;
|
||||
};
|
||||
|
||||
|
||||
struct TIntValueStatus
|
||||
{
|
||||
int value;
|
||||
int status;
|
||||
};
|
||||
|
||||
|
||||
struct TFloatValueStatus
|
||||
{
|
||||
float value;
|
||||
int status;
|
||||
};
|
||||
|
||||
struct TCharValueStatus
|
||||
{
|
||||
unsigned char value;
|
||||
int status;
|
||||
};
|
||||
|
||||
struct TLongValueStatus
|
||||
{
|
||||
cmnInt64 value;
|
||||
int status;
|
||||
};
|
||||
|
||||
struct TUnionValueStatus
|
||||
{
|
||||
union_data_type value;
|
||||
int status;
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef vector< TIntValueStatus > SEQ_INT_VAL_STA;
|
||||
|
||||
typedef vector< TFloatValueStatus > SEQ_FLOAT_VAL_STA;
|
||||
|
||||
typedef vector< TCharValueStatus > SEQ_CHAR_VAL_STA;
|
||||
|
||||
typedef vector< TLongValueStatus > SEQ_LONG_VAL_STA;
|
||||
|
||||
typedef vector< TUnionValueStatus > SEQ_UNION_VAL_STA;
|
||||
|
||||
struct RSP_INT_VAL_STA
|
||||
{
|
||||
SEQ_INT_VAL_STA rsp_val_sta;
|
||||
};
|
||||
|
||||
struct RSP_FLOAT_VAL_STA
|
||||
{
|
||||
SEQ_FLOAT_VAL_STA rsp_val_sta;
|
||||
};
|
||||
|
||||
struct RSP_CHAR_VAL_STA
|
||||
{
|
||||
SEQ_CHAR_VAL_STA rsp_val_sta;
|
||||
};
|
||||
|
||||
struct RSP_LONG_VAL_STA
|
||||
{
|
||||
SEQ_LONG_VAL_STA rsp_val_sta;
|
||||
};
|
||||
|
||||
struct RSP_UNION_VAL_STA
|
||||
{
|
||||
SEQ_UNION_VAL_STA rsp_val_sta;
|
||||
};
|
||||
|
||||
//wj added for ConGet -- 2008.08.11
|
||||
struct REQ_CON
|
||||
{
|
||||
REQ_BASE base_info;//base_info.seq_field.length() == 1
|
||||
//FIELD_STRU get_field_info;//non or only one get_field
|
||||
SEQ_FIELD_STRU get_field_info;//non or more than one get_field
|
||||
SEQ_CHAR con_field_value;
|
||||
};
|
||||
|
||||
struct RSP_CON
|
||||
{
|
||||
int fit_num;
|
||||
int one_fit_size;//if non get_field, one_fit_size == one_record_size
|
||||
SEQ_CHAR seq_data;
|
||||
int data_size;
|
||||
};
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
//wuqx added for xdb layer access -- 2012-07-10
|
||||
struct REQ_XDB
|
||||
{
|
||||
short op_no;
|
||||
cmnInt64 table_no;
|
||||
cmnInt64 id;
|
||||
};
|
||||
|
||||
struct RSP_XDB
|
||||
{
|
||||
cmnInt64 oid;
|
||||
cmnInt64 cnt;
|
||||
};
|
||||
//jinjing 20120815 for virtual field
|
||||
struct VIR_FIELD_STRU
|
||||
{
|
||||
short v_field_no; //rtdbms 内部虚拟域号
|
||||
short vr_field_no; //虚拟域号
|
||||
short r_field_no; //bit field no 对应实际域号
|
||||
short bit_no; // 1 - 32 位号
|
||||
varchar vir_field_name_eng;
|
||||
varchar vir_field_name_chn;
|
||||
};
|
||||
|
||||
struct REQ_VIR_FIELD
|
||||
{
|
||||
REQ_BASE base_info;
|
||||
};
|
||||
|
||||
typedef vector<VIR_FIELD_STRU> SEQ_VIRFIELD_STRU;
|
||||
struct RSP_VIR_FIELD
|
||||
{
|
||||
//TABLE_PARAMETER table_para;
|
||||
SEQ_VIRFIELD_STRU seq_virfield_para;
|
||||
};
|
||||
#endif
|
||||
/*------------------------------------------------------------------------------
|
||||
10. rtdb_server function number
|
||||
|
||||
2008-11-28
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
const int FUNC_TABLECREATE_NO = 1;
|
||||
const int FUNC_TABLEDELETE_NO = 2;
|
||||
|
||||
const int FUNC_TABLEGET_NO = 3;
|
||||
const int FUNC_TABLEGETBYNAME_NO = 4;
|
||||
const int FUNC_TABLEGETBYFIELDVALUE_NO = 5;
|
||||
const int FUNC_TABLEWRITE_NO = 6;
|
||||
const int FUNC_TABLEMODIFY_NO = 7;
|
||||
const int FUNC_TABLEUPDATE_NO = 8;
|
||||
const int FUNC_DELETERECORD_NO = 9;
|
||||
const int FUNC_TABLECLEAR_NO = 10;
|
||||
|
||||
const int FUNC_GETTABLEPARA_NO = 11;
|
||||
const int FUNC_GETTABLEPARAMETER_NO = 12;
|
||||
const int FUNC_GETAPPTABLEPARAMETER_NO = 13;
|
||||
const int FUNC_GETFIELDPARA_NO = 14;
|
||||
|
||||
const int FUNC_GETKEYINFO_NO = 15;
|
||||
const int FUNC_TABLEGETBYSQL_NO = 16;
|
||||
const int FUNC_MENUREAD_NO = 17;
|
||||
const int FUNC_TABLERELEMENUREAD_NO = 18;
|
||||
const int FUNC_GETNAMESTRINGBYKEYID_NO = 19;
|
||||
const int FUNC_GETREFMENUSTRING_NO = 20;
|
||||
|
||||
const int FUNC_GETNAMESTRINGBYMULTIKEYID_NO = 21;
|
||||
|
||||
const int FUNC_GRAPHGETDATA_NO = 22;
|
||||
const int FUNC_GRAPHGETAPPINFO_NO = 23;
|
||||
|
||||
const int FUNC_EXCHANGENAMENO_NO = 24;
|
||||
|
||||
const int FUNC_GETFACNAMEBYKEYNO_NO = 25;
|
||||
const int FUNC_GETFACNAMEBYFACID_NO = 26;
|
||||
const int FUNC_GETFACNAMEBYFACNO_NO = 27;
|
||||
|
||||
const int FUNC_GETFACIDBYFACNAME_NO = 28;
|
||||
const int FUNC_GETFACNOBYFACNAME_NO = 29;
|
||||
|
||||
const int FUNC_GETFACIDBYFACNO_NO = 30;
|
||||
const int FUNC_GETFACNOBYFACID_NO = 31;
|
||||
|
||||
const int FUNC_GETVALUEANDSTATUS_NO = 32;
|
||||
|
||||
const int FUNC_PINGRTDBSERVER_NO = 33;
|
||||
const int FUNC_DELETERECORDS_NO = 34;
|
||||
const int FUNC_TABLEGET_OPT_NO = 40;
|
||||
const int FUNC_TABLEGETBYNAME_OPT_NO = 41;
|
||||
const int FUNC_GETVALUEANDSTATUS_YCOPT_NO = 42;
|
||||
const int FUNC_GETVALUEANDSTATUS_YXOPT_NO = 43;
|
||||
const int FUNC_GETTABLEPARA_PARA3_NO = 44;
|
||||
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
const int FUNC_GETTABLEPARAALL_NO = 35;
|
||||
|
||||
const int FUNC_TABLEGETALL_NO = 36;
|
||||
|
||||
const int FUNC_XDBACCESS_NO = 37;
|
||||
|
||||
const int FUNC_GETTABLEPARAVIR_NO = 38;
|
||||
//for xdb should not been used in other situation
|
||||
const int GETPARENT_NO = 1;
|
||||
const int CHDFIRST_NO = 2;
|
||||
const int CHDNEXT_NO = 3;
|
||||
const int CHDCNT_NO = 4;
|
||||
#endif
|
||||
1102
code/sys_nicmonitor/include/db_api/odb_net_m.h
Normal file
1102
code/sys_nicmonitor/include/db_api/odb_net_m.h
Normal file
File diff suppressed because it is too large
Load Diff
193
code/sys_nicmonitor/include/db_api/odb_netfactory.h
Normal file
193
code/sys_nicmonitor/include/db_api/odb_netfactory.h
Normal file
@@ -0,0 +1,193 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_netfactory.h
|
||||
DESCRIPTION: for class CTableNet of net access
|
||||
FUNCTION LIST:
|
||||
COMMENT: for net access
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2003-12-12 1.0 modify
|
||||
================================================================================
|
||||
2003-01-09 1.0 created
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ODB_NETFACTORY_h__
|
||||
#define __ODB_NETFACTORY_h__
|
||||
|
||||
#ifndef __ODB_DEFINE_H__
|
||||
#include "db_api/odb_define.h"
|
||||
#endif
|
||||
|
||||
//#ifndef __ODB_ORBMGR_H__
|
||||
//#include "odb_orbmgr.h"
|
||||
//#endif
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include "system.h"
|
||||
#include "task_service.h"
|
||||
#include "sysadm/scn_service.h"
|
||||
|
||||
#include "db_api/odb_net_m.h"
|
||||
#include "db_api/codb_net.h"
|
||||
|
||||
#ifndef _WINDOWS64
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
//#include "serviceglobal.h"
|
||||
#include "servicemanage.h"
|
||||
|
||||
#define NET_FAC_LOCAL_DOMAIN "local_domain"
|
||||
|
||||
#ifdef _WINDOWS64
|
||||
#ifdef ODB_API_LIB_EXPORTS
|
||||
#define ODB_API_LIB_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODB_API_LIB_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define ODB_API_LIB_API
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
//using namespace RTDB_SERVER;
|
||||
//using namespace ODB;
|
||||
|
||||
//============================================================================//
|
||||
struct SERVICE_MESSAGE
|
||||
{
|
||||
char service_name[80];
|
||||
char service_object[40];
|
||||
char service_port[40];
|
||||
int run_port;
|
||||
};
|
||||
|
||||
struct NET_INFO
|
||||
{
|
||||
RTDB_SERVER::CODB_NET* net_ptr;
|
||||
|
||||
NET_INFO& operator= (const NET_INFO& other)
|
||||
{
|
||||
if( this == &other )
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
net_ptr = other.net_ptr ;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
//============================================================================//
|
||||
|
||||
|
||||
namespace NET_ODB
|
||||
{
|
||||
class ODB_API_LIB_API CNetFactory
|
||||
{
|
||||
public:
|
||||
CNetFactory();
|
||||
CNetFactory(const int app_no, const short context_no = 0); //obsolete
|
||||
CNetFactory(const struct SCENARIO_PARA& scn_para);
|
||||
//CNetFactory(const char* host_name);
|
||||
~CNetFactory();
|
||||
|
||||
public:
|
||||
RTDB_SERVER::CODB_NET* GetInstance();
|
||||
//RTDB_SERVER::CODB_NET* GetInstance(const int app_no, const short context_no = 0, const bool is_managed=true);//obsolete
|
||||
//RTDB_SERVER::CODB_NET* GetInstance(const char* host_name , const int app_no, const short context_no = 0);//obsolete
|
||||
//RTDB_SERVER::CODB_NET* GetInstance(const char* domain_name, const tSecLabel& sec_label, const int app_no, const short context_no = 0, const bool is_managed=true);//obsolete
|
||||
|
||||
RTDB_SERVER::CODB_NET* GetInstance(const char* domain_name, const tSecLabel& sec_label, const struct SCENARIO_PARA& scn_para);
|
||||
RTDB_SERVER::CODB_NET* GetInstance(const char* host_name , const struct SCENARIO_PARA& scn_para);
|
||||
RTDB_SERVER::CODB_NET* GetInstance(const struct SCENARIO_PARA& scn_para);
|
||||
|
||||
|
||||
public:
|
||||
int DefaultService();
|
||||
int SetServiceInfo();
|
||||
int SetServiceName(const char* server_name);
|
||||
int SetServiceObject(const char* server_object);
|
||||
int SetServiceName(const int server_port);
|
||||
void SetDomainInfo();
|
||||
void SetScnPara(const struct SCENARIO_PARA& scn_para);
|
||||
int SetManagedMode(const bool is_managed);
|
||||
|
||||
void LocalRemoteChanged();
|
||||
|
||||
public:
|
||||
//void GetServiceHandle(Handle& handle);
|
||||
|
||||
private:
|
||||
int start();
|
||||
int InitNet();
|
||||
int AddToMap();
|
||||
|
||||
int ReadHostFromfile(char* host_name);
|
||||
int GetHostByAppNo(char* host_name, const int app_no, const short context_no );//obsolete
|
||||
int GetSubScnHost(char* host_name, const struct SCENARIO_PARA& scn_para);
|
||||
|
||||
int CheckHost(const int app_no, const short context_no); ////obsolete
|
||||
|
||||
int CheckHost(const struct SCENARIO_PARA& scn_para);
|
||||
int CheckHost(const char* host_name);
|
||||
|
||||
int IsCreated(const int app_no, const short context_no); ///obsolete
|
||||
|
||||
int IsCreated(const struct SCENARIO_PARA& scn_para);
|
||||
int IsCreated(const std::string& host_name);
|
||||
|
||||
void PrnMap();
|
||||
|
||||
private:
|
||||
CNetFactory(const CNetFactory& table_net);
|
||||
CNetFactory& operator=(const CNetFactory& table_net);
|
||||
|
||||
private:
|
||||
//std::map<int, std::string> m_MAppHost;
|
||||
std::map<std::string, std::string> m_MAppHost;
|
||||
std::map<std::string, struct NET_INFO> m_MHostNet;
|
||||
std::map<std::string, struct NET_INFO> m_MScnNet; //lmj add
|
||||
std::map<std::string, struct NET_INFO> m_MScnHostNet; //lmj add
|
||||
|
||||
//CORBA::ORB_var m_Orb;
|
||||
//CORBA::Object_var m_Obj;
|
||||
RTDB_SERVER::CODB_NET* m_OdbNet;
|
||||
|
||||
struct SERVICE_MESSAGE m_ServiceMsg;
|
||||
|
||||
ServiceInfo m_Serviceinfo;
|
||||
DomainInfo* m_pDomaininfo;
|
||||
|
||||
short m_ContextNo;//obsolete
|
||||
int m_AppNo;//obsolete
|
||||
|
||||
struct SCENARIO_PARA m_scn_para;
|
||||
|
||||
char m_HostName[MAX_NAME_STRING_LEN];
|
||||
char m_AppStr[20];
|
||||
char m_AppCtxHostStr[40];
|
||||
char m_IpAddress[64];
|
||||
|
||||
char m_DomainName[40];
|
||||
tSecLabel m_SecLabel;
|
||||
char m_ServiceName[40];
|
||||
|
||||
bool m_IsSysAdmHost;
|
||||
|
||||
//COrbMgr* m_OrbMgr;
|
||||
//CServicesManage* m_ServicesManage; ////obsolete
|
||||
TaskService* m_TaskService;
|
||||
NS_SYSADMIN::CScnService* m_ServicesManage;
|
||||
//Handle m_Handle; //for service_bus
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
66
code/sys_nicmonitor/include/db_api/odb_nooverflow_pk.h
Normal file
66
code/sys_nicmonitor/include/db_api/odb_nooverflow_pk.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: Real Time Database management system
|
||||
FileName: rtdb_api.cpp
|
||||
DESCRIPTION: rtdb api interfaces implementation
|
||||
FUNCTION LIST:
|
||||
COMMENT:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2009-01-10 1.1 add net interfaces
|
||||
================================================================================
|
||||
2008-10-30 1.0 created
|
||||
*******************************************************************************/
|
||||
#include "db_api/odb_baseindex.h"
|
||||
#ifndef _CNOOVERFLOWPK
|
||||
#define _CNOOVERFLOWPK
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
|
||||
class CNoOverflowPK:public CBaseIndex
|
||||
{
|
||||
public:
|
||||
virtual int need_rebuilt(char *existed_table_ptr,struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id);
|
||||
virtual int CreateIndex(struct STDB_TAB *stdb_tab_ptr,struct STDB_FIELD_TAB *stdb_field_tab_ptr,INDEX_DEFINE &index_define,int &shm_id,int &shm_size);
|
||||
virtual int Open(char *index_file_name,int table_id,int index_id); //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int Open(int index_shmid,int table_id,int index_id); //table_id、index_id用来和INDEX_STDB_TAB::table_id、INDEX_STDB_TAB::field_id匹配校验
|
||||
virtual int SetIndexPtr(char *index_ptr); //把缓存的指针赋值给索引类,这样就不用使用前面的Open函数。
|
||||
virtual int GetKeyByIndex(char *index_ptr,std::vector<char *> &index_array);
|
||||
virtual int GetKeyPointerByIndex(char *index_ptr, int& pointer);//只对主键索引有效,根据index得到记录的物理位置
|
||||
virtual int IndexInsert(char *index_ptr,char *key_ptr);
|
||||
virtual int BulkIndexInsert(char *bulk_index_key_ptr);//下装的时候
|
||||
virtual int Indexdelete(char *index_ptr,char *key_ptr);
|
||||
virtual int IndexClear();
|
||||
virtual int GetIdxMthd();
|
||||
virtual int FreeResource();//譬如unmap或者shmdt掉指针。
|
||||
virtual int DebugDisp(int type);//方便调试用,不同的type,显示不同或者详细程度不同的信息。
|
||||
virtual int GetIndexRecNum();//返回索引记录总的个数,包括索引区、溢出区、主溢出区有效记录个数的总和。但是无溢出HASH索引只是返回0。
|
||||
virtual DB_STATUS_T GetIndexStatus()//返回索引的状态
|
||||
{
|
||||
return m_IndexStdbPtr->index_status;
|
||||
}
|
||||
virtual void SetIndexStatus(DB_STATUS_T idx_status)//设置索引头上的索引状态
|
||||
{
|
||||
m_IndexStdbPtr->index_status = idx_status;
|
||||
}
|
||||
|
||||
//virtual int ModifyIndex(char *pk_ptr, int pos);
|
||||
CNoOverflowPK();
|
||||
~CNoOverflowPK();//考虑在析构函数里面调用FreeResource()
|
||||
|
||||
public:
|
||||
int GetMaxIndexPointer();
|
||||
int SetTableEnv(struct STDB_TAB *stdb_tab_ptr,char *table_data_area_ptr);
|
||||
|
||||
private:
|
||||
struct INDEX_STDB_TAB* m_IndexStdbPtr;
|
||||
struct STDB_TAB *m_StdbTabPtr; //added for optimization of IndexDelete
|
||||
char *m_TableDataAreaPtr; //added for optimization of IndexDelete
|
||||
//struct INDEX_STDB_FIELD_TAB *m_IndexStdbFieldPtr;
|
||||
int* m_PkIndexStgDirectPtr;
|
||||
int (*hash_func_ptr)(char *index,int length,int hash_prime);//这种索引算法只有一种,不一定使用
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
50
code/sys_nicmonitor/include/db_api/odb_orbmgr.h
Normal file
50
code/sys_nicmonitor/include/db_api/odb_orbmgr.h
Normal file
@@ -0,0 +1,50 @@
|
||||
//***********************************************************************************
|
||||
//
|
||||
// 本公共类作为CORBA客户端调用的封装类
|
||||
// version: no.3
|
||||
// time: 2003.03.16
|
||||
//
|
||||
//
|
||||
// Created by Wangx / Huanghf // 2003-01-01
|
||||
//***********************************************************************************
|
||||
|
||||
#include <OB/CORBA.h>
|
||||
#include <OB/Properties.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_STD_IOSTREAM
|
||||
using namespace std;
|
||||
#endif
|
||||
|
||||
#ifndef __ODB_ORBMGR_H__
|
||||
#define __ODB_ORBMGR_H__
|
||||
namespace ODB
|
||||
{
|
||||
class COrbMgr
|
||||
{
|
||||
public:
|
||||
COrbMgr();
|
||||
~COrbMgr();
|
||||
|
||||
bool InitOrb();
|
||||
bool InitOrb(const char* n_orbname);
|
||||
bool DelInitOrb();
|
||||
bool DelOrb();
|
||||
|
||||
bool SetOrbPara(const char* n_str_para_name, const char* n_str_para_value);
|
||||
|
||||
CORBA::Object_var GetRemoteObj(CORBA::ORB_var n_orb, const char* n_reffilename);
|
||||
CORBA::Object_var GetRemoteObj(CORBA::ORB_var n_orb, const char* n_server, const char* n_port, const char* n_objectname);
|
||||
|
||||
CORBA::ORB_var GetOrb();
|
||||
bool GetOrb(CORBA::ORB_var & in_orb);
|
||||
|
||||
//bool SetOrb(CORBA::ORB_var n_orb);
|
||||
|
||||
private:
|
||||
OB::Properties_var m_Props;
|
||||
CORBA::ORB_var m_Orb;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
66
code/sys_nicmonitor/include/db_api/odb_profile.h
Normal file
66
code/sys_nicmonitor/include/db_api/odb_profile.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef __ODB_PROFILE_H__
|
||||
#define __ODB_PROFILE_H__
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace NProfile
|
||||
{
|
||||
|
||||
#define MAX_LINE_LENGTH 1000
|
||||
|
||||
class CProfile
|
||||
{
|
||||
public:
|
||||
typedef map<string, string> KeyMapType;
|
||||
typedef map<string, KeyMapType> SectionMapType;
|
||||
typedef set<string> StringSetType;
|
||||
|
||||
private:
|
||||
SectionMapType m_mapSection;
|
||||
string m_strFileName;
|
||||
|
||||
bool GetSection(string &strSource);
|
||||
bool GetKeyAndValue(const string &strSource, string &strKey, string &strValue);
|
||||
|
||||
bool Trim(string &strSource);
|
||||
|
||||
public:
|
||||
CProfile();
|
||||
~CProfile();
|
||||
|
||||
CProfile(const char *pProfileName);
|
||||
CProfile(const string &strProfileName);
|
||||
|
||||
void SetFileName(const char *pProfileName);
|
||||
void SetFileName(const string &strProfileName);
|
||||
|
||||
int ReadFile(void);
|
||||
|
||||
bool IsSectionExists(const string &strSection);
|
||||
bool IsKeyExists(const string &strSection, const string &strKey);
|
||||
|
||||
string GetString(const string &strSection, const string &strKey,
|
||||
const string &strDefalut);
|
||||
|
||||
int GetInt(const string &strSection, const string &strKey, int nDefault);
|
||||
|
||||
void GetSections(StringSetType &setSections);
|
||||
void GetSectionKeys(StringSetType &setKeys, const string &strSection);
|
||||
void GetSectionValues(StringSetType &setValues, const string &strSection);
|
||||
|
||||
int GetKeyByValue(string& strKey, const char* pValue); //
|
||||
int GetKeyByValue(string& strKey, const string& strValue); //
|
||||
|
||||
void PrintAllValue(void);
|
||||
void TestFunctions(void);
|
||||
};
|
||||
|
||||
CProfile * CProfileInstance();
|
||||
CProfile * CProfileInstance(char* _filename);
|
||||
|
||||
} //End of namespace NProfile
|
||||
#endif // __PROFILE_FILE_H__
|
||||
2342
code/sys_nicmonitor/include/db_api/odb_prv_struct.h
Normal file
2342
code/sys_nicmonitor/include/db_api/odb_prv_struct.h
Normal file
File diff suppressed because it is too large
Load Diff
375
code/sys_nicmonitor/include/db_api/odb_public.h
Normal file
375
code/sys_nicmonitor/include/db_api/odb_public.h
Normal file
@@ -0,0 +1,375 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: publics.h
|
||||
DESCRIPTION: public define
|
||||
FUNCTION LIST:
|
||||
COMMENT: 操作相关结构定义 同odb_api_struct.h
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2002-09-01 1.0 modify
|
||||
================================================================================
|
||||
2002-09-01 1.0 created
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __ODB_PUBLIC_H__
|
||||
#define __ODB_PUBLIC_H__
|
||||
|
||||
//公共头文件
|
||||
#ifndef _WINDOWS64
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef _HPUX
|
||||
#include <pthread.h>
|
||||
#else
|
||||
#include <sys/pthread.h>
|
||||
#endif
|
||||
|
||||
#include <dirent.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#include <process.h>
|
||||
#include <time.h>
|
||||
#include <sys/timeb.h>
|
||||
//#include <afxmt.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <iostream>
|
||||
#include "ThreadKit/ThreadKit.h"
|
||||
|
||||
#ifndef __ODB_DEFINE_H__
|
||||
#include "db_api/odb_define.h"
|
||||
#endif
|
||||
|
||||
#include "db_api/odb_struct.h"
|
||||
|
||||
//namespace ODB
|
||||
//{
|
||||
struct TABLE_PARA
|
||||
{
|
||||
char table_name_eng[ENG_NAME_LEN];
|
||||
char table_name_chn[CHN_NAME_LEN];
|
||||
int key_len;
|
||||
int subkey_num;
|
||||
int record_number;
|
||||
int record_size;
|
||||
short field_sum;
|
||||
unsigned char is_auto_generated; //key_generate_type
|
||||
|
||||
};
|
||||
|
||||
struct FIELD_PARA
|
||||
{
|
||||
int table_id; //表ID号 INT
|
||||
short field_id; //域ID号 SHORT
|
||||
short column_id; //域内部ID号 SHORT
|
||||
char field_name_eng[ENG_NAME_LEN]; //域英文名 STRING(32)
|
||||
char field_name_chn[CHN_NAME_LEN]; //域中文名 STRING(64)
|
||||
short field_length; //数据长度 SHORT
|
||||
unsigned char data_type; //数据类型 UCHAR
|
||||
unsigned char is_keyword; //是否主键 UCHAR
|
||||
unsigned char allow_null; //是否允许空值 UCHAR
|
||||
|
||||
int app_type; //应用类型 INT
|
||||
unsigned char is_app_syn; //是否更新时全应用同步 UCHAR
|
||||
unsigned char index_order_no; //检索器索引顺序号 UCHAR
|
||||
unsigned char sort_order_no; //默认排序顺序号 UCHAR
|
||||
|
||||
// // // // //
|
||||
unsigned char is_input; //是否允许输入 UCHAR
|
||||
unsigned char is_display; //是否显示 UCHAR
|
||||
short display_order_no; //显示顺序号 SHORT
|
||||
unsigned char is_fix; //卷滚时是否固定 UCHAR
|
||||
short display_length; //默认显示长度 SHORT
|
||||
unsigned char display_precision; //小数显示精度 UCHAR
|
||||
unsigned char align_type; //对齐方式 UCHAR
|
||||
unsigned char display_type; //显示类型 UCHAR
|
||||
char menu_name[MENU_NAME_LEN]; //菜单名 STRING(40)
|
||||
|
||||
unsigned char reference_flag; //数据引用类型 UCHAR
|
||||
unsigned char reference_mode; //数据引用方式 UCHAR
|
||||
int reference_table; //引用表名 INT
|
||||
short reference_column; //引用域号 SHORT
|
||||
unsigned char reference_display; //被引用时是否显示 UCHAR
|
||||
|
||||
char init_value[DEFAULT_VALUE_LEN]; //缺省值 STRING(20)
|
||||
char min_value[DEFAULT_VALUE_LEN]; //最小值 STRING(20)
|
||||
char max_value[DEFAULT_VALUE_LEN]; //最大值 STRING(20)
|
||||
|
||||
int column_special; //域特殊属性 INT
|
||||
unsigned char auto_meas_type; //自动生成量测类型 UCHAR
|
||||
short gen_array_dimension; //数组维数 SHORT
|
||||
char gen_array_name[ARRAY_NAME_LEN]; //数组名称 STRING(32)
|
||||
char column_description[DESCRIPTION_LEN]; //域描述信息 STRING(100)
|
||||
|
||||
unsigned char is_index; //
|
||||
int offset; //added by RTDBMS
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// for down load //
|
||||
// //
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*============================================================================*/
|
||||
|
||||
struct STDB_CREAT_REQ
|
||||
{
|
||||
int app_no;
|
||||
int table_no;
|
||||
int table_version;
|
||||
int field_sum; //short
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
int bit_field_sum;
|
||||
int vir_field_sum;
|
||||
#endif
|
||||
char table_name_eng[ENG_NAME_LEN];
|
||||
char table_name_chn[CHN_NAME_LEN];
|
||||
int record_num;
|
||||
int record_sum;
|
||||
int record_length; //short
|
||||
|
||||
unsigned char is_system_table;
|
||||
unsigned char is_auto_generated; //key_generate_type;
|
||||
unsigned char is_record_apped;
|
||||
unsigned char is_record_lock;
|
||||
unsigned char is_record_resp;
|
||||
|
||||
DB_MEDIA_T stdb_media; //no used
|
||||
ACCESS_METHODS_T access_meth; //
|
||||
int seq_field_no; //
|
||||
char passwd[MAX_NAME_STRING_LEN]; //
|
||||
|
||||
|
||||
int table_type; //for graph, etc
|
||||
|
||||
/******Added for index begin ************/
|
||||
int pk_index_method;
|
||||
int pk_storage_type;//主键存储方法,譬如共享内存或者文件映射内存。
|
||||
int pk_mem_alloc_type;//主键内存分配方法,譬如带溢出HASH的分配方法;无溢出的HASH分配方法。
|
||||
/******Added for index end**************/
|
||||
|
||||
int reserved_1;
|
||||
int reserved_2;
|
||||
int reserved_3;
|
||||
int reserved_4;
|
||||
int reserved_5;
|
||||
int area_num;
|
||||
int area_no[MAX_AREA_NUM];
|
||||
char area_name[MAX_AREA_NUM][ENG_NAME_LEN];
|
||||
int slice_flag;
|
||||
};
|
||||
|
||||
struct FIELD_CREAT_REQ
|
||||
{
|
||||
int app_no; //app_type
|
||||
short field_no;
|
||||
short r_field_no;
|
||||
short field_id;
|
||||
short column_id;
|
||||
short field_length;
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
short is_bit_field;
|
||||
#endif
|
||||
char field_name_eng[ENG_NAME_LEN];
|
||||
char field_name_chn[CHN_NAME_LEN];
|
||||
|
||||
int column_special;
|
||||
int ref_tableno; //long reference_table;
|
||||
short ref_fieldno; //short reference_column;
|
||||
|
||||
unsigned char reference_flag;
|
||||
unsigned char reference_mode;
|
||||
unsigned char reference_display;
|
||||
|
||||
unsigned char data_type;
|
||||
unsigned char allow_null;
|
||||
unsigned char is_keyword;
|
||||
unsigned char display_type;
|
||||
unsigned char is_index; //octet index_order_no;
|
||||
unsigned char sort_order_no;
|
||||
|
||||
unsigned char is_app_syn;
|
||||
unsigned char auto_meas_type;
|
||||
|
||||
char menu_name[MENU_NAME_LEN];
|
||||
char default_asciival[DEFAULT_VALUE_LEN]; //init_value
|
||||
char min_asciival[DEFAULT_VALUE_LEN]; //min_value
|
||||
char max_asciival[DEFAULT_VALUE_LEN]; //max_value
|
||||
|
||||
|
||||
int search_attribute; // 检索器的域特性 //Added 2003-09-01
|
||||
int statics_attribute; // 统计的域特性
|
||||
int reserved_1; // 系统保留
|
||||
int reserved_2; // 系统保留
|
||||
int reserved_3; // 系统保留
|
||||
int reserved_4; // 系统保留
|
||||
int reserved_5; // 系统保留
|
||||
};
|
||||
|
||||
#ifdef _APP_SYS_SUBSTATION
|
||||
struct VIR_FIELD_CREAT_REQ
|
||||
{
|
||||
short v_field_no; //rtdbms
|
||||
short vr_field_no;
|
||||
short r_field_no; //bit field no
|
||||
short bit_no;
|
||||
char vir_field_name_eng[ENG_NAME_LEN];
|
||||
char vir_field_name_chn[CHN_NAME_LEN];
|
||||
};
|
||||
#endif
|
||||
|
||||
struct STDB_DELETE_REQ
|
||||
{
|
||||
int app_no;
|
||||
int table_no;
|
||||
char passwd[MAX_PASSWD_LEN];
|
||||
};
|
||||
|
||||
|
||||
//struct FIELD_TYPE
|
||||
//{
|
||||
// short field_no;
|
||||
// short field_type; //data type for get; byte len for write
|
||||
//};
|
||||
|
||||
struct FIELD_BASE_INFO
|
||||
{
|
||||
int offset;
|
||||
int field_length;
|
||||
short field_no;
|
||||
unsigned char data_type;
|
||||
unsigned char is_keyword;
|
||||
};
|
||||
|
||||
|
||||
#ifndef __i386
|
||||
static char strFILE[100];
|
||||
static int iLINE;
|
||||
#endif
|
||||
|
||||
#ifndef __i386
|
||||
// #define TRACE strFILE = __FILE__; iLINE = __LINE__; odb_trace
|
||||
#define TRACE strcpy(strFILE, __FILE__); iLINE = __LINE__; printf("\t%s:%d-->",strFILE,iLINE); odb_trace
|
||||
#else
|
||||
#define TRACE(...) odb_trace(__FILE__, __LINE__, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#ifndef _WINDOWS64
|
||||
#ifndef __i386
|
||||
inline void odb_trace(const char *p,...)
|
||||
{
|
||||
#else
|
||||
inline void odb_trace(const char *strFILE, const int iLINE, const char *p,...)
|
||||
{
|
||||
printf("\t%s:%d-->",strFILE,iLINE);
|
||||
#endif
|
||||
/*
|
||||
#ifndef __i386
|
||||
static char strFILE[100];
|
||||
static int iLINE;
|
||||
// #define TRACE strFILE = __FILE__; iLINE = __LINE__; odb_trace
|
||||
#define TRACE strcpy(strFILE, __FILE__); iLINE = __LINE__; printf("\t%s:%d-->",strFILE,iLINE); odb_trace
|
||||
inline void odb_trace(const char *p,...)
|
||||
{
|
||||
#else
|
||||
#define TRACE(...) odb_trace(__FILE__, __LINE__, __VA_ARGS__)
|
||||
inline void odb_trace(const char *strFILE, const int iLINE, const char *p,...)
|
||||
{
|
||||
printf("\t%s:%d-->",strFILE,iLINE);
|
||||
#endif
|
||||
*/
|
||||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
va_list va;
|
||||
va_start(va,p);
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
vfprintf(stdout,p,va);
|
||||
fflush(stdout);
|
||||
pthread_mutex_unlock(&lock);
|
||||
va_end(va);
|
||||
}
|
||||
#else
|
||||
inline void odb_trace(const char *p,...)
|
||||
{
|
||||
/*
|
||||
//printf("\t%s:%d-->",strFILE,iLINE);
|
||||
static CRITICAL_SECTION cs; //定义临界区
|
||||
InitializeCriticalSection(&cs);//初始化临界区
|
||||
|
||||
va_list va;
|
||||
va_start(va,p);
|
||||
|
||||
EnterCriticalSection(&cs);//加锁
|
||||
vfprintf(stdout,p,va);
|
||||
fflush(stdout);
|
||||
LeaveCriticalSection(&cs);//解锁
|
||||
va_end(va);
|
||||
*/
|
||||
//printf("\t%s:%d-->",strFILE,iLINE);
|
||||
THREADKIT::Mutex g_mutex;
|
||||
va_list va;
|
||||
va_start(va,p);
|
||||
|
||||
{
|
||||
THREADKIT::Guard<THREADKIT::Mutex> guard(g_mutex);
|
||||
vfprintf(stdout,p,va);
|
||||
fflush(stdout);
|
||||
}
|
||||
va_end(va);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
class SecClock
|
||||
{
|
||||
public:
|
||||
SecClock(int time_out):timer(time(NULL)),time_out(time_out){}
|
||||
bool TimeOut(){return time(NULL)-timer>time_out;}
|
||||
private:
|
||||
time_t timer;
|
||||
int time_out;
|
||||
|
||||
};
|
||||
|
||||
/*============================================================================*/
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void do_nothing1(int nn);
|
||||
void do_nothing2(int nn);
|
||||
}
|
||||
//}
|
||||
#endif
|
||||
155
code/sys_nicmonitor/include/db_api/odb_rtdbbase.h
Normal file
155
code/sys_nicmonitor/include/db_api/odb_rtdbbase.h
Normal file
@@ -0,0 +1,155 @@
|
||||
/*******************************************************************************
|
||||
ModuleName: ODB Real Time Database management system
|
||||
FileName: odb_rtdbbase.h
|
||||
DESCRIPTION: class system interface define
|
||||
FUNCTION LIST:
|
||||
COMMENT:
|
||||
History:
|
||||
Date Version Modifier Activities
|
||||
2003-09-10 1.0 modify
|
||||
2003-12-03 1.1 modify
|
||||
================================================================================
|
||||
2003-09-10 1.0 created
|
||||
*******************************************************************************/
|
||||
#ifndef __ODB_RTDBBASE_H__
|
||||
#define __ODB_RTDBBASE_H__
|
||||
|
||||
#ifndef __ODB_PUBLIC_H__
|
||||
#include "db_api/odb_public.h"
|
||||
#endif
|
||||
|
||||
#include "db_api/odb_prv_struct.h"
|
||||
|
||||
/*
|
||||
#ifndef __ODB_INCLUDE_H__
|
||||
#include "odb_include.h"
|
||||
#endif
|
||||
*/
|
||||
/*
|
||||
#ifndef __ODB_BASEBUFFER_H__
|
||||
#include "odb_basebuffer.h"
|
||||
#endif
|
||||
*/
|
||||
|
||||
#include "pub.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ODB
|
||||
{
|
||||
class CRtdbBase
|
||||
{
|
||||
public:
|
||||
CRtdbBase(){}
|
||||
virtual ~CRtdbBase(){}
|
||||
|
||||
public:
|
||||
//
|
||||
//query the whole table
|
||||
//
|
||||
virtual int TableGet(CBuffer& buf_base) const = 0;
|
||||
virtual int TableGet(const int field_no, CBuffer& buf_base) const = 0;
|
||||
virtual int TableGet(const char* field_name, CBuffer& buf_base) const = 0;
|
||||
virtual int TableGet(const std::vector<int>& vec_field_no, CBuffer& buf_base) const = 0;
|
||||
|
||||
//
|
||||
//query by key word
|
||||
//
|
||||
virtual int TableGetByKey(const char* key_ptr, char* buf_ptr, const int buf_size) const = 0;
|
||||
virtual int TableGetByKey(const char* key_ptr, const int field_no, char* field_buf_ptr, const int buf_size) const = 0;
|
||||
virtual int TableGetByKey(const char* key_ptr, const char* field_name, char* field_buf_ptr, const int buf_size) const = 0;
|
||||
virtual int TableGetByKey(const char* key_ptr, const std::vector<int>& vec_field_no, char* field_buf_ptr, const int buf_size) const = 0;
|
||||
virtual int TableGetByKey(const char* key_ptr, const int keybuf_size, const std::vector<int>& vec_field_no, char* field_buf_ptr, const int buf_size) const = 0;
|
||||
|
||||
//
|
||||
//modify
|
||||
//
|
||||
virtual int TableModify(const char* buf_ptr, const int record_num, const int record_size) const = 0;
|
||||
virtual int TableModify(const int field_no, const char* field_buf_ptr, const int buf_size) const = 0;
|
||||
virtual int TableModify(const char* field_name, const char* field_buf_ptr, const int buf_size) const = 0;
|
||||
virtual int TableModify(const std::vector<int>& vec_field_no, const char* field_buf_ptr, const int buf_size) const = 0;
|
||||
|
||||
//
|
||||
//by keyword && fields
|
||||
//
|
||||
virtual int TableModifyByKey(const char* key_ptr, const int field_no, const char* field_buf_ptr, const int buf_size) const = 0;
|
||||
virtual int TableModifyByKey(const char* key_ptr, const char* field_name, const char* field_buf_ptr, const int buf_size) const = 0;
|
||||
virtual int TableModifyByKey(const char* key_ptr, const std::vector<int>& vec_field_no, const char* field_buf_ptr, const int buf_size) const = 0;
|
||||
|
||||
//
|
||||
//SQL interface
|
||||
//
|
||||
virtual int SqlGet(const char* str_sql, CBuffer& buf_base) const = 0;
|
||||
|
||||
public:
|
||||
//
|
||||
//Table PARA
|
||||
//
|
||||
virtual int GetTablePara(short& field_num, int& record_num, int& record_size) const = 0;
|
||||
virtual int GetTablePara(struct TABLE_PARA& table_para, std::vector<struct STDB_FIELD_TAB>& vec_field_para) const = 0;
|
||||
virtual int GetTablePara(const char* str_attribute, CBuffer& buf_base) const = 0;
|
||||
|
||||
virtual int GetFieldInfo(const std::vector<int> vec_field_no, std::vector<struct FIELD_BASE_INFO>& vec_field) const = 0;
|
||||
|
||||
public:
|
||||
//
|
||||
//Name and No
|
||||
//
|
||||
virtual int GetFieldNameByNo(char* field_name, const int field_no, const bool is_eng=true) = 0;
|
||||
virtual int GetFieldNoByName(int& field_no, const char* field_name, const bool is_eng=true) = 0;
|
||||
|
||||
virtual int GetTableNameByNo(char* table_name, const int table_no, const bool is_eng=true) = 0;
|
||||
virtual int GetTableNoByName(int& table_no, const char* table_name, const bool is_eng=true) = 0;
|
||||
|
||||
virtual int GetAppNameByNo(char* app_name, const int app_no) = 0;
|
||||
virtual int GetAppNoByName(int& app_no, const char* app_name) = 0;
|
||||
|
||||
public:
|
||||
virtual int MenuRead(const char* menu_name, std::vector<struct MENU_INFO>& vec_menu, const int menu_status=MENU_ON) = 0;
|
||||
|
||||
virtual int TableReleMenuRead(const int table_no, std::vector<struct MENU_RELEVANT>& vec_menu) = 0;
|
||||
|
||||
virtual int GetRefMenuString(const int table_no, std::vector<struct MENU_STRING>& vec_menu) = 0;
|
||||
|
||||
//virtual int GetNameStringByKeyID(const KEY_ID_STRU& keyid_stru, string& ref_string) = 0;
|
||||
|
||||
//virtual int GetNameStringByKeyID(const std::vector<KEY_ID_STRU>& vec_keyid, std::vector<string>& vec_ref_string) = 0;
|
||||
|
||||
virtual int GetNameStringByID(const cmnInt64 reference_id, string& ref_string) = 0;
|
||||
|
||||
virtual int GetNameStringBykey(const char* key_ptr, string& ref_string) = 0;
|
||||
|
||||
virtual int GetNameStringByAppKeyID( const std::vector<struct APP_KEY_STRU>& vec_appkeyid, std::vector<string>& vec_name_string) = 0;
|
||||
|
||||
virtual int GetNameStringByAppID( const std::vector<APP_ID_STRU>& vec_appid, std::vector<string>& vec_name_string) = 0;
|
||||
|
||||
// virtual int ColMeasType( const std::vector<KEY_ID_STRU> vec_keyid , std::vector<int>& vec_col_prop ) = 0;
|
||||
// virtual int GraphGetAppInfo(const struct ODB::GRAPH_ORDER_KEY_REQ& graph_req, struct ODB::GRAPH_ORDER_KEY_RSP& graph_rsp) const = 0;
|
||||
|
||||
// virtual int GraphGetData(const struct CODB_NET::GRAPH_REAL_REQ& real_req, CODB_NET::GRAPH_REAL_RSP_var& real_rsp) const = 0;
|
||||
|
||||
public:
|
||||
virtual int GetFacNameByKeyNo(const int table_no, const char* key_ptr, string& ref_string) = 0;
|
||||
virtual int GetFacNameByFacID(char* fac_name, const cmnInt64 fac_id) = 0;
|
||||
virtual int GetFacNameByFacNo(char* fac_name, const int fac_no) = 0;
|
||||
|
||||
virtual int GetFacIDByFacName(cmnInt64& fac_id, const char* fac_name) = 0;
|
||||
//virtual int GetFacNoByFacName(int& fac_no, const char* fac_name) = 0; //obsolete 2004-04-03
|
||||
virtual int GetFacNoByFacName(int& fac_no, const char* fac_name) = 0;
|
||||
|
||||
//virtual int GetFacIDByFacNo(int& fac_id, const int fac_no) = 0; //obsolete 2004-04-03
|
||||
virtual int GetFacIDByFacNo(cmnInt64& fac_id, const int fac_no) = 0;
|
||||
virtual int GetFacNoByFacID(int& fac_no, const cmnInt64 fac_id) = 0;
|
||||
|
||||
public:
|
||||
virtual int GetValueAndStatus(const vector<struct KEY_ID> &struVec , vector< struct INT_VALUE_STATUS > &KeyIdValVec) = 0; //yc
|
||||
virtual int GetValueAndStatus(const vector<struct KEY_ID> &struVec , vector< struct FLOAT_VALUE_STATUS> & KeyIdValVec) = 0; //yx
|
||||
virtual int GetValueAndStatus(const vector<struct KEY_ID> &struVec , vector< struct CHAR_VALUE_STATUS > & KeyIdValVec)= 0; //ym
|
||||
virtual int GetValueAndStatus(const vector<struct KEY_ID> &struVec , vector< struct UNION_VALUE_STATUS> & KeyIdValVec ) = 0; //union type
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user