Thermodynamical theory of boundary conditions for polyatomic gases