wangzhengquan
2020-06-08 e861f79cb75d2fd14985f17f4094917ecfae4cf8
update
5个文件已删除
9个文件已添加
6个文件已修改
1600575 ■■■■■ 已修改文件
Makefile 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/include/usg_common.h 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/include/usg_typedef.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hcnetdisk_wrapper/Makefile 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hcnetdisk_wrapper/hcnetdisk_wrapper.c 188 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hcnetdisk_wrapper/include/hcnetdisk_wrapper.h 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
hcnetdisk_wrapper/test 补丁 | 查看 | 原始文档 | blame | 历史
hcnetdisk_wrapper/test.c 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
netdisk/Makefile 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
netdisk/include/netdisk.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
netdisk/netdisk.c 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/Makefile 51 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/stand.txt 400000 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test.txt 400000 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test1.txt 400000 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test2.txt 400000 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test_file 补丁 | 查看 | 原始文档 | blame | 历史
test/test_file.c 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test_io 补丁 | 查看 | 原始文档 | blame | 历史
test/test_io.c 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Makefile
@@ -1,4 +1,4 @@
DIRS = common hcnetdisk_wrapper netdisk
DIRS = common netdisk
all:
    for i in $(DIRS); do \
common/include/usg_common.h
@@ -27,6 +27,7 @@
#include <sys/stat.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/file.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
common/include/usg_typedef.h
@@ -40,8 +40,8 @@
#define DIR_MODE  (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
#define min(a,b)  ((a) < (b) ? (a) : (b))
#define max(a,b)  ((a) > (b) ? (a) : (b))
#define MIN(a,b)  ((a) < (b) ? (a) : (b))
#define MAX(a,b)  ((a) > (b) ? (a) : (b))
 
hcnetdisk_wrapper/Makefile
File was deleted
hcnetdisk_wrapper/hcnetdisk_wrapper.c
File was deleted
hcnetdisk_wrapper/include/hcnetdisk_wrapper.h
File was deleted
hcnetdisk_wrapper/test
Binary files differ
hcnetdisk_wrapper/test.c
File was deleted
netdisk/Makefile
@@ -4,7 +4,7 @@
ROOT=..
LDLIBS+=-Wl,-rpath=../hclib:../hclib/HCNetSDKCom:../common
LDDIR += -L$(ROOT)/hcnetdisk_wrapper -L../hclib -L../hclib/HCNetSDKCom
LDLIBS += -lusgcommon -lhcnetsdk -lhpr -lHCCore $(EXTRALIBS)
LDLIBS += -lhcnetsdk -lhpr -lHCCore $(EXTRALIBS)
LIB_NETDISK = libnetdisk.a
DLIB_NETDISK = libnetdisk.so
PLATFORM=$(shell $(ROOT)/systype.sh)
netdisk/include/netdisk.h
@@ -1,6 +1,7 @@
#ifndef __NETDISK_H__
#define __NETDISK_H__
#include "usg_common.h"
#include "usg_typedef.h"
typedef struct Netdisk_EnvConfig {
    std::string libpath;
@@ -51,10 +52,13 @@
    virtual int downloadByTime(Netdisk_DownloadRequest &request, std::vector<std::string> *files) = 0;
    void saveLoginInfo();
    int getStartChannel() {return startChannel;}
    int getMaxChannels() {return maxChannels;}
};
#endif
netdisk/netdisk.c
New file
@@ -0,0 +1,5 @@
#include "netdisk.h"
Netdisk::saveLoginInfo() {
    int fd = open("./login_info.data", O_CREAT | O_APPEND | O_RDWR, FILE_MODE);
}
test/Makefile
@@ -1,48 +1,23 @@
#
# Makefile for common library.
#
ROOT=..
EXTRALIBS+=
INCLUDE+=
LIBCOMMON=$(ROOT)/common/libusgcommon.a
LDLIBS+=-L../hclib -L../hclib/HCNetSDKCom -Wl,-rpath=../hclib:../hclib/HCNetSDKCom \
    -lhcnetsdk -lhpr -lHCCore
