Beispiel #1
0
GF_EXPORT
GF_Err gf_modules_close_interface(GF_BaseInterface *ifce)
{
	ModuleInstance *par;
	s32 i;
	if (!ifce) return GF_BAD_PARAM;
	par = (ModuleInstance *) ifce->HPLUG;

	if (!par || !ifce->InterfaceType) return GF_BAD_PARAM;

	i = gf_list_find(par->plugman->plug_list, par);
	if (i<0) return GF_BAD_PARAM;

	i = gf_list_find(par->interfaces, ifce);
	if (i<0) return GF_BAD_PARAM;
	gf_list_rem(par->interfaces, (u32) i);
	par->destroy_func(ifce);
	gf_modules_unload_library(par);
	//GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] interface %s unloaded\n", ifce->module_name));
	return GF_OK;
}
Beispiel #2
0
GF_EXPORT
GF_BaseInterface *gf_modules_load_interface(GF_ModuleManager *pm, u32 whichplug, u32 InterfaceFamily)
{
	const char *opt;
	char szKey[32];
	ModuleInstance *inst;
	GF_BaseInterface *ifce;

	if (!pm){
		GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] gf_modules_load_interface() : No Module Manager set\n"));
		return NULL;
	}
	inst = (ModuleInstance *) gf_list_get(pm->plug_list, whichplug);
	if (!inst){
		GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] gf_modules_load_interface() : no module %d exist.\n", whichplug));
		return NULL;
	}
	GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Load interface...%s\n", inst->name));
	/*look in cache*/
	if (!pm->cfg){
		GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] No pm->cfg has been set !!!\n"));
		return NULL;
	}
	opt = gf_cfg_get_key(pm->cfg, "PluginsCache", inst->name);
	if (opt) {
		const char * ifce_str = gf_4cc_to_str(InterfaceFamily);
		snprintf(szKey, 32, "%s:yes", ifce_str ? ifce_str : "(null)");
		if (!strstr(opt, szKey)){
			return NULL;
		}
	}
	if (!gf_modules_load_library(inst)) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] Cannot load library %s\n", inst->name));
		gf_cfg_set_key(pm->cfg, "PluginsCache", inst->name, "Invalid Plugin");
		return NULL;
	}
	if (!inst->query_func) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] Library %s missing GPAC export symbols\n", inst->name));
		gf_cfg_set_key(pm->cfg, "PluginsCache", inst->name, "Invalid Plugin");
		goto err_exit;
	}

	/*build cache*/
	if (!opt) {
		u32 i;
		Bool found = 0;
		char *key;
		const u32 *si = inst->query_func();
		if (!si) {
			GF_LOG(GF_LOG_WARNING, GF_LOG_CORE, ("[Core] GPAC module %s has no supported interfaces - disabling\n", inst->name));
			gf_cfg_set_key(pm->cfg, "PluginsCache", inst->name, "Invalid Plugin");
			goto err_exit;
		}
		i=0;
		while (si[i]) i++;

		key = gf_malloc(sizeof(char) * 10 * i);
		key[0] = 0;
		i=0;
		while (si[i]) {
			snprintf(szKey, 32, "%s:yes ", gf_4cc_to_str(si[i]));
			strcat(key, szKey);
			if (InterfaceFamily==si[i]) found = 1;
			i++;
		}
		gf_cfg_set_key(pm->cfg, "PluginsCache", inst->name, key);
		gf_free(key);
		if (!found) goto err_exit;
	}

	if (!inst->query_func || !inst->query_func(InterfaceFamily) ) goto err_exit;
	ifce = (GF_BaseInterface *) inst->load_func(InterfaceFamily);
	/*sanity check*/
	if (!ifce) goto err_exit;
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
	if (!strcmp(inst->name, "gm_sdl_out.dylib")) {
		if (InterfaceFamily == GF_VIDEO_OUTPUT_INTERFACE) {
			ifce = SDL_Module_Load_Video();
			fprintf(stderr, "***         Loading SDL Video: %p ***\n", ifce);
		} else if (InterfaceFamily == GF_AUDIO_OUTPUT_INTERFACE) {
			ifce = SDL_Module_Load_Audio();
			fprintf(stderr, "***         Loading SDL Audio: %p ***\n", ifce);
		}
	}
