ISAAC
Overview :: Library Doc :: Server Doc :: JSON Commands

In Situ Animation of Accelerated Computations

URIImageConnector.cpp
Go to the documentation of this file.
1 /* This file is part of ISAAC.
2  *
3  * ISAAC is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or(at your option) any later version.
7  *
8  * ISAAC is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with ISAAC. If not, see <www.gnu.org/licenses/>. */
15 
16 #include "URIImageConnector.hpp"
17 
18 #include <boost/archive/iterators/base64_from_binary.hpp>
19 #include <boost/archive/iterators/insert_linebreaks.hpp>
20 #include <boost/archive/iterators/transform_width.hpp>
21 #include <boost/archive/iterators/ostream_iterator.hpp>
22 #include <sstream>
23 
25 {
26 }
27 
29 {
30  return "JPEG_URI_Stream";
31 }
32 
33 errorCode URIImageConnector::init(int minport,int maxport)
34 {
35  return 0;
36 }
37 
38 void isaac_init_destination(j_compress_ptr cinfo)
39 {
40 }
41 boolean isaac_jpeg_empty_output_buffer(j_compress_ptr cinfo)
42 {
43  return true;
44 }
45 void isaac_jpeg_term_destination(j_compress_ptr cinfo)
46 {
47 }
48 
50 {
51  uint64_t finish = 0;
52  while(finish == 0)
53  {
54  ImageBufferContainer* message;
55  while(message = clientGetMessage())
56  {
57  if (message->type == GROUP_OBSERVED)
58  {
59  streams.insert( std::pair<void*,InsituConnectorGroup*>(message->reference,message->group));
60  uint8_t* dummy = (uint8_t*)malloc(1);
61  dummy[0] = 0; //empty string
62  clientSendMessage(new ImageBufferContainer(REGISTER_STREAM,dummy,message->group,1,message->target,message->reference));
63  printf("URIImageConnector: Openend URI JPEG Stream\n");
64  }
65  if (message->type == GROUP_OBSERVED_STOPPED || message->type == GROUP_FINISHED)
66  {
67  auto it = streams.begin();
68  while (it != streams.end())
69  {
70  auto next_it = std::next(it);
71  if ((!message->reference || it->first == message->reference) && it->second == message->group)
72  {
73  streams.erase(it);
74  printf("URIImageConnector: Closed Stream\n");
75  }
76  it = next_it;
77  }
78  }
79  if (message->type == UPDATE_BUFFER)
80  {
81  for (auto it = streams.begin(); it != streams.end(); it++)
82  {
83  if (it->second == message->group)
84  {
85  pthread_mutex_lock (&(message->json_mutex));
86  pthread_mutex_lock (&(message->payload_mutex));
87  if ( json_object_get( message->json, "payload" ) == NULL)
88  json_object_set( message->json, "payload", message->payload );
89  pthread_mutex_unlock (&(message->payload_mutex));
90  pthread_mutex_unlock (&(message->json_mutex));
91  }
92  }
93  }
94  if (message->type == IMG_FORCE_EXIT)
95  finish = 1;
96  clientSendMessage( message );
97  }
98  usleep(1000);
99  }
100 }
101 
103 {
104 }
105 
ImageBufferContainer * clientGetMessage()
Definition: MessageAble.hpp:38
errorCode clientSendMessage(ImageBufferContainer *message)
Definition: MessageAble.hpp:34
InsituConnectorGroup * group
Definition: Common.hpp:196
errorCode init(int minport, int maxport)
pthread_mutex_t json_mutex
Definition: Common.hpp:201
boolean isaac_jpeg_empty_output_buffer(j_compress_ptr cinfo)
int errorCode
Definition: Common.hpp:24
void isaac_jpeg_term_destination(j_compress_ptr cinfo)
ImageBufferType type
Definition: Common.hpp:195
std::string target
Definition: Common.hpp:197
pthread_mutex_t payload_mutex
Definition: Common.hpp:202
void isaac_init_destination(j_compress_ptr cinfo)