#     -lAudioRender        -lPlayCtrl  -lSuperRender \
#     -lcrypto        -lNPQos  -lssl       -lz \
#     -lanalyzedata   -lHCDisplay        -lHCPlayBack     -lSystemTransform \
#      -lHCAlarm       -lHCGeneralCfgMgr  -lHCPreview   \
#      -lHCCoreDevCfg  -lHCIndustry       -lHCVoiceTalk  -libStreamTransClient
# LDLIBS+=libAudioRender.so  libHCCore.so    libhpr.so    libPlayCtrl.so  libSuperRender.so \
#     libcrypto.so      ./libhcnetsdk.so  libNPQos.so  libssl.so       libz.so \
#     HCNetSDKCom/libanalyzedata.so   HCNetSDKCom/libHCGeneralCfgMgr.so  HCNetSDKCom/libHCVoiceTalk.so \
#     HCNetSDKCom/libHCAlarm.so       HCNetSDKCom/libHCIndustry.so       HCNetSDKCom/libiconv2.so \
#     HCNetSDKCom/libHCCoreDevCfg.so  HCNetSDKCom/libHCPlayBack.so       HCNetSDKCom/libStreamTransClient.so \
#     HCNetSDKCom/libHCDisplay.so     HCNetSDKCom/libHCPreview.so        HCNetSDKCom/libSystemTransform.so
LDLIBS+=-Wl,-rpath=../hclib:../hclib/HCNetSDKCom:../common
LDDIR += -L$(ROOT)/hcnetdisk_wrapper -L../hclib -L../hclib/HCNetSDKCom
LDLIBS +=  -lhcnetsdk -lhpr -lHCCore -lpthread
LIB_NETDISK = libnetdisk.a
DLIB_NETDISK = libnetdisk.so
PLATFORM=$(shell $(ROOT)/systype.sh)
include $(ROOT)/Make.defines.$(PLATFORM)
PROGS =    download1 channel
all: $(PROGS)
 
# 如果包A 引用包B, B 要放在 A 后面
# channel:  $(LIBCOMMON)
#test_right_walk: $(ROOT)/algorithm/graph.c $(ROOT)/algorithm/IndirectAlg.c  $(LIBCOMMON)
test_right_walk2: test_right_walk2.c
    #g++  -std=c++11 -mcx16 -Wall  -DLINUX -D_GNU_SOURCE  test_right_walk2.c -o $@  -lalg -lusgcommon
    g++  -std=c++11  test_right_walk2.c -o test_right_walk2  -lalg  -lusgcommon -lpthread
all: test_file test_io
test_file: test_file.c
clean:
    rm -f $(PROGS) $(TEMPFILES) *.o
    rm -f test *.o a.out core temp.* *.a *.so
$(LIBCOMMON):
    (cd $(ROOT)/common && $(MAKE))
