00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "rmst_sink.hh"
00044
00045 #ifdef NS_DIFFUSION
00046 static class RmstSnkClass : public TclClass {
00047 public:
00048 RmstSnkClass() : TclClass("Application/DiffApp/RmstSink") {}
00049 TclObject* create(int , const char*const* ) {
00050 return(new RmstSink());
00051 }
00052 } class_rmst_sink;
00053
00054 int RmstSink::command(int argc, const char*const* argv)
00055 {
00056 if (argc == 2) {
00057 if (strcmp(argv[1], "subscribe") == 0) {
00058 run();
00059 return TCL_OK;
00060 }
00061 }
00062 return DiffApp::command(argc, argv);
00063 }
00064
00065 #endif // NS_DIFFUSION
00066
00067 void RmstSnkReceive::recv(NRAttrVec *data, NR::handle my_handle)
00068 {
00069 NRSimpleAttribute<int> *rmst_id_attr = NULL;
00070 NRSimpleAttribute<void *> *data_buf_attr = NULL;
00071 timeval cur_time;
00072 int rmst_no;
00073 int size;
00074 void *blob_ptr;
00075
00076 printf("RMST-SNK::recv callback got an NRAttrVec.\n");
00077 GetTime (&cur_time);
00078 printf(" time: sec = %d\n", (unsigned int) cur_time.tv_sec);
00079
00080 rmst_id_attr = RmstIdAttr.find(data);
00081 data_buf_attr = RmstDataAttr.find(data);
00082
00083 rmst_no = rmst_id_attr->getVal();
00084 blob_ptr = data_buf_attr->getVal();
00085 size = data_buf_attr->getLen();
00086
00087 printf(" Got a blob, rmstId = %d, size = %d\n", rmst_no, size);
00088 snk_->recv((void *)blob_ptr, size);
00089 }
00090
00091 void RmstSink::run() {
00092 rmst_handle_ = setupInterest();
00093 #ifndef NS_DIFFUSION
00094 while (1){
00095 sleep (1000);
00096 }
00097 #endif // !NS_DIFFUSION
00098 }
00099
00100 void RmstSink::recv(void *blob, int size) {
00101 int i;
00102 char *tmpPtr = (char*)blob;
00103 printf(" Sink received a large blob - size = %d\n", size);
00104 for(i=0; i<size; i+=50){
00105 printf("%s\n", &tmpPtr[i]);
00106 }
00107 no_rec_++;
00108 if(no_rec_ >= blobs_to_rec_){
00109 printf(" Sink unsubscribes\n");
00110 dr_->unsubscribe(rmst_handle_);
00111 }
00112 }
00113
00114 handle RmstSink::setupInterest()
00115 {
00116 NRAttrVec attrs;
00117
00118 printf("RMST-SNK::subscribing to all PCM_SAMPLEs\n");
00119
00120 attrs.push_back(NRClassAttr.make(NRAttribute::IS, NRAttribute::INTEREST_CLASS));
00121 attrs.push_back(RmstTsprtCtlAttr.make(NRAttribute::EQ, RMST_RESP));
00122 attrs.push_back(RmstTargetAttr.make(NRAttribute::EQ, "PCM_SAMPLE"));
00123
00124 handle h = dr_->subscribe(&attrs, mr);
00125
00126 ClearAttrs(&attrs);
00127 return h;
00128 }
00129
00130 #ifdef NS_DIFFUSION
00131 RmstSink::RmstSink() : blobs_to_rec_(4) {
00132 #else
00133 RmstSink::RmstSink(int argc, char **argv) : blobs_to_rec_(4) {
00134 #endif // NS_DIFFUSION
00135
00136 mr = new RmstSnkReceive(this);
00137
00138 #ifndef NS_DIFFUSION
00139 parseCommandLine(argc, argv);
00140 dr_ = NR::createNR(diffusion_port_);
00141 #endif // !NS_DIFFUSION
00142 no_rec_ = 0;
00143 }
00144
00145 #ifndef NS_DIFFUSION
00146 int main(int argc, char **argv){
00147 RmstSink *app;
00148
00149 app = new RmstSink(argc, argv);
00150 app->run();
00151 return 0;
00152 }
00153 #endif // !NS_DIFFUSION