Coder Social home page Coder Social logo

Comments (4)

maximkulkin avatar maximkulkin commented on June 29, 2024 1

Oh, here is an idea: for characteristic you can create your mega wrapper structure like so:

typedef struct {
  union {
    HAPDataCharacteristic data_base;
    HAPBoolCharacteristic bool_base;
    HAPUInt8Characteristic uint8_base;
    // ...
  };

  void *context;
} MyHAPCharacteristic;

So, in your own code you can work with all characteristic types the same way. Assuming you're doing C++ wrappers anyways.

from homekitadk.

maximkulkin avatar maximkulkin commented on June 29, 2024

👍

I'm all supportive for having a contexts on a fine grained level, e.g. characteristic. Not sure why you need a server-wide context that is explicitly passed to every characteristic callback. It's not like you gonna have multiple instances of HAPAccessoryServer anyways, if I wanted to have a global context, I would just create a global variable and reference it directly.

Now, I think you can do it yourself: just create your own structures for HAPAccessory, HAPService and HAP*Characteristic and extend them with additional fields:

typedef struct {
  HAPAccessory base;
  // here go extra fields
  void *context;
} MyHAPAccessory;

Then in your callbacks you can cast structures passed to you in request to your structures and pull whatever extra information you planted there.

from homekitadk.

rojer avatar rojer commented on June 29, 2024

good idea! this will work for accessory and service but will be extremely ugly for characteristics because HAPCharacteristic is cast to a specific characteristic types (poor-man's OOP in C). we'll need to wrap all of those.

from homekitadk.

maximkulkin avatar maximkulkin commented on June 29, 2024

It's not that bad, there's just 10 of them.

from homekitadk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.