include $(ROOT)/Make.common.inc
test/stand.txt
New file
Diff too large
test/test.txt
New file
Diff too large
test/test1.txt
New file
Diff too large
test/test2.txt
New file
Diff too large
test/test_file
Binary files differ
test/test_file.c
New file
@@ -0,0 +1,110 @@
#include "usg_common.h"
#include "usg_typedef.h"
#include <sys/file.h>
#include <fcntl.h>
int open_file(char *filename) {
    int fd = open(filename, O_CREAT | O_APPEND | O_RDWR , FILE_MODE);
    return fd;
}
void write_to_file_with_no_lock(int fd, int start, int end) {
    int i;
    char buf[1024];
    for(i = start;  i< end; i++) {
        sprintf(buf, "%d\n", i);
        if (write(fd,  buf,  strlen(buf)) == -1) {
             err_exit(errno, "write_to_file");
        }
    }
}
void write_to_file_with_lock(int fd, int start, int end) {
    int i;
    char buf[1024];
    for(i = start; i< end; i++) {
        sprintf(buf, "%d\n", i);
        if (flock(fd , LOCK_EX) == -1) {
            err_exit(errno, "LOCK_EX");
        }
        if (write(fd,  buf,  strlen(buf)) == -1) {
             err_exit(errno, "write_to_file");
        }
        if (flock(fd, LOCK_UN) == -1)
            err_exit(errno, "LOCK_UN");
    }
}
void write_to_file(int fd, int start, int end) {
    write_to_file_with_no_lock(fd, start, end);
    //write_to_file_with_lock(fd, start, end);
}
void read_from_file(int fd) {
    lseek(fd, 0, SEEK_SET);
    char buf[1024];
    while(read( fd,   buf,  1024) > 0) {
        printf("%s", buf);
    }
}
int main() {
    int fd = open_file("test.txt");
    int status, i = 0, processors = 4, scale = 100;
    pid_t productors[processors], consumers[processors];
    pid_t pid;
    fd = open_file("stand.txt");
    write_to_file_with_no_lock(fd, 0,  processors * scale);
    read_from_file(fd);
    for ( i = 0; i < processors; i++) {
        if ((productors[i] = fork()) == 0)     /* Child runs user job */
        {
           fd = open_file("test.txt");
           int start = i * scale, end = i * scale + scale;
           printf("======start=%d, end=%d\n", start, end);
           write_to_file(fd, start, end);
           sleep(1);
           exit(0);
        }
    }
    // for ( i = 0; i < processors; i++) {
    //     if ((consumers[i] = fork()) == 0)     /* Child runs user job */
    //     {
    //        // char cmd[1000];
    //        // char  *argv[] = {"productor", start, end, NULL };
    //         const char *cmd = "./consumer  >> c.txt";
    //         if (execl("/bin/bash", "bash", "-c", cmd, 0) < 0)
    //         {
    //             err_exit(errno, "consumers execve");
    //         }
    //     }
    // }
    while ((pid = waitpid(-1, &status, 0)) > 0) {
        if(WIFEXITED(status)) {
            //fprintf(stderr, "child %d terminated normally with exit status=%d\n", pid, WEXITSTATUS(status));
        }else
            fprintf(stderr, "child %d terminated abnormally\n", pid);
    }
    if (errno != ECHILD)
        perror("waitpid error");
    close(fd);
}
test/test_io
Binary files differ
test/test_io.c
New file
@@ -0,0 +1,103 @@
#include "usg_common.h"
#include "usg_typedef.h"
#include <iostream> // not needed for many systems
#include <fstream>
#include <string>
using namespace std;
// void write_to_file_with_no_lock(int fd, int start, int end) {
//     int i;
//     char buf[1024];
//     for(i = start;  i< end; i++) {
//         sprintf(buf, "%d\n", i);
//         if (write(fd,  buf,  strlen(buf)) == -1) {
//              err_exit(errno, "write_to_file");
//         }
//     }
// }
// void write_to_file_with_lock(int fd, int start, int end) {
//     int i;
//     char buf[1024];
//     for(i = start; i< end; i++) {
//         sprintf(buf, "%d\n", i);
//         if (flock(fd , LOCK_EX) == -1) {
//             err_exit(errno, "LOCK_EX");
//         }
//         if (write(fd,  buf,  strlen(buf)) == -1) {
//              err_exit(errno, "write_to_file");
//         }
//         if (flock(fd, LOCK_UN) == -1)
//             err_exit(errno, "LOCK_UN");
//     }
// }
void write_to_file(ofstream &fout, int start, int end) {
    int i;
    for(i = start;  i< end; i++) {
         fout << i << endl;
    }
    //write_to_file_with_lock(fd, start, end);
}
void read_from_file(ifstream &fin) {
    fin.seekg(0);
    char buf[1024];
    while(fin.getline(buf, 1024)) {
        printf("%s\n", buf);
    }
}
int main() {
    ofstream fout;
    ifstream fin("stand.txt");
    int status, i = 0, processors = 4, scale = 100000;
    pid_t productors[processors], consumers[processors];
    pid_t pid;
    fout.open("stand.txt", ios_base::app);
    write_to_file(fout, 0,  processors * scale);
    fout.close();
    //read_from_file(fin);
    fout.open("test.txt", ios_base::out | ios_base::app);
    for ( i = 0; i < processors; i++) {
        if ((productors[i] = fork()) == 0)     /* Child runs user job */
        {
           int start = i * scale, end = i * scale + scale;
           printf("======start=%d, end=%d\n", start, end);
           write_to_file(fout, start, end);
           exit(0);
        }
    }
    while ((pid = waitpid(-1, &status, 0)) > 0) {
        if(WIFEXITED(status)) {
            //fprintf(stderr, "child %d terminated normally with exit status=%d\n", pid, WEXITSTATUS(status));
        }else
            fprintf(stderr, "child %d terminated abnormally\n", pid);
    }
    if (errno != ECHILD)
        perror("waitpid error");
    fout.close();
    fin.close();
}