summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/mpeg/source/server/Video_Repository.cpp
blob: 620cbe65189f584c6a38af8a9788af548a963820 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// $Id$

#include "Video_Repository.h"
#include "ace/Read_Buffer.h"

ACE_RCSID(server, Video_Repository, "$Id$")

const char* TAO_Video_Repository::MOVIE_INFO = "Movie_Info";

TAO_Video_Repository::TAO_Video_Repository (const char* file_name)
  : filename_ (file_name),
    movie_info_ (0),
    num_movies_ (0),
    lastchanged_ (0)
{
}

TAO_Video_Repository::~TAO_Video_Repository (void)
{
  TAO_VR::Movie_Info::freebuf (this->movie_info_);
}

CORBA::Any*
TAO_Video_Repository::evalDP (const char* name,
                              CORBA::TypeCode_ptr returned_type,
                              const CORBA::Any& extra_info,
			      CORBA::Environment& _env)
  TAO_THROW_SPEC ((CosTradingDynamic::DPEvalFailure))
{
  CORBA::Any* return_value = 0;
  ACE_NEW_RETURN (return_value, CORBA::Any, 0);
  
  struct stat file_stat;
  if (ACE_OS::stat (this->filename_, &file_stat) == 0)
    {      
      if (this->lastchanged_ < file_stat.st_mtime)
	{
	  FILE* file = ACE_OS::fopen (this->filename_, "r");
	  
	  if (file != 0)
	    {
	      // Read the file into a buffer
	      ACE_Read_Buffer read_file (file, 1);
	      char* database = read_file.read (EOF, '\n', '%');	      

	      // Parse the file into a sequence and insert it into an
	      // Any (i.e., this->return_)
	      TAO_Video_Repository::parse_file (database,
						read_file.replaced ());
	      
	      ACE_Allocator* alloc = ACE_Allocator::instance ();
	      alloc->free (database);

	      this->lastchanged_ = file_stat.st_mtime;
	    }
	}

      TAO_VR::Movie_Info* movie_info = 0;
      ACE_NEW_RETURN (movie_info,
		      TAO_VR::Movie_Info (this->num_movies_,
					  this->num_movies_,
					  this->movie_info_,
					  CORBA::B_FALSE),
		      0);
      
      (*return_value) <<= movie_info;
    }

  return return_value;
}

void
TAO_Video_Repository::parse_file (const char* database, int num_lines)
{
  const char* delim = "%";
  CORBA::ULong i = 0;
  CORBA::Any* return_value = 0;
  char* current = (char *) database;

  ACE_DEBUG ((LM_DEBUG, "Recomputing the movie stats.\n"));
  
  TAO_VR::Movie_Info::freebuf (this->movie_info_);

  this->movie_info_ = TAO_VR::Movie_Info::allocbuf (num_lines);

  if (this->movie_info_ != 0)
    {
      current = ACE_OS::strtok (current, "%");
      while (current != 0)
	{
	  TAO_VR::Movie& movie = this->movie_info_[i];
	  
	  movie.name_ = (const char*) current;
	  movie.filename_ = (const char*) ACE_OS::strtok (0, delim);
	  movie.description_ = (const char*) ACE_OS::strtok (0, delim);
	  
	  ACE_DEBUG ((LM_DEBUG,
		      "Movie Name: %s\nFile Name: %s\nDescription: %s\n",
		      (const char *) movie.name_,
		      (const char *) movie.filename_,
		      (const char *) movie.description_));
	  
	  // From the actual movie file, extract the techincal information.
	  TAO_Video_Repository::
	    obtain_movie_info (movie.filename_, movie);
           
	  current = ACE_OS::strtok (0, delim);
	  i++;
	}
    }

  this->num_movies_ = num_lines;
}

void
TAO_Video_Repository::
export_properties (TAO_Property_Exporter& prop_exporter)
{
  CORBA::Any extra_info;

  extra_info <<= MOVIE_INFO;
  CosTradingDynamic::DynamicProp* dp_struct =
    this->construct_dynamic_prop (MOVIE_INFO,
                                  TAO_VR::_tc_Movie_Info,
                                  extra_info);  

  prop_exporter.add_dynamic_property (MOVIE_INFO, dp_struct);
}

int
TAO_Video_Repository::
define_properties (CosTradingRepos::ServiceTypeRepository::PropStructSeq& prop_seq,
		   CORBA::ULong offset) const
{
  CORBA::ULong num_props = prop_seq.length ();

  if (num_props <= offset)
    prop_seq.length (offset + 1);

  prop_seq[offset].name = MOVIE_INFO;
  prop_seq[offset].value_type = CORBA::TypeCode::_duplicate (TAO_VR::_tc_Movie_Info);
  prop_seq[offset].mode = CosTradingRepos::ServiceTypeRepository::PROP_MANDATORY;

  return 1;
}