GreenCloud Simulator
provideroutagent.cc
Go to the documentation of this file.
1 /*
2  * provideroutagent.cc
3  *
4  * @date Nov 12, 2013
5  * @author Guzek:Mateusz
6  */
7 
8 #include "provideroutagent.h"
9 #include "cloudtask.h"
10 
11 static class ProvOutAgentClass : public TclClass {
12 public:
13  ProvOutAgentClass() : TclClass("Agent/TCP/ProvOutAgent") {}
14  TclObject* create(int, const char*const*) {
15  return (new ProviderOutAgent());
16  }
18 
19 ProviderOutAgent::ProviderOutAgent() : lastTrackedBytes_(0),lastTrackedTime_(0.0){
20 
21  lastTrackedTime_ = Scheduler::instance().clock();
22 // lastTrackedBytes = this->getNdatabytes();
23 }
24 
26  PoaBuf* tmp;
27  while(true){
28  tmp = poabuf_.detach();
29  if(tmp!=NULL){
30  delete tmp;
31  } else {
32  break;}
33  }
34 }
35 
37  int result = getNdatabytes() - lastTrackedBytes_;
38  lastTrackedBytes_ = getNdatabytes();
39  return result;
40 }
41 
43  double result = lastTrackedTime_;
44  lastTrackedTime_ = Scheduler::instance().clock();
45  return result;
46 }
47 
48 void ProviderOutAgent::sendmsg(int nbytes, void* pointer){
49  poabuf_.insert(new PoaBuf( pointer,nbytes));
50  tryToSend();
51 }
52 
54  if(current_pointer_==NULL){
55  PoaBuf* cb = poabuf_.detach();
56  if(cb!=NULL){
57  TcpAgent::sendmsg(cb->bytes(),(void*) cb->pointer());
58  delete cb;
59  }
60  }
61 }
62 
63 PoaBuf::PoaBuf(void *c, int nbytes)
64 {
65  nbytes_ = nbytes;
66  pointer_=c;
67  next_ = NULL;
68 }
69 
71 {
72  while (head_ != NULL) {
73  tail_ = head_;
74  head_ = head_->next_;
75  delete tail_;
76  }
77 }
78 
80 {
81  if (tail_ == NULL)
82  head_ = tail_ = poabuf;
83  else {
84  tail_->next_ = poabuf;
85  tail_ = poabuf;
86  }
87 }
88 
90 {
91  if (head_ == NULL)
92  return NULL;
93  PoaBuf *p = head_;
94  if ((head_ = head_->next_) == NULL)
95  tail_ = NULL;
96  return p;
97 }
98 
99 
100 
TclObject * create(int, const char *const *)
virtual ~ProviderOutAgent()
void * pointer()
void insert(PoaBuf *poabuf)
PoaBuf * next_
PoaBuf * detach()
ProvOutAgentClass class_tsk_provoutagent
PoaBuf(void *c, int nbytes)
int bytes()
void sendmsg(int nbytes, void *pointer)