Logo Search packages:      
Sourcecode: gaia version File versions  Download package

void GPSLayer::AddEntity ( char *  name,
char *  source 
)

Adds one GPS entity

Parameters:
name arbitary name for an entity
source URL-like source description (like gpsd://host:port or nmea://path)

Definition at line 69 of file GPSLayer.cc.

References GPSEntity::color, GPSEntity::datamutex, GPSEntity::lastupdate, m_Entities, GPSEntity::name, GPSEntity::source, StartEntityThread(), and GPSEntity::thread.

                                                 {
      /* First, create corresponding source */
      GPSSource *s;
      if (strlen(source) >= 7 && memcmp(source, "gpsd://", 7) == 0) {
#ifdef WITH_GPSD
            source = source+7;
            if (strlen(source) > 1023)
                  throw Exception("GPS source description too long");

            char buf[1024];
            strcpy(buf, source);

            char *delim = strchr(buf, ':');
            if (delim) {
                  /* source is in gpsd://host:port form */
                  *(delim++) = '\0';
                  s = new GPSSourceGPSD(buf, delim);
            } else {
                  s = new GPSSourceGPSD(buf, "2947");
            }
#else
            throw Exception("Compiled without GPSD support");
#endif
      } else if (strlen(source) >= 7 && memcmp(source, "nmea://", 7) == 0) {
            source = source+7;
            s = new GPSSourceNMEA(source);
      } else if (strlen(source) >= 7 && memcmp(source, "test://", 7) == 0) {
            s = new GPSSourceTest();
      } else {
            throw Exception("Unknown GPS source");
      }

      GPSEntity *e = new GPSEntity();
      strncpy(e->name, name, MAX_ENTITY_NAME);
      e->name[MAX_ENTITY_NAME-1] = '\0';
      e->lastupdate = 0;
      e->color[0] = 0;  /* TODO: take color from somewhere */
      e->color[1] = 128;
      e->color[2] = 255;
      e->source = s;

      if (pthread_mutex_init(&e->datamutex, 0) != 0) {
            delete s;
            delete e;
            throw ErrnoException("pthread_mutex_init() failed", errno);
      }

      if (pthread_create(&e->thread, 0, StartEntityThread, (void*)e) != 0) {
            pthread_mutex_destroy(&e->datamutex);
            delete s;
            delete e;
            throw ErrnoException("pthread_create() failed", errno);
      }

      m_Entities.push_back(e);
}


Generated by  Doxygen 1.6.0   Back to index