#endif
	if (!ifce->module_name || (ifce->InterfaceType != InterfaceFamily)) {
		inst->destroy_func(ifce);
		goto err_exit;
	}
	gf_list_add(inst->interfaces, ifce);
	/*keep track of parent*/
	ifce->HPLUG = inst;
	GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Load interface %s DONE.\n", inst->name));
	return ifce;

err_exit:
	GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Load interface %s exit label, freing library...\n", inst->name));
	gf_modules_unload_library(inst);
	GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("[Core] Load interface %s EXIT.\n", inst->name));
	return NULL;
}
Beispiel #3
0
 Literal invoke() {
   return instance->callExport(name, arguments);
 }
Beispiel #4
0
int main(int argc, char *argv[]){
  try {
    // JBS little trick. Baptize the logger with a nice module
    // instance so that the logging will be focused.
    
    ModuleInstance myself("localhost", "anycast", "core", "theonlyone");
    OcfaLogger::Instance()->baptize(&myself);
    OcfaGroup groupguard("ocfa");
    Anycast::AnyCast *a;
    
    if (OcfaConfig::Instance()->getValue("daemonize") != "false"){
      daemonize();
    }
    if (OcfaConfig::Instance()->getValue("recover") == "true"){
      a = new Anycast::AnyCast("anycast", "anycast", true); 
    } else {
      a = new Anycast::AnyCast("anycast", "anycast", false);
    }
    AnycastMessageBox *mb = dynamic_cast<AnycastMessageBox *>(MessageBox::createInstance("anycast", "anycast"));
    if (!mb){
      OcfaLogger::Instance()->syslog(LOG_ERR, "main ") << "MessageBox not expected type !" << endl;
      return 1;
    }
    Anycast::MonitorMessageFactory *factory = new Anycast::MonitorMessageFactory(mb);
    a->setMonitorMessageFactory(&factory);
    Message *msg = 0;
    bool haltreceived = false;
    while ((!haltreceived) || (a->getActiveModuleCount() > 0)){
      
      msg = mb->getNextMessage(100, 0);
      
      if (msg != 0){
	ModuleInstance *sender = msg->getSender();  
	string instanceuri = sender->getInstanceURI();
	string modulename = sender->getModuleName();
	a->getLogStream(LOG_INFO) << "Received message type: " << static_cast<int>(msg->getType()) 
				  << "and prio " << msg->getPriority() << endl;
	switch (msg->getType()){
	case Message::mtTaskProgress:{
	  a->getLogStream(LOG_INFO) << "Message::mtTaskProgress" << endl;
	  ModuleInstance *receiver = msg->getReceiver();
	  string instreceiver = receiver->getInstanceURI();
	  string instmodname = receiver->getModuleName();
	  unsigned int id = atoi(msg->getSubject().c_str());
	  a->dropMessage(instmodname, instreceiver, id);
	  if (haltreceived){
	    break; // stop sending new messages when halt is received
	  }
	  Message *tosend = a->getMessage(instmodname);
	  id = MsgIDBroker::Instance()->lastID();
	  if (tosend != 0){
	    mb->sendTask(tosend, id); // the message 'tosend' will be deleted if task is done
	  }
	  break;
	};		   
	case Message::mtModuleInstance:{
	  a->getLogStream(LOG_INFO) << "Message::mtModuleInstance" << endl;
          OcfaLogger::Instance()->syslog(ocfa::misc::LOG_INFO, "Anycast: ") << "Received mtModuleInstance: " << instanceuri << endl;
          // copy sender because it will be used and stored by anycast
          ModuleInstance *copysender = new ModuleInstance(sender);
	  a->addModuleInstance(modulename, instanceuri, copysender);
	  Message *tosend = 0;
	  while ((tosend = a->getMessage(modulename))!= 0){
	    unsigned int id = MsgIDBroker::Instance()->lastID();
	    mb->sendTask(tosend, id); // the message 'tosend' will be deleted if task is done
	  }
	  a->printQueues();
	  break;
	};
	case Message::mtModuleDisconnect:{
	  a->getLogStream(LOG_INFO) << "Message::mtModuleDisconnect" << endl;
	  a->removeModuleInstance(modulename, instanceuri);
	  a->printQueues();
	  break;
	}
	case Message::mtHalt: {
	  OcfaLogger::Instance()->syslog(ocfa::misc::LOG_NOTICE, "Anycast: ") << "Received HALT. Waiting for " << a->getActiveModuleCount() << " modules to go away ..." << endl;
       
	  haltreceived = true;
	  break;
	}
	case Message::mtRecover: {//FIXME: think we need to do something here.
	  a->getLogStream(LOG_INFO) << "Message::mtRecover" << endl;   
	  break;
	}
	case Message::mtEvidence:{
	  a->getLogStream(LOG_INFO) << "Message::mtEvidence" << endl;
	}
	case Message::mtSubscribe:
	case Message::mtUnsubscribe:
	case Message::mtEOC:
	case Message::mtHeartBeat:
	case Message::mtSystem:			 
	  // all other messages should probably be relayed
	  a->getLogStream(LOG_INFO) << "Processable message" << endl;
	  ModuleInstance *recepient = msg->getReceiver();
	  string rcptmodulename = recepient->getModuleName(); // modulename is used to denote moduletype
	  a->addMessage(rcptmodulename, msg);
	  if (haltreceived){
	    a->getLogStream(LOG_INFO) << "HALT STATE: dropping message" << endl;
	    break; // if we receive a halt, we stop sending new tasks
	  }
	  Message *tosend = a->getMessage(rcptmodulename);
	  unsigned int id = MsgIDBroker::Instance()->lastID();
	  a->printQueues();
	  if (tosend != 0){
	    a->getLogStream(LOG_INFO) << "Calling sendTask on messagebox" << endl;
	    mb->sendTask(tosend, id); // the message 'tosend' will be deleted if task is done
	  } else {
            a->getLogStream(LOG_INFO) << "Problem getting at message" << endl;
	  }
	  // Check whether there are any messages for the monitor. This is one of the times that the
	  // anycast cannot simple react on new messages. 
	  tosend = a->getMessage("monitor");
	  if (tosend != 0){
	    unsigned int id = MsgIDBroker::Instance()->lastID();
	    a->printQueues();
	    if (tosend != 0){
	      a->getLogStream(LOG_INFO) << "Calling sendTask on messagebox" << endl;
	      mb->sendTask(tosend, id); // the message 'tosend' will be deleted if task is done
	    } else {
	      a->getLogStream(LOG_INFO) << "Problem getting at message" << endl;
	    }
	  }
	}
	delete msg;
        msg = 0;
      }
    }

    a->Log( "Exiting the Anycast module on user request!");

    delete a;
    OcfaLogger::Instance()->syslog(LOG_DEBUG, "main: ") << "Deleted AnyCast object. Deleting MessageBox .." << endl;
    delete mb;
    OcfaLogger::Instance()->syslog(LOG_DEBUG, "main: ") << "MessageBox deleted. Anycast done !" << endl;
  } catch (OcfaException &e) {
    std::cerr << "Exception: " << e.what() << endl;
    //e.logWhat();
    return -1;
  } catch (exception &e) {
    OcfaLogger::Instance()->syslog(LOG_ERR, "main ") << "Exception: " << e.what() << endl;
    return -1; 
  }


  return 0;
}
Beispiel #5
0
static void run_asserts(size_t* i, bool* checked, AllocatingModule* wasm,
                        Element* root,
                        std::unique_ptr<SExpressionWasmBuilder>* builder,
                        Name entry) {
  ShellExternalInterface* interface = nullptr;
  ModuleInstance* instance = nullptr;
  if (wasm) {
    interface = new ShellExternalInterface();
    instance = new ModuleInstance(*wasm, interface);
    if (entry.is()) {
      Function* function = wasm->getFunction(entry);
      if (!function) {
        std::cerr << "Unknown entry " << entry << std::endl;
      } else {
        ModuleInstance::LiteralList arguments;
        for (NameType param : function->params) {
          arguments.push_back(Literal(param.type));
        }
        try {
          instance->callExport(entry, arguments);
        } catch (ExitException&) {
        }
      }
    }
  }
  while (*i < root->size()) {
    Element& curr = *(*root)[*i];
    IString id = curr[0]->str();
    if (id == MODULE) break;
    *checked = true;
    Colors::red(std::cerr);
    std::cerr << *i << '/' << (root->size() - 1);
    Colors::green(std::cerr);
    std::cerr << " CHECKING: ";
    Colors::normal(std::cerr);
    std::cerr << curr << '\n';
    if (id == ASSERT_INVALID) {
      // a module invalidity test
      AllocatingModule wasm;
      bool invalid = false;
      std::unique_ptr<SExpressionWasmBuilder> builder;
      try {
        builder = std::unique_ptr<SExpressionWasmBuilder>(
          new SExpressionWasmBuilder(wasm, *curr[1], [&]() {
            invalid = true;
            throw ParseException();
          })
        );
      } catch (const ParseException&) {
        invalid = true;
      }
      if (!invalid) {
        // maybe parsed ok, but otherwise incorrect
        invalid = !WasmValidator().validate(wasm);
      }
      assert(invalid);
    } else if (id == INVOKE) {
      assert(wasm);
      Invocation invocation(curr, instance, *builder->get());
      invocation.invoke();
    } else {
      // an invoke test
      assert(wasm);
      bool trapped = false;
      Literal result;
      try {
        Invocation invocation(*curr[1], instance, *builder->get());
        result = invocation.invoke();
      } catch (const TrapException&) {
        trapped = true;
      }
      if (id == ASSERT_RETURN) {
        assert(!trapped);
        if (curr.size() >= 3) {
          Literal expected = builder->get()
                                 ->parseExpression(*curr[2])
                                 ->dyn_cast<Const>()
                                 ->value;
          std::cerr << "seen " << result << ", expected " << expected << '\n';
          verify_result(expected, result);
        } else {
          Literal expected;
          std::cerr << "seen " << result << ", expected " << expected << '\n';
          verify_result(expected, result);
        }
      }
      if (id == ASSERT_TRAP) assert(trapped);
    }
    *i += 1;
  }
}
    // this method should only be called by client-like applications
    bool ConnectMessagingEndPoint::connect(){
      ACE_SOCK_Connector _connector_send, _connector_receive ;

      // try creating a listen in range 23200-30000
      int baseport=23200;
      ReceiveSockHandler *receivesockhandler = 0;

      while (baseport < 30000){
	try {
	  receivesockhandler = new ReceiveSockHandler(baseport);
	  break;
	} catch (std::string &e){
	  getLogStream(LOG_INFO) << "SockHandler construct failed for port " << baseport << endl;
	  baseport++;
	}
      }
      if (receivesockhandler == 0){
	throw OcfaException("Create listen failed");
      } else {
	getLogStream(LOG_DEBUG) << "Listening on " << baseport << endl;
      }

      if (ACE_Reactor::instance()->register_handler(receivesockhandler, ACE_Event_Handler::ACCEPT_MASK) == -1){
	ocfaLog(LOG_ERR,"Register of receivehandler failed");
	return false;
      }
     
      // now start the thread which waits for incoming connections
      activate();

      // connect our outgoing stream
      if (_connector_send.connect(_sock_outstream,_remote_addr_send) == -1){
	ocfaLog(LOG_ERR, "connect failed"); 
	return false;  
      } else {
	ocfaLog(LOG_DEBUG, "Connector open succeeded");	
	// connected ! 
	// create message holding info, serialize and send
	ACE_INET_Addr localendpoint;
	_sock_outstream.get_local_addr(localendpoint);
	ostringstream instname; 
	instname << "Inst" << localendpoint.get_port_number();

	// delete the old modinst and replace with a more accurate one
	string mname = _moduleinstance->getModuleName();
	string mnamespace = _moduleinstance->getNameSpace(); 
	delete(_moduleinstance);
	ocfaLog(LOG_DEBUG,"IP is: " + string(localendpoint.get_host_addr()));
	_moduleinstance = new ModuleInstance(localendpoint.get_host_addr(), mname, mnamespace, instname.str());
	_moduleinstance->setPort(localendpoint.get_port_number());

	ModuleInstance *mcopy = new ModuleInstance(*_moduleinstance); 
	mcopy->setPort(localendpoint.get_port_number());
	ostringstream strbaseport;
	strbaseport << baseport;
	Message *sockinfo = new ConcreteMessage(_moduleinstance, mcopy, Message::BROADCAST, Message::mtModuleInstance, strbaseport.str(), "", 0);
	//RJM:CODEREVIEW shouldn't we be deleting mcopy
	MessageWrapper *msgwrapper = new MessageWrapper(MessageWrapper::mwInternalConnect, sockinfo);  
	getLogStream(LOG_DEBUG) << "MessageType: " <<  static_cast<int>(sockinfo->getType()) 
				<< " moduleinstance: " << sockinfo->getReceiver()->getInstanceURI() << endl;
        sndMessage(msgwrapper);	
	ocfaLog(LOG_DEBUG, "Sent message. Deleting");  
	delete msgwrapper;
	delete sockinfo;
	return true;
      }
    }