//defining s Constructor for every RHINO node that runs the ClusterServer Application int main(int argc, char *argv[]) { //defining variables int pid; int portno; char buffer[256]; RhinoT rhinoDevice, *rhinoDevicePtr; RegisterT *rhinoRegistersPtr, rhinoRegisters; server_stateT *st; /* Is the structure containing an internet address and is defined in netinet/in.h Will contain the address of the client and serv_addr will contain address of the server */ printf("Entering main\n"); rhinoDevicePtr = &rhinoDevice; rhinoRegistersPtr = &rhinoRegisters; //if no arguments have been passed in on the console if (argc < 2) { error("Error, no port provided\n"); } st = create_server(); if(st == NULL){ error("unable to allocate local server state"); } portno = atoi(argv[1]); //getting the port number from the console //MAYBE INITIALIZE THE RHINO HERE BEFORE USED initializeMethod(rhinoDevicePtr, rhinoRegistersPtr); if(connect_sockets(portno, rhinoDevicePtr,rhinoRegistersPtr, st) < 0) { error("Error connecting socket\n"); } destroy_server(st); return 0; //this terminates the whole main program but we never get here }
/** the main loop for a task creator */ void TaskCreator::mainLoop(){ if(!m_initialized){ #ifdef DEBUG_TASK_CREATOR cout<<"Initializing"<<endl; #endif initializeMethod(); m_initialized=true; m_completedJobs=0; } if(hasUnassignedTask()){ if(m_virtualProcessor->canAddWorker()){ Worker*worker=assignNextTask(); #ifdef DEBUG_TASK_CREATOR cout<<"Adding worker to pool worker= "<<worker<<" processor="<<m_virtualProcessor<<endl; #endif #ifdef CONFIG_ASSERT assert(worker != NULL); assert(m_virtualProcessor != NULL); #endif m_virtualProcessor->addWorker(worker); /* tell the VirtualProcessor that no more tasks will be created */ if(!hasUnassignedTask()){ #ifdef DEBUG_TASK_CREATOR cout<<"No more task are coming."<<endl; #endif m_virtualProcessor->noMoreTasksAreComing(); } } } Worker*worker=NULL; bool aWorkerWorked=m_virtualProcessor->run(); if(aWorkerWorked){ worker=m_virtualProcessor->getCurrentWorker(); } if(worker!=NULL && worker->isDone()){ #ifdef DEBUG_TASK_CREATOR cout<<"Current worker is done"<<endl; #endif processWorkerResult(worker); destroyWorker(worker); m_completedJobs++; } if(!hasUnassignedTask() && !m_virtualProcessor->hasWorkToDo()){ finalizeMethod(); m_virtualProcessor->printStatistics(); m_virtualProcessor->reset(); #ifdef DEBUG_TASK_CREATOR cout<<"calling finalizeMethod()"<<endl; #endif } }