diff options
| -rw-r--r-- | src/encoder.cc | 14 | ||||
| -rw-r--r-- | src/encoder.h | 2 | ||||
| -rw-r--r-- | src/file.cc | 135 | ||||
| -rw-r--r-- | src/file.h | 2 | ||||
| -rw-r--r-- | src/server.cc | 1 | 
5 files changed, 49 insertions, 105 deletions
| diff --git a/src/encoder.cc b/src/encoder.cc index 208dd79..b4227b0 100644 --- a/src/encoder.cc +++ b/src/encoder.cc @@ -65,6 +65,8 @@ Encoder::Encoder(Info *ginfo,    frozen = false; +  savestate = NO_CHANGE; +    //  shoot_request = 0;    //  shoot_value = 0;    //  freeze_request = 0; @@ -116,7 +118,7 @@ void Encoder::encode()          h.header.h_data.freeze = frame->freeze;          h.header.h_data.snapshot = frame->shoot;          h.header.h_data.record = frame->record; -        h.header.h_data.savestate = NO_CHANGE; +        h.header.h_data.savestate = savestate;//NO_CHANGE;          //        if(freeze_request != freeze_value) freeze_value = freeze_request;          //        if(shoot_request != shoot_value) shoot_value = shoot_request; @@ -192,7 +194,8 @@ void Encoder::shoot()  } -void Encoder::thread_main() { +void Encoder::thread_main() +{    encode();    if(s) {      if(n) delete n; @@ -204,7 +207,8 @@ void Encoder::thread_main() {  } -void Encoder::start() { +void Encoder::start() +{    /*    if(!s) {      s = new Socket(port, errobj); @@ -216,7 +220,9 @@ void Encoder::start() {  } -void Encoder::stop(n_savestate save) { +void Encoder::stop(n_savestate save) +{ +  savestate = save;  /*    struct timespec ts;    // TODO: set save state in package header. diff --git a/src/encoder.h b/src/encoder.h index 29d139b..2aa8729 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -102,6 +102,8 @@ private:    //  int shoot_value;    //  volatile int freeze_request;    //  int freeze_value; + +  volatile n_savestate savestate;    sem_t	record_sem;    void encode(); diff --git a/src/file.cc b/src/file.cc index f3c0cbc..3a59334 100644 --- a/src/file.cc +++ b/src/file.cc @@ -27,12 +27,16 @@  #include <config.h>  #include "file.h" +#include "miav_config.h" +  #include <sys/types.h>  #include <sys/stat.h>  #include <fcntl.h>  #include <string.h>  #include <unistd.h> +#include <errno.h> +  // For ntoh*  #include <netinet/in.h> @@ -77,6 +81,9 @@ File::~File()      info->info("[%s]", filelist[cnt].c_str());    } +  std::string *trash = config->readString("server_trash"); +  std::string *later = config->readString("server_later"); +    switch(savestate) {    case NO_CHANGE:      info->warn("File had no savestate!"); @@ -88,16 +95,12 @@ File::~File()    case DELETE:      info->info("Files in this session is to be deleted (moved to trash)."); -    for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) { -      // TODO: Move file filelist[cnt] to trash -    } +    Move((char*)trash->c_str());      break;    case LATER:      info->info("Files in this session is stored for later decisson."); -    for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) { -      // TODO: Move file filelist[cnt] to the later folder. -    } +    Move((char*)later->c_str());      break;    } @@ -105,6 +108,28 @@ File::~File()    delete extension;  } +int File::Move(char *destination) +{ +  char newfile[256]; +  char filename[256]; + +  createPath(destination); +  for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) { +    // TODO: Check is the file exists... if not make som noise! +     + +    // TODO: Move file filelist[cnt] to the destination folder. +    strcpy(filename, (char*)filelist[cnt].c_str()); +    sprintf(newfile, "%s%s", destination, strrchr(filename, '/')); +    if(rename((char*)filelist[cnt].c_str(), newfile) == -1) +      info->error("Error moving file %s to %s:",  +                  (char*)filelist[cnt].c_str(), +                  newfile, +                  strerror(errno)); +  } +  return 0; +} +  int File::Open()  {    char fname[256]; @@ -162,100 +187,7 @@ int File::Write(void* data, int size)    return w;  } -/* -int File::Write(char* data, int size) -{ -  return Write((void*)data, size); -} - -int File::Write(unsigned long long int val) -{ -  int res; -  int written = 0; -  unsigned long int *h_u = (unsigned long int *)&val; -  unsigned long int *h_l = (unsigned long int *)(((char*)&val) + sizeof(unsigned long int)); - -  *h_u = htonl(*h_u); -  *h_l = htonl(*h_l); - -  if((res = Write((void*)h_l, sizeof(*h_l))) < 0) { -    return res; -  } -  written += res; - -  if((res = Write((void*)h_u, sizeof(*h_u))) < 0) { -    return res; -  } -  written += res; - -  return written; -} - -int File::Write(long long int val) -{ -  int res; -  int written = 0; -  unsigned long int *h_u = (unsigned long int *)&val; -  unsigned long int *h_l = (unsigned long int *)(((char*)&val) + sizeof(unsigned long int)); - -  *h_u = htonl(*h_u); -  *h_l = htonl(*h_l); - -  if((res = Write((void*)h_l, sizeof(*h_l))) < 0) { -    return res; -  } -  written += res; - -  if((res = Write((void*)h_u, sizeof(*h_u))) < 0) { -    return res; -  } -  written += res; - -  return written;  -} - -int File::Write(long int val) -{ -  val = htonl(val); - -  return Write((char*)&val, sizeof(val)); -} - -int File::Write(unsigned long int val) -{ -  val = htonl(val); - -  return Write((char*)&val, sizeof(val)); -} - -int File::Write(int val) -{ -  val = htonl(val); - -  return Write((char*)&val, sizeof(val)); -} - -int File::Write(unsigned int val) -{ -  val = htonl(val); - -  return Write((char*)&val, sizeof(val)); -} -int File::Write(short int val) -{ -  val = htons(val); - -  return Write((char*)&val, sizeof(val)); -} - -int File::Write(unsigned short int val) -{ -  val = htons(val); - -  return Write((char*)&val, sizeof(val)); -} -*/  int File::createPath(char* path)  {    //  struct stat stats; @@ -281,9 +213,10 @@ int File::createPath(char* path)    return 0;  } -void File::setSaveState(n_savestate savestate) +void File::setSaveState(n_savestate s)  { -  this->savestate = savestate; +  savestate = s; +  info->info("SETTING SAVESTATE TO: %d", savestate);  }  #ifdef __TEST_FILE @@ -68,6 +68,8 @@ private:    int Open(); +  int Move(char *destination); +    int fd;    int num; diff --git a/src/server.cc b/src/server.cc index 2ecb4be..f4b6806 100644 --- a/src/server.cc +++ b/src/server.cc @@ -101,6 +101,7 @@ void newConnection(Socket *socket, Info *info)      if(h.header.h_data.savestate) {        savestate = h.header.h_data.savestate; +      info->info("GOT SAVESTATE FROM NETWORK: %d", savestate );      }      if(h.header.h_data.freeze) { | 
