Example #1
0
 /** Searches for a config file in the command-line arguments,
  * environment, and finally in a default location.  WARNING:
  * if no valid config file is found, the value of the result
  * parameter is unspecified!  Always make sure to check the return
  * value!
  * @param argc Argument count
  * @param argv Argument list
  * @param result std::string reference to store the path, if any
  * @return true if a config file is found, false otherwise.
  */
 bool findConfigFile(int argc, char** argv, string& result)
 {
   if      ( checkArgs(argc, argv, result) ) return true;
   else if ( checkEnv(result) ) return true;
   else if ( checkDefault(result) ) return true;
   else return false;
 }
SOM_Scope void  SOMLINK deleteEventChannel(ApptBookEventService *somSelf,
                                            Environment *ev)
{
    ApptBookEventServiceData *somThis = ApptBookEventServiceGetData(somSelf);
    ApptBookEventServiceMethodDebug("ApptBookEventService","deleteEventChannel");

    CosNaming_NamingContext      *nameContext=NULL;
    CosNaming_Name               Name;


    nameContext = somThis->ECNameContext;
    Name = somThis->ECName;
    if (nameContext != NULL)
    {
     nameContext->unbind(ev, &Name);
     checkEnv(ev);
    }
}
void getEnvPackage (link_datatype *buf)
{
	struct getEnvMsg pack;
	memcpy (&pack, buf->text, 20);
	int sto_no = pack.sto_no;

	pthread_mutex_lock (&mutex_global);
	struct storage_info current = all_info_RT.storage_no[sto_no];
	pthread_mutex_unlock (&mutex_global);

	current.storage_status = 1;
	current.x = pack.x;
	current.y = pack.y;
	current.z = pack.z;
	current.temperature = pack.tem[0] + dota_atof (pack.tem[1]);
	current.humidity = pack.hum[0] + dota_atof (pack.hum[1]);
	current.illumination = pack.ill;
	current.battery = dota_adc (pack.battery);
	current.adc = dota_adc (pack.adc);

	printf ("no = %d tem = %0.2f hum = %0.2f ill = %0.2f battery = %0.2f adc = %0.2f x = %d y = %d z = %d\n", sto_no,
			current.temperature, current.humidity, current.illumination, current.battery, current.adc, current.x, current.y, current.z);

	checkEnv (sto_no, &current);	

	pthread_mutex_lock (&mutex_global);
	all_info_RT.storage_no[sto_no] = current;

	pthread_mutex_lock (&mutex_slinklist);
	sqlite_InsertLinknode (COLLECT_INSERTER, all_info_RT, sto_no, 0);//0,0分别是仓库号和货物种类号
	pthread_mutex_unlock (&mutex_slinklist);
	pthread_mutex_unlock (&mutex_global);

	pthread_cond_signal (&cond_refresh);
	pthread_cond_signal (&cond_sqlite);


	return ;
}
SOM_Scope void  SOMLINK initEventService(ApptBookEventService *somSelf,
                                          Environment *ev)
{

  ApptBookEventServiceMethodDebug("ApptBookEventService","initEventService");
  ApptBookEventServiceData *somThis = ApptBookEventServiceGetData(somSelf);


  CosNaming_NamingContext      *rootContext;
  LName                        *eventContextName;
  LNameComponent               *lnc;                     // Library Name Component
  CosNaming_Name               Name;
  CosNaming_NamingContext      *nameContext=NULL;
  SomEventService_EventChannel *eventChannel = NULL;
  char                         *exId;
  AppointmentEventHandler *myAppointmentEventHandler;


  // Check to see if the event channel exists. If not, create it and
  //Register it in the name service
  eventChannel = (SomEventService_EventChannel *) somSelf->getEventChannelRef(ev);
  if(ev->_major != NO_EXCEPTION)
  {
   somExceptionFree(ev);
   rootContext = (CosNaming_NamingContext *)SOMD_ORBObject->
                   resolve_initial_references(ev, "NameService");

   if (ev->_major != NO_EXCEPTION) {
      somPrintf("Failed to get the root Naming Context");
   } else { // Root Context OK

     // Set up the context name for the Event Service
     lnc = create_lname_component();
     lnc->set_id(ev, "EventService");
     lnc->set_kind(ev, "");
     eventContextName = create_lname();
     eventContextName->insert_component(ev, 0, lnc);
     Name = eventContextName->to_idl_form(ev);
     nameContext = rootContext->bind_new_context(ev, &Name);
     exId = somExceptionId(ev);
     if (exId != NULL &&
         strcmp(exId,ex_CosNaming_NamingContext_AlreadyBound) == 0) {
       somExceptionFree(ev);
       nameContext = (CosNaming_NamingContext *) rootContext->resolve(ev, &Name);
    }
     if (ev->_major != NO_EXCEPTION) {
        somPrintf("Failed to get the Event Service Naming Context");
     } else {  // Event Service Name Context OK

       // Set up the context name for the Event Channel
       lnc = create_lname_component();
       lnc->set_id(ev, "EventChannel");
       lnc->set_kind(ev, "");
       eventContextName = create_lname();
       eventContextName->insert_component(ev, 0, lnc);
       Name = eventContextName->to_idl_form(ev);
       if (ev->_major != NO_EXCEPTION)
       { // Error resolving Event Channel

         somPrintf("Failed to get the existing Event Channel.\n");
       }
       else
       { // Event channel does not exist - Create it

         // Create an Event Channel and bind a name to it
         somPrintf("Creating Event channel\n");
         eventChannel =
           (SomEventService_EventChannel *) (void *)
              somdCreate(ev, "SomEventService::EventChannel", TRUE);
         checkEnv(ev);

         //register the event channel with the name service
         nameContext->unbind(ev, &Name);
         somExceptionFree(ev);

         nameContext->bind(ev, &Name, (SOMObject *)(void *) eventChannel);

         if (ev->_major != NO_EXCEPTION)
         { // Unable to bind the name to an Event Channel
           somPrintf("Unable to bind Event Channel to name.\n");
         }
       } // End - Event channel Name does not exist - Create it
     } // End - Event Service Name Context OK
   } // End - Root context OK

 }
  // Create the event handler object and connect to event channel
  myAppointmentEventHandler  = new AppointmentEventHandler;
  myAppointmentEventHandler->eventChannelConnect(ev);

  //Save the name of the event channel
  somThis->ECNameContext = nameContext;
  somThis->ECName = Name;

  return;

}
SOM_Scope unsigned long  SOMLINK getEventChannelRef(ApptBookEventService *somSelf,
                                                     Environment *ev)
{

    /* ApptBookEventServiceData *somThis = ApptBookEventServiceGetData(somSelf); */
    ApptBookEventServiceMethodDebug("ApptBookEventService","getEventChannelRef");

    SomEventService_EventChannel *eventChannel = NULL;
    char                         *ECStringRef;   //Stringified name of event channel

    CosNaming_NamingContext      *rootContext;
    LName                        *eventContextName;
    LNameComponent               *lnc;                     // Library Name Component
    CosNaming_Name               Name;
    CosNaming_NamingContext      *nameContext = NULL;
    long                         error = 0;
    EventError                   *eventError;


    rootContext = (CosNaming_NamingContext *)SOMD_ORBObject->
                   resolve_initial_references(ev, "NameService");

    if (!(checkEnv(ev) || !rootContext))
    {
      // Set up the context name for the Event Service
      lnc = create_lname_component();
      lnc->set_id(ev, "EventService");
      lnc->set_kind(ev, "");
      eventContextName = create_lname();
      eventContextName->insert_component(ev, 0, lnc);
      Name = eventContextName->to_idl_form(ev);
      nameContext = (CosNaming_NamingContext *) rootContext->resolve(ev, &Name);
      if (ev->_major == NO_EXCEPTION)
      {


        // Set up the context name for the Event Channel
        lnc = create_lname_component();
        lnc->set_id(ev, "EventChannel");
        lnc->set_kind(ev, "");
        eventContextName = create_lname();
        eventContextName->insert_component(ev, 0, lnc);
        Name = eventContextName->to_idl_form(ev);

        // check to see if the event channel already registered in name server
        eventChannel =
            (SomEventService_EventChannel*)(void *) nameContext->resolve(ev, &Name);
        if(ev->_major == NO_EXCEPTION)
        {
           //Test for a valid reference
           CosEventChannelAdmin_ConsumerAdmin *consumerAdmin =
             eventChannel->for_consumers(ev);

           if(ev->_major != NO_EXCEPTION)
           {
              // Failed to get Event channel reference
              somExceptionFree(ev);
              error = ApptBookEventService_EventChannelReferenceFailure;
           }

        }
        else
        {
            // Failed to get Event channel reference
            somExceptionFree(ev);
            error = ApptBookEventService_EventChannelReferenceFailure;
        }

     }
     else
     {
       //Failed to get the Event Service Naming Context
       somExceptionFree(ev);
       error = ApptBookEventService_EventContextFailure;
     }
    }
    else
    {
      //Failed to get the root Naming Context
      error = ApptBookEventService_RootContextFailure;
    }

    // Build an exception if needed
    if (error != 0)
    {
     eventError = (EventError *)SOMMalloc(sizeof(EventError));
     eventError->errorCode = error;
     strcpy(eventError->reason, "Event Channel Reference Error");
     somSetException(ev,
                     USER_EXCEPTION,
                     ex_ApptBookEventService_EventError,
                     (void *) eventError);
                     eventChannel = NULL;

    }


    return (long) eventChannel;

}
Example #6
0
void NameMgr::DumpContext
    (Environment* ev, ExtendedNaming_ExtendedNamingContext* nc, int indent)
  {
        BindingList bl;
        Binding bind;
        CosNaming_BindingIterator *biter;
        int i,k,l;
        LName* anLName;
        LNameComponent* lnc;
        unsigned long numComps;
        char buf500[500];
        PropertyBindingList pbl;
        PropertyBinding propBind;
        ExtendedNaming_PropertyBindingIterator *pbIterator;
        ExtendedNaming_ExtendedNamingContext* passNC;
        CosNaming_Name anyName;
        ExtendedNaming_Property prop;

        // get a binding list of the current (passed) naming context
        nc->list(ev, 100000, &bl, &biter);

        if (this->checkEnv(ev)) return ;

        // create an Lname
        anLName = create_lname();

        // for the number of objects/contexts in our context...
        for (i = 0; i < bl._length; ++i)
            {
            // for however many level we are down in the naming tree
            for (l=0;l<=indent;++l)
                // print a space so the indetation is correct
                {cout<<" ";}
            // fill in the LName from the binding list buffer
            anLName->from_idl_form (ev, &(bl._buffer[i].binding_name));
            // print the first text for the object
            cout<<"Name<";
            // for as many components as ther are in the object
            for (k=1,numComps=anLName->num_components(ev);k<=numComps;k++)
                {
                // get the component
                lnc=anLName->get_component(ev,k);
                // print the id and kind of the objects
                cout<<"["<<lnc->get_id(ev)<<"/"<<lnc->get_kind(ev)<<"]";
                // if there are more components, separate with a blank
                if(k<numComps) cout<<" ";
                }
             // print the end of name symbol
            cout<<">";

            // print the type of the object
            if (bl._buffer[i].binding_type==CosNaming_nobject)
                cout<<"type<object>";
            else
                cout<<"type<context>";

            // Set the property binding list length, maximun, and buffer
            pbl._maximum = pbl._length = 0;
            pbl._buffer = NULL;
            // convert the LName to idl form
            anyName = anLName->to_idl_form(ev);
            checkEnv(ev);
            // get a list of the properties associated with the object/context
            nc->list_properties (ev,&anyName,100000,&pbl,&pbIterator);
            // if there are no properties, do nothing else, print 'em
            if (this->checkEnv(ev))
               {}
            else
                {
                // property names leading string
                cout<<"PropertyNames<";
                // for as many properties as there are
                for (k=0;k<pbl._length;k++)
                    {
                    // print the name of the property
                    cout<<"["<<pbl._buffer[k].property_name<<"]";
                    // from the name, get the property itself
                    nc->get_property(ev, &anyName, pbl._buffer[k].property_name, &prop);
                    // print the value of the property. in this sample I know
                    // that the _value pointer points to a long, so I can readily cast and
                    // stream out the result.  If I did not know what type the value was I
                    // would have to use a large case structure on prop.value._type.
                    cout<<"/";
                    cout<<*(long*)prop.value._value<<" ";
                    // cout<<"/"anyPrint(prop.value, ev)<<" "<<endl;
                    }
                }
            // end of properties character
            cout<<">"<<endl;

            // if the object we are looking at is a context,
            // we need to see if there are other objects bound in
            if (bl._buffer[i].binding_type==CosNaming_ncontext)
               {
               // resolve the context into our temp variable
               passNC = (ExtendedNaming_ExtendedNamingContext*)nc->resolve(ev, &anyName);
               // recursively call dumpacontext on the child context
               this->DumpContext(ev, passNC, ++indent);
               --indent;
               }
            else
               {}
            }
  }