On Jun 5, 2007, at 4:28 PM, J. Ryan Stinnett wrote:

I'm still pretty new to the concept of generics in T2, and I'm unsure of the best way to design the following set of components. I was trying to use something similar to the pattern in AMSenderC, where a configuration hides the creation of a unique instance of the Send interface from the application. However, in my case, not only can there be an arbitrary number of clients (the role of AMSenderC), but the service is also generic and there could be an arbitrary number of those as well.

As an example, let's say there are two service instances, A and B, and 5 client instances, 1 through 5. 1 and 2 are connected to A and 3 through 5 are connected to B. What would be a clean way to do this? My goal would be to do it all through wiring so there's no need for a table mapping clients to services.

I looked over the design pattens in the TinyOS Programming Manual, and the Keymap seems close, but it doesn't add generics into the picture which seems to complicate things.

Take a look at the flash driver example in the document text. Here's an example. The bottom level thing that has 5 clients is called UnderlyingService. On top of it you have two services ServiceA and ServiceB. The coding trick is in the ClientA and ClientB configurations, where you allocate a key for the UnderlyingService keyspace (5 entries) as well as one for the ServiceA or ServiceB keyspace (2 or 3 entries), and map them by doing a parameterized-to- parameterized wiring.


module UnderlyingService {
  provides interface X[uint8_t key];
}

generic module Service {
  provides interface X as TopX[uint8_t key];
  uses interface X as BottomX[uint8_t key];
}

configuration ServiceA {
  provides interface X as TopX[uint8_t key];
  uses interface X as BottomX[uint8_t key];
}
implementation {
  components new Service();
  TopX = Service.TopX;
  BottomX = Service.BottomX;
}

configuration ServiceB {
  provides interface X as TopX[uint8_t key];
  uses interface X as BottomX[uint8_t key];
}
implementation {
  components new Service();
  TopX = Service.TopX;
  BottomX = Service.BottomX;
}

configuration ClientA {
  provides interface X;
}
implementation {
  enum {
SERVICE_KEY = unique("ServiceA.TopX"), // Should be a #define string, but I omitted for clarity
    IMPL_KEY = unique("UnderlyingService.X"),
  };
  components ServiceA, UnderlyingService;
  X = ServiceA.TopX[SERVICE_KEY];
  ServiceA.BottomX[SERVICE_KEY] -> UnderlyingService.X[IMPL_KEY];
}

configuration ClientB {
  provides interface X;
}
implementation {
  enum {
SERVICE_KEY = unique("ServiceB.TopX"), // Should be a #define string, but I omitted for clarity
    IMPL_KEY = unique("UnderlyingService.X"),
  };
  components ServiceB, UnderlyingService;
  X = ServiceB.TopX[SERVICE_KEY];
  ServiceB.BottomX[SERVICE_KEY] -> UnderlyingService.X[IMPL_KEY];
}

Hope this helps,

Phil

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to